Subject: bug#24193: 25.1; `window-min-size' fails for horizontal width when margins >= body text

From: martin rudalics <[email-masked]>
Date: Mon, 15 Aug 2016 10:28:12 +0200

> I'm not sure we want to change window-min-size.  That function is used
 > for purposes that have nothing to do with splitting the window.  E.g.,
 > we also use its value when deciding whether a window can be resized,
 > when fitting window to buffer, etc.
 >
 > The lowest level function for splitting windows is split-window, so
 > the change should IMO be either in split-window-right or in
 > split-window.  Martin, WDYT?

This wouldnn't help much because as soon as a user has two side-by-side
windows she might want to drag the divider between those windows and
complain that it doesn't move.  We can install the attached hack in
Emacs 25.1 and leave this subject alone until someone has a better
solution.

martin
diff --git a/doc/lispref/windows.texi b/doc/lispref/windows.texi
index 55d90bd..7c07dd1 100644
--- a/doc/lispref/windows.texi
+++ b/doc/lispref/windows.texi
@@ -4349,6 +4349,24 @@ Window Parameters
 The fourth element is the buffer whose display caused the creation of
 this parameter.  @code{quit-restore-window} deletes the specified window
 only if it still shows that buffer.
+
+@item @code{min-margins}
+The value of this parameter is a cons cell specifying the minimum values
+(in columns) for the left and right margin of this window.  When
+present, Emacs will use these values instead of the real margin widths
+for determining whether a window can be split or shrunk.
+
+Emacs does not auto-adjust the margins of any window after splitting or
+resizing it.  It is sole responsibility of the application that sets
+this parameter to adjust the margins of this window as well as those of
+any new window created by a split.  The hooks to achieve that are
+@code{window-configuration-change-hook} and
+@code{window-size-change-functions} (@pxref{Window Hooks}).
+
+This parameter was introduced in Emacs version 25.1 as a conspiracy hack
+for applications that use large margins to center buffer text within a
+window and should be used with extreme care.  It can be replaced by an
+improved solution in future versions of Emacs.
 @end table

 There are additional parameters @code{window-atom} and @code{window-side};
diff --git a/lisp/window.el b/lisp/window.el
index f7a547b..ca8141b 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -1383,10 +1383,17 @@ window--min-size-1
 	  (let* ((char-size (frame-char-size window t))
 		 (fringes (window-fringes window))
 		 (margins (window-margins window))
+                 (min-margins (window-parameter window 'min-margins))
+                 (left-min-margin (and min-margins
+                                       (numberp (car min-margins))
+                                       (car min-margins)))
+                 (right-min-margin (and min-margins
+                                        (numberp (cdr min-margins))
+                                        (cdr min-margins)))
 		 (pixel-width
 		  (+ (window-safe-min-size window t t)
-		     (* (or (car margins) 0) char-size)
-		     (* (or (cdr margins) 0) char-size)
+		     (* (or left-min-margin (car margins) 0) char-size)
+		     (* (or right-min-margin(cdr margins) 0) char-size)
 		     (car fringes) (cadr fringes)
 		     (window-scroll-bar-width window)
 		     (window-right-divider-width window))))