Subject: bug#22009: PATCH: Use `window-total-width' in `window-splittable-p'

From: martin rudalics <[email-masked]>
Date: Fri, 27 Nov 2015 09:28:19 +0100

> The problem I'd like to solve (and the reason I submitted the patch) is
 > that if a window has wide margins that are used to center the text,
 > `window-splittable-p' will say that the window cannot be split
 > horizontally, even though it can, because the margins are disposable.
 >
 > But actually, that's not the real problem. The real problem is that
 > `window-splittable-p' simply has too little information to make an
 > informed decision.
 >
 > The point is that the margins may be used for two different kinds of
 > purposes:
 >
 > (1) The margins can be used to display useful information, in which case
 > they should be retained when the window is split.

But ‘window-splittable-p’ is used in a context where usually we use the
new window to display another buffer than that of the original window.
To my knowledge nobody wants *help* or *completions* buffers to display
line numbers.  And if the original window has no margins but the new
window should display them, the current code won't help either.

 > (2) The margins can be used to reduce the width of the text area. In
 > this case, the margins are disposable.

Let's specify the reason more explicitly: The margins are used to center
the text area in the window.  Correct?

 > Right now, `window-splittable-p' does the right thing for case (1),

It usually does not as I tried to sketch above.

 > but
 > not for case (2). With the patch I submitted, it would do the right
 > thing for case (2), but no longer for case (1). So I agree it's actually
 > a bad patch.
 >
 > The only way to deal with both (1) and (2) correctly, and also with the
 > case where different modes use the margins for (1) and (2) *at the same
 > time*, would be to store information about the modes that use the
 > margins and for which purpose. Then `window-splittable-p' could tell
 > which part of the margins must be retained and which part is disposable.

It would have to be clairvoyant wrt which kind of margins the buffer
displayed in the new window will have.  ‘find-file’ can enable
‘linum-mode’ in ‘find-file-hook’ but the real width of the margin needed
to display them will be known only when ‘linum-mode’ calculates it, that
is, _not_ at the time of splitting.

 > We were discussing just such a proposal on emacs-devel, so perhaps it
 > would be best to continue the discussion there?

That thread is for Emacs 26.  Here we have to decide how to proceed with
Emacs 25.

martin