From 157bc61d63741133c7ccee719b4f1988c45fd9e5 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 8 Aug 2020 02:59:59 -0400 Subject: [PATCH] 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. --- core/core-ui.el | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/core/core-ui.el b/core/core-ui.el index c2585fe93..169c9b27e 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -244,25 +244,30 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original (message "Can't kill the fallback buffer.") t) ((doom-real-buffer-p buf) - (if (and buffer-file-name - (buffer-modified-p buf) - (not (y-or-n-p - (format "Buffer %s is modified; kill anyway?" buf)))) - (message "Aborted") - (set-buffer-modified-p nil) - (let (buffer-list-update-hook) - (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))) - ;; if we end up back where we start (or previous-buffer - ;; returns nil), we have nowhere left to go - (memq (switch-to-prev-buffer nil t) (list buf 'nil))) - (switch-to-buffer (doom-fallback-buffer))) - (unless (delq (selected-window) (get-buffer-window-list buf nil t)) - (kill-buffer buf))) - (run-hooks 'buffer-list-update-hook)) - t)))) + (let ((visible-p (delq (selected-window) (get-buffer-window-list buf nil t))) + (doom-inhibit-switch-buffer-hooks t) + (inhibit-redisplay t) + buffer-list-update-hook) + (unless visible-p + (when (and (buffer-modified-p buf) + (not (y-or-n-p + (format "Buffer %s is modified; kill anyway?" + buf)))) + (user-error "Aborted"))) + (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))) + ;; if we end up back where we start (or previous-buffer + ;; returns nil), we have nowhere left to go + (memq (switch-to-prev-buffer nil t) (list buf 'nil))) + (switch-to-buffer (doom-fallback-buffer))) + (unless visible-p + (with-current-buffer buf + (restore-buffer-modified-p nil)) + (kill-buffer buf)) + (run-hooks 'buffer-list-update-hook) + t))))) ;;