emacs: Use pop-to-buffer-same-window rather than switch-to-buffer

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.
This commit is contained in:
Sean Whitton 2020-08-11 09:59:13 -07:00 committed by David Bremner
parent d7732b2b6a
commit 88ae4f0251
5 changed files with 18 additions and 12 deletions

View file

@ -232,7 +232,8 @@ applied to newly inserted messages)."
(draft (equal tags (notmuch-update-tags tags notmuch-draft-tags)))) (draft (equal tags (notmuch-update-tags tags notmuch-draft-tags))))
(when (or draft (when (or draft
(yes-or-no-p "Message does not appear to be a draft: edit as new? ")) (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) (setq buffer-read-only nil)
(erase-buffer) (erase-buffer)
(let ((coding-system-for-read 'no-conversion)) (let ((coding-system-for-read 'no-conversion))

View file

@ -973,7 +973,7 @@ following:
(let ((notmuch-hello-auto-refresh nil)) (let ((notmuch-hello-auto-refresh nil))
(if no-display (if no-display
(set-buffer "*notmuch-hello*") (set-buffer "*notmuch-hello*")
(switch-to-buffer "*notmuch-hello*"))) (pop-to-buffer-same-window "*notmuch-hello*")))
;; Install auto-refresh hook ;; Install auto-refresh hook
(when notmuch-hello-auto-refresh (when notmuch-hello-auto-refresh
(add-hook 'window-configuration-change-hook (add-hook 'window-configuration-change-hook

View file

@ -1244,7 +1244,7 @@ matched."
(eval (car (get 'mm-inline-override-types 'standard-value)))) (eval (car (get 'mm-inline-override-types 'standard-value))))
(cons "application/*" mm-inline-override-types) (cons "application/*" mm-inline-override-types)
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. ;; No need to track undo information for this buffer.
(setq buffer-undo-list t) (setq buffer-undo-list t)
(notmuch-show-mode) (notmuch-show-mode)
@ -2001,7 +2001,7 @@ to show, nil otherwise."
(let* ((id (notmuch-show-get-message-id)) (let* ((id (notmuch-show-get-message-id))
(buf (get-buffer-create (concat "*notmuch-raw-" id "*"))) (buf (get-buffer-create (concat "*notmuch-raw-" id "*")))
(inhibit-read-only t)) (inhibit-read-only t))
(switch-to-buffer buf) (pop-to-buffer-same-window buf)
(erase-buffer) (erase-buffer)
(let ((coding-system-for-read 'no-conversion)) (let ((coding-system-for-read 'no-conversion))
(call-process notmuch-command nil t nil "show" "--format=raw" id)) (call-process notmuch-command nil t nil "show" "--format=raw" id))
@ -2060,7 +2060,7 @@ message."
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(setq buffer-read-only t) (setq buffer-read-only t)
(unless (zerop exit-code) (unless (zerop exit-code)
(switch-to-buffer-other-window buf) (pop-to-buffer buf)
(message (format "Command '%s' exited abnormally with code %d" (message (format "Command '%s' exited abnormally with code %d"
shell-command exit-code)))))))) shell-command exit-code))))))))
@ -2468,7 +2468,7 @@ If the part is displayed in an external application then close
the new buffer." the new buffer."
(let ((buf (get-buffer-create (generate-new-buffer-name (let ((buf (get-buffer-create (generate-new-buffer-name
(concat " *notmuch-internal-part*"))))) (concat " *notmuch-internal-part*")))))
(switch-to-buffer buf) (pop-to-buffer-same-window buf)
(if (eq (mm-display-part handle) 'external) (if (eq (mm-display-part handle) 'external)
(kill-buffer buf) (kill-buffer buf)
(goto-char (point-min)) (goto-char (point-min))

View file

@ -552,9 +552,14 @@ NOT change the database."
(setq notmuch-tree-message-window (setq notmuch-tree-message-window
(split-window-vertically (/ (window-height) 4))) (split-window-vertically (/ (window-height) 4)))
(with-selected-window notmuch-tree-message-window (with-selected-window notmuch-tree-message-window
;; Since we are only displaying one message do not indent. (let (;; Since we are only displaying one message do not indent.
(let ((notmuch-show-indent-messages-width 0) (notmuch-show-indent-messages-width 0)
(notmuch-show-only-matching-messages t)) (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)))) (setq buffer (notmuch-show id))))
;; We need the `let' as notmuch-tree-message-window is buffer local. ;; We need the `let' as notmuch-tree-message-window is buffer local.
(let ((window notmuch-tree-message-window)) (let ((window notmuch-tree-message-window))
@ -1119,7 +1124,7 @@ The arguments are:
(if unthreaded "unthreaded-" "tree-") (if unthreaded "unthreaded-" "tree-")
query "*"))))) query "*")))))
(inhibit-read-only t)) (inhibit-read-only t))
(switch-to-buffer buffer)) (pop-to-buffer-same-window buffer))
;; Don't track undo information for this buffer ;; Don't track undo information for this buffer
(set 'buffer-undo-list t) (set 'buffer-undo-list t)
(notmuch-tree-worker query query-context target open-target unthreaded) (notmuch-tree-worker query query-context target open-target unthreaded)

View file

@ -994,7 +994,7 @@ the configured default sort order."
(buffer (get-buffer-create (notmuch-search-buffer-title query)))) (buffer (get-buffer-create (notmuch-search-buffer-title query))))
(if no-display (if no-display
(set-buffer buffer) (set-buffer buffer)
(switch-to-buffer buffer)) (pop-to-buffer-same-window buffer))
;; avoid wiping out third party buffer-local variables in the case ;; avoid wiping out third party buffer-local variables in the case
;; where we're just refreshing or changing the sort order of an ;; where we're just refreshing or changing the sort order of an
;; existing search results buffer ;; 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 ;; If the first one we found is any other than the starting
;; buffer, switch to it. ;; buffer, switch to it.
(unless (eq first start) (unless (eq first start)
(switch-to-buffer first)) (pop-to-buffer-same-window first))
(notmuch)))) (notmuch))))
;;;; Imenu Support ;;;; Imenu Support