[PATCH 1/7] emacs: hello: separate out the saved-search display function

Mark Walters markwalters1009 at gmail.com
Sun May 11 01:34:36 PDT 2014


Separate the code that prints a saved-search and count into its own
function.
---
 emacs/notmuch-hello.el |   30 +++++++++++++++++++-----------
 1 file changed, 19 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index 3de5238..0a7004c 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -475,6 +475,22 @@ (defun notmuch-hello-filtered-query (query filter)
     (concat "(" query ") and (" filter ")"))
    (t query)))
 
+(defun notmuch-hello-batch-message-count (elem-plist options)
+  "Update the message count for a saved search.
+
+This takes the next line in the current buffer (the output from a
+call to notmuch count --batch) as the message count and sets
+the :count property in ELEM-PLIST to it."
+  (let* ((count (prog1 (read (current-buffer))
+		  (forward-line 1)))
+	 (search-query (plist-get elem-plist :query))
+	 (filtered-query (notmuch-hello-filtered-query
+			  search-query (plist-get options :filter))))
+    (when (and filtered-query (or (plist-get options :show-empty-searches)
+				  (> count 0)))
+      (setq elem-plist (plist-put elem-plist :query filtered-query))
+      (plist-put elem-plist :count (notmuch-hello-nice-number count)))))
+
 (defun notmuch-hello-query-counts (query-list &rest options)
   "Compute list of counts of matched messages from QUERY-LIST.
 
@@ -514,15 +530,8 @@ (defun notmuch-hello-query-counts (query-list &rest options)
      #'identity
      (mapcar
       (lambda (elem)
-	(let* ((elem-plist (notmuch-hello-saved-search-to-plist elem))
-	       (search-query (plist-get elem-plist :query))
-	       (filtered-query (notmuch-hello-filtered-query
-				search-query (plist-get options :filter)))
-	       (message-count (prog1 (read (current-buffer))
-				(forward-line 1))))
-	  (when (and filtered-query (or (plist-get options :show-empty-searches) (> message-count 0)))
-	    (setq elem-plist (plist-put elem-plist :query filtered-query))
-	    (plist-put elem-plist :count message-count))))
+	(let* ((elem-plist (notmuch-hello-saved-search-to-plist elem)))
+	  (notmuch-hello-batch-message-count elem-plist options)))
       query-list))))
 
 (defun notmuch-hello-insert-buttons (searches)
@@ -558,8 +567,7 @@ (defun notmuch-hello-insert-buttons (searches)
 				     (oldest-first t)
 				     (otherwise notmuch-search-oldest-first)))
 		     (msg-count (plist-get elem :count)))
-		(widget-insert (format "%8s "
-				       (notmuch-hello-nice-number msg-count)))
+		(widget-insert (format "%8s " msg-count))
 		(widget-create 'push-button
 			       :notify #'notmuch-hello-widget-search
 			       :notmuch-search-terms query
-- 
1.7.10.4



More information about the notmuch mailing list