unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* notmuch.el: notmuch-search: avoid wiping out buffer-local variables
@ 2020-07-21 23:03 Sean Whitton
  2020-07-22 10:32 ` David Edmondson
  0 siblings, 1 reply; 5+ messages in thread
From: Sean Whitton @ 2020-07-21 23:03 UTC (permalink / raw)
  To: notmuch

Hello,

I have some code to cycle through a list of searches.  The remaining
searches are stored in a buffer-local variable, working something like
this (simplified):

    (defun spw/next-unread-group ()
           (interactive)
           (notmuch-search (car spw/more-unread-groups)
           (set (make-local-variable 'spw/more-unread-groups)
                (cdr spw/more-unread-groups))))

However, my spw/more-unread-groups variable gets wiped out by
notmuch-refresh-this-buffer, because the latter calls
notmuch-search-mode, and major modes wipe out buffer-local variables.

So far as I can tell that call doesn't actually have any effect when the
mode is already notmuch-search-mode, so may I propose this patch to
support my use case:

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index dd18f2e1..dcbc1eb2 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -987,7 +987,8 @@ the configured default sort order."
     (if no-display
 	(set-buffer buffer)
       (switch-to-buffer buffer))
-    (notmuch-search-mode)
+    (unless (eq major-mode 'notmuch-search-mode)
+      (notmuch-search-mode))
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
     (set 'notmuch-search-query-string query)

-- 
Sean Whitton

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

* Re: notmuch.el: notmuch-search: avoid wiping out buffer-local variables
  2020-07-21 23:03 notmuch.el: notmuch-search: avoid wiping out buffer-local variables Sean Whitton
@ 2020-07-22 10:32 ` David Edmondson
  2020-07-22 15:11   ` [PATCH] emacs: " Sean Whitton
  0 siblings, 1 reply; 5+ messages in thread
From: David Edmondson @ 2020-07-22 10:32 UTC (permalink / raw)
  To: Sean Whitton, notmuch

On Tuesday, 2020-07-21 at 16:03:27 -07, Sean Whitton wrote:

> Hello,
>
> I have some code to cycle through a list of searches.  The remaining
> searches are stored in a buffer-local variable, working something like
> this (simplified):
>
>     (defun spw/next-unread-group ()
>            (interactive)
>            (notmuch-search (car spw/more-unread-groups)
>            (set (make-local-variable 'spw/more-unread-groups)
>                 (cdr spw/more-unread-groups))))
>
> However, my spw/more-unread-groups variable gets wiped out by
> notmuch-refresh-this-buffer, because the latter calls
> notmuch-search-mode, and major modes wipe out buffer-local variables.
>
> So far as I can tell that call doesn't actually have any effect when the
> mode is already notmuch-search-mode, so may I propose this patch to
> support my use case:

Seems reasonable. Could you add a comment in the code explaining that
it's to avoid clobbering third-party buffer local variables?

> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index dd18f2e1..dcbc1eb2 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -987,7 +987,8 @@ the configured default sort order."
>      (if no-display
>  	(set-buffer buffer)
>        (switch-to-buffer buffer))
> -    (notmuch-search-mode)
> +    (unless (eq major-mode 'notmuch-search-mode)
> +      (notmuch-search-mode))
>      ;; Don't track undo information for this buffer
>      (set 'buffer-undo-list t)
>      (set 'notmuch-search-query-string query)
>
> -- 
> Sean Whitton
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

dme.
-- 
What did you learn today? I learnt nothing.

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

* [PATCH] emacs: notmuch-search: avoid wiping out buffer-local variables
  2020-07-22 10:32 ` David Edmondson
@ 2020-07-22 15:11   ` Sean Whitton
  2020-07-22 15:46     ` David Edmondson
  2020-07-22 22:51     ` David Bremner
  0 siblings, 2 replies; 5+ messages in thread
From: Sean Whitton @ 2020-07-22 15:11 UTC (permalink / raw)
  To: notmuch; +Cc: Sean Whitton

---
 emacs/notmuch.el | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index dd18f2e1..c97997fe 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -987,7 +987,11 @@ the configured default sort order."
     (if no-display
 	(set-buffer buffer)
       (switch-to-buffer buffer))
-    (notmuch-search-mode)
+    ;; avoid wiping out third party buffer-local variables in the case
+    ;; where we're just refreshing or changing the sort order of an
+    ;; existing search results buffer
+    (unless (eq major-mode 'notmuch-search-mode)
+      (notmuch-search-mode))
     ;; Don't track undo information for this buffer
     (set 'buffer-undo-list t)
     (set 'notmuch-search-query-string query)
-- 
2.27.0

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

* Re: [PATCH] emacs: notmuch-search: avoid wiping out buffer-local variables
  2020-07-22 15:11   ` [PATCH] emacs: " Sean Whitton
@ 2020-07-22 15:46     ` David Edmondson
  2020-07-22 22:51     ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: David Edmondson @ 2020-07-22 15:46 UTC (permalink / raw)
  To: Sean Whitton, notmuch

On Wednesday, 2020-07-22 at 08:11:32 -07, Sean Whitton wrote:
>

Reviewed-by: David Edmondson <dme@dme.org>

> ---
>  emacs/notmuch.el | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index dd18f2e1..c97997fe 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -987,7 +987,11 @@ the configured default sort order."
>      (if no-display
>  	(set-buffer buffer)
>        (switch-to-buffer buffer))
> -    (notmuch-search-mode)
> +    ;; avoid wiping out third party buffer-local variables in the case
> +    ;; where we're just refreshing or changing the sort order of an
> +    ;; existing search results buffer
> +    (unless (eq major-mode 'notmuch-search-mode)
> +      (notmuch-search-mode))
>      ;; Don't track undo information for this buffer
>      (set 'buffer-undo-list t)
>      (set 'notmuch-search-query-string query)
> -- 
> 2.27.0
> _______________________________________________
> notmuch mailing list -- notmuch@notmuchmail.org
> To unsubscribe send an email to notmuch-leave@notmuchmail.org

dme.
-- 
Hello? Is anybody home? Well, you don't know me, but I know you.

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

* Re: [PATCH] emacs: notmuch-search: avoid wiping out buffer-local variables
  2020-07-22 15:11   ` [PATCH] emacs: " Sean Whitton
  2020-07-22 15:46     ` David Edmondson
@ 2020-07-22 22:51     ` David Bremner
  1 sibling, 0 replies; 5+ messages in thread
From: David Bremner @ 2020-07-22 22:51 UTC (permalink / raw)
  To: Sean Whitton, notmuch; +Cc: Sean Whitton

Sean Whitton <spwhitton@spwhitton.name> writes:

> ---
>  emacs/notmuch.el | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)

applied to master

d

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

end of thread, other threads:[~2020-07-22 22:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 23:03 notmuch.el: notmuch-search: avoid wiping out buffer-local variables Sean Whitton
2020-07-22 10:32 ` David Edmondson
2020-07-22 15:11   ` [PATCH] emacs: " Sean Whitton
2020-07-22 15:46     ` David Edmondson
2020-07-22 22:51     ` David Bremner

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).