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:
parent
61376a2ca0
commit
195ad0fec6
2 changed files with 24 additions and 11 deletions
|
@ -130,17 +130,27 @@ modified."
|
|||
|
||||
;;;###autoload
|
||||
(defun +magit/quit (&optional kill-buffer)
|
||||
"Clean up magit buffers after quitting `magit-status' and refresh version
|
||||
control in buffers."
|
||||
"Bury the current magit buffer.
|
||||
|
||||
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")
|
||||
(let ((topdir (magit-toplevel)))
|
||||
(funcall magit-bury-buffer-function kill-buffer)
|
||||
(unless (delq nil
|
||||
(mapcar (lambda (win)
|
||||
(or (cl-find-if (lambda (win)
|
||||
(with-selected-window win
|
||||
(eq major-mode 'magit-status-mode)))
|
||||
(window-list)))
|
||||
(and (derived-mode-p 'magit-mode)
|
||||
(equal magit--default-directory topdir))))
|
||||
(window-list))
|
||||
(+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)))
|
||||
(+magit-mark-stale-buffers-h))
|
||||
|
||||
(defun +magit--kill-buffer (buf)
|
||||
"TODO"
|
||||
|
|
|
@ -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
|
||||
;; 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
|
||||
(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
|
||||
;; modules from the blacklist.
|
||||
(map! (:map magit-mode-map
|
||||
:nv "q" #'+magit/quit
|
||||
:nv "Q" #'+magit/quit-all
|
||||
:nv "]" #'magit-section-forward-sibling
|
||||
:nv "[" #'magit-section-backward-sibling
|
||||
:nv "gr" #'magit-refresh
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue