changeset 68188:dcf226991252

* mh-search.el (mh-index-next-result-function): Add format to docstring. (mh-mairix-next-result): Use nil instead of () which doesn't stand out as well. (mh-pick-execute-search): Operate across all folders if no folder given and recurse folder(s). (mh-pick-next-result): Handle new output. * mh-utils.el: (mh-collect-folder-names): Fix docstring. (mh-children-p, mh-folder-list): New functions.
author Bill Wohler <wohler@newt.com>
date Sat, 14 Jan 2006 02:05:23 +0000
parents fc9311c473a3
children bb73cb6860d2
files lisp/mh-e/ChangeLog lisp/mh-e/mh-search.el lisp/mh-e/mh-utils.el
diffstat 3 files changed, 78 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/mh-e/ChangeLog	Fri Jan 13 23:25:48 2006 +0000
+++ b/lisp/mh-e/ChangeLog	Sat Jan 14 02:05:23 2006 +0000
@@ -1,3 +1,16 @@
+2006-01-13  Bill Wohler  <wohler@newt.com>
+
+	* mh-search.el (mh-index-next-result-function): Add format to
+	docstring.
+	(mh-mairix-next-result): Use nil instead of () which doesn't stand
+	out as well.
+	(mh-pick-execute-search): Operate across all folders if no folder
+	given and recurse folder(s).
+	(mh-pick-next-result): Handle new output.
+
+	* mh-utils.el: (mh-collect-folder-names): Fix docstring.
+	(mh-children-p, mh-folder-list): New functions.	
+
 2006-01-12  Bill Wohler  <wohler@newt.com>
 
 	* mh-search.el: New file containing contents of mh-index.el and
--- a/lisp/mh-e/mh-search.el	Fri Jan 13 23:25:48 2006 +0000
+++ b/lisp/mh-e/mh-search.el	Sat Jan 14 02:05:23 2006 +0000
@@ -58,7 +58,9 @@
   "Function which executes the search program.")
 
 (defvar mh-index-next-result-function nil
-  "Function to parse the next line of output.")
+  "Function to parse the next line of output.
+Expected to return a list of three strings: name of the folder,
+message number, and optionally the match.")
 
 (defvar mh-index-regexp-builder nil
   "Function used to construct search regexp.")
@@ -1180,7 +1182,7 @@
                                (point) (1- msg-start)))
                 (car (read-from-string
                       (buffer-substring-no-properties msg-start end)))
-                ())))
+                nil)))
     (forward-line)))
 
 (defun mh-mairix-regexp-builder (regexp-list)
@@ -1330,31 +1332,36 @@
 are simply treated as strings. Case is ignored when all lowercase
 is used, and regular expressions (a la \"ed\") are available.
 
-Unlike the other index search programs, you must specify a
-folder. In addition, this command does not descend into any
-sub-folders that may be present.
-
 In a program, FOLDER-PATH is the directory in which SEARCH-REGEXP
 is used to search."
   (set-buffer (get-buffer-create mh-temp-index-buffer))
   (erase-buffer)
-  (setq mh-index-pick-folder
-        (concat "+" (substring folder-path (length mh-user-path))))
-  (apply #'call-process (expand-file-name "pick" mh-progs) nil '(t nil) nil
-         mh-index-pick-folder "-list" search-regexp)
+  (let ((folders
+         (mh-folder-list (substring folder-path (length mh-user-path)))))
+    (loop for folder in folders do
+          (setq folder (concat "+" folder))
+          (insert folder "\n")
+          (apply #'call-process (expand-file-name "pick" mh-progs)
+                 nil '(t nil) nil folder "-list" search-regexp)))
   (goto-char (point-min)))
 
 (defun mh-pick-next-result ()
   "Return the next pick search result."
-  (prog1 (block nil
-           (when (eobp) (return nil))
-           (unless (re-search-forward "^[1-9][0-9]*$" (line-end-position) t)
-             (return 'error))
-           (list mh-index-pick-folder
-                 (car (read-from-string (buffer-substring-no-properties
-                                         (line-beginning-position)
-                                         (line-end-position))))
-                 nil))
+  (prog1
+      (block nil
+        (when (eobp) (return nil))
+        (when (search-forward-regexp "^\+" (line-end-position) t)
+          (setq mh-index-pick-folder
+                (buffer-substring-no-properties (line-beginning-position)
+                                                (line-end-position)))
+          (return 'error))
+        (unless (search-forward-regexp "^[1-9][0-9]*$" (line-end-position) t)
+          (return 'error))
+        (list mh-index-pick-folder
+              (string-to-number
+               (buffer-substring-no-properties (line-beginning-position)
+                                               (line-end-position)))
+              nil))
     (forward-line)))
 
 ;; All implementations of pick have special options -cc, -date, -from and
--- a/lisp/mh-e/mh-utils.el	Fri Jan 13 23:25:48 2006 +0000
+++ b/lisp/mh-e/mh-utils.el	Sat Jan 14 02:05:23 2006 +0000
@@ -2059,7 +2059,7 @@
 
 ;; Initialize mh-sub-folders-cache...
 (defun mh-collect-folder-names ()
-  "Collect folder names by running \"flists\"."
+  "Collect folder names by running \"folders\"."
   (unless mh-flists-process
     (setq mh-flists-process
           (mh-exec-cmd-daemon "folders" 'mh-collect-folder-names-filter
@@ -2158,6 +2158,44 @@
           ((not (equal (aref folder 0) ?+)) (setq folder (concat "+" folder)))))
   folder)
 
+(defmacro mh-children-p (folder)
+  "Return t if FOLDER from sub-folders cache has children.
+The car of folder is the name, and the cdr is either t or some
+sort of count that I do not understand. It's too small to be the
+number of messages in the sub-folders and too large to be the
+number of sub-folders. XXX"
+  `(if (cdr ,folder)
+       t
+     nil))
+
+(defun mh-folder-list (folder)
+  "Return FOLDER and its descendents.
+Returns a list of strings. For example,
+
+  '(\"inbox\" \"lists\" \"lists/mh-e\").
+
+If folder is nil, then all folders are considered. Respects the
+value of `mh-recursive-folders-flag'. If this flag is nil, and
+the sub-folders have not been explicitly viewed, then they will
+not be returned."
+  (let ((folder-list))
+    ;; Normalize folder. Strip leading +. Add trailing slash. If no
+    ;; folder is specified, ensure it is nil to ensure we get the
+    ;; top-level folders; otherwise mh-sub-folders returns all the
+    ;; files in / if given an empty string or +.
+    (when folder
+      (setq folder (replace-regexp-in-string "^\+" "" folder))
+      (setq folder (replace-regexp-in-string "/*$" "/" folder))
+      (if (equal folder "")
+        (setq folder nil)))
+    (loop for f in (mh-sub-folders folder) do
+          (setq folder-list (append folder-list (list (concat folder (car f)))))
+          (if (mh-children-p f)
+              (setq folder-list
+                    (append folder-list
+                            (mh-folder-list (concat folder (car f)))))))
+    folder-list))
+
 (defun mh-sub-folders (folder &optional add-trailing-slash-flag)
   "Find the subfolders of FOLDER.
 The function avoids running folders unnecessarily by caching the