[notmuch] [PATCH] Make search filters handle disjunctive queries.
Jed Brown
jed at 59A2.org
Mon Nov 23 03:49:26 PST 2009
notmuch-search-filter accepts now accepts an arbitrary query and will
group if necessary so that we get
tag:inbox AND (gravy OR biscuits)
notmuch-search-filter-tag now handles multiple terms. All terms in the
query except AND and OR are interpreted as tags.
Signed-off-by: Jed Brown <jed at 59A2.org>
---
notmuch.el | 23 ++++++++++++++++++-----
1 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/notmuch.el b/notmuch.el
index 0cabbe2..43e0566 100644
--- a/notmuch.el
+++ b/notmuch.el
@@ -1057,15 +1057,28 @@ search."
Runs a new search matching only messages that match both the
current search results AND the additional query string provided."
(interactive "sFilter search: ")
- (notmuch-search (concat notmuch-search-query-string " and " query) notmuch-search-oldest-first))
+ (let ((grouped-query (if (string-match-p "\\<[oO][rR]\\>" query) (concat "( " query " )") query)))
+ (notmuch-search (concat notmuch-search-query-string " and " grouped-query) notmuch-search-oldest-first)))
-(defun notmuch-search-filter-by-tag (tag)
- "Filter the current search results based on a single tag.
+(defun notmuch-search-filter-by-tag (query)
+ "Filter the current search results based on one or more tags.
Runs a new search matching only messages that match both the
-current search results AND that are tagged with the given tag."
+current search results AND that are tagged with the given
+expression involving tags. For example, the input
+
+ chicken and (gravy or biscuits)
+
+will filter the current search by
+
+ tag:chicken and ( tag:gravy or tag:biscuits )"
(interactive "sFilter by tag: ")
- (notmuch-search (concat notmuch-search-query-string " and tag:" tag) notmuch-search-oldest-first))
+ (let ((tagged-query (replace-regexp-in-string "\\([_\+\-]\\|\\w\\)+"
+ (lambda (match) ; Prepend `tag:' to all matches except AND and OR
+ (if (string-match-p "\\([aA][nN][dD]\\)\\|\\([oO][rR]\\)" match)
+ match (concat "tag:" match)))
+ query)))
+ (notmuch-search-filter tagged-query)))
(defun notmuch ()
"Run notmuch to display all mail with tag of 'inbox'"
--
1.6.5.3
More information about the notmuch
mailing list