[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: w3m-uri-replace-alist: necessity of using colons in keys
- From: Katsumi Yamaoka <yamaoka@xxxxxxx>
- Date: Mon, 02 Sep 2013 13:29:32 +0900
- X-ml-name: emacs-w3m
- X-mail-count: 12131
- References: <87hae5c27g.fsf@xxxxxx>
In [emacs-w3m : No.12130] Michael Heerdegen wrote:
> Currently, all keys in `w3m-uri-replace-alist' must include a colon. If
> you try something without colon like
> (put-alist 'w3m-uri-replace-alist "\\`ew"
> '(w3m-search-uri-replace "emacswiki"))
If you're talking about APEL's put-alist, I think this should be:
(setq w3m-uri-replace-alist
(put-alist "\\`ew" '(w3m-search-uri-replace "emacswiki")
w3m-uri-replace-alist))
> and then enter a uri like "ew w3m" this won't work (try it!)
Well, you don't want "http //www.gnu.org" to work as well as
"http://www.gnu.org", do you?
> because
> before `w3m-uri-replace' is called, `w3m-canonicalize-url' "fixes" the
> url to a Google feeling lucky thing. The colon is hardcoded in
> `w3m-url-components-regexp'.
Because "gg:" and the like is the scheme name + delimiter like
"http:". Of course it's a local rule, so those schemes are valid
only in emacs-w3m. But it might be better to let an "ew w3m" thing
work iff the key you registered is "\\`ew " (or "\\`ew[\t ]+").
Is it ok? If so, I'll install this patch:
--- w3m.el~ 2013-08-26 10:46:18.000000000 +0000
+++ w3m.el 2013-09-02 04:26:00.864628700 +0000
@@ -4584,17 +4584,21 @@
(if (string-match "\\`\\(https?://[-.0-9a-z]+\\)\\([#?].*\\)" url)
(concat (match-string 1 url) "/" (match-string 2 url))
(w3m-string-match-url-components url)
- (cond
- ((match-beginning 1)
- url)
- ((and (file-name-absolute-p url) (file-exists-p url))
- (concat "file://" url))
- (feeling-lucky
- (concat "\
+ (let (replaced)
+ (cond
+ ((match-beginning 1)
+ url)
+ ((and (file-name-absolute-p url) (file-exists-p url))
+ (concat "file://" url))
+ ((and (setq replaced (ignore-errors (w3m-uri-replace url)))
+ (not (string= url replaced)))
+ replaced)
+ (feeling-lucky
+ (concat "\
http://www.google.com/search?btnI=I%%27m+Feeling+Lucky&ie=UTF-8&oe=UTF-8&q="
- (w3m-url-encode-string url nil t)))
- (t
- (concat "http://" url)))))
+ (w3m-url-encode-string url nil t)))
+ (t
+ (concat "http://" url))))))
(defun w3m-input-url (&optional prompt initial default quick-start
feeling-lucky no-initial)
@@ -9033,18 +9037,16 @@
(catch 'found-replacement
(dolist (elem w3m-uri-replace-alist uri)
(when (string-match (car elem) uri)
- (if (setq uri
- (cond
- ((consp (cdr elem))
- (apply (cadr elem) uri (cddr elem)))
- ;; Rest conditions are inserted in order to keep
- ;; backward compatibility.
- ((functionp (cdr elem))
- (funcall (cdr elem) uri))
- ((stringp (cdr elem))
- (w3m-pattern-uri-replace uri (cdr elem)))))
- (throw 'found-replacement uri)
- (error "Invalid replacement: %s" elem))))))
+ (throw 'found-replacement
+ (cond
+ ((consp (cdr elem))
+ (apply (cadr elem) uri (cddr elem)))
+ ;; Rest conditions are inserted in order to keep
+ ;; backward compatibility.
+ ((functionp (cdr elem))
+ (funcall (cdr elem) uri))
+ ((stringp (cdr elem))
+ (w3m-pattern-uri-replace uri (cdr elem)))))))))
(defun w3m-goto-mailto-url (url &optional post-data)
(let ((before (nreverse (buffer-list)))
@@ -9388,7 +9390,6 @@
(not (w3m-interactive-p)))
(setq url (w3m-canonicalize-url url)))
(set-text-properties 0 (length url) nil url)
- (setq url (w3m-uri-replace url))
(unless (or (w3m-url-local-p url)
(string-match "\\`about:" url))
(w3m-string-match-url-components url)