[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Quicksearch support in Emacs-w3m
- From: Romain FRANCOISE <romain@xxxxxxxxxxxxx>
- Date: Fri, 08 Nov 2002 21:39:23 +0100
- X-ml-name: emacs-w3m
- X-mail-count: 04252
I need a way to perform searches in search engines in a fast way, and I
don't really like the C-u S way of doing it. I have therefore
implemented a similar system to Konqueror's "Enhanced Browsing", which
allows the user to use a regular url to launch searches. If you're not
familiar with this system, it's very simple: each search engine is
identified by a small prefix (e.g. "gg" for Google) and you begin a
search by going to a url like "gg:emacs-w3m". It takes you to the
result page of the search on Google. You don't need to use the normal
Launching a new search in a new session while reading another page is
easy with this system: use G, then type a quicksearch url. My patch also
works with Emacs-w3m's grouping features, you can use for example
"group:gg:emacs&ya:w3m" to launch two searches: one on Google for
"emacs" and the other on Yahoo! for "w3m". You can also bookmark a
search by using its short name, for example if you want to keep an eye
on what people say about you on Usenet, bookmark "ggg:John Doe" and
you'll be set.
It has a few drawbacks though:
- w3m-search needs to always be loaded in w3m.el since the quicksearch
function insinuates the main w3m function (w3m-goto-url). Maybe
making the quicksearch feature optional would be nice?
- you cannot use accentuated characters in quicksearch urls
- to use a space, you have to prefix it with C-q (since it completes
the url by default)
I believe my code to be quite reliable since I've been using it for
some days without problems. However, I'm not a very skilled Elisp
programmer, nor do I know Emacs-w3m in depth, so I'd be glad to hear
comments from the authors about it.
PS the patch also contains a few docfixes to w3m-search.el.
Romain FRANCOISE <email@example.com> | I've become someone else's
it's a miracle -- http://orebokech.com/ | nightmare...
RCS file: /storage/cvsroot/emacs-w3m/w3m-search.el,v
retrieving revision 1.18
diff -u -r1.18 w3m-search.el
--- w3m-search.el 18 Jun 2002 07:30:18 -0000 1.18
+++ w3m-search.el 8 Nov 2002 20:09:29 -0000
@@ -35,8 +35,8 @@
;;; How to install:
-;; Please put this file to appropriate directory, and if you want
-;; byte-compile it. And add following lisp expressions to your
+;; Put this file in the appropriate directory, and if you want,
+;; byte-compile it. Then add the following lisp expression to your
;; (autoload 'w3m-search "w3m-search" "Search QUERY using SEARCH-ENGINE." t)
@@ -55,6 +55,7 @@
(, (if (equal "Japanese" w3m-language)
'("google" "http://www.google.com/search?q=%s&hl=ja" shift_jis)
'("google" "http://www.google.com/search?q=%s" nil)))
+ ("google groups" "http://groups.google.com/groups?q=%s" nil)
("google-ja" "http://www.google.com/search?q=%s&hl=ja&lr=lang_ja" shift_jis)
("goo-ja" "http://www.goo.ne.jp/default.asp?MT=%s" euc-japan)
("excite-ja" "http://www.excite.co.jp/search.gw?target=combined&look=excite_jp&lang=jp&tsug=-1&csug=-1&search=%s" shift_jis)
@@ -66,7 +67,7 @@
("freebsd-users-jp" "http://home.jp.FreeBSD.org/cgi-bin/namazu.cgi?key=\"%s\"&whence=0&max=50&format=long&sort=score&dbname=FreeBSD-users-jp" euc-japan)
"*An alist of search engines.
-Each elemnt looks like (ENGINE ACTION CODING)
+Each element looks like (ENGINE ACTION CODING)
ENGINE is a string, the name of the search engine.
ACTION is a string, the URL that performs a search.
ACTION must contain a \"%s\", which is substituted by a query string.
@@ -86,6 +87,21 @@
+ '(("gg" . "google")
+ ("ggg" . "google groups")
+ ("ya" . "yahoo")
+ ("al" . "altavista")
+ ("bts" . "debian-bts")
+ ("dpkg" . "debian-pkg"))
+ "*An alist of short names for defined search engine names.
+Each element follows the scheme (NAME . ENGINE)
+NAME if the short name you want to use for this engine.
+ENGINE is the name of the engine as defined in `w3m-search-engine-alist'.
+Be careful: the names you use here must match exactly the names of the
+engines defined in `w3m-search-engine-alist'."
+ :group 'w3m)
(defcustom w3m-search-word-at-point t
"*Non-nil means that the word at point is used as initial string."
@@ -101,8 +117,8 @@
(defun w3m-search (search-engine query)
"Search QUERY using SEARCH-ENGINE.
-When called interactively with prefix argument, you can choose search
-engine deinfed in `w3m-search-engine-alist'. Otherwise use
+When called interactively with a prefix argument, you can choose one of
+the search engines defined in `w3m-search-engine-alist'. Otherwise use
@@ -135,6 +151,22 @@
(w3m-search-escape-query-string query (caddr info))))
(error "Unknown search engine: %s" search-engine)))))
+(defun w3m-search-quick-search-handler (url)
+ "Check if the url is a quicksearch url.
+If URL is a quicksearch url, replace it with the real url needed to access
+the search engine. If not, leave it alone."
+ (let ((ret url))
+ (dolist (quick-search-engine w3m-search-quick-search-engine-alist ret)
+ (if (string-match (concat "\\`" (car quick-search-engine) ":") url)
+ (let ((query (substring url (match-end 0))))
+ (unless (string= query "")
+ (let ((info (assoc (cdr quick-search-engine)
+ (if info
+ (setq ret (format (cadr info)
+ query (caddr info))))))))))))
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.762
diff -u -r1.762 w3m.el
--- w3m.el 6 Nov 2002 23:04:45 -0000 1.762
+++ w3m.el 8 Nov 2002 20:09:30 -0000
@@ -103,6 +103,7 @@
"Add link of current page to bookmark." t)
(autoload 'w3m-search "w3m-search"
"Search QUERY using SEARCH-ENGINE." t)
+ (autoload 'w3m-search-quick-search-handler "w3m-search")
(autoload 'w3m-weather "w3m-weather"
"Display weather report." t)
(autoload 'w3m-about-weather "w3m-weather")
@@ -5811,7 +5812,11 @@
car of a cell is used as the content-type and the cdr of a cell is
used as the body.
If the fifth argument REFERER is specified, it is used for a Referer:
-field for this request."
+field for this request.
+You can also use \"quicksearch\" url schemes such as \"gg:emacs\" which
+would search for the term \"emacs\" with the Google search engine. See
+the `w3m-search' function and the variable
@@ -5825,7 +5830,8 @@
(w3m-static-if (fboundp 'universal-coding-system-argument)
(set-text-properties 0 (length url) nil url)
- (setq url (w3m-uri-replace url))
+ ;; quicksearch
+ (setq url (w3m-search-quick-search-handler (w3m-uri-replace url)))
;; process mailto: protocol
((string-match "\\`mailto:\\(.*\\)" url)