unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / Atom feed
* [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer
@ 2020-08-11 16:59 Sean Whitton
  2020-08-15 11:02 ` David Bremner
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Sean Whitton @ 2020-08-11 16:59 UTC (permalink / raw)
  To: notmuch; +Cc: Sean Whitton

This means that notmuch commands obey display-buffer-alist so the user
can customize how buffers show up.

It also permits the use of C-x 4 4, C-x 5 5 and C-x t t, available in
Emacs 28.  For example, one can use C-x 4 4 M-x notmuch-jump-search RET
to open a saved search in another window rather than the current window.
Or in notmuch-search mode, C-x 5 5 RET to view the message at point in
a new frame.

notmuch-tree has custom buffer display logic, so bind
display-buffer-overriding-action to make pop-to-buffer-same-window
behave exactly as switch-to-buffer while that function is running.
---
Changes since v1: rebased onto latest master.

 emacs/notmuch-draft.el |  3 ++-
 emacs/notmuch-hello.el |  2 +-
 emacs/notmuch-show.el  |  8 ++++----
 emacs/notmuch-tree.el  | 13 +++++++++----
 emacs/notmuch.el       |  4 ++--
 5 files changed, 18 insertions(+), 12 deletions(-)

diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
index 759e6c9e..283830ad 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -232,7 +232,8 @@ applied to newly inserted messages)."
 	 (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
     (when (or draft
 	      (yes-or-no-p "Message does not appear to be a draft: edit as new? "))
-      (switch-to-buffer (get-buffer-create (concat "*notmuch-draft-" id "*")))
+      (pop-to-buffer-same-window
+       (get-buffer-create (concat "*notmuch-draft-" id "*")))
       (setq buffer-read-only nil)
       (erase-buffer)
       (let ((coding-system-for-read 'no-conversion))
diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
index c127bba9..bb60a890 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -973,7 +973,7 @@ following:
   (let ((notmuch-hello-auto-refresh nil))
     (if no-display
 	(set-buffer "*notmuch-hello*")
-      (switch-to-buffer "*notmuch-hello*")))
+      (pop-to-buffer-same-window "*notmuch-hello*")))
   ;; Install auto-refresh hook
   (when notmuch-hello-auto-refresh
     (add-hook 'window-configuration-change-hook
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index b0f2d28b..98d9c935 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1241,7 +1241,7 @@ matched."
 		    (eval (car (get 'mm-inline-override-types 'standard-value))))
 	     (cons "application/*" mm-inline-override-types)
 	   mm-inline-override-types)))
-    (switch-to-buffer (get-buffer-create buffer-name))
+    (pop-to-buffer-same-window (get-buffer-create buffer-name))
     ;; No need to track undo information for this buffer.
     (setq buffer-undo-list t)
     (notmuch-show-mode)
@@ -1998,7 +1998,7 @@ to show, nil otherwise."
   (let* ((id (notmuch-show-get-message-id))
 	 (buf (get-buffer-create (concat "*notmuch-raw-" id "*")))
 	 (inhibit-read-only t))
-    (switch-to-buffer buf)
+    (pop-to-buffer-same-window buf)
     (erase-buffer)
     (let ((coding-system-for-read 'no-conversion))
       (call-process notmuch-command nil t nil "show" "--format=raw" id))
@@ -2057,7 +2057,7 @@ message."
 	  (set-buffer-modified-p nil)
 	  (setq buffer-read-only t)
 	  (unless (zerop exit-code)
-	    (switch-to-buffer-other-window buf)
+	    (pop-to-buffer buf)
 	    (message (format "Command '%s' exited abnormally with code %d"
 			     shell-command exit-code))))))))
 
@@ -2465,7 +2465,7 @@ If the part is displayed in an external application then close
 the new buffer."
   (let ((buf (get-buffer-create (generate-new-buffer-name
 				 (concat " *notmuch-internal-part*")))))
-    (switch-to-buffer buf)
+    (pop-to-buffer-same-window buf)
     (if (eq (mm-display-part handle) 'external)
 	(kill-buffer buf)
       (goto-char (point-min))
diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
index fbba4bb3..f36a6e72 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -543,9 +543,14 @@ NOT change the database."
       (setq notmuch-tree-message-window
 	    (split-window-vertically (/ (window-height) 4)))
       (with-selected-window notmuch-tree-message-window
-	;; Since we are only displaying one message do not indent.
-	(let ((notmuch-show-indent-messages-width 0)
-	      (notmuch-show-only-matching-messages t))
+	(let (;; Since we are only displaying one message do not indent.
+	      (notmuch-show-indent-messages-width 0)
+	      (notmuch-show-only-matching-messages t)
+	      ;; Ensure that `pop-to-buffer-same-window' uses the
+	      ;; window we want it to use.
+	      (display-buffer-overriding-action
+		 '((display-buffer-same-window)
+		   (inhibit-same-window . nil))))
 	  (setq buffer (notmuch-show id))))
       ;; We need the `let' as notmuch-tree-message-window is buffer local.
       (let ((window notmuch-tree-message-window))
@@ -1076,7 +1081,7 @@ The arguments are:
 						(if unthreaded "unthreaded-" "tree-")
 						query "*")))))
 	(inhibit-read-only t))
-    (switch-to-buffer buffer))
+    (pop-to-buffer-same-window buffer))
   ;; Don't track undo information for this buffer
   (set 'buffer-undo-list t)
   (notmuch-tree-worker query query-context target open-target unthreaded)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index babddbb6..4e2ea9eb 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -994,7 +994,7 @@ the configured default sort order."
 	 (buffer (get-buffer-create (notmuch-search-buffer-title query))))
     (if no-display
 	(set-buffer buffer)
-      (switch-to-buffer buffer))
+      (pop-to-buffer-same-window buffer))
     ;; 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
@@ -1134,7 +1134,7 @@ notmuch buffers exist, run `notmuch'."
 	;; If the first one we found is any other than the starting
 	;; buffer, switch to it.
 	(unless (eq first start)
-	  (switch-to-buffer first))
+	  (pop-to-buffer-same-window first))
       (notmuch))))
 
 ;;;; Imenu Support
