]> code.delx.au - gnu-emacs/blobdiff - lisp/mail/mh-pick.el
(comint-postoutput-scroll-to-bottom): Cope with unset
[gnu-emacs] / lisp / mail / mh-pick.el
index b74379c2baa53010681053fbd518cf4dce13b9c6..a297d5e6f5c92704f5a39da1b54e7e167f66fd9d 100644 (file)
@@ -1,44 +1,51 @@
 ;;; mh-pick --- make a search pattern and search for a message in mh-e
-;; Time-stamp: <93/08/22 22:56:53 gildea>
+;; Time-stamp: <95/08/19 16:45:16 gildea>
 
-;; Copyright 1993 Free Software Foundation, Inc.
+;; Copyright (C) 1993, 1995 Free Software Foundation, Inc.
 
-;; This file is part of mh-e.
+;; This file is part of mh-e, part of GNU Emacs.
 
-;; mh-e is free software; you can redistribute it and/or modify
+;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
 ;; the Free Software Foundation; either version 2, or (at your option)
 ;; any later version.
 
-;; mh-e is distributed in the hope that it will be useful,
+;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with mh-e; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; 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.
 
 ;;; Commentary:
 
 ;; Internal support for mh-e package.
 
+;;; Change Log:
+
+;; $Id: mh-pick.el,v 1.4 1995/11/03 02:30:09 kwzh Exp erik $
+
 ;;; Code:
 
 (provide 'mh-pick)
 (require 'mh-e)
 
-(defvar mh-pick-mode-map (make-sparse-keymap)
-  "Keymap for searching folder.")
-
 (defvar mh-pick-mode-hook nil
   "Invoked in `mh-pick-mode' on a new pattern.")
 
-(defvar mh-searching-folder nil
-  "Folder this pick is searching.")
+;;; Internal variables:
+
+(defvar mh-pick-mode-map (make-sparse-keymap)
+  "Keymap for searching folder.")
+
+(defvar mh-searching-folder nil)       ;Folder this pick is searching.
 
 (defun mh-search-folder (folder)
-  "Search FOLDER for messages matching a pattern."
+  "Search FOLDER for messages matching a pattern.
+Add the messages found to the sequence named `search'."
   (interactive (list (mh-prompt-for-folder "Search"
                                           mh-current-folder
                                           t)))
 
 (defun mh-pick-mode ()
   "Mode for creating search templates in mh-e.\\<mh-pick-mode-map>
-After each field name, enter the pattern to search for.  To search
-the entire message, supply the pattern in the \"body\" of the template.
+After each field name, enter the pattern to search for.  If a field's
+value does not matter for the search, leave it empty.  To search the
+entire message, supply the pattern in the \"body\" of the template.
+Each non-empty field must be matched for a message to be selected.
+To effect a logical \"or\", use \\[mh-search-folder] multiple times.
 When you have finished, type  \\[mh-do-pick-search]  to do the search.
 \\{mh-pick-mode-map}
 Turning on mh-pick-mode calls the value of the variable mh-pick-mode-hook
@@ -84,38 +94,41 @@ if that value is non-nil."
 (defun mh-do-pick-search ()
   "Find messages that match the qualifications in the current pattern buffer.
 Messages are searched for in the folder named in mh-searching-folder.
-Add messages found to the sequence named `search'."
+Add the messages found to the sequence named `search'."
   (interactive)
   (let ((pattern-buffer (buffer-name))
        (searching-buffer mh-searching-folder)
-       range msgs
+       range
+       msgs
+       (finding-messages t)
        (pattern nil)
        (new-buffer nil))
     (save-excursion
       (cond ((get-buffer searching-buffer)
             (set-buffer searching-buffer)
-            (setq range (format "%d-%d" mh-first-msg-num mh-last-msg-num)))
+            (setq range (list (format "%d-%d"
+                                      mh-first-msg-num mh-last-msg-num))))
            (t
             (mh-make-folder searching-buffer)
-            (setq range "all")
+            (setq range '("all"))
             (setq new-buffer t))))
     (message "Searching...")
     (goto-char (point-min))
-    (while (setq pattern (mh-next-pick-field pattern-buffer))
+    (while (and range
+               (setq pattern (mh-next-pick-field pattern-buffer)))
       (setq msgs (mh-seq-from-command searching-buffer
                                      'search
-                                     (nconc (cons "pick" pattern)
-                                            (list searching-buffer
-                                                  range
-                                                  "-sequence" "search"
-                                                  "-list"))))
-      (setq range "search"))
+                                     (mh-list-to-string
+                                      (list "pick" pattern searching-buffer
+                                            "-list"
+                                            (mh-coalesce-msg-list range)))))
+      (setq range msgs))               ;restrict the pick range for next pass
     (message "Searching...done")
     (if new-buffer
        (mh-scan-folder searching-buffer msgs)
        (switch-to-buffer searching-buffer))
-    (delete-other-windows)
-    (mh-notate-seq 'search ?% (1+ mh-cmd-note))))
+    (mh-add-msgs-to-seq msgs 'search)
+    (delete-other-windows)))
 
 
 (defun mh-seq-from-command (folder seq seq-command)
@@ -128,18 +141,20 @@ Add messages found to the sequence named `search'."
     (save-excursion
       (save-window-excursion
        (if (eq 0 (apply 'mh-exec-cmd-quiet nil seq-command))
+           ;; "pick" outputs one number per line
            (while (setq msg (car (mh-read-msg-list)))
              (setq msgs (cons msg msgs))
              (forward-line 1))))
       (set-buffer folder)
-      (setq msgs (nreverse msgs))      ; Put in ascending order
-      (setq mh-seq-list (cons (mh-make-seq seq msgs) mh-seq-list))
+      (setq msgs (nreverse msgs))      ;put in ascending order
       msgs)))
 
 
 (defun mh-next-pick-field (buffer)
   ;; Return the next piece of a pick argument that can be extracted from the
-  ;; BUFFER.  Returns nil if no pieces remain.
+  ;; BUFFER.
+  ;; Return a list like ("--fieldname" "pattern") or ("-search" "bodypat")
+  ;; or NIL if no pieces remain.
   (set-buffer buffer)
   (let ((case-fold-search t))
     (cond ((eobp)
@@ -166,12 +181,15 @@ Add messages found to the sequence named `search'."
 (define-key mh-pick-mode-map "\C-c\C-c" 'mh-do-pick-search)
 (define-key mh-pick-mode-map "\C-c\C-f\C-b" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-f\C-c" 'mh-to-field)
+(define-key mh-pick-mode-map "\C-c\C-f\C-d" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-f\C-f" 'mh-to-field)
+(define-key mh-pick-mode-map "\C-c\C-f\C-r" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-f\C-s" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-f\C-t" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-fb" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-fc" 'mh-to-field)
+(define-key mh-pick-mode-map "\C-c\C-fd" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-ff" 'mh-to-field)
+(define-key mh-pick-mode-map "\C-c\C-fr" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-fs" 'mh-to-field)
 (define-key mh-pick-mode-map "\C-c\C-ft" 'mh-to-field)
-(define-key mh-pick-mode-map "\C-c\C-w" 'mh-check-whom)