On Sun, Dec 15, 2024 at 8:48 AM Juri Linkov <juri@linkov.net> wrote:
> I don't want to scroll twice more because of a vertical split, whereas I
> have the 2/3 of my screen free to show another buffer of code.

What frame dimensions do you consider in this case?  Does the frame width allow
showing two horizontally split windows with enough number of columns?

> In this scenario both splits would succeed because the frame dimension
> exceeds by a lot their respective threshold.

Maybe increasing the value of split-height-threshold will help you?
For example, I customized it to a large value, so I have no problems
because then windows are split only horizontally.

Yes, but I do want it to split vertically at some point.
Typically, in fullscreen mode, after 3 or 4 horizontal splits, I want it to split vertically.


> My point is about the order in which splits are tried. I would like it to
> first tries the longest edge.

Trying the longest edge might cause problems.  For example, for
frame dimension 100x90, the longest edge is the width 100.
But splitting the frame horizontally will create two windows
with only 50 columns that are too narrow for comfortable editing.

> So that if it succeed it is likely to be the direction where there is the
> more space available.

Not only the criteria for more available space is important.
Another criteria to not make too narrow window has no less importance.

Agreed. See below.


> But I understand the bias toward vertical splitting, that's why I added a
> condition to prioritize vertical split if the width is less than 80. This
> heuristic could be improved, thought.

I don't see the bias toward vertical splitting.

Vertical split will be preferred even if you have a large width and a very narrow height as long as it is higher than the threshold.
 

But if you could write in a clear form the current rules for an overview
and what changes do you propose, then the heuristic could be improved.
For example, how these rules could look:

1. split vertically if the width is less than 80
2. split horizontally if split-width-threshold is more than 160
3. split vertically otherwise

The patch I attached does this:

if width > height and width > 80
   try to split horizontally, then try vertically and finally fallback to horizontal split
else
   try to split vertically, then try horizontally and finally fallback to vertical split

I have been using it for a couple of weeks and it is working fine.
The condition could be tweaked, specially the (widht > 80) part. We could also decide to always fallback to vertical split at the end (which will fix my implementation problem).

The else part is the original behavior.