doom-kill-buffer: extract protect-visible-buffers logic

Protecting buffers that were visible in other windows (burying them
instead) is not the responsibility of doom-kill-buffer. This is a job
for kill-buffer-query-functions, hence doom|protect-visible-buffers.
This commit is contained in:
Henrik Lissner 2017-12-28 21:43:48 -05:00
parent ca56d08dd9
commit 60e8f6297e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
2 changed files with 11 additions and 8 deletions

View file

@ -179,11 +179,9 @@ DONT-SAVE is non-nil.
See `doom-real-buffer-p' for what 'real' means."
(setq buffer (or buffer (current-buffer)))
(when (and (bufferp buffer) (buffer-live-p buffer))
(let ((buffer-win (get-buffer-window buffer))
(only-buffer-window-p (= 1 (length (get-buffer-window-list buffer nil t)))))
(let ((buffer-win (get-buffer-window buffer)))
;; deal with unsaved buffers
(when (and only-buffer-window-p
(buffer-file-name buffer)
(when (and (buffer-file-name buffer)
(buffer-modified-p buffer))
(with-current-buffer buffer
(if (and (not dont-save)
@ -201,10 +199,9 @@ See `doom-real-buffer-p' for what 'real' means."
(doom--cycle-real-buffers -1)
(when buffer-win
(unrecord-window-buffer buffer-win buffer))
(when only-buffer-window-p
(kill-buffer buffer)))
(not (eq (current-buffer) buffer)))
(kill-buffer buffer)))))
(kill-buffer buffer)))
(kill-buffer buffer)))
(not (eq (current-buffer) buffer))))
;;;###autoload
(defun doom-force-kill-buffer (&optional buffer dont-save)

View file

@ -228,6 +228,12 @@ local value, whether or not it's permanent-local. Therefore, we cycle
(add-hook! '(doom-post-init-hook minibuffer-setup-hook)
#'doom|no-fringes-in-minibuffer)
(defun doom|protect-visible-buffers ()
"Don't kill the current buffer if it is visible in another window (bury it
instead)."
(not (and after-init-time (get-buffer-window-list nil t))))
(add-hook 'kill-buffer-query-functions #'doom|protect-visible-buffers)
;;
;; Plugins