From 0a681590268a4039f95a5a919b6b6d4f4e880d4c Mon Sep 17 00:00:00 2001 From: pillule Date: Sat, 15 May 2021 10:47:07 +0200 Subject: [PATCH] Fix `quit-restore-window' when all previous buffers got killed (Bug#48367) * lisp/window.el (quit-restore-window): Simplify calculation of WINDOW's previous buffer. Avoid that killing WINDOW's previous buffers results in a state where `quit-window' has no more effect, by simply deleting WINDOW in that case (Bug#48367). Copyright-paperwork-exempt: yes --- lisp/window.el | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lisp/window.el b/lisp/window.el index 8928308eb26..026cde5901c 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5036,14 +5036,10 @@ nil means to not handle the buffer in a particular way. This (setq window (window-normalize-window window t)) (let* ((buffer (window-buffer window)) (quit-restore (window-parameter window 'quit-restore)) - (prev-buffer - (let* ((prev-buffers (window-prev-buffers window)) - (prev-buffer (caar prev-buffers))) - (and (or (not (eq prev-buffer buffer)) - (and (cdr prev-buffers) - (not (eq (setq prev-buffer (cadr prev-buffers)) - buffer)))) - prev-buffer))) + (prev-buffer (catch 'prev-buffer + (dolist (buf (window-prev-buffers window)) + (unless (eq (car buf) buffer) + (throw 'prev-buffer (car buf)))))) quad entry) (cond ((and (not prev-buffer) @@ -5114,7 +5110,10 @@ nil means to not handle the buffer in a particular way. This (set-window-parameter window 'quit-restore nil) ;; Make sure that WINDOW is no more dedicated. (set-window-dedicated-p window nil) - (switch-to-prev-buffer window bury-or-kill))) + (if prev-buffer + (switch-to-prev-buffer window bury-or-kill) + ;; Delete WINDOW if there is no previous buffer (Bug#48367). + (window--delete window nil (eq bury-or-kill 'kill))))) ;; Deal with the buffer. (cond -- 2.39.5