2006-04-11 Sascha Wilde <wilde@sha-bang.de> (tiny patch)
[gnus] / contrib / nnir.el
index 9f6d294..0c0f2b4 100644 (file)
@@ -18,8 +18,8 @@
 
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
 
 ;;; Commentary:
 
 
 ;;; Setup Code:
 
-(defconst nnir-version "$Id: nnir.el,v 1.80 2002/12/22 17:38:15 grossjoh Exp $"
-  "Version of NNIR.")
-
 (require 'cl)
 (require 'nnoo)
 (require 'gnus-group)
 (eval-and-compile
   (require 'gnus-util))
 (eval-when-compile
-  (require 'nnimap))
+  (require 'nnimap)
+  (autoload 'read-kbd-macro "edmacro" nil t))
 
 (nnoo-declare nnir)
 (nnoo-define-basics nnir)
 
 (gnus-declare-backend "nnir" 'mail)
 
+(defvar nnir-imap-search-field "TEXT"
+  "The IMAP search item when doing an nnir search")
+
+(defvar nnir-imap-search-arguments
+  '(("Whole message" . "TEXT")
+    ("Subject" . "SUBJECT")
+    ("To" . "TO")
+    ("From" . "FROM")
+    (nil . "HEADER \"%s\""))
+  "Mapping from user readable strings to IMAP search items for use in nnir")
+
+(defvar nnir-imap-search-argument-history ()
+  "The history for querying search options in nnir")
+
 ;;; Developer Extension Variable:
 
 (defvar nnir-engines
-  '((glimpse nnir-run-glimpse
+  `((glimpse nnir-run-glimpse
              ((group . "Group spec: ")))
     (wais    nnir-run-waissearch
              ())
     (excite  nnir-run-excite-search
             ())
     (imap    nnir-run-imap
-             ())
+             ((criteria 
+              "Search in: "                      ; Prompt
+              ,nnir-imap-search-arguments        ; alist for completing
+              nil                                ; no filtering
+              nil                                ; allow any user input
+              nil                                ; initial value
+              nnir-imap-search-argument-history  ; the history to use
+              ,nnir-imap-search-field            ; default
+              )))
     (swish++ nnir-run-swish++
              ((group . "Group spec: ")))
     (swish-e nnir-run-swish-e
@@ -356,7 +376,8 @@ Add an entry here when adding a new search engine.")
 ;;; User Customizable Variables:
 
 (defgroup nnir nil
-  "Search nnmh and nnml groups in Gnus with Glimpse, freeWAIS-sf, or EWS.")
+  "Search nnmh and nnml groups in Gnus with Glimpse, freeWAIS-sf, or EWS."
+  :group 'gnus)
 
 ;; Mail backend.
 
@@ -511,18 +532,31 @@ that it is for swish++, not Glimpse."
   :type '(regexp)
   :group 'nnir)
 
-;; Swish-E.  Next three variables Copyright (C) 2000 Christoph Conrad
-;; <christoph.conrad@gmx.de>.
+;; Swish-E.
 ;; URL: http://sunsite.berkeley.edu/SWISH-E/
 ;; New version: http://www.boe.es/swish-e
+;; Variables `nnir-swish-e-index-file', `nnir-swish-e-program' and
+;; `nnir-swish-e-additional-switches'
+;; Copyright (C) 2000 Christoph Conrad <christoph.conrad@gmx.de>.
 
+(make-obsolete-variable 'nnir-swish-e-index-file
+                       'nnir-swish-e-index-files)
 (defcustom nnir-swish-e-index-file
   (expand-file-name "~/Mail/index.swish-e")
   "*Index file for swish-e.
-This could be a server parameter."
+This could be a server parameter.
+It is never consulted once `nnir-swish-e-index-files', which should be
+used instead, has been customized."
   :type '(file)
   :group 'nnir)
 
+(defcustom nnir-swish-e-index-files
+  (list nnir-swish-e-index-file)
+  "*List of index files for swish-e.
+This could be a server parameter."
+  :type '(repeat (file))
+  :group 'nnir)
+
 (defcustom nnir-swish-e-program "swish-e"
   "*Name of swish-e search executable.
 This cannot be a server parameter."
@@ -669,7 +703,17 @@ that it is for Namazu, not Glimpse."
     'gnus-group-make-nnir-group))
 (add-hook 'gnus-group-mode-hook 'nnir-group-mode-hook)
 
-
+(defmacro nnir-group-server (group)
+  "Return the server for a foreign newsgroup GROUP.
+The returned format is as `gnus-server-to-method' needs it.  See
+`gnus-group-real-prefix' and `gnus-group-real-name'."
+  `(let ((gname ,group))
+     (if (string-match "^\\([^:]+\\):" gname)
+        (setq gname (match-string 1 gname))
+       nil)
+     (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname)
+        (format "%s:%s" (match-string 1 gname) (match-string 2 gname))
+       (concat gname ":"))))
 
 ;; Summary mode commands.
 
@@ -842,7 +886,7 @@ pairs (also vectors, actually)."
     (let ((artlist nil)
           (groupspec (cdr (assq 'group query)))
           (qstring (cdr (assq 'query query)))
-         (prefix (nnir-read-server-parm 'nnir-glimps-remove-prefix server))
+         (prefix (nnir-read-server-parm 'nnir-glimpse-remove-prefix server))
          artno dirnam)
       (when (and group groupspec)
         (error (concat "It does not make sense to use a group spec"
@@ -1001,15 +1045,16 @@ pairs (also vectors, actually)."
 ;; send queries as literals
 ;; handle errors
 
-(defun nnir-run-imap (query srv &optional group)
+(defun nnir-run-imap (query srv &optional group-option)
   (require 'imap)
   (require 'nnimap)
-  (unless group
-    (error "Must process-mark groups for IMAP searching."))
   (save-excursion
     (let ((qstring (cdr (assq 'query query)))
          (server (cadr (gnus-server-to-method srv)))
+         (group (or group-option (gnus-group-group-name)))
          (defs (caddr (gnus-server-to-method srv)))
+         (criteria (or (cdr (assq 'criteria query))
+                       nnir-imap-search-field))
          artlist buf)
       (message "Opening server %s" server)
       (condition-case ()
@@ -1023,7 +1068,7 @@ pairs (also vectors, actually)."
                  (lambda (artnum)
                    (push (vector group artnum 1) artlist)
                    (setq arts (1+ arts)))
-                 (imap-search (concat "TEXT \"" qstring "\"") buf))
+                 (imap-search (concat criteria " \"" qstring "\"") buf))
                 (message "Searching %s... %d matches" mbx arts)))
             (message "Searching %s...done" group))
         (quit nil))
@@ -1102,7 +1147,7 @@ Windows NT 4.0."
               dirnam (file-name-directory (match-string 2)))
 
         ;; don't match directories
-        (when (string-match "^[0-9]+$" artno)
+        (when (string-match "^[0-9]+\\(\\.gz\\)?$" artno)
           (when (not (null dirnam))
 
            ;; maybe limit results to matching groups.
@@ -1164,18 +1209,18 @@ Tested with swish-e-2.0.1 on Windows NT 4.0."
       (erase-buffer)
 
       (message "Doing swish-e query %s..." query)
-      (let* ((index-file
+      (let* ((index-files
              (or (nnir-read-server-parm
-                  'nnir-swish-e-index-file server)
-                 (error "Missing parameter `nnir-swish-e-index-file'")))
+                  'nnir-swish-e-index-files server)
+                 (error "Missing parameter `nnir-swish-e-index-files'")))
             (additional-switches
              (nnir-read-server-parm
-              'nnir-swish++-additional-switches server))
+              'nnir-swish-e-additional-switches server))
             (cp-list `(,nnir-swish-e-program
                        nil             ; input from /dev/null
                        t               ; output
                        nil             ; don't redisplay
-                       "-f" ,index-file
+                       "-f" ,@index-files
                        ,@additional-switches
                        "-w"
                        ,qstring        ; the query, in swish-e format
@@ -1402,7 +1447,12 @@ Tested with Namazu 2.0.6 on a GNU/Linux system."
 `parmspec' is a cons cell, the car is a symbol, the cdr is a prompt."
   (let ((sym (car parmspec))
         (prompt (cdr parmspec)))
-    (cons sym (read-string prompt))))
+    (if (listp prompt)
+       (let* ((result (apply 'completing-read prompt))
+              (mapping (or (assoc result nnir-imap-search-arguments)
+                           (assoc nil nnir-imap-search-arguments))))
+         (cons sym (format (cdr mapping) result)))
+      (cons sym (read-string prompt)))))
 
 (defun nnir-run-query (query)
   "Invoke appropriate search engine function (see `nnir-engines').
@@ -1457,17 +1507,6 @@ form 'backend:name'."
 ;;       (symbol-value key))
 ;;     ))
 
-(defmacro nnir-group-server (group)
-  "Returns the server for a foreign newsgroup in the format as gnus-server-to-method needs it. Compare to gnus-group-real-prefix and gnus-group-real-name."
-  `(let ((gname ,group))
-    (if (string-match "^\\([^:]+\\):" gname)
-       (setq gname (match-string 1 gname))
-      nil)
-    (if (string-match "^\\([^+]+\\)\\+\\(.+\\)$" gname)
-       (format "%s:%s" (match-string 1 gname) (match-string 2 gname))
-      (concat gname ":"))
-    ))
-
 (defun nnir-group-full-name (shortname server)
   "For the given group name, return a full Gnus group name.
 The Gnus backend/server information is added."
@@ -1528,3 +1567,5 @@ The Gnus backend/server information is added."
 
 ;; The end.
 (provide 'nnir)
+
+;;; arch-tag: 9b3fecf8-4397-4bbb-bf3c-6ac3cbbc6664