[PATCH 4/7] emacs: hello: add a threads-and-messages function

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


This is an example of a possible display function. It displays the
count for a search as messages/threads. This will be slow on a large
search but could be useful for a small search.

It also extends and renames the existing (unused)
notmuch-saved-search-count function to count threads if wanted. The
rename is done because the function is not saved-search specific.
---
 emacs/notmuch-hello.el |   30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index e11006b..6b2dedc 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -90,8 +90,13 @@ (define-widget 'notmuch-saved-search-plist 'list
 				    (const :tag "Default" nil)
 				    (const :tag "Oldest-first" oldest-first)
 				    (const :tag "Newest-first" newest-first)))
-		     (group :format "%v" :inline t (const :format "Display-function: " :display-function) (function :format "%v")))))
-
+		     (group :format "%v" :inline t
+			    (const :format "" :display-function)
+			    (choice :tag  " Display function"
+				    (const :tag "Default (messages)" nil)
+				    (function-item :tag "messages/threads"
+						   notmuch-hello-display-count-threads-and-messages)
+				    function)))))
 
 (defcustom notmuch-saved-searches '((:name "inbox" :query "tag:inbox")
 				    (:name "unread" :query "tag:unread"))
@@ -435,9 +440,6 @@ (defun notmuch-hello-widget-search (widget &rest ignore)
 		  (widget-get widget
 			      :notmuch-search-oldest-first)))
 
-(defun notmuch-saved-search-count (search)
-  (car (process-lines notmuch-command "count" search)))
-
 (defun notmuch-hello-tags-per-line (widest)
   "Determine how many tags to show per line and how wide they
 should be. Returns a cons cell `(tags-per-line width)'."
@@ -487,6 +489,24 @@ (defun notmuch-hello-filtered-query (query filter)
     (concat "(" query ") and (" filter ")"))
    (t query)))
 
+(defun notmuch-hello-count (query &optional threads)
+  (let ((arg (if threads "--output=threads" "--output=messages")))
+    (string-to-number
+     (car (process-lines notmuch-command "count" arg query)))))
+
+(defun notmuch-hello-display-count-threads-and-messages (&rest args)
+  "Display the saved search count as messages/threads.
+
+This will be slow for large queries."
+  (let* ((current (plist-get args :current))
+	 (query (plist-get current :query))
+	 (messages (notmuch-hello-count query nil))
+	 (threads (notmuch-hello-count query t))
+	 (display (concat (notmuch-hello-nice-number messages)
+			  "/"
+			  (notmuch-hello-nice-number threads))))
+    (plist-put current :count display)))
+
 (defun notmuch-hello-batch-message-count (elem-plist options)
   "Update the message count for a saved search.
 
-- 
1.7.10.4



More information about the notmuch mailing list