Subject: bug#39822: 27.0.90; Cannot set *Completions* buffer height using display-buffer-alist

From: Juri Linkov <[email-masked]>
Date: Sun, 15 Mar 2020 01:24:44 +0200

>> Here is the first step, this patch seems to keep the original behavior,
>> but I need your help to finish it.  Could you confirm that calls of
>> window-preserve-size at the end of with-displayed-buffer-window are
>> not needed anymore after this patch is applied, because there are the
>> same calls of window-preserve-size at the end of window--display-buffer
>> that are called later after buffer contents is filled
>> by after-display-function in the middle of window--display-buffer:
>
> Didn't we agree that 'vaction' is harmful anyway so these "same calls"
> should never have been applied in the first place?  I wouldn't bother
> about them at the moment, when something fails we find out soon enough.

These calls should remain in 'window--display-buffer' to adjust the
window height afterwards.

> But what if a function like 'dired-format-columns-of-files' wanted to
>
> (1) know the width of the window used for displaying the buffer,

'dired-format-columns-of-files' is called when the window
is already displayed, so it can find the width of the window,
and it uses 'completion--insert-strings' for that, see below.

> (2) according to that (presumably fixed) width adjust columns, establish
> a maximum width of buffer lines or do something else width related,

Same as above.

> (3) leave it to 'window--display-buffer' to adjust the window height
> afterwards?

It already allows 'window--display-buffer' to adjust the window height
afterwards in the previous patch.

> And be able to do (1)-(3) in the orthogonal direction, that is, base (2)
> on a presumably fixed window height?

You mean to not allow adjusting the window height afterwards?
Then the call of 'display-buffer' should be without alist entries
'window-height' and 'preserve-size'.

> I conjecture that in such case, the function (functions?) specified by
> 'after-display-function' should be supplied the window to display the
> buffer as first argument (just in case there's another window showing
> the same buffer).  WDYT?

The current implementation doesn't supply the window, and
'dired-format-columns-of-files' and 'minibuffer-completion-help'
use 'completion--insert-strings':

	   (window (get-buffer-window (current-buffer) 0))
	   (wwidth (if window (1- (window-width window)) 79))

Do you propose to rewrite 'completion--insert-strings' for accept a new
argument 'window'?  Or to rely on the fact that the displayed window should
be already selected by its caller?  Will this break backward-compatibility
for packages that use it?