From: Kiso Katsuyuki <katsuyuki2388@gmail.com> When kill and exit from a notmuch mode buffer (notmuch-show-mode, notmuch-tree-mode, notmuch-search-mode, notmuch-hello-mode, notmuch-message-mode), return to the previous notmuch mode buffer. It's because the previous notmuch buffer is often buried and I have to select it with a buffer-switching command. --- emacs/notmuch-draft.el | 6 ++++-- emacs/notmuch-lib.el | 17 +++++++++++++++-- emacs/notmuch-mua.el | 7 +++++-- emacs/notmuch-tree.el | 6 ++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/emacs/notmuch-draft.el b/emacs/notmuch-draft.el index fb7f4f55..8717f317 100644 --- a/emacs/notmuch-draft.el +++ b/emacs/notmuch-draft.el @@ -214,10 +214,12 @@ applied to newly inserted messages)." (set-buffer-modified-p nil))) (defun notmuch-draft-postpone () - "Save the draft message in the notmuch database and exit buffer." + "Save the draft message in the notmuch database, exit buffer, +and select the previous notmuch buffer." (interactive) (notmuch-draft-save) - (kill-buffer)) + (kill-buffer) + (notmuch-select-previous-notmuch-buffer)) (defun notmuch-draft-resume (id) "Resume editing of message with id ID." diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el index 337b20ac..0371c23f 100644 --- a/emacs/notmuch-lib.el +++ b/emacs/notmuch-lib.el @@ -260,15 +260,28 @@ depending on the value of `notmuch-poll-script'." (error "Notmuch: poll script `%s' failed!" notmuch-poll-script))) (notmuch-call-notmuch-process "new"))) +(defun notmuch-select-previous-notmuch-buffer () + "Select the previous notmuch buffer." + (catch 'get-notmuch-buffer + (dolist (buffer (buffer-list)) + (let ((buffer-mode (buffer-local-value 'major-mode buffer))) + (when (memq buffer-mode '(notmuch-show-mode + notmuch-tree-mode + notmuch-search-mode + notmuch-hello-mode + notmuch-message-mode)) + (throw 'get-notmuch-buffer (switch-to-buffer buffer))))))) + (defun notmuch-bury-or-kill-this-buffer () "Undisplay the current buffer. Bury the current buffer, unless there is only one window showing -it, in which case it is killed." +it, in which case it is killed. Then, select the previous notmuch buffer." (interactive) (if (> (length (get-buffer-window-list nil nil t)) 1) (bury-buffer) - (kill-buffer))) + (kill-buffer)) + (notmuch-select-previous-notmuch-buffer)) (defun notmuch-documentation-first-line (symbol) "Return the first line of the documentation string for SYMBOL." diff --git a/emacs/notmuch-mua.el b/emacs/notmuch-mua.el index 93747b1c..c1d533f7 100644 --- a/emacs/notmuch-mua.el +++ b/emacs/notmuch-mua.el @@ -292,6 +292,7 @@ mutiple parts get a header." (define-key notmuch-message-mode-map (kbd "C-c C-c") #'notmuch-mua-send-and-exit) (define-key notmuch-message-mode-map (kbd "C-c C-s") #'notmuch-mua-send) +(define-key notmuch-message-mode-map (kbd "C-c C-k") #'notmuch-mua-kill-buffer) (define-key notmuch-message-mode-map (kbd "C-c C-p") #'notmuch-draft-postpone) (define-key notmuch-message-mode-map (kbd "C-x C-s") #'notmuch-draft-save) @@ -552,7 +553,8 @@ unencrypted. Really send? ")))) (defun notmuch-mua-send-and-exit (&optional arg) (interactive "P") - (notmuch-mua-send-common arg 't)) + (notmuch-mua-send-common arg 't) + (notmuch-select-previous-notmuch-buffer)) (defun notmuch-mua-send (&optional arg) (interactive "P") @@ -560,7 +562,8 @@ unencrypted. Really send? ")))) (defun notmuch-mua-kill-buffer () (interactive) - (message-kill-buffer)) + (message-kill-buffer) + (notmuch-select-previous-notmuch-buffer)) (defun notmuch-mua-message-send-hook () "The default function used for `notmuch-mua-send-hook', this diff --git a/emacs/notmuch-tree.el b/emacs/notmuch-tree.el index d4d40761..64706397 100644 --- a/emacs/notmuch-tree.el +++ b/emacs/notmuch-tree.el @@ -531,10 +531,12 @@ Shows in split pane or whole window according to value of (notmuch-tree-next-matching-message))) (defun notmuch-tree-quit () - "Close the split view or exit tree." + "Close the split view or exit tree. When exit from tree, select the +previous notmuch buffer" (interactive) (unless (notmuch-tree-close-message-window) - (kill-buffer (current-buffer)))) + (kill-buffer (current-buffer)) + (notmuch-select-previous-notmuch-buffer))) (defun notmuch-tree-close-message-window () "Close the message-window. Return t if close succeeds." -- 2.12.2