[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

Re: Quicksearch support in Emacs-w3m


This article contains a new patch which realizes the Quicksearch
feature only for the interactive calls and the bookmarks.  It
also supports a group url!

>>>>> In [emacs-w3m : No.04265]
>>>>>	Romain FRANCOISE <romain@orebokech.com> wrote:

> Hm.  I'm not sure what you mean by "backend function",

Maybe he said that the function is called from shimbun modules
or any other application programs outside of emacs-w3m.
TSUCHIYA-san, didn't you mean so?

> but I don't think
> it would be a good idea to restrict quicksearches to interactive calls.


It probably solved.  Now, how is it?

> When you're used to it, it's hard to live without. :)

Yes, indeed. :)

The following patch should be applied to the CVS HEAD:
--- emacs-w3m/w3m-search.el~	2002-06-18 07:30:18 +0000
+++ emacs-w3m/w3m-search.el	2002-11-12 07:07:20 +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
 ;; ~/.emacs.
 ;;     (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)
       ("iij-archie" "http://www.iij.ad.jp/cgi-bin/archieplexform?query=%s&type=Case+Insensitive+Substring+Match&order=host&server=archie1.iij.ad.jp&hits=95&nice=Nice";)))
   "*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 @@
   :group 'w3m
   :type 'string)
+(defcustom w3m-search-quick-search-engine-alist
+  '(("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."
   :group 'w3m
@@ -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
    (let ((engine
@@ -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) 
+				 w3m-search-engine-alist)))
+		(if info
+		    (setq ret (format (cadr info)
+				      (w3m-search-escape-query-string 
+				       query (caddr info))))))))))))
 (provide 'w3m-search)
--- emacs-w3m/w3m.el~	2002-11-06 23:04:45 +0000
+++ emacs-w3m/w3m.el	2002-11-12 07:07:20 +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")
@@ -4325,9 +4326,11 @@
   (lexical-let (pos)
     (when new-session
       (setq pos (point-marker))
-      (if w3m-view-this-url-new-session-in-background
-	  (set-buffer (w3m-copy-buffer nil nil nil 'empty))
-	(switch-to-buffer (w3m-copy-buffer nil nil t 'empty)))
+      (let ((referer w3m-current-url))
+	(if w3m-view-this-url-new-session-in-background
+	    (set-buffer (w3m-copy-buffer nil nil nil 'empty))
+	  (switch-to-buffer (w3m-copy-buffer nil nil t 'empty)))
+	(setq w3m-current-url referer))
       ;; When new URL has `name' portion, we have to goto the base url
       ;; because generated buffer has no content at this moment.
       (when (and (string-match w3m-url-components-regexp url)
@@ -5799,7 +5802,8 @@
-(defun w3m-goto-url (url &optional reload charset post-data referer handler)
+(defun w3m-goto-url
+  (url &optional reload charset post-data referer handler qsearch)
   "Retrieve contents of URL.
 If the second argument RELOAD is non-nil, reload a content of URL.
 Except that if it is 'redisplay, re-display the page without reloading.
@@ -5811,7 +5815,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 
     (w3m-input-url nil
@@ -5824,8 +5832,15 @@
     (w3m-static-if (fboundp 'universal-coding-system-argument)
+ (setq x1 (nconc x1 (list last-command)))
   (set-text-properties 0 (length url) nil url)
   (setq url (w3m-uri-replace url))
+  (when (or qsearch
+	    (interactive-p)
+	    (equal referer "about://bookmark/"))
+    ;; quicksearch
+    (setq qsearch t
+	  url (w3m-search-quick-search-handler url)))
    ;; process mailto: protocol
    ((string-match "\\`mailto:\\(.*\\)" url)
@@ -5854,11 +5869,12 @@
 			    (split-string (substring url (match-end 0)) "&"))))
 	      (type (prog1
-			(w3m-goto-url (car urls))
+			(w3m-goto-url (car urls) nil nil nil nil nil qsearch)
 		      (dolist (url (cdr urls))
 			  (set-buffer (w3m-copy-buffer nil nil nil 'empty))
-			  (save-window-excursion (w3m-goto-url url))))))
+			  (save-window-excursion
+			    (w3m-goto-url url nil nil nil nil nil qsearch))))))
       ;; Retrieve the page.
       (lexical-let ((orig url)
@@ -6033,8 +6049,10 @@
 	(when (and (string-match w3m-url-components-regexp url)
 		   (match-beginning 8))
 	  (w3m-goto-url (substring url 0 (match-beginning 8))
-			reload charset post-data referer))
-	(w3m-goto-url url reload charset post-data referer))
+			reload charset post-data referer
+			nil (interactive-p)))
+	(w3m-goto-url url reload charset post-data referer
+		      nil (interactive-p)))
     (w3m url t)))
 (defun w3m-move-point-for-localcgi (url)