diff --git a/lisp/window.el b/lisp/window.el index a6cdd4dec2..8651d7502f 100644 --- a/lisp/window.el +++ b/lisp/window.el @@ -5528,6 +5528,24 @@ split-window-keep-point :type 'boolean :group 'windows) +(defun window--split-window-quit-restore (old-window new-window) + "Copy 'quit-restore' parameter to new window after splitting. +OLD-WINDOW is the window that was split, NEW-WINDOW is the new +window. This cleans up any height value that could be used to +restore the old height of NEW-WINDOW in a later invocation of +`display-buffer'." + (let* ((quit-restore (window-parameter old-window 'quit-restore)) + (quad (nth 1 quit-restore))) + (when quit-restore + (when (and (listp quad) (integerp (nth 3 quad))) + ;; nth 3 of quad is the old-window height of OLD-WINDOW. This + ;; value is meaningless in NEW-WINDOW so set it to the present + ;; height of NEW-WINDOW. + (setq quit-restore (copy-tree quit-restore)) + (rplaca (cdddr (nth 1 quit-restore)) (window-total-height new-window))) + + (set-window-parameter new-window 'quit-restore quit-restore)))) + (defun split-window-below (&optional size) "Split the selected window into two windows, one above the other. The selected window is above. The newly split-off window is @@ -5575,9 +5593,7 @@ split-window-below (set-window-point new-window old-point) (select-window new-window)))) ;; Always copy quit-restore parameter in interactive use. - (let ((quit-restore (window-parameter old-window 'quit-restore))) - (when quit-restore - (set-window-parameter new-window 'quit-restore quit-restore))) + (window--split-window-quit-restore old-window new-window) new-window)) (defalias 'split-window-vertically 'split-window-below) @@ -5604,9 +5620,7 @@ split-window-right (error "Size of new window too small")) (setq new-window (split-window nil size t)) ;; Always copy quit-restore parameter in interactive use. - (let ((quit-restore (window-parameter old-window 'quit-restore))) - (when quit-restore - (set-window-parameter new-window 'quit-restore quit-restore))) + (window--split-window-quit-restore old-window new-window) new-window)) (defalias 'split-window-horizontally 'split-window-right)