Source

net-utils / google-query.el

Diff from to

google-query.el

 
 ;; Copyright (C) 2003, 2004 Steve Youngs
 
-;; RCS: $Id$
 ;; Author:        Steve Youngs <sryoungs@bigpond.net.au>
 ;; Maintainer:    Steve Youngs <sryoungs@bigpond.net.au>
 ;; Created:       <2003-12-16>
-;; Last-Modified: <2005-05-01 10:49:42 (steve)>
 ;; Keywords:      web google search query
 
 ;; This file is part of google-query.
 ;;
 
 ;;; Code:
+(defconst google-query-version 1.8
+  "Version number of google-query.el.")
 
 (defun google-query-version (&optional arg)
   "Return the current version info for google-query.
 With optional argument ARG, insert version info at point in the current
 buffer."
   (interactive "P")
-  (let (ver)
-    (with-temp-buffer
-      (erase-buffer)
-      (insert-file (locate-library "google-query.el"))
-      (goto-char (point-min))
-      (re-search-forward 
-       "google-query\\.el,v\\s-\\([0-9]+[0-9\\.]*[0-9]+\\)" nil t)
-      (setq ver (match-string 1)))
+  (let ((ver google-query-version))
     (if (interactive-p)
 	(if arg
-	    (insert (format "Google Query v%s" ver))
-	  (message "Google Query v%s" ver))
+	    (insert (format "Google Query v%.1f" ver))
+	  (message "Google Query v%.1f" ver))
       ver)))
 
 (eval-and-compile
 (defun google-query-process-results (results)
   "Process the RESULTS of `google-query'."
   (let ((buf (get-buffer-create "*google-query-results*"))
-	matches)
+	matches
+	titles)
     (switch-to-buffer buf)
     (google-query-mode)
     (erase-buffer)
     (insert results)
-    (goto-char (point-min))
-    ;; Get rid of lots of useless raw HTML and advertising.
-    (re-search-forward "dict&q=" nil t)
-    (forward-line 1)
-    (kill-region (point-min) (point))
-    (goto-char (point-min))
-    (re-search-forward "<span class" nil t)
-    (forward-line -1)
-    (kill-region (point) (point-max))
     ;; Collect the stuff we want.
-    (goto-char (point-min))
-    (while (re-search-forward "<a href=\\(.*\\)<br>" nil t)
-      (setq matches (push (match-string 1) matches)))
-    (setq matches (nreverse matches))
+    (goto-char (point-max))
+    (while (re-search-backward "<a class=l href=\"\\(.*\\)\">\\(.*\\)</a>" nil t)
+      (setq matches (push (match-string 1) matches)
+	    titles (push (match-string 2) titles)))
     ;; Replace the contents of the buffer with our matches.
     (erase-buffer)
     (insert "Google Query Results\n====================\n\n")
     (while matches
-      (insert (car matches))
+      (insert (car titles) "\n" (car matches))
       (insert "\n\n")
-      (setq matches (cdr matches)))
+      (setq titles (cdr titles)
+	    matches (cdr matches)))
     (goto-char (point-min))
     (center-line 2)
     (mapcar
-     '(lambda (x) (save-excursion (eval x)))
+     #'(lambda (x) (save-excursion (eval x)))
      '((replace-string "<b>" " ")
        (replace-string "</b>" "")
        (replace-regexp "<.*>" " ")
   "Query google for STRING."
   (interactive "sQuery Google for: ")
   (let* ((host google-query-mirror)
-	 (user-agent (concat "XEmacs-" emacs-program-version))
+	 (user-agent (concat (if (featurep 'sxemacs)
+				 "SXEmacs-"
+			       "XEmacs-")
+			     emacs-program-version))
 	 (str (google-query-hexify-string 
 	       (truncate-string-to-width string google-query-maxlen)))
 	 (query (concat "search?&q=" str 
      (concat "GET /" query " HTTP/1.1\r\n"
 	     "MIME-Version: 1.0\r\n"
 	     "Connection: close\r\n"
-	     "Extension: Security/Digest Security/SSL\r\n"
 	     "Host: " host "\r\n"
 	     "Accept: */*\r\n"
 	     "User-Agent: " user-agent "\r\n\r\n"))
 
 (provide 'google-query)
 ;;; google-query.el ends here
-
-;Local Variables:
-;time-stamp-start: "Last-Modified:[ 	]+\\\\?[\"<]+"
-;time-stamp-end: "\\\\?[\">]"
-;time-stamp-line-limit: 10
-;time-stamp-format: "%4y-%02m-%02d %02H:%02M:%02S (%u)"
-;End: