emacs: Improve the behaviour of the 'q' binding.

When a user hits 'q' in a notmuch buffer, kill the buffer only if
there are no other windows currently showing it.
This commit is contained in:
David Edmondson 2014-10-29 14:18:49 +00:00 committed by David Bremner
parent 0f35ddcdfc
commit 30f1c43efe
4 changed files with 13 additions and 8 deletions

View file

@ -135,7 +135,7 @@ For example, if you wanted to remove an \"inbox\" tag and add an
(defvar notmuch-common-keymap (defvar notmuch-common-keymap
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(define-key map "?" 'notmuch-help) (define-key map "?" 'notmuch-help)
(define-key map "q" 'notmuch-kill-this-buffer) (define-key map "q" 'notmuch-bury-or-kill-this-buffer)
(define-key map "s" 'notmuch-search) (define-key map "s" 'notmuch-search)
(define-key map "z" 'notmuch-tree) (define-key map "z" 'notmuch-tree)
(define-key map "m" 'notmuch-mua-new-mail) (define-key map "m" 'notmuch-mua-new-mail)
@ -239,10 +239,15 @@ depending on the value of `notmuch-poll-script'."
(call-process notmuch-poll-script nil nil)) (call-process notmuch-poll-script nil nil))
(call-process notmuch-command nil nil nil "new"))) (call-process notmuch-command nil nil nil "new")))
(defun notmuch-kill-this-buffer () (defun notmuch-bury-or-kill-this-buffer ()
"Kill the current buffer." "Undisplay the current buffer.
Bury the current buffer, unless there is only one window showing
it, in which case it is killed."
(interactive) (interactive)
(kill-buffer (current-buffer))) (if (> (length (get-buffer-window-list nil nil t)) 1)
(bury-buffer)
(kill-buffer)))
(defun notmuch-documentation-first-line (symbol) (defun notmuch-documentation-first-line (symbol)
"Return the first line of the documentation string for SYMBOL." "Return the first line of the documentation string for SYMBOL."

View file

@ -1956,7 +1956,7 @@ buffer. If PREVIOUS is non-nil, move to the previous item in the
search results instead." search results instead."
(interactive "P") (interactive "P")
(let ((parent-buffer notmuch-show-parent-buffer)) (let ((parent-buffer notmuch-show-parent-buffer))
(notmuch-kill-this-buffer) (notmuch-bury-or-kill-this-buffer)
(when (buffer-live-p parent-buffer) (when (buffer-live-p parent-buffer)
(switch-to-buffer parent-buffer) (switch-to-buffer parent-buffer)
(and (if previous (and (if previous

View file

@ -234,7 +234,7 @@ FUNC."
;; Override because we want to close message pane first. ;; Override because we want to close message pane first.
(define-key map [remap notmuch-help] (notmuch-tree-close-message-pane-and #'notmuch-help)) (define-key map [remap notmuch-help] (notmuch-tree-close-message-pane-and #'notmuch-help))
;; Override because we first close message pane and then close tree buffer. ;; Override because we first close message pane and then close tree buffer.
(define-key map [remap notmuch-kill-this-buffer] 'notmuch-tree-quit) (define-key map [remap notmuch-bury-or-kill-this-buffer] 'notmuch-tree-quit)
;; Override because we close message pane after the search query is entered. ;; Override because we close message pane after the search query is entered.
(define-key map [remap notmuch-search] 'notmuch-tree-to-search) (define-key map [remap notmuch-search] 'notmuch-tree-to-search)
;; Override because we want to close message pane first. ;; Override because we want to close message pane first.

View file

@ -153,7 +153,7 @@ there will be called at other points of notmuch execution."
(defvar notmuch-search-mode-map (defvar notmuch-search-mode-map
(let ((map (make-sparse-keymap))) (let ((map (make-sparse-keymap)))
(set-keymap-parent map notmuch-common-keymap) (set-keymap-parent map notmuch-common-keymap)
(define-key map "x" 'notmuch-kill-this-buffer) (define-key map "x" 'notmuch-bury-or-kill-this-buffer)
(define-key map (kbd "<DEL>") 'notmuch-search-scroll-down) (define-key map (kbd "<DEL>") 'notmuch-search-scroll-down)
(define-key map "b" 'notmuch-search-scroll-down) (define-key map "b" 'notmuch-search-scroll-down)
(define-key map " " 'notmuch-search-scroll-up) (define-key map " " 'notmuch-search-scroll-up)
@ -961,7 +961,7 @@ same relative position within the new buffer."
(oldest-first notmuch-search-oldest-first) (oldest-first notmuch-search-oldest-first)
(target-thread (notmuch-search-find-thread-id 'bare)) (target-thread (notmuch-search-find-thread-id 'bare))
(query notmuch-search-query-string)) (query notmuch-search-query-string))
(notmuch-kill-this-buffer) (notmuch-bury-or-kill-this-buffer)
(notmuch-search query oldest-first target-thread target-line) (notmuch-search query oldest-first target-thread target-line)
(goto-char (point-min)))) (goto-char (point-min))))