mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
tools/magit: clean up after magit more intelligently #506
Ensures magit buffers are cleaned up after magit-status is closed. Will defer cleanup on process buffers, until the processes have finished. Also fixes issue where quitting magit will leave leftover windows.
This commit is contained in:
@ -2,9 +2,21 @@
|
||||
|
||||
;;;###autoload
|
||||
(defun +magit/quit (&optional _kill-buffer)
|
||||
"TODO"
|
||||
"Clean up magit buffers after quitting `magit-status'."
|
||||
(interactive)
|
||||
(magit-restore-window-configuration)
|
||||
(cl-loop for buf in (doom-buffers-in-mode 'magit-mode (buffer-list) t)
|
||||
unless (eq (buffer-local-value 'major-mode buf) 'magit-process-mode)
|
||||
do (kill-buffer buf)))
|
||||
(let ((buffers (magit-mode-get-buffers)))
|
||||
(magit-restore-window-configuration)
|
||||
(mapc #'+magit--kill-buffer buffers)))
|
||||
|
||||
(defun +magit--kill-buffer (buf)
|
||||
"TODO"
|
||||
(when (and (bufferp buf) (buffer-live-p buf))
|
||||
(let ((process (get-buffer-process buf)))
|
||||
(if (not (processp process))
|
||||
(kill-buffer buf)
|
||||
(with-current-buffer buf
|
||||
(if (process-live-p process)
|
||||
(run-with-timer 5 nil #'+magit--kill buf)
|
||||
(kill-process process)
|
||||
(kill-buffer buf)))))))
|
||||
|
||||
|
Reference in New Issue
Block a user