Subject: Re: bug#78835: Wrong pop-to-buffer behavior after one display-buffer-in-side-window call

From: martin rudalics <[email-masked]>
Date: Thu, 19 Jun 2025 17:06:33 +0200

Hi Dmitry

 > Anyway, the crux of the problem is that after a side window had been
 > used, later commands that use pop-to-buffer would reside the window
 > unnecessarily, and then not restore the previous size on quit either.

It's not specifically related to side windows, a plain 'display-buffer'
should suffice.  The problem is that 'pop-to-buffer' reusing the bs.el
window tries to restore the height of the initial *scratch* window after
first displaying bs.el in it and later splitting it vertically.  In the
patch below I now try to remove the reference to the old height when a
window is split vertically.  Please try it.

Thanks, martin

diff --git a/lisp/window.el b/lisp/window.el
index e372ef8b9bb..f24e581ba1e 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5899,6 +5899,16 @@ split-window
  	   window (- (if new-parent 1.0 (window-normal-size window horizontal))
  		     new-normal)))

+	(unless horizontal
+	  (let ((quit-restore (window-parameter window 'quit-restore)))
+	    (when quit-restore
+	      (let ((quad (nth 1 quit-restore)))
+		(when (and (listp quad) (integerp (nth 3 quad)))
+		  ;; When WINDOW has a 'quit-restore' parameter that
+		  ;; specifies a previous height to restore, remove that
+		  ;; - it does more harm than good now (Bug#78835).
+		  (setf (nth 3 quad) nil))))))
+
  	(let ((new (split-window-internal
  		    window new-pixel-size side new-normal refer)))
            (window--pixel-to-total frame horizontal)