* 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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; 41+ 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] 41+ 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
2024-12-15 7:34 ` Juri Linkov
0 siblings, 1 reply; 41+ 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] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-14 20:10 ` Nicolas Desprès
@ 2024-12-15 7:34 ` Juri Linkov
2024-12-15 9:29 ` Nicolas Desprès
0 siblings, 1 reply; 41+ messages in thread
From: Juri Linkov @ 2024-12-15 7:34 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: emacs-devel
> 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.
> 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.
> 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.
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
...
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-15 7:34 ` Juri Linkov
@ 2024-12-15 9:29 ` Nicolas Desprès
2024-12-16 7:55 ` Juri Linkov
0 siblings, 1 reply; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-15 9:29 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
[-- Attachment #1: Type: text/plain, Size: 2840 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 4939 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-15 9:29 ` Nicolas Desprès
@ 2024-12-16 7:55 ` Juri Linkov
2024-12-16 11:56 ` Nicolas Desprès
2024-12-16 17:15 ` [External] : " Drew Adams
0 siblings, 2 replies; 41+ messages in thread
From: Juri Linkov @ 2024-12-16 7:55 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: emacs-devel
>> 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.
Makes sense. Then what about adding a new option that defines
the minimal number of columns each window should have after split?
With a name like 'split-columns-threshold'.
As long as the width of a new window will fit into 'split-columns-threshold',
split horizontally, otherwise vertically.
Then you can split to 3 or 4 horizontal splits until reaching the limit
of 'split-columns-threshold'. After that should split the narrow windows
vertically.
>>> 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.
Agreed, this is a problem.
>> 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
We need to carefully check if it can handle various use cases.
> 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).
Indeed, better to fallback to vertical split when all options are exhausted.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 7:55 ` Juri Linkov
@ 2024-12-16 11:56 ` Nicolas Desprès
2024-12-16 17:14 ` Eli Zaretskii
` (2 more replies)
2024-12-16 17:15 ` [External] : " Drew Adams
1 sibling, 3 replies; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-16 11:56 UTC (permalink / raw)
To: Juri Linkov; +Cc: emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 2301 bytes --]
On Mon, Dec 16, 2024 at 8:59 AM Juri Linkov <juri@linkov.net> wrote:
> >> 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.
>
> Makes sense. Then what about adding a new option that defines
> the minimal number of columns each window should have after split?
> With a name like 'split-columns-threshold'.
>
> As long as the width of a new window will fit into
> 'split-columns-threshold',
> split horizontally, otherwise vertically.
>
> Then you can split to 3 or 4 horizontal splits until reaching the limit
> of 'split-columns-threshold'. After that should split the narrow windows
> vertically.
>
I think the variables split-width-threshold and split-height-threshold
already do that.
[...]
>
> > 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
>
> We need to carefully check if it can handle various use cases.
>
Yes, one can install the new behavior using split-window-preferred-function
to try it out.
>
> > 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).
>
> Indeed, better to fallback to vertical split when all options are
> exhausted.
>
I wrote a new patch that always fallback on vertical split, and I got rid
of the weird (width > 80) condition since split-width-threshold already
does it.
The result is a simpler patch that works perfectly.
It basically does that:
if width > height:
try to split horizontally, then try to split vertically
else
try to split vertically, then try to split horizontally
fallback to vertical split
Cheers,
-Nico
[-- Attachment #1.2: Type: text/html, Size: 4222 bytes --]
[-- Attachment #2: 0001-Prioritize-split-along-the-longest-edge-by-default.patch --]
[-- Type: application/octet-stream, Size: 5058 bytes --]
From b6639a615a590a69ad66ab730c975fea74fcdb62 Mon Sep 17 00:00:00 2001
From: Nicolas Despres <nicolas.despres@gmail.com>
Date: Mon, 16 Dec 2024 12:40:20 +0100
Subject: [PATCH] Prioritize split along the longest edge by default.
Currently, `split-window-sensibly' prefer to try to split vertically
first 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) trying to split vertically is
generally not the things to do because there is plenty more space
available 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.
This patch preserves the behavior of the `split-height-threshold' and
`split-width-threshold' variables. Splitting continue not be permitted
if the edge lenght is below the threshold.
* lisp/window.el (split-window-sensibly): Always prefer to try first the
longest edge instead of blindly trying to split vertically.
A part from that, the patch carefully preserves the current split logic.
---
lisp/window.el | 53 +++++++++++++++++++++++++++-----------------------
1 file changed, 29 insertions(+), 24 deletions(-)
diff --git a/lisp/window.el b/lisp/window.el
index e9d57652ec6..a91666837c6 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-vertical-split (window)
+ "Helper function for `split-window-sensibly'"
+ (when (window-splittable-p window)
+ (with-selected-window window
+ (split-window-below))))
+
+(defun window--try-horizontal-split (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
@@ -7380,14 +7390,11 @@ split-window-sensibly
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)))
+ (or (if (> (frame-width) (frame-height))
+ (or (window--try-horizontal-split window)
+ (window--try-vertical-split window))
+ (or (window--try-vertical-split window)
+ (window--try-horizontal-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
@@ -7405,10 +7412,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))))))))
+ (let ((split-height-threshold 0))
+ (window--try-vertical-split window))))))
(defun window--try-to-split-window (window &optional alist)
"Try to split WINDOW.
--
2.47.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 11:56 ` Nicolas Desprès
@ 2024-12-16 17:14 ` Eli Zaretskii
2024-12-16 17:44 ` Juri Linkov
2024-12-17 6:06 ` Nicolas Desprès
2024-12-16 17:32 ` Juri Linkov
2024-12-17 1:51 ` Liu Hui
2 siblings, 2 replies; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-16 17:14 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: juri, emacs-devel
> From: Nicolas Desprès <nicolas.despres@gmail.com>
> Date: Mon, 16 Dec 2024 12:56:47 +0100
> Cc: emacs-devel@gnu.org
>
> I wrote a new patch that always fallback on vertical split, and I got rid of the weird (width > 80) condition since
> split-width-threshold already does it.
>
> The result is a simpler patch that works perfectly.
>
> It basically does that:
>
> if width > height:
> try to split horizontally, then try to split vertically
> else
> try to split vertically, then try to split horizontally
> fallback to vertical split
AFAIU, this is an incompatible change in behavior, with no way for
users who want the old behavior to get it back.
If so, please augment the change by a user option which controls
whether windows are split as they were before or according to the new
algorithm. We can then discuss whether the default will be the old
behavior or the new one.
In any case, such a change needs a NEW entry, and probably also an
update for the manuals.
Last, but not least: for a contribution this size we'll need you to
assign copyright for your code to the FSF. If you agree, I will send
you the form to fill and the instructions to start the paperwork of
assigning the copyright.
Thanks.
^ permalink raw reply [flat|nested] 41+ messages in thread
* RE: [External] : Re: Prefer to split along the longest edge
2024-12-16 7:55 ` Juri Linkov
2024-12-16 11:56 ` Nicolas Desprès
@ 2024-12-16 17:15 ` Drew Adams
2024-12-17 8:39 ` Nicolas Desprès
1 sibling, 1 reply; 41+ messages in thread
From: Drew Adams @ 2024-12-16 17:15 UTC (permalink / raw)
To: Juri Linkov, Nicolas Desprès; +Cc: emacs-devel@gnu.org
> Makes sense. Then what about adding a new option that defines
> the minimal number of columns each window should have after split?
> With a name like 'split-columns-threshold'.
(Caveat: not following this thread.)
Just a comment that a name such as `*-threshold' doesn't
tell you whether the threshold is a lower or upper bound.
Usually, a word such as `min' or `max' in the name is
more helpful.
(Of course, regardless of the name, the doc string should
anyway spell things out appropriately.)
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 11:56 ` Nicolas Desprès
2024-12-16 17:14 ` Eli Zaretskii
@ 2024-12-16 17:32 ` Juri Linkov
2024-12-17 9:01 ` martin rudalics
2024-12-17 1:51 ` Liu Hui
2 siblings, 1 reply; 41+ messages in thread
From: Juri Linkov @ 2024-12-16 17:32 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: martin rudalics, emacs-devel
> I wrote a new patch that always fallback on vertical split, and I got rid
> of the weird (width > 80) condition since split-width-threshold already
> does it.
>
> The result is a simpler patch that works perfectly.
Thanks, a new patch is much better.
> It basically does that:
>
> if width > height:
> try to split horizontally, then try to split vertically
> else
> try to split vertically, then try to split horizontally
> fallback to vertical split
This makes sense, so Cc-ing Martin to confirm
if this is the right thing to do.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 17:14 ` Eli Zaretskii
@ 2024-12-16 17:44 ` Juri Linkov
2024-12-16 19:07 ` Eli Zaretskii
2024-12-17 6:06 ` Nicolas Desprès
1 sibling, 1 reply; 41+ messages in thread
From: Juri Linkov @ 2024-12-16 17:44 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Nicolas Desprès, emacs-devel
>> I wrote a new patch that always fallback on vertical split, and I got rid of the weird (width > 80) condition since
>> split-width-threshold already does it.
>>
>> The result is a simpler patch that works perfectly.
>>
>> It basically does that:
>>
>> if width > height:
>> try to split horizontally, then try to split vertically
>> else
>> try to split vertically, then try to split horizontally
>> fallback to vertical split
>
> AFAIU, this is an incompatible change in behavior, with no way for
> users who want the old behavior to get it back.
>
> If so, please augment the change by a user option which controls
> whether windows are split as they were before or according to the new
> algorithm. We can then discuss whether the default will be the old
> behavior or the new one.
There is already the existing option 'split-window-preferred-function'.
It could provide a choice of more values to select a predefined
behavior.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 17:44 ` Juri Linkov
@ 2024-12-16 19:07 ` Eli Zaretskii
2024-12-16 19:14 ` Juri Linkov
0 siblings, 1 reply; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-16 19:07 UTC (permalink / raw)
To: Juri Linkov; +Cc: nicolas.despres, emacs-devel
> From: Juri Linkov <juri@linkov.net>
> Cc: Nicolas Desprès <nicolas.despres@gmail.com>,
> emacs-devel@gnu.org
> Date: Mon, 16 Dec 2024 19:44:04 +0200
>
> >> I wrote a new patch that always fallback on vertical split, and I got rid of the weird (width > 80) condition since
> >> split-width-threshold already does it.
> >>
> >> The result is a simpler patch that works perfectly.
> >>
> >> It basically does that:
> >>
> >> if width > height:
> >> try to split horizontally, then try to split vertically
> >> else
> >> try to split vertically, then try to split horizontally
> >> fallback to vertical split
> >
> > AFAIU, this is an incompatible change in behavior, with no way for
> > users who want the old behavior to get it back.
> >
> > If so, please augment the change by a user option which controls
> > whether windows are split as they were before or according to the new
> > algorithm. We can then discuss whether the default will be the old
> > behavior or the new one.
>
> There is already the existing option 'split-window-preferred-function'.
> It could provide a choice of more values to select a predefined
> behavior.
We cannot ask users to write a function in order to get back old
behavior. Customizations via functions is not user-friendly enough
for such simple tasks.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 19:07 ` Eli Zaretskii
@ 2024-12-16 19:14 ` Juri Linkov
2024-12-16 19:53 ` Eli Zaretskii
0 siblings, 1 reply; 41+ messages in thread
From: Juri Linkov @ 2024-12-16 19:14 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: nicolas.despres, emacs-devel
>> > If so, please augment the change by a user option which controls
>> > whether windows are split as they were before or according to the new
>> > algorithm. We can then discuss whether the default will be the old
>> > behavior or the new one.
>>
>> There is already the existing option 'split-window-preferred-function'.
>> It could provide a choice of more values to select a predefined
>> behavior.
>
> We cannot ask users to write a function in order to get back old
> behavior. Customizations via functions is not user-friendly enough
> for such simple tasks.
I meant a choice from predefined functions.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 19:14 ` Juri Linkov
@ 2024-12-16 19:53 ` Eli Zaretskii
2024-12-17 6:12 ` Nicolas Desprès
0 siblings, 1 reply; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-16 19:53 UTC (permalink / raw)
To: Juri Linkov; +Cc: nicolas.despres, emacs-devel
> From: Juri Linkov <juri@linkov.net>
> Cc: nicolas.despres@gmail.com, emacs-devel@gnu.org
> Date: Mon, 16 Dec 2024 21:14:46 +0200
>
> >> > If so, please augment the change by a user option which controls
> >> > whether windows are split as they were before or according to the new
> >> > algorithm. We can then discuss whether the default will be the old
> >> > behavior or the new one.
> >>
> >> There is already the existing option 'split-window-preferred-function'.
> >> It could provide a choice of more values to select a predefined
> >> behavior.
> >
> > We cannot ask users to write a function in order to get back old
> > behavior. Customizations via functions is not user-friendly enough
> > for such simple tasks.
>
> I meant a choice from predefined functions.
Which ones? I don't see any.
And how will we advertise this in a way that users affected by this
change will discover it easily? split-window-sensibly is not a
command that users could look up, and split-window-preferred-function
is called by display-buffer, so finding this information in order to
use it for restoring previous behavior will not be easy.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 11:56 ` Nicolas Desprès
2024-12-16 17:14 ` Eli Zaretskii
2024-12-16 17:32 ` Juri Linkov
@ 2024-12-17 1:51 ` Liu Hui
2024-12-17 7:43 ` Juri Linkov
2024-12-17 8:26 ` Nicolas Desprès
2 siblings, 2 replies; 41+ messages in thread
From: Liu Hui @ 2024-12-17 1:51 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: emacs-devel, Juri Linkov
在 2024/12/16 19:56, Nicolas Desprès 写道:
>
> I wrote a new patch that always fallback on vertical split, and I got
> rid of the weird (width > 80) condition since split-width-threshold
> already does it.
>
> The result is a simpler patch that works perfectly.
>
> It basically does that:
>
> if width > height:
> try to split horizontally, then try to split vertically
> else
> try to split vertically, then try to split horizontally
> fallback to vertical split
Hi,
I have the same problem when using emacs. Thank you for the patch.
I think the main reason is that vertical split is always preferred
when vertical and horizontal split are both feasible (i.e. width >
split-width-threshold and height > split-height-threshold).
So it seems unnecessary to compare the width and height. How about
adding an option, e.g. split-window-preferred-direction, and change
the condition as follows?
if user prefers horizontal split
try to split horizontally, then try to split vertically
else
try to split vertically, then try to split horizontally
Hui
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 17:14 ` Eli Zaretskii
2024-12-16 17:44 ` Juri Linkov
@ 2024-12-17 6:06 ` Nicolas Desprès
2024-12-17 12:52 ` Eli Zaretskii
2024-12-17 12:59 ` Eli Zaretskii
1 sibling, 2 replies; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 6:06 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: juri, emacs-devel
[-- Attachment #1.1: Type: text/plain, Size: 1571 bytes --]
On Mon, Dec 16, 2024 at 6:14 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Nicolas Desprès <nicolas.despres@gmail.com>
> > Date: Mon, 16 Dec 2024 12:56:47 +0100
> > Cc: emacs-devel@gnu.org
> >
> > I wrote a new patch that always fallback on vertical split, and I got
> rid of the weird (width > 80) condition since
> > split-width-threshold already does it.
> >
> > The result is a simpler patch that works perfectly.
> >
> > It basically does that:
> >
> > if width > height:
> > try to split horizontally, then try to split vertically
> > else
> > try to split vertically, then try to split horizontally
> > fallback to vertical split
>
> AFAIU, this is an incompatible change in behavior, with no way for
> users who want the old behavior to get it back.
>
> If so, please augment the change by a user option which controls
> whether windows are split as they were before or according to the new
> algorithm. We can then discuss whether the default will be the old
> behavior or the new one.
>
> In any case, such a change needs a NEW entry, and probably also an
> update for the manuals.
>
I have attached a new patch that should address all your remarks.
I added a new option `preferred-split-edge' and updated the NEWS file and
the manual.
>
> Last, but not least: for a contribution this size we'll need you to
> assign copyright for your code to the FSF. If you agree, I will send
> you the form to fill and the instructions to start the paperwork of
> assigning the copyright.
>
>
I agree.
-Nico
[-- Attachment #1.2: Type: text/html, Size: 2946 bytes --]
[-- Attachment #2: 0001-Prioritize-split-along-the-longest-edge-by-default.patch --]
[-- Type: application/octet-stream, Size: 7545 bytes --]
From 6e1ebcbb7768f73b5d6498e8baccb899cebb1c0b Mon Sep 17 00:00:00 2001
From: Nicolas Despres <nicolas.despres@gmail.com>
Date: Tue, 17 Dec 2024 06:58:33 +0100
Subject: [PATCH] Prioritize split along the longest edge by default.
Currently, `split-window-sensibly' prefer to try to split vertically
first disregarding the actual shape of the frame or the users
preferences. This is a good default when Emacs is taller than wider.
However, when Emacs is in full-screen (landscape screen layout) trying to
split vertically may not be what the user expected since there is plenty
of space available on the right.
Typical scenario: Emacs is in landscape layout, one buffer is open in a
window covering the entire frame. Another buffer is opened in a second
window (C-x 4 f). Both split are feasible but users may prefer the
horizontal one.
This patch preserves the behavior of the `split-height-threshold' and
`split-width-threshold' variables. Splitting continue not be permitted
if the edge length is below the threshold.
* lisp/window.el (split-window-sensibly): Always prefer to try first the
longest edge instead of blindly trying to split vertically. * etc/NEWS:
Add an entry for new variable `preferred-split-edge'. *
doc/emacs/windows.texi: Document new variable `preferred-split-edge'.
---
doc/emacs/windows.texi | 5 ++-
etc/NEWS | 6 ++++
lisp/window.el | 73 ++++++++++++++++++++++++++++--------------
3 files changed, 59 insertions(+), 25 deletions(-)
diff --git a/doc/emacs/windows.texi b/doc/emacs/windows.texi
index 69f24ec192f..9e67cb1e07d 100644
--- a/doc/emacs/windows.texi
+++ b/doc/emacs/windows.texi
@@ -511,6 +511,7 @@ Window Choice
@vindex split-height-threshold
@vindex split-width-threshold
+@vindex preferred-split-edge
The split can be either vertical or horizontal, depending on the
variables @code{split-height-threshold} and
@code{split-width-threshold}. These variables should have integer
@@ -519,7 +520,9 @@ Window Choice
@code{split-width-threshold} is smaller than the window's width, the
split puts the new window on the right. If neither condition holds,
Emacs tries to split so that the new window is below---but only if the
-window was not split before (to avoid excessive splitting).
+window was not split before (to avoid excessive splitting). Whether
+Emacs tries to split the vertical or horizontal edge first, is
+determined by the value of @code{preferred-split-edge}.
@item
Otherwise, display the buffer in a window previously showing it.
diff --git a/etc/NEWS b/etc/NEWS
index 4f74795043e..3338e95bcaf 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -174,6 +174,12 @@ It has been obsolete since Emacs 30.1. Use '(category . comint)' instead.
Another user option 'display-tex-shell-buffer-action' has been removed too
for which you can use '(category . tex-shell)'.
++++
+*** New user option 'preferred-split-edge'.
+Users can now choose which edge (vertical or horizontal) is tried to be
+split first. With this new setting, when the frame is in landscape shape
+for instance, Emacs could split horizontally before to split vertically.
+
** Frames
+++
diff --git a/lisp/window.el b/lisp/window.el
index e9d57652ec6..db6affaf1dd 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -7347,20 +7347,47 @@ window-splittable-p
(* 2 (max window-min-height
(if mode-line-format 2 1))))))))))
+(defcustom preferred-split-edge 'vertical
+ "The edge that `split-window-sensibly' will try to split first.
+This order matter when both edges can be split according to
+`split-width-threshold' and `split-height-threshold'."
+ :type '(choice
+ (const :tag "Try to split vertically first (legacy behavior)"
+ vertical)
+ (const :tag "Try to split horizontally first"
+ horizontal)
+ (const :tag "Try to split along the longest edge first"
+ longest))
+ :version "30.1"
+ :group 'windows)
+
+(defun window--try-vertical-split (window)
+ "Helper function for `split-window-sensibly'"
+ (when (window-splittable-p window)
+ (with-selected-window window
+ (split-window-below))))
+
+(defun window--try-horizontal-split (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. If the threshold
+(`split-height-threshold' respectively `split-width-threshold')
+specifies an integer, WINDOW is at least that threshold lines tall
+(respectively wide) and can be split (vertically respectively
+horizontally). If that fails, try to split along the other edge. If
+this can't be done either and WINDOW is the only window on its frame,
+try to split WINDOW along the vertical edge disregarding any value
+specified by `split-height-threshold' respectively
+`split-width-threshold'. If that succeeds, return the lower window.
+Return nil otherwise.
+
+The edge that is tried first can be configured by setting
+`preferred-split-edge'.
By default `display-buffer' routines call this function to split
the largest or least recently used window. To change the default
@@ -7380,14 +7407,14 @@ split-window-sensibly
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)))
+ (or (if (or
+ (eql preferred-split-edge 'horizontal)
+ (and (eql preferred-split-edge 'longest)
+ (> (frame-width) (frame-height))))
+ (or (window--try-horizontal-split window)
+ (window--try-vertical-split window))
+ (or (window--try-vertical-split window)
+ (window--try-horizontal-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
@@ -7405,10 +7432,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))))))))
+ (let ((split-height-threshold 0))
+ (window--try-vertical-split window))))))
(defun window--try-to-split-window (window &optional alist)
"Try to split WINDOW.
--
2.47.1
^ permalink raw reply related [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 19:53 ` Eli Zaretskii
@ 2024-12-17 6:12 ` Nicolas Desprès
2024-12-17 7:40 ` Juri Linkov
0 siblings, 1 reply; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 6:12 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: Juri Linkov, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 1611 bytes --]
On Mon, Dec 16, 2024 at 8:54 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > From: Juri Linkov <juri@linkov.net>
> > Cc: nicolas.despres@gmail.com, emacs-devel@gnu.org
> > Date: Mon, 16 Dec 2024 21:14:46 +0200
> >
> > >> > If so, please augment the change by a user option which controls
> > >> > whether windows are split as they were before or according to the
> new
> > >> > algorithm. We can then discuss whether the default will be the old
> > >> > behavior or the new one.
> > >>
> > >> There is already the existing option
> 'split-window-preferred-function'.
> > >> It could provide a choice of more values to select a predefined
> > >> behavior.
> > >
> > > We cannot ask users to write a function in order to get back old
> > > behavior. Customizations via functions is not user-friendly enough
> > > for such simple tasks.
> >
> > I meant a choice from predefined functions.
>
> Which ones? I don't see any.
>
> And how will we advertise this in a way that users affected by this
> change will discover it easily? split-window-sensibly is not a
> command that users could look up, and split-window-preferred-function
> is called by display-buffer, so finding this information in order to
> use it for restoring previous behavior will not be easy.
>
'split-window-preferred-function' is well suited for a completely different
behavior.
Providing multiple functions for slightly different variants will most
likely duplicate code.
This patch already factors the code a bit.
I am more in favor of an option to choose the behavior of
`split-window-sensibly'.
[-- Attachment #2: Type: text/html, Size: 2721 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 6:12 ` Nicolas Desprès
@ 2024-12-17 7:40 ` Juri Linkov
2024-12-17 8:35 ` Nicolas Desprès
0 siblings, 1 reply; 41+ messages in thread
From: Juri Linkov @ 2024-12-17 7:40 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: martin rudalics, Eli Zaretskii, emacs-devel
> 'split-window-preferred-function' is well suited for a completely different
> behavior.
There is another aspect that still can't be customized.
The choice of the window to split is hard-coded
in 'display-buffer-pop-up-window'. It's either
the largest window or lru:
;; Attempt to split largest or least recently used window.
(setq window (or (window--try-to-split-window
(get-largest-window frame t) alist)
(window--try-to-split-window
(get-lru-window frame t) alist)))
Maybe another option needed here as well?
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 1:51 ` Liu Hui
@ 2024-12-17 7:43 ` Juri Linkov
2024-12-17 8:27 ` Nicolas Desprès
2024-12-17 8:26 ` Nicolas Desprès
1 sibling, 1 reply; 41+ messages in thread
From: Juri Linkov @ 2024-12-17 7:43 UTC (permalink / raw)
To: Liu Hui; +Cc: Nicolas Desprès, emacs-devel
> I have the same problem when using emacs. Thank you for the patch.
>
> I think the main reason is that vertical split is always preferred
> when vertical and horizontal split are both feasible (i.e. width >
> split-width-threshold and height > split-height-threshold).
>
> So it seems unnecessary to compare the width and height. How about
> adding an option, e.g. split-window-preferred-direction
split-window-preferred-direction is a better option name indeed.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 1:51 ` Liu Hui
2024-12-17 7:43 ` Juri Linkov
@ 2024-12-17 8:26 ` Nicolas Desprès
1 sibling, 0 replies; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 8:26 UTC (permalink / raw)
To: Liu Hui; +Cc: emacs-devel, Juri Linkov
[-- Attachment #1: Type: text/plain, Size: 634 bytes --]
On Tue, Dec 17, 2024 at 2:51 AM Liu Hui <liuhui1610@gmail.com> wrote:
>
>
> 在 2024/12/16 19:56, Nicolas Desprès 写道:
>
>
[...]
So it seems unnecessary to compare the width and height. How about
> adding an option, e.g. split-window-preferred-direction, and change
> the condition as follows?
>
> if user prefers horizontal split
> try to split horizontally, then try to split vertically
> else
> try to split vertically, then try to split horizontally
>
>
I think the longest choice is still needed for setup with one frame on a
portrait screen and another one on a landscape screen.
-Nico
[-- Attachment #2: Type: text/html, Size: 1563 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 7:43 ` Juri Linkov
@ 2024-12-17 8:27 ` Nicolas Desprès
0 siblings, 0 replies; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 8:27 UTC (permalink / raw)
To: Juri Linkov; +Cc: Liu Hui, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 310 bytes --]
On Tue, Dec 17, 2024 at 8:47 AM Juri Linkov <juri@linkov.net> wrote:
[...]
> > So it seems unnecessary to compare the width and height. How about
> > adding an option, e.g. split-window-preferred-direction
>
> split-window-preferred-direction is a better option name indeed.
>
Ok. I change it.
[-- Attachment #2: Type: text/html, Size: 865 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 7:40 ` Juri Linkov
@ 2024-12-17 8:35 ` Nicolas Desprès
2024-12-17 9:02 ` martin rudalics
0 siblings, 1 reply; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 8:35 UTC (permalink / raw)
To: Juri Linkov; +Cc: martin rudalics, Eli Zaretskii, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 947 bytes --]
On Tue, Dec 17, 2024 at 8:47 AM Juri Linkov <juri@linkov.net> wrote:
> > 'split-window-preferred-function' is well suited for a completely
> different
> > behavior.
>
> There is another aspect that still can't be customized.
> The choice of the window to split is hard-coded
> in 'display-buffer-pop-up-window'. It's either
> the largest window or lru:
>
> ;; Attempt to split largest or least recently used window.
> (setq window (or (window--try-to-split-window
> (get-largest-window frame t) alist)
> (window--try-to-split-window
> (get-lru-window frame t) alist)))
>
> Maybe another option needed here as well?
>
That's right, there is the same logic pattern that could be customized the
same way. But that should come in another patch. I could make one if people
agree.
What would be the variable name ? split-window-preferred-selection ?
-Nico
[-- Attachment #2: Type: text/html, Size: 1762 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: [External] : Re: Prefer to split along the longest edge
2024-12-16 17:15 ` [External] : " Drew Adams
@ 2024-12-17 8:39 ` Nicolas Desprès
0 siblings, 0 replies; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 8:39 UTC (permalink / raw)
To: Drew Adams; +Cc: Juri Linkov, emacs-devel@gnu.org
[-- Attachment #1: Type: text/plain, Size: 871 bytes --]
On Mon, Dec 16, 2024 at 6:15 PM Drew Adams <drew.adams@oracle.com> wrote:
> > Makes sense. Then what about adding a new option that defines
> > the minimal number of columns each window should have after split?
> > With a name like 'split-columns-threshold'.
>
> (Caveat: not following this thread.)
>
> Just a comment that a name such as `*-threshold' doesn't
> tell you whether the threshold is a lower or upper bound.
>
> Usually, a word such as `min' or `max' in the name is
> more helpful.
>
> (Of course, regardless of the name, the doc string should
> anyway spell things out appropriately.)
>
I agree. It actually brings confusion to the original conversation.
In our case, more explicit names would be split-line-min and
split-column-min.
If people agree on that, I could make another patch defining new aliases.
Cheers,
-Nico
[-- Attachment #2: Type: text/html, Size: 1771 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-16 17:32 ` Juri Linkov
@ 2024-12-17 9:01 ` martin rudalics
2024-12-17 13:32 ` Eli Zaretskii
0 siblings, 1 reply; 41+ messages in thread
From: martin rudalics @ 2024-12-17 9:01 UTC (permalink / raw)
To: Juri Linkov, Nicolas Desprès; +Cc: emacs-devel
>> It basically does that:
>>
>> if width > height:
>> try to split horizontally, then try to split vertically
The only thing I can say is that for some time people strongly opposed
the idea of splitting windows side by side by default. It's possible
that this attitude has changed by now.
>> else
>> try to split vertically, then try to split horizontally
>> fallback to vertical split
>
> This makes sense, so Cc-ing Martin to confirm
> if this is the right thing to do.
martin
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 8:35 ` Nicolas Desprès
@ 2024-12-17 9:02 ` martin rudalics
2024-12-17 9:09 ` Nicolas Desprès
2024-12-17 13:34 ` Eli Zaretskii
0 siblings, 2 replies; 41+ messages in thread
From: martin rudalics @ 2024-12-17 9:02 UTC (permalink / raw)
To: Nicolas Desprès, Juri Linkov; +Cc: Eli Zaretskii, emacs-devel
> What would be the variable name ? split-window-preferred-selection ?
Why a variable name? At least this should become an alist entry so an
application doesn't have to bind it separately.
martin
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 9:02 ` martin rudalics
@ 2024-12-17 9:09 ` Nicolas Desprès
2024-12-17 13:34 ` Eli Zaretskii
1 sibling, 0 replies; 41+ messages in thread
From: Nicolas Desprès @ 2024-12-17 9:09 UTC (permalink / raw)
To: martin rudalics; +Cc: Juri Linkov, Eli Zaretskii, emacs-devel
[-- Attachment #1: Type: text/plain, Size: 352 bytes --]
On Tue, Dec 17, 2024 at 10:02 AM martin rudalics <rudalics@gmx.at> wrote:
> > What would be the variable name ? split-window-preferred-selection ?
>
> Why a variable name? At least this should become an alist entry so an
> application doesn't have to bind it separately.
>
That's right. I did not think about the context of this change.
[-- Attachment #2: Type: text/html, Size: 869 bytes --]
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 6:06 ` Nicolas Desprès
@ 2024-12-17 12:52 ` Eli Zaretskii
2024-12-17 12:59 ` Eli Zaretskii
1 sibling, 0 replies; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-17 12:52 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: juri, emacs-devel
> From: Nicolas Desprès <nicolas.despres@gmail.com>
> Date: Tue, 17 Dec 2024 07:06:07 +0100
> Cc: juri@linkov.net, emacs-devel@gnu.org
>
> Last, but not least: for a contribution this size we'll need you to
> assign copyright for your code to the FSF. If you agree, I will send
> you the form to fill and the instructions to start the paperwork of
> assigning the copyright.
>
> I agree.
Form sent off-list.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 6:06 ` Nicolas Desprès
2024-12-17 12:52 ` Eli Zaretskii
@ 2024-12-17 12:59 ` Eli Zaretskii
2024-12-17 13:12 ` Robert Pluim
1 sibling, 1 reply; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-17 12:59 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: juri, emacs-devel
> From: Nicolas Desprès <nicolas.despres@gmail.com>
> Date: Tue, 17 Dec 2024 07:06:07 +0100
> Cc: juri@linkov.net, emacs-devel@gnu.org
>
> I have attached a new patch that should address all your remarks.
Thanks.
> @@ -519,7 +520,9 @@ Window Choice
> @code{split-width-threshold} is smaller than the window's width, the
> split puts the new window on the right. If neither condition holds,
> Emacs tries to split so that the new window is below---but only if the
> -window was not split before (to avoid excessive splitting).
> +window was not split before (to avoid excessive splitting). Whether
^^
Our convention is to leave two spaces between sentences. (The same is
true for the text in the commit log messages.)
> ++++
> +*** New user option 'preferred-split-edge'.
> +Users can now choose which edge (vertical or horizontal) is tried to be
> +split first. With this new setting, when the frame is in landscape shape
> +for instance, Emacs could split horizontally before to split vertically.
This should say what is the default behavior.
> +(defcustom preferred-split-edge 'vertical
> + "The edge that `split-window-sensibly' will try to split first.
> +This order matter when both edges can be split according to
> +`split-width-threshold' and `split-height-threshold'."
This doc string should explain the meaning of each value. (Yes, I
know that the text which describes each option does, but that doesn't
help when the user reads the doc string shown by "C-h v", for
example.)
> + :type '(choice
> + (const :tag "Try to split vertically first (legacy behavior)"
> + vertical)
> + (const :tag "Try to split horizontally first"
> + horizontal)
> + (const :tag "Try to split along the longest edge first"
> + longest))
> + :version "30.1"
^^^^^^^^^^^^^^
This should be "31.1".
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 12:59 ` Eli Zaretskii
@ 2024-12-17 13:12 ` Robert Pluim
0 siblings, 0 replies; 41+ messages in thread
From: Robert Pluim @ 2024-12-17 13:12 UTC (permalink / raw)
To: Nicolas Desprès; +Cc: Eli Zaretskii, juri, emacs-devel
>>>>> On Tue, 17 Dec 2024 14:59:34 +0200, Eli Zaretskii <eliz@gnu.org> said:
>> + :type '(choice
>> + (const :tag "Try to split vertically first (legacy behavior)"
>> + vertical)
I donʼt think you need the parenthetical comment (especially as
'legacy' can be seen as somewhat pejorative).
>> + (const :tag "Try to split horizontally first"
>> + horizontal)
>> + (const :tag "Try to split along the longest edge first"
>> + longest))
>> + :version "30.1"
Eli> ^^^^^^^^^^^^^^
Eli> This should be "31.1".
Please consider using `radio' instead of `choice'. I believe it looks
better for variables with only small number of options.
Robert
--
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 9:01 ` martin rudalics
@ 2024-12-17 13:32 ` Eli Zaretskii
0 siblings, 0 replies; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-17 13:32 UTC (permalink / raw)
To: martin rudalics; +Cc: juri, nicolas.despres, emacs-devel
> Date: Tue, 17 Dec 2024 10:01:01 +0100
> Cc: emacs-devel@gnu.org
> From: martin rudalics <rudalics@gmx.at>
>
> >> It basically does that:
> >>
> >> if width > height:
> >> try to split horizontally, then try to split vertically
>
> The only thing I can say is that for some time people strongly opposed
> the idea of splitting windows side by side by default. It's possible
> that this attitude has changed by now.
Not here, it didn't. Maybe because I'm not in the widespread business
of making every frame full-screen, or even close. But given a user
options, personal preferences can be easily accounted for.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 9:02 ` martin rudalics
2024-12-17 9:09 ` Nicolas Desprès
@ 2024-12-17 13:34 ` Eli Zaretskii
2024-12-18 10:05 ` martin rudalics
1 sibling, 1 reply; 41+ messages in thread
From: Eli Zaretskii @ 2024-12-17 13:34 UTC (permalink / raw)
To: martin rudalics; +Cc: nicolas.despres, juri, emacs-devel
> Date: Tue, 17 Dec 2024 10:02:23 +0100
> Cc: Eli Zaretskii <eliz@gnu.org>, emacs-devel@gnu.org
> From: martin rudalics <rudalics@gmx.at>
>
> > What would be the variable name ? split-window-preferred-selection ?
>
> Why a variable name? At least this should become an alist entry so an
> application doesn't have to bind it separately.
It could be both. But I firmly object to make this be customizable
_only_ through display-buffer action alists, because that is even less
user-friendly than function values of defcustoms.
^ permalink raw reply [flat|nested] 41+ messages in thread
* Re: Prefer to split along the longest edge
2024-12-17 13:34 ` Eli Zaretskii
@ 2024-12-18 10:05 ` martin rudalics
0 siblings, 0 replies; 41+ messages in thread
From: martin rudalics @ 2024-12-18 10:05 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: nicolas.despres, juri, emacs-devel
> It could be both. But I firmly object to make this be customizable
> _only_ through display-buffer action alists, because that is even less
> user-friendly than function values of defcustoms.
If we make this and other display buffer options a defcustom too, we'd
have to specify the semantics of that defcustom. In particular:
- Should the defcustom hold for any buffer to be displayed?
- Should it override what the calling program specifies in the ALIST
argument.
- Would a 'display-buffer-alist' entry override it?
Once these have been resolved, we can easily add defcustoms for most
options that are currently only available via 'display-buffer-alist'.
martin
^ permalink raw reply [flat|nested] 41+ messages in thread
end of thread, other threads:[~2024-12-18 10:05 UTC | newest]
Thread overview: 41+ 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
2024-12-15 7:34 ` Juri Linkov
2024-12-15 9:29 ` Nicolas Desprès
2024-12-16 7:55 ` Juri Linkov
2024-12-16 11:56 ` Nicolas Desprès
2024-12-16 17:14 ` Eli Zaretskii
2024-12-16 17:44 ` Juri Linkov
2024-12-16 19:07 ` Eli Zaretskii
2024-12-16 19:14 ` Juri Linkov
2024-12-16 19:53 ` Eli Zaretskii
2024-12-17 6:12 ` Nicolas Desprès
2024-12-17 7:40 ` Juri Linkov
2024-12-17 8:35 ` Nicolas Desprès
2024-12-17 9:02 ` martin rudalics
2024-12-17 9:09 ` Nicolas Desprès
2024-12-17 13:34 ` Eli Zaretskii
2024-12-18 10:05 ` martin rudalics
2024-12-17 6:06 ` Nicolas Desprès
2024-12-17 12:52 ` Eli Zaretskii
2024-12-17 12:59 ` Eli Zaretskii
2024-12-17 13:12 ` Robert Pluim
2024-12-16 17:32 ` Juri Linkov
2024-12-17 9:01 ` martin rudalics
2024-12-17 13:32 ` Eli Zaretskii
2024-12-17 1:51 ` Liu Hui
2024-12-17 7:43 ` Juri Linkov
2024-12-17 8:27 ` Nicolas Desprès
2024-12-17 8:26 ` Nicolas Desprès
2024-12-16 17:15 ` [External] : " Drew Adams
2024-12-17 8:39 ` 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).