-- 
2.27.0

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

* Re: [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer
  2020-08-11 16:59 [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer Sean Whitton
@ 2020-08-15 11:02 ` David Bremner
  2020-08-22  9:04 ` Tomi Ollila
  2020-08-22 12:52 ` David Bremner
  2 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2020-08-15 11:02 UTC (permalink / raw)
  To: Sean Whitton, notmuch

Sean Whitton <spwhitton@spwhitton.name> writes:

> This means that notmuch commands obey display-buffer-alist so the user
> can customize how buffers show up.
>
> It also permits the use of C-x 4 4, C-x 5 5 and C-x t t, available in
> Emacs 28.  For example, one can use C-x 4 4 M-x notmuch-jump-search RET
> to open a saved search in another window rather than the current window.
> Or in notmuch-search mode, C-x 5 5 RET to view the message at point in
> a new frame.
>
> notmuch-tree has custom buffer display logic, so bind
> display-buffer-overriding-action to make pop-to-buffer-same-window
> behave exactly as switch-to-buffer while that function is running.

I only tested this in emacs 26.3, but I think I hit all the modified
code paths and it didn't crash.  It would be nice to have one or two
more people try it out before I apply to master; I tend to be somewhat
oblivious to subtle changes in emacs window behaviour.

d

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

* Re: [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer
  2020-08-11 16:59 [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer Sean Whitton
  2020-08-15 11:02 ` David Bremner
@ 2020-08-22  9:04 ` Tomi Ollila
  2020-08-22 14:38   ` Sean Whitton
  2020-08-22 12:52 ` David Bremner
  2 siblings, 1 reply; 5+ messages in thread
From: Tomi Ollila @ 2020-08-22  9:04 UTC (permalink / raw)
  To: Sean Whitton, notmuch

On Tue, Aug 11 2020, Sean Whitton wrote:

> This means that notmuch commands obey display-buffer-alist so the user
> can customize how buffers show up.
>
> It also permits the use of C-x 4 4, C-x 5 5 and C-x t t, available in
> Emacs 28.  For example, one can use C-x 4 4 M-x notmuch-jump-search RET
> to open a saved search in another window rather than the current window.
> Or in notmuch-search mode, C-x 5 5 RET to view the message at point in
> a new frame.
>
> notmuch-tree has custom buffer display logic, so bind
> display-buffer-overriding-action to make pop-to-buffer-same-window
> behave exactly as switch-to-buffer while that function is running.
> ---
> Changes since v1: rebased onto latest master.

I've been having this in my emacs setup (one-notmuch.elc =D) couple
of days, and haven't seen anything strange.

Just now I tested a bit more, tried show and tree modes, with 
M-x debug-on-entry pop-to-buffer-same-window active and see some
call paths (interestingly (or not so), starting this mail composition
pop-to-buffer-same-window was not in call path -- but probably 
switch-to-buffer would be neither and there is no change in status quo)

So LGTM.

Tomi

>
>  emacs/notmuch-draft.el |  3 ++-
>  emacs/notmuch-hello.el |  2 +-
>  emacs/notmuch-show.el  |  8 ++++----
>  emacs/notmuch-tree.el  | 13 +++++++++----
>  emacs/notmuch.el       |  4 ++--
>  5 files changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el
> index 759e6c9e..283830ad 100644
> --- a/emacs/notmuch-draft.el
> +++ b/emacs/notmuch-draft.el
> @@ -232,7 +232,8 @@ applied to newly inserted messages)."
>  	 (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
>      (when (or draft
>  	      (yes-or-no-p "Message does not appear to be a draft: edit as new? "))
> -      (switch-to-buffer (get-buffer-create (concat "*notmuch-draft-" id "*")))
> +      (pop-to-buffer-same-window
> +       (get-buffer-create (concat "*notmuch-draft-" id "*")))
>        (setq buffer-read-only nil)
>        (erase-buffer)
>        (let ((coding-system-for-read 'no-conversion))
> diff --git a/emacs/notmuch-hello.el b/emacs/notmuch-hello.el
> index c127bba9..bb60a890 100644
> --- a/emacs/notmuch-hello.el
> +++ b/emacs/notmuch-hello.el
> @@ -973,7 +973,7 @@ following:
>    (let ((notmuch-hello-auto-refresh nil))
>      (if no-display
>  	(set-buffer "*notmuch-hello*")
> -      (switch-to-buffer "*notmuch-hello*")))
> +      (pop-to-buffer-same-window "*notmuch-hello*")))
>    ;; Install auto-refresh hook
>    (when notmuch-hello-auto-refresh
>      (add-hook 'window-configuration-change-hook
> diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
> index b0f2d28b..98d9c935 100644
> --- a/emacs/notmuch-show.el
> +++ b/emacs/notmuch-show.el
> @@ -1241,7 +1241,7 @@ matched."
>  		    (eval (car (get 'mm-inline-override-types 'standard-value))))
>  	     (cons "application/*" mm-inline-override-types)
>  	   mm-inline-override-types)))
> -    (switch-to-buffer (get-buffer-create buffer-name))
> +    (pop-to-buffer-same-window (get-buffer-create buffer-name))
>      ;; No need to track undo information for this buffer.
>      (setq buffer-undo-list t)
>      (notmuch-show-mode)
> @@ -1998,7 +1998,7 @@ to show, nil otherwise."
>    (let* ((id (notmuch-show-get-message-id))
>  	 (buf (get-buffer-create (concat "*notmuch-raw-" id "*")))
>  	 (inhibit-read-only t))
> -    (switch-to-buffer buf)
> +    (pop-to-buffer-same-window buf)
>      (erase-buffer)
>      (let ((coding-system-for-read 'no-conversion))
>        (call-process notmuch-command nil t nil "show" "--format=raw" id))
> @@ -2057,7 +2057,7 @@ message."
>  	  (set-buffer-modified-p nil)
>  	  (setq buffer-read-only t)
>  	  (unless (zerop exit-code)
> -	    (switch-to-buffer-other-window buf)
> +	    (pop-to-buffer buf)
>  	    (message (format "Command '%s' exited abnormally with code %d"
>  			     shell-command exit-code))))))))
>  
> @@ -2465,7 +2465,7 @@ If the part is displayed in an external application then close
>  the new buffer."
>    (let ((buf (get-buffer-create (generate-new-buffer-name
>  				 (concat " *notmuch-internal-part*")))))
> -    (switch-to-buffer buf)
> +    (pop-to-buffer-same-window buf)
>      (if (eq (mm-display-part handle) 'external)
>  	(kill-buffer buf)
>        (goto-char (point-min))
> diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el
> index fbba4bb3..f36a6e72 100644
> --- a/emacs/notmuch-tree.el
> +++ b/emacs/notmuch-tree.el
> @@ -543,9 +543,14 @@ NOT change the database."
>        (setq notmuch-tree-message-window
>  	    (split-window-vertically (/ (window-height) 4)))
>        (with-selected-window notmuch-tree-message-window
> -	;; Since we are only displaying one message do not indent.
> -	(let ((notmuch-show-indent-messages-width 0)
> -	      (notmuch-show-only-matching-messages t))
> +	(let (;; Since we are only displaying one message do not indent.
> +	      (notmuch-show-indent-messages-width 0)
> +	      (notmuch-show-only-matching-messages t)
> +	      ;; Ensure that `pop-to-buffer-same-window' uses the
> +	      ;; window we want it to use.
> +	      (display-buffer-overriding-action
> +		 '((display-buffer-same-window)
> +		   (inhibit-same-window . nil))))
>  	  (setq buffer (notmuch-show id))))
>        ;; We need the `let' as notmuch-tree-message-window is buffer local.
>        (let ((window notmuch-tree-message-window))
> @@ -1076,7 +1081,7 @@ The arguments are:
>  						(if unthreaded "unthreaded-" "tree-")
>  						query "*")))))
>  	(inhibit-read-only t))
> -    (switch-to-buffer buffer))
> +    (pop-to-buffer-same-window buffer))
>    ;; Don't track undo information for this buffer
>    (set 'buffer-undo-list t)
>    (notmuch-tree-worker query query-context target open-target unthreaded)
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index babddbb6..4e2ea9eb 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -994,7 +994,7 @@ the configured default sort order."
>  	 (buffer (get-buffer-create (notmuch-search-buffer-title query))))
>      (if no-display
>  	(set-buffer buffer)
> -      (switch-to-buffer buffer))
> +      (pop-to-buffer-same-window buffer))
>      ;; 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
> @@ -1134,7 +1134,7 @@ notmuch buffers exist, run `notmuch'."
>  	;; If the first one we found is any other than the starting
>  	;; buffer, switch to it.
>  	(unless (eq first start)
> -	  (switch-to-buffer first))
> +	  (pop-to-buffer-same-window first))
>        (notmuch))))
>  
>  ;;;; Imenu Support
> -- 
> 2.27.0

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

