[PATCH 2/2] emacs: Fix saved-search buffer titles

Subject: [PATCH 2/2] emacs: Fix saved-search buffer titles

Date: Thu, 10 Jul 2025 09:04:21 -0300

To: Rudolf Adamkovič, notmuch@notmuchmail.org

Cc:

From: David Bremner


From: Rudolf Adamkovič <salutis@me.com>

REPRODUCTION STEPS:

  (let ((notmuch-saved-searches
         (list (list :name "Emacs List"
                     :query "query:lists-emacs")
               (list :name "All Lists"
                     :query "query:lists"))))
    (notmuch-search-buffer-title "query:lists-emacs" ))

ACTUAL:

  "*notmuch-saved-search-[ All Lists ]-emacs*"

EXPECTED:

   "*notmuch-saved-search-Emacs List*"
---
 emacs/notmuch.el   | 25 ++++++++++++++-----------
 test/T310-emacs.sh |  1 -
 2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 69aff347..c2bca420 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -989,17 +989,20 @@ unthreaded) and whether it's SAVED (t or nil)."
 (defun notmuch-search-buffer-title (query &optional type)
   "Returns the title for a buffer with notmuch search results."
   (let* ((saved-search
-	  (let (longest
-		(longest-length 0))
-	    (cl-loop for tuple in notmuch-saved-searches
-		     if (let ((quoted-query
-			       (regexp-quote
-				(notmuch-saved-search-get tuple :query))))
-			  (and (string-match (concat "^" quoted-query) query)
-			       (> (length (match-string 0 query))
-				  longest-length)))
-		     do (setq longest tuple))
-	    longest))
+	  (cl-loop with match
+		   with match-length = 0
+		   for candidate in notmuch-saved-searches
+		   for length = (let* ((query* (notmuch-saved-search-get
+						candidate
+						:query))
+				       (regexp (concat "^"
+						       (regexp-quote query*))))
+				  (and (string-match regexp query)
+				       (length (match-string 0 query))))
+		   if (and length (> length match-length))
+		   do (setq match candidate
+			    match-length length)
+		   finally return match))
 	 (saved-search-name (notmuch-saved-search-get saved-search :name))
 	 (saved-search-type (notmuch-saved-search-get saved-search :search-type))
 	 (saved-search-query (notmuch-saved-search-get saved-search :query)))
diff --git a/test/T310-emacs.sh b/test/T310-emacs.sh
index 211429e6..f23169f6 100755
--- a/test/T310-emacs.sh
+++ b/test/T310-emacs.sh
@@ -36,7 +36,6 @@ test_emacs '(let ((notmuch-saved-searches
 test_expect_equal_file $EXPECTED/notmuch-hello-no-saved-searches OUTPUT
 
 test_begin_subtest "Buffer name from saved searches"
-test_subtest_known_broken
 test_emacs '
     (test-log-error
      (let ((notmuch-saved-searches
-- 
2.47.2

_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: