[WIP PATCH 3/4] emacs: search: split foreach-result into list and region variants

Mark Walters markwalters1009 at gmail.com
Tue Apr 22 13:11:49 PDT 2014


---
 emacs/notmuch.el |   20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 7b06458..e1ece47 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -380,7 +380,20 @@ (defun notmuch-search-result-end (&optional pos)
     (next-single-property-change (or pos (point)) 'notmuch-search-result
 				 nil (point-max))))
 
-(defun notmuch-search-foreach-result (beg end thread-list function)
+(defun notmuch-search-foreach-result-in-list (thread-list function)
+  "Invoke function for each thread in list."
+  (lexical-let ((thread-list (copy-sequence thread-list)))
+    (save-excursion
+      (goto-char (point-min))
+      (while (and (notmuch-search-get-result)
+		  thread-list)
+	(let ((thread (notmuch-search-find-thread-id)))
+	  (when (member thread thread-list)
+	    (funcall function)
+	    (setq thread-list (delete thread thread-list))))
+	(notmuch-search-next-thread)))))
+
+(defun notmuch-search-foreach-result-in-region (beg end function)
   "Invoke FUNCTION for each result between BEG and END.
 
 FUNCTION should take no arguments.  It will be applied at the
@@ -401,6 +414,11 @@ (defun notmuch-search-foreach-result (beg end thread-list function)
 	  (funcall function)
 	  (notmuch-search-next-thread))))))
 
+(defun notmuch-search-foreach-result (beg end thread-list function)
+  (if thread-list
+      (notmuch-search-foreach-result-in-list thread-list function)
+    (notmuch-search-foreach-result-in-region beg end function)))
+
 ;; Unindent the function argument of notmuch-search-foreach-result so
 ;; the indentation of callers doesn't get out of hand.
 (put 'notmuch-search-foreach-result 'lisp-indent-function 2)
-- 
1.7.10.4



More information about the notmuch mailing list