* First split horizontally, and then vertically
@ 2015-08-11 20:37 Alexander Shukaev
2015-08-12 14:45 ` Jorge A. Alfaro-Murillo
0 siblings, 1 reply; 5+ messages in thread
From: Alexander Shukaev @ 2015-08-11 20:37 UTC (permalink / raw)
To: help-gnu-emacs
Hello,
which values should I put into
(setq-default split-width-threshold ?)
(setq-default split-height-threshold ?)
so that Emacs first splits windows horizontally (until the limit) and
only then splits them vertically. Schematically this would look as
follows:
+-----+
| |
| |
| |
+-----+
+--+--+
| | |
| | |
| | |
+--+--+
+--+--+
| | |
+--+ |
| | |
+--+--+
+--+--+
+--+ |
+--+ |
| | |
+--+--+
+--+--+
+--+ |
+--+--+
| | |
+--+--+
etc. Thanks.
Regards,
Alexander
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First split horizontally, and then vertically
2015-08-11 20:37 First split horizontally, and then vertically Alexander Shukaev
@ 2015-08-12 14:45 ` Jorge A. Alfaro-Murillo
2015-08-12 16:06 ` Alexander Shukaev
0 siblings, 1 reply; 5+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-08-12 14:45 UTC (permalink / raw)
To: help-gnu-emacs
Alexander Shukaev writes:
> which values should I put into
>
> (setq-default split-width-threshold ?)
> (setq-default split-height-threshold ?)
>
> so that Emacs first splits windows horizontally (until the
> limit) and only then splits them vertically.
I also prefer vertical splitting, I have it set up so that no
windows are split horizontally unless I do it myself:
#+BEGIN_SRC emacs-lisp
(setq split-height-threshold nil)
(setq split-width-threshold 150)
#+END_SRC
You can also try setting split-height-threshold to 0, to make a
vertical split more likely than a horizontal one.
Best,
--
Jorge.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First split horizontally, and then vertically
2015-08-12 14:45 ` Jorge A. Alfaro-Murillo
@ 2015-08-12 16:06 ` Alexander Shukaev
2015-08-12 16:45 ` Jorge A. Alfaro-Murillo
0 siblings, 1 reply; 5+ messages in thread
From: Alexander Shukaev @ 2015-08-12 16:06 UTC (permalink / raw)
To: Jorge A. Alfaro-Murillo; +Cc: help-gnu-emacs
>> which values should I put into
>> (setq-default split-width-threshold ?)
>> (setq-default split-height-threshold ?)
>> so that Emacs first splits windows horizontally (until the limit) and only
>> then splits them vertically.
>
>
> I also prefer vertical splitting, I have it set up so that no windows are
> split horizontally unless I do it myself:
>
> #+BEGIN_SRC emacs-lisp
> (setq split-height-threshold nil)
> (setq split-width-threshold 150)
> #+END_SRC
>
> You can also try setting split-height-threshold to 0, to make a vertical
> split more likely than a horizontal one.
That's the problem. I've tried this already, and as soon as I have
some integer (0, for example) in `split-height-threshold' the first
split by `split-window-sensibly' is vertical one, i.e.
+-----+
| |
+-----+
| |
+-----+
but I want a horizontal split first
+--+--+
| | |
| | |
| | |
+--+--+
maybe even further (if the size of the monitor permits)
+--+--+--+
| | | |
| | | |
| | | |
+--+--+--+
and only then vertical splits should start.
Concerning
(setq split-height-threshold nil)
as you said, this one forbids vertical splits completely which is also
something I don't like.
Kind regards,
Alexander
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First split horizontally, and then vertically
2015-08-12 16:06 ` Alexander Shukaev
@ 2015-08-12 16:45 ` Jorge A. Alfaro-Murillo
2015-08-12 19:43 ` Alexander Shukaev
0 siblings, 1 reply; 5+ messages in thread
From: Jorge A. Alfaro-Murillo @ 2015-08-12 16:45 UTC (permalink / raw)
To: help-gnu-emacs
Alexander Shukaev writes:
>>> which values should I put into
>>> (setq-default split-width-threshold ?)
>>> (setq-default split-height-threshold ?)
>>> so that Emacs first splits windows horizontally (until the
>>> limit) and only then splits them vertically.
>>
>> I also prefer vertical splitting, I have it set up so that no
>> windows are split horizontally unless I do it myself:
>>
>> #+BEGIN_SRC emacs-lisp
>> (setq split-height-threshold nil)
>> (setq split-width-threshold 150)
>> #+END_SRC
>>
>> You can also try setting split-height-threshold to 0, to make a
>> vertical split more likely than a horizontal one.
>
> That's the problem. I've tried this already, and as soon as I
> have some integer (0, for example) in `split-height-threshold'
> the first split by `split-window-sensibly' is vertical one
I think the problem is the way that split-window-sensibly works,
it first checks if the window is at least split-height-threshold
lines tall, if it is then it splits horizontally, if it is not
then it checks if the window is at least split-width-threshold
columns wide to split vertically. You want the opposite to happen.
You should look at the code of split-window-sensibly and make your
own function, one that first checks split-width-threshold. Then
you should set split-window-preferred-function to that function.
This is not tested but could work:
#+BEGIN_SRC emacs-lisp
(defun split-window-more-sensibly (&optional window)
(let ((window (or window (selected-window))))
(or (and (window-splittable-p window t)
;; Split window horizontally.
(with-selected-window window
(split-window-right)))
(and (window-splittable-p window)
;; Split window vertically.
(with-selected-window window
(split-window-below)))
(and (eq window (frame-root-window (window-frame window)))
(not (window-minibuffer-p window))
;; If WINDOW is the only window on its frame and is
not the
;; minibuffer window, try to split it vertically
;; disregarding the value of
`split-height-threshold'.
(let ((split-height-threshold 0)) (when
(window-splittable-p window)
(with-selected-window window
(split-window-below))))))))
(setq split-window-preferred-function
'split-window-more-sensibly)
#+END_SRC
--
Jorge.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: First split horizontally, and then vertically
2015-08-12 16:45 ` Jorge A. Alfaro-Murillo
@ 2015-08-12 19:43 ` Alexander Shukaev
0 siblings, 0 replies; 5+ messages in thread
From: Alexander Shukaev @ 2015-08-12 19:43 UTC (permalink / raw)
To: Jorge A. Alfaro-Murillo; +Cc: help-gnu-emacs
> You should look at the code of split-window-sensibly and make your own
> function, one that first checks split-width-threshold. Then you should set
> split-window-preferred-function to that function. This is not tested but
> could work:
>
> #+BEGIN_SRC emacs-lisp
> (defun split-window-more-sensibly (&optional window)
> (let ((window (or window (selected-window))))
> (or (and (window-splittable-p window t)
> ;; Split window horizontally.
> (with-selected-window window
> (split-window-right)))
> (and (window-splittable-p window)
> ;; Split window vertically.
> (with-selected-window window
> (split-window-below)))
> (and (eq window (frame-root-window (window-frame window)))
> (not (window-minibuffer-p window))
> ;; If WINDOW is the only window on its frame and is
> not the
> ;; minibuffer window, try to split it vertically
> ;; disregarding the value of
> `split-height-threshold'.
> (let ((split-height-threshold 0)) (when
> (window-splittable-p window)
> (with-selected-window window
> (split-window-below))))))))
>
> (setq split-window-preferred-function 'split-window-more-sensibly)
> #+END_SRC
Thanks for pointing this out Jorge. Indeed, I've tailored a
comprehensive solution:
(with-eval-after-load "window"
(defcustom split-window-below nil
"If non-nil, vertical splits produce new windows below."
:group 'windows
:type 'boolean)
(defcustom split-window-right nil
"If non-nil, horizontal splits produce new windows to the right."
:group 'windows
:type 'boolean)
(fmakunbound #'split-window-sensibly)
(defun split-window-sensibly
(&optional window)
"Split WINDOW in a way suitable for `display-buffer'.
WINDOW defaults to the currently selected window. 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 either the right
window if `split-window-right' is non-nil or the left window if
`split-window-right' is nil. Otherwise, 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 either the lower window if
`split-window-below' is non-nil or the upper window if
`split-window-below' is nil. If this can't be done either and WINDOW
is the only window on its frame, try to split WINDOW horizontally
disregarding any value specified by `split-width-threshold'. If that
succeeds, return either the right window if `split-window-right' is
non-nil or the left window if `split-window-right' is nil. Return nil
otherwise.
By default `display-buffer' routines call this function to split the
largest or least recently used window. To change the default customize
the option `split-window-preferred-function'.
You can enforce this function to not split WINDOW horizontally, by
setting (or binding) the variable `split-width-threshold' to nil. If,
in addition, you set `split-height-threshold' to zero, chances increase
that this function does split WINDOW vertically.
In order to not split WINDOW vertically, set (or bind) the variable
`split-height-threshold' to nil. Additionally, you can set
`split-width-threshold' to zero to make a horizontal split more likely
to occur.
Have a look at the function `window-splittable-p' if you want to know
how `split-window-sensibly' determines whether WINDOW can be split."
(setq window (or window (selected-window)))
(or (and (window-splittable-p window t)
;; Split window horizontally.
(split-window window nil (if split-window-right 'left 'right)))
(and (window-splittable-p window)
;; Split window vertically.
(split-window window nil (if split-window-below 'above 'below)))
(and (eq window (frame-root-window (window-frame window)))
(not (window-minibuffer-p window))
;; If WINDOW is the only window on its frame and is not the
;; minibuffer window, try to split it horizontally disregarding the
;; value of `split-width-threshold'.
(let ((split-width-threshold 0))
(when (window-splittable-p window t)
(split-window window nil (if split-window-right
'left
'right))))))))
It does exactly what I wanted: first horizontal splits (until the
reasonable limit is reached), and then only vertical splits; as long
as
(setq-default
split-height-threshold 0
split-width-threshold 160) ; the reasonable limit for horizontal splits
What I wanted to point out also, are the two new `defcustom'
variables, `split-window-below' and `split-window-right'. I believe
they could extend configurability of the standard
`split-window-sensibly' quite well. I would like to propose
developers to add these to Emacs's 'window.el'.
Kind regards,
Alexander
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-08-12 19:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-11 20:37 First split horizontally, and then vertically Alexander Shukaev
2015-08-12 14:45 ` Jorge A. Alfaro-Murillo
2015-08-12 16:06 ` Alexander Shukaev
2015-08-12 16:45 ` Jorge A. Alfaro-Murillo
2015-08-12 19:43 ` Alexander Shukaev
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).