Subject: Re: bug#14825: 24.3.50; split-window-below miscounts window lines

From: martin rudalics <[email-masked]>
Date: Tue, 15 Oct 2019 19:38:15 +0200

> To reproduce:
 >
 >   emacs -Q
 >   Click S-mouse-1 and select "Change Buffer Font"
 >   Under "Size" type 6 and click OK
 >
 > You should now have *scratch* buffer displayed with a very small font
 >
 >   Hit RET 5 times to have a 10-line buffer
 >   C-x 2
 >   C-u 10 C-x ^
 >
 > You should now have 2 windows displaying *scratch*, the lower one about
 > 10 lines tall.
 >
 >   C-x o
 >   C-x 2
 >    => Window #<window 0x3817df0 on *scratch*> too small for splitting
 >
 > But that window is 10 lines tall, while the minimum window height is 4
 > lines, so I would expect Emacs to honor the request and produce 2
 > windows.  And indeed, if I do the same with a 10-line window without
 > making the font smaller, the window is split.

I attached a patch that tries to fix this scenario.  Please have a
look.

Thanks, martin
diff --git a/lisp/window.el b/lisp/window.el
index af35f9abe6..7470ffc1d3 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5365,10 +5365,22 @@ split-window-below
   (let ((old-window (selected-window))
 	(old-point (window-point))
 	(size (and size (prefix-numeric-value size)))
-        moved-by-window-height moved new-window bottom)
-    (when (and size (< size 0) (< (- size) window-min-height))
+        line-height moved-by-window-height moved new-window bottom)
+    (cond
+     ((and size (< size 0) (< (- size) window-min-height))
       ;; `split-window' would not signal an error here.
       (error "Size of new window too small"))
+     ((and (not size)
+           (< (setq line-height (window-default-line-height))
+              (frame-char-height))
+           (>= (/ (float (window-size nil nil t)) line-height)
+               window-min-height))
+        ;; As a special case when SIZE is not specified and the
+        ;; selected window has a default line height that is smaller
+        ;; than the character height of its frame, try to split the
+        ;; window even if the resulting windows would otherwise
+        ;; violate the `window-min-height' contstraints (Bug#14825).
+      (setq size (/ (window-size) 2))))
     (setq new-window (split-window nil size))
     (unless split-window-keep-point
       (with-current-buffer (window-buffer)