[PATCH] Support function values in notmuch-saved-searches so that searches can be generated dynamically

Jed Brown jed at 59A2.org
Fri Nov 19 10:42:49 PST 2010


This permits saved searches like "today".
---
This is similar functionality to David's patch, but uses an accessor so that queries are always evaluated dynamically.

 emacs/notmuch-hello.el |    4 ++--
 emacs/notmuch-lib.el   |   11 ++++++++++-
 emacs/notmuch.el       |    2 +-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index e58dd24..15eaafb 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -234,7 +234,7 @@ should be. Returns a cons cell `(tags-per-line width)'."
 	    ;; (not elem) indicates an empty slot in the matrix.
 	    (when elem
 	      (let* ((name (car elem))
-		     (query (cdr elem))
+		     (query (notmuch-saved-search-get-query elem))
 		     (formatted-name (format "%s " name)))
 		(widget-insert (format "%8s "
 				       (notmuch-hello-nice-number
@@ -393,7 +393,7 @@ Complete list of currently available key bindings:
 	      (if notmuch-show-empty-saved-searches
 		  notmuch-saved-searches
 		(loop for elem in notmuch-saved-searches
-		      if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0)
+		      if (> (string-to-number (notmuch-saved-search-count (notmuch-saved-search-get-query elem))) 0)
 		      collect elem)))
 	     (saved-widest (notmuch-hello-longest-label saved-alist))
 	     (alltags-alist (if notmuch-show-all-tags-list
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index dd180ee..3fcb837 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -37,7 +37,9 @@
 
 (defcustom notmuch-saved-searches nil
   "A list of saved searches to display."
-  :type '(alist :key-type string :value-type string)
+  :type '(alist :key-type (string :tag "Name")
+                :value-type (choice (string :tag "Search")
+                                    (function :tag "Function")))
   :group 'notmuch)
 
 (defvar notmuch-folders nil
@@ -56,6 +58,13 @@ the user hasn't set this variable with the old or new value."
       '(("inbox" . "tag:inbox")
 	("unread" . "tag:unread")))))
 
+(defun notmuch-saved-search-get-query (tuple)
+  "Get the query string for a saved tuple."
+  (let ((q (cdr tuple)))
+    (if (stringp q)
+        q
+      (funcall q))))
+
 (defun notmuch-version ()
   "Return a string with the notmuch version number."
   (let ((long-string
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 5933747..5864b21 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -763,7 +763,7 @@ characters as well as `_.+-'.
 	  (let (longest
 		(longest-length 0))
 	    (loop for tuple in notmuch-saved-searches
-		  if (let ((quoted-query (regexp-quote (cdr tuple))))
+		  if (let ((quoted-query (regexp-quote (notmuch-saved-search-get-query tuple))))
 		       (and (string-match (concat "^" quoted-query) query)
 			    (> (length (match-string 0 query))
 			       longest-length)))
-- 
1.7.3.2



More information about the notmuch mailing list