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

From: martin rudalics <[email-masked]>
Date: Tue, 3 May 2022 11:21:26 +0200

>> BTW I do not understand well in which sense your original scenario
 >>
 >>    (pop-to-buffer (generate-new-buffer "*edit string*")
 >>                   '(display-buffer-below-selected
 >>                     (window-min-height . 10)
 >>                     (window-height . fit-window-to-buffer)))
 >>
 >> fails.  Do you mean that the window should be at least ten lines high
 >> despite of the fact that it's fit to an empty buffer?
 >
 > Exactly.  I expected that window-min-height takes precedence over window-height.

We could do something like the untested attached .diff.  But we really
should install it only if at least two or three people confirm that it's
the expected behavior.

Note: ‘shrink-window-if-larger-than-buffer’ does not re-enlarge a window
that already shows the buffer if its height is less than the specified
'window-min-height'.

martin
diff --git a/lisp/window.el b/lisp/window.el
index dd297a3169..5643fb9af3 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7245,8 +7245,12 @@ window--display-buffer
     (let* ((frame (window-frame window))
            (quit-restore (window-parameter window 'quit-restore))
 	   (window-height (assq 'window-height alist))
+           (min-height (or (cdr (assq 'window-min-height alist))
+                           window-min-height))
            (height (cdr window-height))
 	   (window-width (assq 'window-width alist))
+           (min-width (or (cdr (assq 'window-min-width alist))
+                          window-min-width))
            (width (cdr window-width))
            (window-size (assq 'window-size alist))
            (size (cdr window-size))
@@ -7300,26 +7304,31 @@ window--display-buffer
             (setq resize-temp-buffer-window-inhibit 'vertical)))
 	 ((numberp height)
 	  (let* ((new-height
-		  (if (integerp height)
-		      height
-		    (round
-		     (* (window-total-height (frame-root-window window))
-			height))))
+		  (max (if (integerp height)
+		           height
+		         (round
+		          (* (window-total-height (frame-root-window window))
+			     height)))
+                       min-height))
 		 (delta (- new-height (window-total-height window))))
 	    (when (and (window--resizable-p window delta nil 'safe)
 		       (window-combined-p window))
 	      (window-resize window delta nil 'safe)))
           (setq resize-temp-buffer-window-inhibit 'vertical))
          ((and (consp height) (eq (car height) 'body-lines))
-	  (let* ((delta (- (* (frame-char-height frame) (cdr height))
-                           (window-body-height window t))))
-	    (and (window--resizable-p window delta nil 'safe nil nil nil t)
+	  (let* ((delta (max (- (* (frame-char-height frame) (cdr height))
+                                (window-body-height window t))
+                             (- (* (frame-char-height frame) min-height)
+                                (window-pixel-height window)))))
+            (and (window--resizable-p window delta nil 'safe nil nil nil t)
 		 (window-combined-p window)
 	         (window-resize window delta nil 'safe t)))
           (setq resize-temp-buffer-window-inhibit 'vertical))
          ((functionp height)
-	  (ignore-errors (funcall height window))
-          (setq resize-temp-buffer-window-inhibit 'vertical)))
+          (let* ((min-height (cdr (assq 'window-min-height alist)))
+                 (window-min-height min-height))
+            (ignore-errors (funcall height window))
+            (setq resize-temp-buffer-window-inhibit 'vertical))))
 	;; Adjust width of window if asked for.
 	(cond
 	 ((not width)
@@ -7327,26 +7336,31 @@ window--display-buffer
             (setq resize-temp-buffer-window-inhibit 'horizontal)))
 	 ((numberp width)
 	  (let* ((new-width
-		  (if (integerp width)
-		      width
-		    (round
-		     (* (window-total-width (frame-root-window window))
-			width))))
+                  (max
+                   (if (integerp width)
+		       width
+		     (round
+		      (* (window-total-width (frame-root-window window))
+			 width)))
+                   min-width))
 		 (delta (- new-width (window-total-width window))))
 	    (when (and (window--resizable-p window delta t 'safe)
 		       (window-combined-p window t))
 	      (window-resize window delta t 'safe)))
           (setq resize-temp-buffer-window-inhibit 'horizontal))
          ((and (consp width) (eq (car width) 'body-columns))
-	  (let* ((delta (- (* (frame-char-width frame) (cdr width))
-                           (window-body-width window t))))
+	  (let* ((delta (max (- (* (frame-char-width frame) (cdr width))
+                                (window-body-width window t))
+                             (- (* (frame-char-width frame) min-width)
+                                (window-pixel-width window)))))
 	    (and (window--resizable-p window delta t 'safe nil nil nil t)
 		 (window-combined-p window t)
 	         (window-resize window delta t 'safe t)))
           (setq resize-temp-buffer-window-inhibit 'horizontal))
 	 ((functionp width)
-	  (ignore-errors (funcall width window))
-          (setq resize-temp-buffer-window-inhibit 'horizontal)))
+          (let* ((window-min-width min-width))
+	    (ignore-errors (funcall width window))
+            (setq resize-temp-buffer-window-inhibit 'horizontal))))
 
 	;; Preserve window size if asked for.
 	(when (consp preserve-size)