Fix #5003: rethink +magit/quit

Changes +magit/quit to behave more like canonical
magit-mode-bury-buffer, but after burying/killing the last magit buffer
for the current repo, kill all the other buried ones too.

Also binds Q in magit to kill all magit buffers for the current repo.
This commit is contained in:
Henrik Lissner 2021-05-07 14:10:52 -04:00
parent 61376a2ca0
commit 195ad0fec6
2 changed files with 24 additions and 11 deletions

View file

@ -130,17 +130,27 @@ modified."
;;;###autoload ;;;###autoload
(defun +magit/quit (&optional kill-buffer) (defun +magit/quit (&optional kill-buffer)
"Clean up magit buffers after quitting `magit-status' and refresh version "Bury the current magit buffer.
control in buffers."
If KILL-BUFFER, kill this buffer instead of burying it.
If the buried/killed magit buffer was the last magit buffer open for this repo,
kill all magit buffers for this repo."
(interactive "P") (interactive "P")
(funcall magit-bury-buffer-function kill-buffer) (let ((topdir (magit-toplevel)))
(unless (delq nil (funcall magit-bury-buffer-function kill-buffer)
(mapcar (lambda (win) (or (cl-find-if (lambda (win)
(with-selected-window win (with-selected-window win
(eq major-mode 'magit-status-mode))) (and (derived-mode-p 'magit-mode)
(window-list))) (equal magit--default-directory topdir))))
(mapc #'+magit--kill-buffer (magit-mode-get-buffers)) (window-list))
(+magit-mark-stale-buffers-h))) (+magit/quit-all))))
;;;###autoload
(defun +magit/quit-all ()
"Kill all magit buffers for the current repository."
(interactive)
(mapc #'+magit--kill-buffer (magit-mode-get-buffers))
(+magit-mark-stale-buffers-h))
(defun +magit--kill-buffer (buf) (defun +magit--kill-buffer (buf)
"TODO" "TODO"

View file

@ -100,7 +100,8 @@ For example, diffs and log buffers. Accepts `left', `right', `up', and `down'.")
;; Clean up after magit by killing leftover magit buffers and reverting ;; Clean up after magit by killing leftover magit buffers and reverting
;; affected buffers (or at least marking them as need-to-be-reverted). ;; affected buffers (or at least marking them as need-to-be-reverted).
(define-key magit-status-mode-map [remap magit-mode-bury-buffer] #'+magit/quit) (define-key magit-mode-map "q" #'+magit/quit)
(define-key magit-mode-map "Q" #'+magit/quit-all)
;; Close transient with ESC ;; Close transient with ESC
(define-key transient-map [escape] #'transient-quit-one) (define-key transient-map [escape] #'transient-quit-one)
@ -216,6 +217,8 @@ ensure it is built when we actually use Forge."
;; REVIEW There must be a better way to exclude particular evil-collection ;; REVIEW There must be a better way to exclude particular evil-collection
;; modules from the blacklist. ;; modules from the blacklist.
(map! (:map magit-mode-map (map! (:map magit-mode-map
:nv "q" #'+magit/quit
:nv "Q" #'+magit/quit-all
:nv "]" #'magit-section-forward-sibling :nv "]" #'magit-section-forward-sibling
:nv "[" #'magit-section-backward-sibling :nv "[" #'magit-section-backward-sibling
:nv "gr" #'magit-refresh :nv "gr" #'magit-refresh