]> git.eshelyaron.com Git - emacs.git/commitdiff
In 'replace-buffer-in-windows' try to preserve current buffer (Bug#75949)
authorMartin Rudalics <rudalics@gmx.at>
Fri, 31 Jan 2025 08:31:05 +0000 (09:31 +0100)
committerEshel Yaron <me@eshelyaron.com>
Mon, 3 Feb 2025 11:11:35 +0000 (12:11 +0100)
* lisp/window.el (replace-buffer-in-windows): Preserve current
buffer when 'kill-buffer-quit-windows' is non-nil and a window
showing BUFFER shall be quit.  Running 'kill-buffer-hook' relies
on it (Bug#75949).

(cherry picked from commit 4354cf73d7a5bdd18a5e5b385a06d9d140e8e472)

lisp/window.el

index b8798e09f8b3239fde0179a20e3a74cd9aed859b..53e0ddf5e84c96badd888ce9facd4252de945cd5 100644 (file)
@@ -5165,7 +5165,12 @@ buffer by itself."
        (cond
         ((window-minibuffer-p window))
         (kill-buffer-quit-windows
-         (quit-restore-window window 'killing))
+         ;; Try to preserve the current buffer set up by 'kill-buffer'
+         ;; before running the hooks on 'kill-buffer-hook' (Bug#75949).
+         (let ((current-buffer (current-buffer)))
+           (quit-restore-window window 'killing)
+           (when (buffer-live-p current-buffer)
+             (set-buffer current-buffer))))
         (t
          (let ((dedicated-side (eq (window-dedicated-p window) 'side)))
             (when (or dedicated-side (not (window--delete window t 'kill)))