diff --git a/core/autoload/buffers.el b/core/autoload/buffers.el index ea9f472f4..ce4a05866 100644 --- a/core/autoload/buffers.el +++ b/core/autoload/buffers.el @@ -150,32 +150,6 @@ If DERIVED-P, test with `derived-mode-p', otherwise use `eq'." when (string-match-p pattern (buffer-name buf)) collect buf)) -(defun doom--cycle-real-buffers (n) - "Switch to the next buffer N times (previous, if N < 0), skipping over unreal -buffers. If there's nothing left, switch to `doom-fallback-buffer'. See -`doom-real-buffer-p' for what 'real' means." - (if (null n) - (switch-to-buffer (doom-fallback-buffer) nil t) - (let ((buffers (delq (current-buffer) (doom-real-buffer-list)))) - (cond ((or (not buffers) - (zerop (% n (1+ (length buffers))))) - (switch-to-buffer (doom-fallback-buffer) nil t)) - ((= (length buffers) 1) - (switch-to-buffer (car buffers) nil t)) - (t - ;; Why this instead of switching straight to the Nth buffer in - ;; BUFFERS? Because `switch-to-next-buffer' and - ;; `switch-to-prev-buffer' properly update buffer list order. - (cl-loop with move-func = - (if (> n 0) #'switch-to-next-buffer #'switch-to-prev-buffer) - for i to 20 - while (not (memq (current-buffer) buffers)) - do - (dotimes (_i (abs n)) - (funcall move-func))))))) - (force-mode-line-update) - (current-buffer)) - ;;;###autoload (defun doom-set-buffer-real (buffer flag) "Forcibly mark BUFFER as FLAG (non-nil = real)." diff --git a/core/core-ui.el b/core/core-ui.el index 906f3ddf0..c1767576d 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -540,16 +540,20 @@ instead)." (not (eq (current-buffer) (doom-fallback-buffer)))) (defun doom*switch-to-fallback-buffer-maybe (orig-fn) - "Advice for `kill-this-buffer'. If there are no real buffers left, switch to -`doom-fallback-buffer'." + "Advice for `kill-this-buffer'. If in a dedicated window, delete it. If there +are no real buffers left, switch to `doom-fallback-buffer'. Otherwise, delegate +to original `kill-this-buffer'." (let ((buf (current-buffer))) (cond ((window-dedicated-p) (delete-window)) ((doom-real-buffer-p buf) - (previous-buffer) - (doom--cycle-real-buffers - (if (delq buf (doom-real-buffer-list)) -1)) - (kill-buffer buf)) + (or (kill-buffer buf) + (previous-buffer)) + ;; if there are no (real) buffers left to switch to, land on the + ;; fallback buffer. + (unless (cl-set-difference (doom-real-buffer-list) + (doom-visible-buffers)) + (switch-to-buffer (doom-fallback-buffer)))) (t (funcall orig-fn))))) diff --git a/core/test/autoload-buffers.el b/core/test/autoload-buffers.el index 389231195..49f27c113 100644 --- a/core/test/autoload-buffers.el +++ b/core/test/autoload-buffers.el @@ -109,27 +109,6 @@ (should (buffer-live-p fallback)) (should (equal (buffer-name fallback) doom-fallback-buffer-name)))) -;; `doom--cycle-real-buffers' -(def-test! kill-buffer-then-show-real-buffer - (with-temp-buffers!! (a b c d) - (let-advice!! ((kill-this-buffer :around doom*switch-to-fallback-buffer-maybe)) - (dolist (buf (list a b d)) - (with-current-buffer buf - (setq-local buffer-file-name "x"))) - (should (cl-every #'buffer-live-p (buffer-list))) - (switch-to-buffer a) - (should (eq (current-buffer) a)) - (should (eq (selected-window) (get-buffer-window a))) - (kill-this-buffer) - (should-not (eq (current-buffer) a)) - (should-not (buffer-live-p a)) - ;; eventually end up in the fallback buffer - (let ((fallback (doom-fallback-buffer))) - (while (not (eq (current-buffer) fallback)) - (should (doom-real-buffer-p)) - (kill-this-buffer)) - (should (eq (current-buffer) fallback)))))) - ;; `doom-kill-buffer-and-windows' (def-test! kill-buffer-and-windows (with-temp-buffers!! (a b)