unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] Fix saved-search buffer titles
@ 2023-12-14 22:50 Rudolf Adamkovič
  2024-06-20 12:29 ` Fwd: " Rudolf Adamkovič
  2024-08-06  9:41 ` David Bremner
  0 siblings, 2 replies; 4+ messages in thread
From: Rudolf Adamkovič @ 2023-12-14 22:50 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 535 bytes --]

Fellow hackers,

So, I have always wondered why Notmuch uses the strangest buffer titles
ever, and yesterday I decided to take a look under the hood...  I found
that the code in 'notmuch-search-buffer-title' defines and uses a pair
of variables, named 'longest' and 'longest-length', but never sets the
latter, which causes the strange buffer titles I observe.  Please see
the attached patch with a fix.

P.S. I could not make the test suite work, not in the time I had for the
fix, so ... see the test in the commit message. :)

Rudy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-emacs-Fix-saved-search-buffer-titles.patch --]
[-- Type: text/x-patch, Size: 2167 bytes --]

From c0cb08a843b5c904642da639f94c4a5e43d1ef14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com>
Date: Wed, 13 Dec 2023 22:39:02 +0100
Subject: [PATCH] emacs: Fix saved-search buffer titles

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 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6eef4af1..1ac145f0 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -964,17 +964,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)))
-- 
2.39.3 (Apple Git-145)


[-- Attachment #3: Type: text/plain, Size: 240 bytes --]

-- 
"The introduction of suitable abstractions is our only mental aid to
organize and master complexity."
--- Edsger Wybe Dijkstra, 1930-2002

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Fwd: [PATCH] Fix saved-search buffer titles
  2023-12-14 22:50 [PATCH] Fix saved-search buffer titles Rudolf Adamkovič
@ 2024-06-20 12:29 ` Rudolf Adamkovič
  2024-08-06  9:41 ` David Bremner
  1 sibling, 0 replies; 4+ messages in thread
From: Rudolf Adamkovič @ 2024-06-20 12:29 UTC (permalink / raw)
  To: notmuch

[-- Attachment #1: Type: text/plain, Size: 240 bytes --]

Ping.

-------------------- Start of forwarded message --------------------
From: Rudolf Adamkovič <salutis@me.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] Fix saved-search buffer titles
Date: Thu, 14 Dec 2023 23:50:14 +0100


[-- Attachment #2.1: Type: text/plain, Size: 535 bytes --]

Fellow hackers,

So, I have always wondered why Notmuch uses the strangest buffer titles
ever, and yesterday I decided to take a look under the hood...  I found
that the code in 'notmuch-search-buffer-title' defines and uses a pair
of variables, named 'longest' and 'longest-length', but never sets the
latter, which causes the strange buffer titles I observe.  Please see
the attached patch with a fix.

P.S. I could not make the test suite work, not in the time I had for the
fix, so ... see the test in the commit message. :)

Rudy

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2.2: 0001-emacs-Fix-saved-search-buffer-titles.patch --]
[-- Type: text/x-patch, Size: 2167 bytes --]

From c0cb08a843b5c904642da639f94c4a5e43d1ef14 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com>
Date: Wed, 13 Dec 2023 22:39:02 +0100
Subject: [PATCH] emacs: Fix saved-search buffer titles

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 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index 6eef4af1..1ac145f0 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -964,17 +964,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)))
-- 
2.39.3 (Apple Git-145)


[-- Attachment #2.3: Type: text/plain, Size: 240 bytes --]

-- 
"The introduction of suitable abstractions is our only mental aid to
organize and master complexity."
--- Edsger Wybe Dijkstra, 1930-2002

Rudolf Adamkovič <salutis@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

[-- Attachment #3: Type: text/plain, Size: 333 bytes --]

-------------------- End of forwarded message --------------------

-- 
"I do not fear death.  I had been dead for billions and billions of years
before I was born, and had not suffered the slightest inconvenience from it."
--- Mark Twain, paraphrased

Rudolf Adamkovič <rudolf@adamkovic.org> [he/him]
http://adamkovic.org

[-- Attachment #4: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix saved-search buffer titles
  2023-12-14 22:50 [PATCH] Fix saved-search buffer titles Rudolf Adamkovič
  2024-06-20 12:29 ` Fwd: " Rudolf Adamkovič
@ 2024-08-06  9:41 ` David Bremner
  2024-08-06 21:44   ` Rudolf Adamkovič
  1 sibling, 1 reply; 4+ messages in thread
From: David Bremner @ 2024-08-06  9:41 UTC (permalink / raw)
  To: Rudolf Adamkovič, notmuch

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

> From c0cb08a843b5c904642da639f94c4a5e43d1ef14 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salutis@me.com>
> Date: Wed, 13 Dec 2023 22:39:02 +0100
> Subject: [PATCH] emacs: Fix saved-search buffer titles
>
> 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*"

If you can make a reproducer that does not rely on your private notmuch
config (query:list), I might be able to turn that into a test.

> +	  (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))

Sorry, I don't really speak cl-loop. You can either hope someone else
reviews it and convinces me, or try a less intrusive restructuring of
the existing code.

\r

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix saved-search buffer titles
  2024-08-06  9:41 ` David Bremner
@ 2024-08-06 21:44   ` Rudolf Adamkovič
  0 siblings, 0 replies; 4+ messages in thread
From: Rudolf Adamkovič @ 2024-08-06 21:44 UTC (permalink / raw)
  To: David Bremner, Rudolf Adamkovič, notmuch

David Bremner <david@tethera.net> writes:

> If you can make a reproducer that does not rely on your private notmuch
> config (query:list), I might be able to turn that into a test.

The reproducer does not rely on anything private.  Simply evaluate the
expression, say using C-x C-e.  You should see it evaluate to the
ACTUAL, as opposed to the EXPECTED, value.

Rudy
-- 
"Great minds discuss ideas; average minds discuss events; small minds
discuss people."  --- Anna Eleanor Roosevelt (1884-1962)

Rudolf Adamkovič <rudolf@adamkovic.org> [he/him]
http://adamkovic.org\r

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-06 21:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-14 22:50 [PATCH] Fix saved-search buffer titles Rudolf Adamkovič
2024-06-20 12:29 ` Fwd: " Rudolf Adamkovič
2024-08-06  9:41 ` David Bremner
2024-08-06 21:44   ` Rudolf Adamkovič

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).