From: "Nicolas Desprès" <nicolas.despres@gmail.com>
To: Juri Linkov <juri@linkov.net>
Cc: emacs-devel@gnu.org
Subject: Re: Prefer to split along the longest edge
Date: Mon, 16 Dec 2024 12:56:47 +0100 [thread overview]
Message-ID: <CAPqtr1+CzO+rfxSOVAQgrag=-SD_0kKt24-Qwi=Q_u5V8aY1Jg@mail.gmail.com> (raw)
In-Reply-To: <8734io2hac.fsf@mail.linkov.net>
[-- 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
next prev parent reply other threads:[~2024-12-16 11:56 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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-18 14:12 ` Eli Zaretskii
2024-12-18 16:24 ` martin rudalics
2024-12-18 16:55 ` Eli Zaretskii
2024-12-18 17:41 ` martin rudalics
2024-12-18 18:41 ` Eli Zaretskii
2024-12-18 19:13 ` martin rudalics
2024-12-19 7:06 ` Juri Linkov
2024-12-18 17:25 ` Juri Linkov
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-18 21:08 ` Nicolas Desprès
2024-12-19 6:39 ` Eli Zaretskii
2024-12-19 8:52 ` martin rudalics
2024-12-19 9:21 ` Eli Zaretskii
2024-12-19 16:20 ` Nicolas Desprès
2024-12-20 9:03 ` martin rudalics
2024-12-20 14:43 ` Nicolas Desprès
2024-12-20 15:05 ` Robert Pluim
2024-12-20 20:25 ` Stephen Berman
2024-12-21 11:54 ` Nicolas Desprès
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAPqtr1+CzO+rfxSOVAQgrag=-SD_0kKt24-Qwi=Q_u5V8aY1Jg@mail.gmail.com' \
--to=nicolas.despres@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=juri@linkov.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.