Subject: Re: bug#69983: Use category for display-buffer-alist

From: Juri Linkov <[email-masked]>
Date: Tue, 09 Apr 2024 09:30:31 +0300

>>> One problem is that I can't find an alist item to limit
>>> the window height, i.e. can't find window-max-height
>>> that would be like window-min-height, but to set a max height.
>>> Could you suggest such an alist item?
>>
>> The intention was to have such behavior:
>> 1. after the first call that adds 1 line to the output buffer,
>>     resize the displayed buffer to 1 line height;
>> 2. after the second call grow the output window height to 2 lines,
>>     it seems fit-window-to-buffer should do this;
>> 3. after 10th call limit the window height to 10 lines only,
>>     so later calls should not increase the output window height
>>     more than 10 lines.
>
> You mean that when a 'window-height' action alist entry is provided that
> specifies 'fit-window-to-buffer' as 'window-height' value, we should
> pass it the value of any 'window-max-height' entry present as MAX-HEIGHT
> argument here
>
>          ((functionp height)
> 	  (ignore-errors (funcall height window))
>
> and probably do the same for all the other arguments of
> 'fit-window-to-buffer'?

Probably we can't change the existing arguments to not break
backward-compatibility.  But this is fine since still can use
the explicit function call:

diff --git a/lisp/emacs-lisp/warnings.el b/lisp/emacs-lisp/warnings.el
index 8b43c6a8726..75b519067ac 100644
--- a/lisp/emacs-lisp/warnings.el
+++ b/lisp/emacs-lisp/warnings.el
@@ -362,7 +362,12 @@ display-warning
 		 (or (< (warning-numeric-level level)
 			(warning-numeric-level warning-minimum-level))
 		     (warning-suppress-p type warning-suppress-types)
-		     (let ((window (display-buffer buffer)))
+		     (let ((window (display-buffer
+				    buffer
+				    '(display-buffer--maybe-at-bottom
+				      (window-height . (lambda (window)
+					(fit-window-to-buffer window 10)))
+				      (category . warning)))))
 		       (when (and (markerp warning-series)
 				  (eq (marker-buffer warning-series) buffer))
 			 (set-window-start window warning-series))
diff --git a/lisp/progmodes/flymake.el b/lisp/progmodes/flymake.el
index 779c612f479..3344402c893 100644
--- a/lisp/progmodes/flymake.el
+++ b/lisp/progmodes/flymake.el
@@ -1866,7 +1866,11 @@ flymake-show-buffer-diagnostics
                        (current-buffer)))))
     (with-current-buffer target
       (setq flymake--diagnostics-buffer-source source)
-      (display-buffer (current-buffer))
+      (display-buffer (current-buffer)
+                      `((display-buffer-reuse-window
+                         display-buffer-below-selected)
+                        (window-height . (lambda (window)
+                          (fit-window-to-buffer window 10)))))
       (revert-buffer))))