[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: use google "I feel lucky" to handle url
From: Katsumi Yamaoka <yamaoka@xxxxxxx> said
Subject: [emacs-w3m:08625] Re: use google "I feel lucky" to handle url
Message-ID: <b4maca6y5ts.fsf@xxxxxxx>
Date: Fri, 28 Apr 2006 08:08:47 +0900
> > In firefox, when I type "emacs w3m" in the url location, it will use
> > google "I feel lucky" to direct me to the right page. This is a very
> > cool feature.
>
> Interesting! "No Gnus v0.4" brings me to the Gmane page, and
> your e-mail address brings me to the Gmail chat room. On the
> other hand, Netspace and IE bring me to the page showing the
> search result.
Me, too.
> > In w3m, however, it will report an url error. I think we can take use
> > of "I feel lucky" to make emacs-w3m more smart.
>
> > Any comments?
>
> I guess Firefox inquires of some search engine the given words
> and visits the url which appears in the beginning of the result.
> If they are all of what Firefox does, it doesn't seem to be very
> hard to make emacs-w3m do so. If we have time. ;-)
I hacked quickly, but this code has any problems, so do not
commit to CVS yet.
(defvar w3m-feeling-lucky-format
(concat "http://www.google.com/search?btnI=I%%27m+Feeling+Lucky"
"&ie=%s&oe=%s&q=%s"))
(defsubst w3m-canonicalize-url (url &optional feeling-lucky)
"Add a scheme part to an URL if it has no scheme part."
(w3m-string-match-url-components url)
(cond
((match-beginning 1)
url)
(feeling-lucky
(let* ((cs 'utf-8)
(charset "UTF-8")
(str (w3m-url-transfer-encode-string url cs)))
(setq url (format w3m-feeling-lucky-format
charset charset str))))
(t
(concat (if (and (file-name-absolute-p url)
(file-exists-p url))
"file://"
"http://")
url))))
(defun w3m-input-url (&optional prompt initial default quick-start)
"Read a url from the minibuffer, prompting with string PROMPT."
(let (url)
(w3m-arrived-setup)
(unless default
(setq default w3m-home-page))
(unless initial
(setq initial (w3m-active-region-or-url-at-point)))
(if (and quick-start
default
(not initial))
default
(setq url (let ((minibuffer-setup-hook
(append minibuffer-setup-hook '(beginning-of-line)))
(ofunc (lookup-key minibuffer-local-completion-map " ")))
(define-key minibuffer-local-completion-map " " 'self-insert-command)
(unwind-protect
(completing-read
(or prompt
(if default
(format "URL (default %s): "
(if (stringp default)
(if (eq default w3m-home-page)
"HOME" default)
(prin1-to-string default)))
"URL: "))
'w3m-url-completion nil nil initial
'w3m-input-url-history)
(define-key minibuffer-local-completion-map " " ofunc))))
(when (string= "" url)
(setq url default))
(if (stringp url)
(progn
;; remove duplication
(setq w3m-input-url-history
(cons url (delete url w3m-input-url-history)))
(w3m-canonicalize-url url 'feeling-lucky))
;; It may be `popup'.
url))))
Sorry Japanese only...
思ったより簡単に出来ちゃいました :-)
で、簡単に思い付く問題点
(1) utf-8 がない Emacs だと、なにを使うのが良いかな?
cs は w3m-default-coding-system で良いと思うのだけど、
w3m-default-coding-system を charset にする関数が無いので面
倒だなぁ。
(2) w3m-canonicalize-url() は w3m-browse-url() でも使われている
けど、こっちも feeling lucky に対応させちゃってよいかしら?
いじょー