From 2d758e73ebd74705484017137f1c255735cac00b Mon Sep 17 00:00:00 2001 From: Martin Rudalics Date: Wed, 21 Jan 2026 11:14:36 +0100 Subject: [PATCH] Fix thinko in 'quit-restore-window' * lisp/window.el (quit-restore-window): Try to restore the previously selected window only if WINDOW is either the selected window or BURY-OR-KILL is neither 'burying' nor 'killing'. Otherwise, this might deliberately change the selected window, for example, when 'kill-buffer-quit-windows' is non-nil and WINDOW shows the buffer to kill. --- lisp/window.el | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lisp/window.el b/lisp/window.el index b6c6c34983e..98722e909a6 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5502,8 +5502,13 @@ elsewhere. This value is used by `quit-windows-on'." ;; If quit-restore-prev was not used, reset the quit-restore ;; parameter (set-window-parameter window 'quit-restore nil)) - ;; If the previously selected window is still alive, select it. - (window--quit-restore-select-window quit-restore-2)) + ;; If WINDOW is the selected window and the previously selected + ;; window is still alive, try to select that window. But do that + ;; only if WINDOW is either the selected window or we are neither + ;; "burying" nor "killing". + (unless (and (not (eq window (selected-window))) + (memq bury-or-kill '(killing burying))) + (window--quit-restore-select-window quit-restore-2))) (t ;; Show some other buffer in WINDOW and leave the ;; quit-restore(-prev) parameters alone (Juri's idea).