]> git.cworth.org Git - notmuch/commitdiff
emacs: Fix saved-search buffer titles
authorRudolf Adamkovič <salutis@me.com>
Wed, 13 Dec 2023 21:39:02 +0000 (22:39 +0100)
committerDavid Bremner <david@tethera.net>
Tue, 6 Aug 2024 09:25:07 +0000 (06:25 -0300)
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

index 2a73ffa571c41a04b0836a50a991102249fad658..f55e9b4243744e447920bb9721c997d8a9b97e96 100644 (file)
@@ -973,17 +973,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)))