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

From: Juri Linkov <[email-masked]>
Date: Fri, 06 May 2022 10:52:44 +0300

>> Because it should be the task of fit-window-to-buffer,
>> and it already has the argument MIN-HEIGHT.
>> Also other arguments of fit-window-to-buffer
>> could be allowed to use in display-buffer-alist.
>
> You mean the value of a 'window-height' entry could also be a
>
>         • A list whose CAR is a function and whose remaining elements
>           are the arguments passed to that function.
>
> so we'd run
>
> 	    (ignore-errors (funcall (car height) window (nth 1 height) ...))
>
> in 'window--display-buffer'?  Which means the caller has to know the
> function and which arguments it needs in which order.  Sounds fragile.

It is intended only for special handling of 'fit-window-to-buffer'.
If 'fit-window-to-buffer' with MIN-HEIGHT will really fix this problem,
then details of the entry format could be adapted later.
And indeed this works exactly as should with

(pop-to-buffer (generate-new-buffer "*edit string*")
                 '(display-buffer-below-selected
                   (window-height . fit-window-to-buffer)))

and an experimental patch:

diff --git a/lisp/window.el b/lisp/window.el
index 9f78784612..a21cf109a4 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7336,7 +7336,9 @@ window--display-buffer
 	         (window-resize window delta nil 'safe t)))
           (setq resize-temp-buffer-window-inhibit 'vertical))
          ((functionp height)
-	  (ignore-errors (funcall height window))
+	  (if (eq height 'fit-window-to-buffer)
+              (ignore-errors (funcall height window nil 10))
+            (ignore-errors (funcall height window)))
           (setq resize-temp-buffer-window-inhibit 'vertical)))
 	;; Adjust width of window if asked for.
 	(cond