Hi,

I noticed a bug with notmuch-search-filter-by-tag and
notmuch-tree-filter-by-tag and thought I could put together a quick
patch.

Let me know if there any amendments are needed.

-- 
Kind regards,
Kristoffer
From bd6399b2edbdd4c2dfc333145b26294d2353716f Mon Sep 17 00:00:00 2001
From: Kristoffer Balintona <[email protected]>
Date: Thu, 13 Nov 2025 14:39:14 -0600
Subject: [PATCH] emacs: fix `notmuch-*-filter-by-tag' query strings

`notmuch-tree-filter-by-tag' and `notmuch-search-filter-by-tag' are
described, in their docstrings, as matching all the messages in the
current view that are ALSO tagged by a given tag.  However, since the
current view's search query was not logically grouped together (with
parentheses), the actual behavior was different for sufficiently
complex search queries.

Fix this by grouping the current view's search query in parentheses
first.
---
 emacs/notmuch-tree.el | 2 +-
 emacs/notmuch.el      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index faec89c4..de5228db 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -1298,7 +1298,7 @@ search results and that are also tagged with the given TAG."
 					     notmuch-tree-basic-query)))
   (let ((notmuch-show-process-crypto (notmuch-tree--message-process-crypto)))
     (notmuch-tree-close-message-window)
-    (notmuch-tree (concat notmuch-tree-basic-query " and tag:" tag)
+    (notmuch-tree (format "(%s) and tag:%s" notmuch-tree-basic-query tag)
 		  notmuch-tree-query-context
 		  nil
 		  nil
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 2a73ffa5..5207b140 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -1176,7 +1176,7 @@ search results and that are also tagged with the given TAG."
   (interactive
    (list (notmuch-select-tag-with-completion "Filter by tag: "
 					     notmuch-search-query-string)))
-  (notmuch-search (concat notmuch-search-query-string " and tag:" tag)
+  (notmuch-search (format "(%s) and tag:%s" notmuch-search-query-string tag)
 		  notmuch-search-oldest-first
 		  notmuch-search-hide-excluded))
 
-- 
2.51.0

_______________________________________________
notmuch mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to