fix: kill-current-buffer: respect kill-buffer-query-functions

This advice is intended to fake the death of buffers that are visible in
other windows, and prevent Emacs from switching to a non-real buffer
after it's killed/buried. It shouldn't even try to do any of this if
`kill-buffer-query-functions` fails, even if it is a fake death.
This commit is contained in:
Henrik Lissner 2024-07-11 15:22:12 -04:00
parent 3965df56e8
commit 12dc195774
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -212,7 +212,8 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
(cond ((eq buf (doom-fallback-buffer))
(message "Can't kill the fallback buffer.")
t)
((doom-real-buffer-p buf)
((and (doom-real-buffer-p buf)
(run-hook-with-args-until-failure 'kill-buffer-query-functions))
(let ((visible-p (delq (selected-window) (get-buffer-window-list buf nil t))))
(unless visible-p
(when (and (buffer-modified-p buf)
@ -221,8 +222,10 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
buf))))
(user-error "Aborted")))
(let ((inhibit-redisplay t)
buffer-list-update-hook)
(when (or ;; if there aren't more real buffers than visible buffers,
buffer-list-update-hook
kill-buffer-query-functions)
(when (or
;; if there aren't more real buffers than visible buffers,
;; then there are no real, non-visible buffers left.
(not (cl-set-difference (doom-real-buffer-list)
(doom-visible-buffers nil t)))