Subject: Re: bug#44483: 27.1.50; Window parameter `min-margins' doesn't split window in half

From: martin rudalics <[email-masked]>
Date: Fri, 6 Nov 2020 19:12:51 +0100

> 1. Open any text file, preferably with long lines (to better see the effect).
 >
 > 2. `M-x visual-line-mode RET`
 >
 > 3. `M-: (set-window-margins (selected-window) 0 150) RET`
 >
 > The number 150 is arbitrary. It's appropriate for my case (with a frame width of
 > about 238 characters).
 >
 > 4. `M-: (set-window-parameter (selected-window) 'min-margins '(0 . 0)) RET`
 >
 > 5. `C-x 3`
 >
 > At this point, I expect the window to be split into two equally-sized
 > side-by-side windows, but the split is at about one third of the original window
 > width.

The problem is that when we split the original window, the new window
does not get its 'min-margins' parameter set and the subsequent
sanitizing step screws up things.  Please try the attached patch.

And please look also into what happens when you shrink a frame with such
large margins to a size that won't accommodate those margins any more
unless they get shrunk.  I'm afraid that the subsequent sanitizing step
might cause troubles there as well.

Thanks, martin
diff --git a/lisp/window.el b/lisp/window.el
index 48005fc93e..6c08e71aae 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -5414,6 +5414,12 @@ split-window

 	  ;; Sanitize sizes unless SIZE was specified.
 	  (unless size
+            ;; Make sure the new window gets any `min-margins' parameter
+            ;; of WINDOW.  Otherwise, sanitizing screws up window sizes
+            ;; considerably (Bug#44483).
+            (let ((min-margins (window-parameter window 'min-margins)))
+              (when min-margins
+                (set-window-parameter new 'min-margins min-margins)))
             (window--sanitize-window-sizes horizontal))

 	  (run-window-scroll-functions new)