I accidentally used `filter' in the previous patch which isn't defined
by default during runtime, updated version in the attachment.
From e8f5e997b7082a50f75d7329a69fccc126a21e5e Mon Sep 17 00:00:00 2001
From: Daniel Schoepe <daniel.scho...@googlemail.com>
Date: Fri, 20 May 2011 00:53:50 +0200
Subject: [PATCH] emacs: Make queries used in the all-tags section
 configurable

This patch adds a customization variable that controls what queries
are used to construct the all-tags section in notmuch-hello. It allows
the user to specify a function to construct the query given a tag or
a string that is used as a filter for each tag.
It also adds a variable to hide various tags from the all-tags section.

Signed-off-by: Daniel Schoepe <daniel.scho...@googlemail.com>
---
 emacs/notmuch-hello.el |   38 +++++++++++++++++++++++++++++++++++---
 emacs/notmuch-lib.el   |   12 ++++++++++++
 2 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index e58dd24..b3f133c 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -55,6 +55,24 @@
   :type 'boolean
   :group 'notmuch)
 
+(defcustom notmuch-hello-tag-list-make-query nil
+  "Function or string to generate queries for the all tags list.
+
+This variable controls which query results are shown for each tag
+in the \"all tags\" list. It can be nil (for default behaviour,
+displaying all messages for a tag), a string that is used as a
+filter for messages having that tag (equivalent to \"tag:TAG
+and (THIS-VARIABLE)\", or a function that is given a tag and
+should return the query that is to be used for the tag. If it
+returns nil, the corresponding tag will be hidden."
+  :type '(choice (const nil :tag "tag:TAG") string function)
+  :group 'notmuch)
+
+(defcustom notmuch-hello-hide-tags nil
+  "List of tags to be hidden in the \"all tags\"-section."
+  :type '(repeat string)
+  :group 'notmuch)
+
 (defface notmuch-hello-logo-background
   '((((class color)
       (background dark))
@@ -318,6 +336,22 @@ Complete list of currently available key bindings:
  ;;(setq buffer-read-only t)
 )
 
+(defun notmuch-hello-generate-tag-alist ()
+  "Return an alist from tags to queries to display in the all-tags section."
+  (notmuch-filter
+   'cdr
+   (mapcar '(lambda (tag)
+	      (cons tag
+		    (cond
+		     ((functionp notmuch-hello-tag-list-make-query)
+		      (funcall notmuch-hello-tag-list-make-query tag))
+		     ((stringp notmuch-hello-tag-list-make-query)
+		      (concat "tag:" tag " and ("
+			      notmuch-hello-tag-list-make-query ")"))
+		     (t (concat "tag:" tag)))))
+	   (notmuch-filter (lambda (tag) (not (member tag notmuch-hello-hide-tags)))
+			   (process-lines notmuch-command "search-tags")))))
+
 ;;;###autoload
 (defun notmuch-hello (&optional no-display)
   "Run notmuch and display saved searches, known tags, etc."
@@ -396,9 +430,7 @@ Complete list of currently available key bindings:
 		      if (> (string-to-number (notmuch-saved-search-count (cdr elem))) 0)
 		      collect elem)))
 	     (saved-widest (notmuch-hello-longest-label saved-alist))
-	     (alltags-alist (if notmuch-show-all-tags-list
-				(mapcar '(lambda (tag) (cons tag (concat "tag:" tag)))
-					(process-lines notmuch-command "search-tags"))))
+	     (alltags-alist (if notmuch-show-all-tags-list (notmuch-hello-generate-tag-alist)))
 	     (alltags-widest (notmuch-hello-longest-label alltags-alist))
 	     (widest (max saved-widest alltags-widest)))
 
diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index cc80fb2..a3195ff 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -120,6 +120,18 @@ within the current window."
       (or (memq prop buffer-invisibility-spec)
 	  (assq prop buffer-invisibility-spec)))))
 
+;; notmuch- prefix to avoid clashes with user-defined filter-functions:
+;; For instance, the filter-function suggested in the elisp cookbook
+;; on the emacswiki always filters out elements that are nil
+;; even if the predicate returns t for nil; hence this has slightly
+;; different semantics than what some users have defined for themselves.
+(defun notmuch-filter (pred lst)
+  "Return a list containing all elements from LST that satisfy PRED."
+  (and lst
+     (if (funcall pred (car lst))
+	 (cons (car lst) (notmuch-filter pred (cdr lst)))
+       (notmuch-filter pred (cdr lst)))))
+
 ; This lets us avoid compiling these replacement functions when emacs
 ; is sufficiently new enough to supply them alone. We do the macro
 ; treatment rather than just wrapping our defun calls in a when form
-- 
1.7.5.1

Attachment: pgpxitXDTxLBx.pgp
Description: PGP signature

_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
http://notmuchmail.org/mailman/listinfo/notmuch

Reply via email to