Testing.
[gnus] / contrib / nnir.el
index 9f6d294..0e3a5a6 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.
 
@@ -669,7 +690,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 +873,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 +1032,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 +1055,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))
@@ -1170,7 +1202,7 @@ Tested with swish-e-2.0.1 on Windows NT 4.0."
                  (error "Missing parameter `nnir-swish-e-index-file'")))
             (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
@@ -1402,7 +1434,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 +1494,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 +1554,5 @@ The Gnus backend/server information is added."
 
 ;; The end.
 (provide 'nnir)
+
+;;; arch-tag: 9b3fecf8-4397-4bbb-bf3c-6ac3cbbc6664