* Re: [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer
  2020-08-11 16:59 [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer Sean Whitton
  2020-08-15 11:02 ` David Bremner
  2020-08-22  9:04 ` Tomi Ollila
@ 2020-08-22 12:52 ` David Bremner
  2 siblings, 0 replies; 5+ messages in thread
From: David Bremner @ 2020-08-22 12:52 UTC (permalink / raw)
  To: Sean Whitton, notmuch; +Cc: Sean Whitton

Sean Whitton <spwhitton@spwhitton.name> writes:

> This means that notmuch commands obey display-buffer-alist so the user
> can customize how buffers show up.
>

applied to release and master

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

* Re: [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer
  2020-08-22  9:04 ` Tomi Ollila
@ 2020-08-22 14:38   ` Sean Whitton
  0 siblings, 0 replies; 5+ messages in thread
From: Sean Whitton @ 2020-08-22 14:38 UTC (permalink / raw)
  To: Tomi Ollila, notmuch

Hello,

On Sat 22 Aug 2020 at 12:04PM +03, Tomi Ollila wrote:

> On Tue, Aug 11 2020, Sean Whitton wrote:
>
>> This means that notmuch commands obey display-buffer-alist so the user
>> can customize how buffers show up.
>>
>> It also permits the use of C-x 4 4, C-x 5 5 and C-x t t, available in
>> Emacs 28.  For example, one can use C-x 4 4 M-x notmuch-jump-search RET
>> to open a saved search in another window rather than the current window.
>> Or in notmuch-search mode, C-x 5 5 RET to view the message at point in
>> a new frame.
>>
>> notmuch-tree has custom buffer display logic, so bind
>> display-buffer-overriding-action to make pop-to-buffer-same-window
>> behave exactly as switch-to-buffer while that function is running.
>> ---
>> Changes since v1: rebased onto latest master.
>
> I've been having this in my emacs setup (one-notmuch.elc =D) couple
> of days, and haven't seen anything strange.

Thanks both for testing it!

-- 
Sean Whitton

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

end of thread, other threads:[~2020-08-22 14:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-11 16:59 [PATCH v2] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer Sean Whitton
2020-08-15 11:02 ` David Bremner
2020-08-22  9:04 ` Tomi Ollila
2020-08-22 14:38   ` Sean Whitton
2020-08-22 12:52 ` David Bremner

unofficial mirror of notmuch@notmuchmail.org

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://yhetil.org/notmuch/0 notmuch/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 notmuch notmuch/ https://yhetil.org/notmuch \
		notmuch@notmuchmail.org
	public-inbox-index notmuch

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.yhetil.org/yhetil.mail.notmuch.general
	nntp://news.gmane.io/gmane.mail.notmuch.general


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git