* [PATCH] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer
@ 2020-08-07 22:05 Sean Whitton
0 siblings, 0 replies; only message in thread
From: Sean Whitton @ 2020-08-07 22:05 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.
---
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 27abc7d9..3a9750e1 100644
--- a/emacs/notmuch-draft.el
+++ b/emacs/notmuch-draft.el
@@ -228,7 +228,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 0ff5aaff..3b4ed2b7 100644
--- a/emacs/notmuch-hello.el
+++ b/emacs/notmuch-hello.el
@@ -967,7 +967,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
diff --git a/emacs/notmuch-show.el b/emacs/notmuch-show.el
index c9170466..4ee34f8e 100644
--- a/emacs/notmuch-show.el
+++ b/emacs/notmuch-show.el
@@ -1270,7 +1270,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)
@@ -2039,7 +2039,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))
@@ -2095,7 +2095,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))))))))
@@ -2503,7 +2503,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 ab90f652..7ed06ffd 100644
--- a/emacs/notmuch-tree.el
+++ b/emacs/notmuch-tree.el
@@ -527,9 +527,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))
@@ -1061,7 +1066,7 @@ The arguments are:
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)
diff --git a/emacs/notmuch.el b/emacs/notmuch.el
index c97997fe..c76861c7 100644
--- a/emacs/notmuch.el
+++ b/emacs/notmuch.el
@@ -986,7 +986,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
@@ -1126,7 +1126,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 related [flat|nested] only message in thread
only message in thread, other threads:[~2020-08-07 22:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 22:05 [PATCH] emacs: Use pop-to-buffer-same-window rather than switch-to-buffer Sean Whitton
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).