Subject: Re: bug#55169: Can't combine window-min-height with window-height

From: Juri Linkov <[email-masked]>
Date: Mon, 09 May 2022 21:58:17 +0300

>>>> (pop-to-buffer (generate-new-buffer "*edit string*")
>>>>                  '(display-buffer-below-selected
>>>>                    (window-height . (lambda (window)
>>>>                                       (fit-window-to-buffer window nil 10)))))
>>>
>>> Sounds too complicated IMO.
>>
>> Actually a lambda is already supported, so no changes are required.
>
> We have to find a suitable way to explain that in the manual.

It's already documented in the manual:

        • If the value specifies a function, that function is called
          with one argument—the chosen window.  The function is supposed
          to adjust the height of the window; its return value is
          ignored.  Suitable functions are ‘fit-window-to-buffer’ and
          ‘shrink-window-if-larger-than-buffer’, see *note Resizing
          Windows::.

It would be nice to add just a small example of a lambda with more args
for fit-window-to-buffer or shrink-window-if-larger-than-buffer.

>> A special case for fit-window-to-buffer, shrink-window-* and other similar
>> could be implemented only when you are sure that a `window-min-height' entry
>> is not going to be used for other purposes besides of using it as an argument
>> of a window-height entry.
>
> You said that this is the case for 'fit-window-to-buffer' and that
> function is the canonical client for a 'window-height' function.  So why
> bother about the rest?

You found another function shrink-window-if-larger-than-buffer.
Then it would be better not to limit only to these two.

>> BTW, fit-window-to-buffer has also other arguments: MAX-WIDTH and MIN-WIDTH.
>> Would they be useful for a window-width entry?
>
> Maybe.  But let's talk about MAX-HEIGHT first.

Maybe MAX-WIDTH is not needed after all, as much as MAX-HEIGHT.

>>> And if we really want to, we can always add a MIN-HEIGHT argument to
>>> 'shrink-window-if-larger-than-buffer' and handle it the same way.
>>
>> This is very much needed, thanks.
>
> See below (this should also fix the lie about the return value).

Thanks, I'll test it.  Does it need more args from fit-window-to-buffer?