Subject: Re: bug#25169: 26.0.50; display-buffer doesn't set window width correctly

From: martin rudalics <[email-masked]>
Date: Sun, 11 Dec 2016 17:19:47 +0100

Thanks for the report.

 > Recipe 1:
 >
 > 1. Emacs -Q
 > 2. evaluate the following code in *scratch*:
 >
 >     (display-buffer (get-buffer-create "aaa")
 >                    '(display-buffer-pop-up-window
 >                      (window-width . 20)))
 >     ;; => correct window width for buffer "aaa"
 >
 >     (display-buffer (get-buffer-create "bbb")
 >                    '(display-buffer-pop-up-window
 >                      (window-width . 20)))
 >     ;; => changed and larger window width for buffer "bbb"

Recipe 1 is difficult to reproduce here.  I made my initial frame 169
columns wide to get a side-by-side split when displaying aaa and to
_not_ get another side-by-side split when displaying bbb.  What happens
is that ‘display-buffer-pop-up-window’ refuses to make a new window for
bbb (you can reduce the value of ‘split-width-threshold’ to get a split)
so ‘display-buffer’ rather uses aaa's window to display bbb via
‘display-buffer-use-some-window’.  The latter ignores the ‘window-width’
entry but applies ‘window--even-window-sizes’ instead.

So this is not a bug but admittedly a very confusing sequence of events.

 > Recipe 2:
 >
 > 1. Emacs -Q
 > 2. evaluate the following code in *scratch*:
 >
 >     (display-buffer (get-buffer-create "aaa")
 >            '(display-buffer-in-side-window
 >              (window-width . 20)
 >              (side . right)))
 >     ;; => correct window width for buffer "aaa"
 >
 >     (display-buffer (get-buffer-create "bbb")
 >            '(display-buffer-in-side-window
 >              (window-width . 20)
 >              (side . left)))
 >     ;; => correct width for buffer "bbb", but the window width of
 >     ;; buffer "aaa" is changed and becomes larger

This is a bug and I attached a fix for it.  Please try it.

Note, however, that in general you can rely on Emacs to preserve the
size of a window like that of aaa in recipe 2 if and only if you run
‘window-preserve-size’ on that window - either explicitly or via a
`preserve-size' argument.

martin

(BTW: Does the ibuffer scenario from bug#25115 work orderly now?)
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -2797,7 +2797,7 @@ window-resize
 		window delta horizontal ignore nil nil nil t)))
       (window--resize-reset frame horizontal)
       (window--resize-this-window window delta horizontal ignore t)
-      (if (and (not window-combination-resize)
+      (if (and (not (eq window-combination-resize t))
 	       (window-combined-p window horizontal)
 	       (setq sibling (or (window-right window) (window-left window)))
 	       (window-sizable-p
@@ -4049,7 +4049,7 @@ delete-window
 	     (sibling (or (window-left window) (window-right window))))
 	(window--resize-reset frame horizontal)
 	(cond
-	 ((and (not window-combination-resize)
+	 ((and (not (eq window-combination-resize t))
 	       sibling (window-sizable-p sibling size horizontal nil t))
 	  ;; Resize WINDOW's sibling.
 	  (window--resize-this-window sibling size horizontal nil t)