Fix kill-current-buffer prompting to save survivor buffers
This advice doesn't kill (real) buffers if they're visible in another window, but would prompt you about unsaved buffers even if it wasn't destined to be killed. Now it only prompts you if the buffer will be killed.
This commit is contained in:
parent
e54bbb7d1e
commit
157bc61d63
1 changed files with 24 additions and 19 deletions
|
@ -244,25 +244,30 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original
|
||||||
(message "Can't kill the fallback buffer.")
|
(message "Can't kill the fallback buffer.")
|
||||||
t)
|
t)
|
||||||
((doom-real-buffer-p buf)
|
((doom-real-buffer-p buf)
|
||||||
(if (and buffer-file-name
|
(let ((visible-p (delq (selected-window) (get-buffer-window-list buf nil t)))
|
||||||
(buffer-modified-p buf)
|
(doom-inhibit-switch-buffer-hooks t)
|
||||||
(not (y-or-n-p
|
(inhibit-redisplay t)
|
||||||
(format "Buffer %s is modified; kill anyway?" buf))))
|
buffer-list-update-hook)
|
||||||
(message "Aborted")
|
(unless visible-p
|
||||||
(set-buffer-modified-p nil)
|
(when (and (buffer-modified-p buf)
|
||||||
(let (buffer-list-update-hook)
|
(not (y-or-n-p
|
||||||
(when (or ;; if there aren't more real buffers than visible buffers,
|
(format "Buffer %s is modified; kill anyway?"
|
||||||
;; then there are no real, non-visible buffers left.
|
buf))))
|
||||||
(not (cl-set-difference (doom-real-buffer-list)
|
(user-error "Aborted")))
|
||||||
(doom-visible-buffers)))
|
(when (or ;; if there aren't more real buffers than visible buffers,
|
||||||
;; if we end up back where we start (or previous-buffer
|
;; then there are no real, non-visible buffers left.
|
||||||
;; returns nil), we have nowhere left to go
|
(not (cl-set-difference (doom-real-buffer-list)
|
||||||
(memq (switch-to-prev-buffer nil t) (list buf 'nil)))
|
(doom-visible-buffers)))
|
||||||
(switch-to-buffer (doom-fallback-buffer)))
|
;; if we end up back where we start (or previous-buffer
|
||||||
(unless (delq (selected-window) (get-buffer-window-list buf nil t))
|
;; returns nil), we have nowhere left to go
|
||||||
(kill-buffer buf)))
|
(memq (switch-to-prev-buffer nil t) (list buf 'nil)))
|
||||||
(run-hooks 'buffer-list-update-hook))
|
(switch-to-buffer (doom-fallback-buffer)))
|
||||||
t))))
|
(unless visible-p
|
||||||
|
(with-current-buffer buf
|
||||||
|
(restore-buffer-modified-p nil))
|
||||||
|
(kill-buffer buf))
|
||||||
|
(run-hooks 'buffer-list-update-hook)
|
||||||
|
t)))))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue