unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Prefer to split along the longest edge
@ 2024-12-14 10:05 Nicolas Desprès
  2024-12-14 11:30 ` Eli Zaretskii
  2024-12-14 18:35 ` Juri Linkov
  0 siblings, 2 replies; 12+ messages in thread
From: Nicolas Desprès @ 2024-12-14 10:05 UTC (permalink / raw)
  To: emacs-devel


[-- Attachment #1.1: Type: text/plain, Size: 2066 bytes --]

Hi,

I have been enjoying using Emacs since more than 20 years now.  So,
thank you all guys for this impressive work.

It is the first time I send a patch to this list.  I am not a very
fluent lisp coder so please do apologies if the style is not very
good and feel free to tell me how to improve it.

Currently, `split-window-sensibly' prefers to split vertically,
disregarding the shape of the frame.  This is a good default when
Emacs is taller than wider.  However, when Emacs is in fullscreen
(landscape screen layout), splitting vertically is generally not the
thing to do because there is plenty of space on the right.

Typical scenario: Emacs is in fullscreen; one buffer is open in a window
covering the entire frame.  Another buffer is opened in a second
window (C-x 4 f). In this case, the split should generally be horizontal.
The attached patch changes `split-window-sensibly' to just try
spliting the longest edge first. It works well when implemented in my
init.el
and installed by setting `split-window-preferred-function'.

However, when the same logic is implemented by directly modifying
`split-window-sensibly' in window.el, it does not work for one very specific
case: when the frame is 80x30 and C-x 4 f is pressed, the window is not
split and the buffer is opened in another frame. The problem seems to
come from the last eval expression at the bottom of `split-window-sensibly',
but I failed to find a solution. I though better elisp coder than me will
find a
solution quickly that's why I am posting here.

Apart from that, I have been using this alternate approach for a couple of
weeks now, and it works well, that's why I am submitting it for inclusion
in Emacs.

I have tested on 8d94a9ec613470b7e8e4ee0e86b643f34f8a724c with emacs built
with --with-imagemagick --with-native-compilation=yes
--with-compress-install --with-mailutils --with-gnutls --with-tree-sitter
--with-xwidgets --disable-gc-mark-trace --no-create --no-recursion on macOS
15.2.

Best regards,
Nico

-- 
Nicolas Desprès

[-- Attachment #1.2: Type: text/html, Size: 3928 bytes --]

[-- Attachment #2: 0001-Split-along-the-longest-edge-by-default.patch --]
[-- Type: application/octet-stream, Size: 5926 bytes --]

From 8d94a9ec613470b7e8e4ee0e86b643f34f8a724c Mon Sep 17 00:00:00 2001
From: Nicolas Despres <nicolas.despres@gmail.com>
Date: Fri, 13 Dec 2024 19:58:13 +0100
Subject: [PATCH] Split along the longest edge by default.

Currently, `split-window-sensibly' prefer to split vertically
disregarding the actual shape of the frame.  This is a good default when
Emacs is taller than wider.  However, when Emacs is in fullscreen
(landscape screen layout) splitting vertically is generally not the
things to do because there is plenty more space on the right.

Typical scenario: Emacs is in fullscreen, one buffer is open in window
covering the entire frame.  Another buffer is opened in a second
window (C-x 4 f). In this case, the split should happen horizontally.

I have tested this approach since a couple of weeks now and it works well
if `split-height-threshold' and `split-width-threshold' are set
properly.

* lisp/window.el (split-window-sensibly): Always prefer the longest edge
instead of blindly splitting vertically, unless width is less than 80 columns.

A part from that, the patch carefully preserves the current split logic.
---
 lisp/window.el | 68 ++++++++++++++++++++++++++++++--------------------
 1 file changed, 41 insertions(+), 27 deletions(-)

diff --git a/lisp/window.el b/lisp/window.el
index e9d57652ec6..58ca6c8679d 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7347,20 +7347,30 @@ window-splittable-p
 		      (* 2 (max window-min-height
 				(if mode-line-format 2 1))))))))))
 
+(defun window--try-split-window-vertically (window)
+  "Helper function for `split-window-sensibly'"
+  (when (window-splittable-p window)
+    (with-selected-window window
+      (split-window-below))))
+
+(defun window--try-split-window-horizontally (window)
+  "Helper function for `split-window-sensibly'"
+  (when (window-splittable-p window t)
+    (with-selected-window window
+      (split-window-right))))
+
 (defun split-window-sensibly (&optional window)
   "Split WINDOW in a way suitable for `display-buffer'.
-WINDOW defaults to the currently selected window.
-If `split-height-threshold' specifies an integer, WINDOW is at
-least `split-height-threshold' lines tall and can be split
-vertically, split WINDOW into two windows one above the other and
-return the lower window.  Otherwise, if `split-width-threshold'
-specifies an integer, WINDOW is at least `split-width-threshold'
-columns wide and can be split horizontally, split WINDOW into two
-windows side by side and return the window on the right.  If this
-can't be done either and WINDOW is the only window on its frame,
-try to split WINDOW vertically disregarding any value specified
-by `split-height-threshold'.  If that succeeds, return the lower
-window.  Return nil otherwise.
+WINDOW defaults to the currently selected window.  First, try to split
+along the longest edge of the window.  If the threshold
+(`split-height-threshold' respectively `split-width-threshold')
+specifies an integer, WINDOW is at least that threshold lines tall
+(resp. wide) and can be split (vertically respectively horizontally).
+If that fails, try to split along the shortest edge.  If this can't be
+done either and WINDOW is the only window on its frame, try to split
+WINDOW along the longest edge disregarding any value specified by
+`split-height-threshold' respectively `split-width-threshold'. If that
+succeeds, return the lower window.  Return nil otherwise.
 
 By default `display-buffer' routines call this function to split
 the largest or least recently used window.  To change the default
@@ -7379,21 +7389,27 @@ split-window-sensibly
 Have a look at the function `window-splittable-p' if you want to
 know how `split-window-sensibly' determines whether WINDOW can be
 split."
-  (let ((window (or window (selected-window))))
-    (or (and (window-splittable-p window)
-	     ;; Split window vertically.
-	     (with-selected-window window
-	       (split-window-below)))
-	(and (window-splittable-p window t)
-	     ;; Split window horizontally.
-	     (with-selected-window window
-	       (split-window-right)))
+  (let ((window (or window (selected-window)))
+        (first-split nil)
+        (second-split nil)
+        (first-threshold-variable nil))
+    ;; Choose preferred splitting edge.
+    (if (and (> (frame-width) (frame-height)) (> (frame-width) 80))
+        (setq first-split 'window--try-split-window-horizontally
+              second-split 'window--try-split-window-vertically
+              first-threshold-variable 'split-width-threshold)
+      (setq first-split 'window--try-split-window-vertically
+            second-split 'window--try-split-window-horizontally
+            first-threshold-variable 'split-height-threshold))
+    (or (funcall first-split window)
+	(funcall second-split window)
 	(and
          ;; If WINDOW is the only usable window on its frame (it is
          ;; the only one or, not being the only one, all the other
          ;; ones are dedicated) and is not the minibuffer window, try
-         ;; to split it vertically disregarding the value of
-         ;; `split-height-threshold'.
+         ;; to split it along the longest edge disregarding the value of
+         ;; the matching threshold (`split-height-threshold'
+         ;; or `split-width-threshold').
          (let ((frame (window-frame window)))
            (or
             (eq window (frame-root-window frame))
@@ -7405,10 +7421,8 @@ split-window-sensibly
                                 frame nil 'nomini)
               t)))
 	 (not (window-minibuffer-p window))
-	 (let ((split-height-threshold 0))
-	   (when (window-splittable-p window)
-	     (with-selected-window window
-	       (split-window-below))))))))
+	 (eval `(let ((,first-threshold-variable 0))
+                  (funcall first-split window)))))))
 
 (defun window--try-to-split-window (window &optional alist)
   "Try to split WINDOW.
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 10:05 Prefer to split along the longest edge Nicolas Desprès
@ 2024-12-14 11:30 ` Eli Zaretskii
  2024-12-14 11:45   ` Nicolas Desprès
  2024-12-14 17:16   ` martin rudalics
  2024-12-14 18:35 ` Juri Linkov
  1 sibling, 2 replies; 12+ messages in thread
From: Eli Zaretskii @ 2024-12-14 11:30 UTC (permalink / raw)
  To: Nicolas Desprès, martin rudalics; +Cc: emacs-devel

> From: Nicolas Desprès <nicolas.despres@gmail.com>
> Date: Sat, 14 Dec 2024 11:05:30 +0100
> 
> Currently, `split-window-sensibly' prefers to split vertically,
> disregarding the shape of the frame.  This is a good default when
> Emacs is taller than wider.  However, when Emacs is in fullscreen
> (landscape screen layout), splitting vertically is generally not the
> thing to do because there is plenty of space on the right.
> 
> Typical scenario: Emacs is in fullscreen; one buffer is open in a window
> covering the entire frame.  Another buffer is opened in a second
> window (C-x 4 f). In this case, the split should generally be horizontal.
> The attached patch changes `split-window-sensibly' to just try
> spliting the longest edge first. It works well when implemented in my init.el
> and installed by setting `split-window-preferred-function'.

Why don't the user options split-height-threshold and
split-width-threshold we already have are not enough to allow to have
this without any code changes?

I add martin to this discussion, since I expect him to have a lot of
insight on these matters.

Thanks.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 11:30 ` Eli Zaretskii
@ 2024-12-14 11:45   ` Nicolas Desprès
  2024-12-14 12:34     ` Eli Zaretskii
  2024-12-14 17:16   ` martin rudalics
  1 sibling, 1 reply; 12+ messages in thread
From: Nicolas Desprès @ 2024-12-14 11:45 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: martin rudalics, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1411 bytes --]

On Sat, Dec 14, 2024 at 12:30 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Nicolas Desprès <nicolas.despres@gmail.com>
> > Date: Sat, 14 Dec 2024 11:05:30 +0100
> >
> > Currently, `split-window-sensibly' prefers to split vertically,
> > disregarding the shape of the frame.  This is a good default when
> > Emacs is taller than wider.  However, when Emacs is in fullscreen
> > (landscape screen layout), splitting vertically is generally not the
> > thing to do because there is plenty of space on the right.
> >
> > Typical scenario: Emacs is in fullscreen; one buffer is open in a window
> > covering the entire frame.  Another buffer is opened in a second
> > window (C-x 4 f). In this case, the split should generally be horizontal.
> > The attached patch changes `split-window-sensibly' to just try
> > spliting the longest edge first. It works well when implemented in my
> init.el
> > and installed by setting `split-window-preferred-function'.
>
> Why don't the user options split-height-threshold and
> split-width-threshold we already have are not enough to allow to have
> this without any code changes?
>
> I add martin to this discussion, since I expect him to have a lot of
> insight on these matters.
>
>
Because these variables define the minimum size to allow splitting, not the
order by which split orientations are tried.

Thanks for replying :)
-Nico

[-- Attachment #2: Type: text/html, Size: 2167 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 11:45   ` Nicolas Desprès
@ 2024-12-14 12:34     ` Eli Zaretskii
  2024-12-14 14:06       ` Nicolas Desprès
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-12-14 12:34 UTC (permalink / raw)
  To: Nicolas Desprès; +Cc: rudalics, emacs-devel

> From: Nicolas Desprès <nicolas.despres@gmail.com>
> Date: Sat, 14 Dec 2024 12:45:26 +0100
> Cc: martin rudalics <rudalics@gmx.at>, emacs-devel@gnu.org
> 
> On Sat, Dec 14, 2024 at 12:30 PM Eli Zaretskii <eliz@gnu.org> wrote:
> 
>  > From: Nicolas Desprès <nicolas.despres@gmail.com>
>  > Date: Sat, 14 Dec 2024 11:05:30 +0100
>  > 
>  > Currently, `split-window-sensibly' prefers to split vertically,
>  > disregarding the shape of the frame.  This is a good default when
>  > Emacs is taller than wider.  However, when Emacs is in fullscreen
>  > (landscape screen layout), splitting vertically is generally not the
>  > thing to do because there is plenty of space on the right.
>  > 
>  > Typical scenario: Emacs is in fullscreen; one buffer is open in a window
>  > covering the entire frame.  Another buffer is opened in a second
>  > window (C-x 4 f). In this case, the split should generally be horizontal.
>  > The attached patch changes `split-window-sensibly' to just try
>  > spliting the longest edge first. It works well when implemented in my init.el
>  > and installed by setting `split-window-preferred-function'.
> 
>  Why don't the user options split-height-threshold and
>  split-width-threshold we already have are not enough to allow to have
>  this without any code changes?
> 
> Because these variables define the minimum size to allow splitting, not the order by which split orientations
> are tried.

Sorry, I don't understand: does it mean you are unable to change the
value of split-height-threshold to cause the function to split
horizontally?  If so, can you show a recipe?



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 12:34     ` Eli Zaretskii
@ 2024-12-14 14:06       ` Nicolas Desprès
  2024-12-14 14:55         ` Eli Zaretskii
  0 siblings, 1 reply; 12+ messages in thread
From: Nicolas Desprès @ 2024-12-14 14:06 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rudalics, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2049 bytes --]

On Sat, Dec 14, 2024 at 1:34 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Nicolas Desprès <nicolas.despres@gmail.com>
> > Date: Sat, 14 Dec 2024 12:45:26 +0100
> > Cc: martin rudalics <rudalics@gmx.at>, emacs-devel@gnu.org
> >
> > On Sat, Dec 14, 2024 at 12:30 PM Eli Zaretskii <eliz@gnu.org> wrote:
> >
> >  > From: Nicolas Desprès <nicolas.despres@gmail.com>
> >  > Date: Sat, 14 Dec 2024 11:05:30 +0100
> >  >
>
[...]

> >  >
> >  > Typical scenario: Emacs is in fullscreen; one buffer is open in a
> window
> >  > covering the entire frame.  Another buffer is opened in a second
> >  > window (C-x 4 f). In this case, the split should generally be
> horizontal.
> >  > The attached patch changes `split-window-sensibly' to just try
> >  > spliting the longest edge first. It works well when implemented in my
> init.el
> >  > and installed by setting `split-window-preferred-function'.
> >
> >  Why don't the user options split-height-threshold and
> >  split-width-threshold we already have are not enough to allow to have
> >  this without any code changes?
> >
> > Because these variables define the minimum size to allow splitting, not
> the order by which split orientations
> > are tried.
>
> Sorry, I don't understand: does it mean you are unable to change the
> value of split-height-threshold to cause the function to split
> horizontally?  If so, can you show a recipe?
>

I can by setting split-height-threshold to nil, but then it will never
split vertically.

The current implementation first tries to split vertically. If it fails, it
tries to split horizontally then it
falls back to vertical splitting.

So to split horizontally, it must first fail to split vertically.

The default threshold values are fine. I just want the default behavior to
try the longest edge first.
This way when both splitting would have succeeded (according to their
respective threshold value) it will split first where there is more room.

Cheers,
-Nico




-- 
Nicolas Desprès

[-- Attachment #2: Type: text/html, Size: 4100 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 14:06       ` Nicolas Desprès
@ 2024-12-14 14:55         ` Eli Zaretskii
  2024-12-14 15:41           ` Nicolas Desprès
  0 siblings, 1 reply; 12+ messages in thread
From: Eli Zaretskii @ 2024-12-14 14:55 UTC (permalink / raw)
  To: Nicolas Desprès; +Cc: rudalics, emacs-devel

> From: Nicolas Desprès <nicolas.despres@gmail.com>
> Date: Sat, 14 Dec 2024 15:06:40 +0100
> Cc: rudalics@gmx.at, emacs-devel@gnu.org
> 
>  > Because these variables define the minimum size to allow splitting, not the order by which split
>  orientations
>  > are tried.
> 
>  Sorry, I don't understand: does it mean you are unable to change the
>  value of split-height-threshold to cause the function to split
>  horizontally?  If so, can you show a recipe?
> 
> I can by setting split-height-threshold to nil, but then it will never split vertically.

You can also set it to a large enough value, no?

> The current implementation first tries to split vertically. If it fails, it tries to split horizontally then it
> falls back to vertical splitting.
> 
> So to split horizontally, it must first fail to split vertically. 

Yes.

> The default threshold values are fine. I just want the default behavior to try the longest edge first.
> This way when both splitting would have succeeded (according to their respective threshold value) it will
> split first where there is more room.

But N columns are not equivalent to N lines.  IOW, if you have a
window that is (N+1)xN, splitting horizontally is not necessarily TRT.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 14:55         ` Eli Zaretskii
@ 2024-12-14 15:41           ` Nicolas Desprès
  0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Desprès @ 2024-12-14 15:41 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: rudalics, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]

On Sat, Dec 14, 2024 at 3:55 PM Eli Zaretskii <eliz@gnu.org> wrote:

> > From: Nicolas Desprès <nicolas.despres@gmail.com>
> > Date: Sat, 14 Dec 2024 15:06:40 +0100
> > Cc: rudalics@gmx.at, emacs-devel@gnu.org
> >
> >  > Because these variables define the minimum size to allow splitting,
> not the order by which split
> >  orientations
> >  > are tried.
> >
> >  Sorry, I don't understand: does it mean you are unable to change the
> >  value of split-height-threshold to cause the function to split
> >  horizontally?  If so, can you show a recipe?
> >
> > I can by setting split-height-threshold to nil, but then it will never
> split vertically.
>
> You can also set it to a large enough value, no?
>

Yes, with the same result of disabling vertical split.


>
> > The current implementation first tries to split vertically. If it fails,
> it tries to split horizontally then it
> > falls back to vertical splitting.
> >
> > So to split horizontally, it must first fail to split vertically.
>
> Yes.
>
> > The default threshold values are fine. I just want the default behavior
> to try the longest edge first.
> > This way when both splitting would have succeeded (according to their
> respective threshold value) it will
> > split first where there is more room.
>
> But N columns are not equivalent to N lines.  IOW, if you have a
> window that is (N+1)xN, splitting horizontally is not necessarily TRT.
>

In such a case, both are equally good, I guess. Most generally, Emacs'
frames are rectangles rather than squarish.

Note that I added a condition when the width is fewer than 80 columns to
preserve the historical behavior of Emacs to split vertically first.

The condition deciding which orientation is tried first could be further
tweaked to accommodate the difference between line height and column width.
It could be pixel-based, for instance.

My main point is that we can achieve a better default than blindly
splitting vertically.

[-- Attachment #2: Type: text/html, Size: 3375 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 11:30 ` Eli Zaretskii
  2024-12-14 11:45   ` Nicolas Desprès
@ 2024-12-14 17:16   ` martin rudalics
  2024-12-14 17:33     ` Eli Zaretskii
  2024-12-14 17:36     ` Eli Zaretskii
  1 sibling, 2 replies; 12+ messages in thread
From: martin rudalics @ 2024-12-14 17:16 UTC (permalink / raw)
  To: Eli Zaretskii, Nicolas Desprès; +Cc: emacs-devel

 > I add martin to this discussion, since I expect him to have a lot of
 > insight on these matters.

'split-window-sensibly' (initially called 'window--try-to-split-window')
was written by Stefan Monnier and was supposed to subsume the
functionality of 'split-window-preferred-horizontally' (written by Juri
Linkov).  Both know more about this issue than I do.

I only recall that initially many people hated the idea that it would
make a window on the right and subsequently set 'split-width-threshold'
to nil (Bug#431, Bug33929).  I'm afraid that changing the default
behavior again may lead to similar reactions even if people who set
‘split-width-threshold’ to nil should not be affected.

So whatever you do here please read the reports on Bug#1806, Bug#3142,
Bug#20189 (unless you have done so already) first and also do a search
for 'split-width-threshold' on emacs-devel.

Thanks, martin

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 17:16   ` martin rudalics
@ 2024-12-14 17:33     ` Eli Zaretskii
  2024-12-14 17:36     ` Eli Zaretskii
  1 sibling, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2024-12-14 17:33 UTC (permalink / raw)
  To: martin rudalics, Stefan Monnier; +Cc: nicolas.despres, emacs-devel

> Date: Sat, 14 Dec 2024 18:16:14 +0100
> Cc: emacs-devel@gnu.org
> From: martin rudalics <rudalics@gmx.at>
> 
>  > I add martin to this discussion, since I expect him to have a lot of
>  > insight on these matters.
> 
> 'split-window-sensibly' (initially called 'window--try-to-split-window')
> was written by Stefan Monnier and was supposed to subsume the
> functionality of 'split-window-preferred-horizontally' (written by Juri
> Linkov).  Both know more about this issue than I do.
> 
> I only recall that initially many people hated the idea that it would
> make a window on the right and subsequently set 'split-width-threshold'
> to nil (Bug#431, Bug33929).  I'm afraid that changing the default
> behavior again may lead to similar reactions even if people who set
> ‘split-width-threshold’ to nil should not be affected.
> 
> So whatever you do here please read the reports on Bug#1806, Bug#3142,
> Bug#20189 (unless you have done so already) first and also do a search
> for 'split-width-threshold' on emacs-devel.

Thanks, I added Stefan and Juri to the discussion.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 17:16   ` martin rudalics
  2024-12-14 17:33     ` Eli Zaretskii
@ 2024-12-14 17:36     ` Eli Zaretskii
  1 sibling, 0 replies; 12+ messages in thread
From: Eli Zaretskii @ 2024-12-14 17:36 UTC (permalink / raw)
  To: martin rudalics, Stefan Monnier, Juri Linkov; +Cc: nicolas.despres, emacs-devel

> Date: Sat, 14 Dec 2024 18:16:14 +0100
> Cc: emacs-devel@gnu.org
> From: martin rudalics <rudalics@gmx.at>
> 
>  > I add martin to this discussion, since I expect him to have a lot of
>  > insight on these matters.
> 
> 'split-window-sensibly' (initially called 'window--try-to-split-window')
> was written by Stefan Monnier and was supposed to subsume the
> functionality of 'split-window-preferred-horizontally' (written by Juri
> Linkov).  Both know more about this issue than I do.
> 
> I only recall that initially many people hated the idea that it would
> make a window on the right and subsequently set 'split-width-threshold'
> to nil (Bug#431, Bug33929).  I'm afraid that changing the default
> behavior again may lead to similar reactions even if people who set
> ‘split-width-threshold’ to nil should not be affected.
> 
> So whatever you do here please read the reports on Bug#1806, Bug#3142,
> Bug#20189 (unless you have done so already) first and also do a search
> for 'split-width-threshold' on emacs-devel.

Thanks, adding Stefan and Juri to the discussion.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 10:05 Prefer to split along the longest edge Nicolas Desprès
  2024-12-14 11:30 ` Eli Zaretskii
@ 2024-12-14 18:35 ` Juri Linkov
  2024-12-14 20:10   ` Nicolas Desprès
  1 sibling, 1 reply; 12+ messages in thread
From: Juri Linkov @ 2024-12-14 18:35 UTC (permalink / raw)
  To: Nicolas Desprès; +Cc: emacs-devel

> Currently, `split-window-sensibly' prefers to split vertically,
> disregarding the shape of the frame.  This is a good default when
> Emacs is taller than wider.  However, when Emacs is in fullscreen
> (landscape screen layout), splitting vertically is generally not the
> thing to do because there is plenty of space on the right.
>
> Typical scenario: Emacs is in fullscreen; one buffer is open in a window
> covering the entire frame.  Another buffer is opened in a second
> window (C-x 4 f). In this case, the split should generally be horizontal.
> The attached patch changes `split-window-sensibly' to just try
> spliting the longest edge first.

I see no symmetry between width and height.

To make a window usable you need to decide how many columns you need
to fit into the window by customizing split-width-threshold.

By default it's 160 that means two horizontally split windows
with 80 columns in each that allows a comfortable use of each window.

OTOH, the window height has less relevance since most of the time
all windows are scrolled vertically.



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Prefer to split along the longest edge
  2024-12-14 18:35 ` Juri Linkov
@ 2024-12-14 20:10   ` Nicolas Desprès
  0 siblings, 0 replies; 12+ messages in thread
From: Nicolas Desprès @ 2024-12-14 20:10 UTC (permalink / raw)
  To: Juri Linkov; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2035 bytes --]

On Sat, Dec 14, 2024 at 7:38 PM Juri Linkov <juri@linkov.net> wrote:

> > Currently, `split-window-sensibly' prefers to split vertically,
> > disregarding the shape of the frame.  This is a good default when
> > Emacs is taller than wider.  However, when Emacs is in fullscreen
> > (landscape screen layout), splitting vertically is generally not the
> > thing to do because there is plenty of space on the right.
> >
> > Typical scenario: Emacs is in fullscreen; one buffer is open in a window
> > covering the entire frame.  Another buffer is opened in a second
> > window (C-x 4 f). In this case, the split should generally be horizontal.
> > The attached patch changes `split-window-sensibly' to just try
> > spliting the longest edge first.
>
> I see no symmetry between width and height.
>
> To make a window usable you need to decide how many columns you need
> to fit into the window by customizing split-width-threshold.
>
> By default it's 160 that means two horizontally split windows
> with 80 columns in each that allows a comfortable use of each window.
>
> OTOH, the window height has less relevance since most of the time
> all windows are scrolled vertically.
>

Thanks for your reply.

My proposal is not about questioning the relevance of the
split-width-threshold and split-height-threshold. They are perfectly fine
to me.

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.

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

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

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

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.

[-- Attachment #2: Type: text/html, Size: 3206 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2024-12-14 20:10 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-14 10:05 Prefer to split along the longest edge Nicolas Desprès
2024-12-14 11:30 ` Eli Zaretskii
2024-12-14 11:45   ` Nicolas Desprès
2024-12-14 12:34     ` Eli Zaretskii
2024-12-14 14:06       ` Nicolas Desprès
2024-12-14 14:55         ` Eli Zaretskii
2024-12-14 15:41           ` Nicolas Desprès
2024-12-14 17:16   ` martin rudalics
2024-12-14 17:33     ` Eli Zaretskii
2024-12-14 17:36     ` Eli Zaretskii
2024-12-14 18:35 ` Juri Linkov
2024-12-14 20:10   ` Nicolas Desprès

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).