Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Windows splitting: prefer only 2 windows horizontal spliting.

175 views
Skip to first unread message

Oleksandr Gavenko (aka gavenkoa)

unread,
Feb 20, 2011, 3:52:39 PM2/20/11
to help-gn...@gnu.org
How prefer horizontal splitting I know:

(when window-system
;; Prefer horizontal windows splitting.
(setq split-height-threshold 0)
(setq split-width-threshold nil)
)

But how stop Emacs from splitting when already 2 windows?
So reuse existing window.

For example I edit file (1 window) then M-x compile (2 windows)
then C-x ` (2 windows, *Compilation* and source with error) -
no other window appear.

Emacs 23.1/22.3/21.4 work in such way on Debian, but new Emacs 23.2.1
work different.

For example: open file, C-x v l (new window show log),
d (new window show diff, there are 3 windows now),
M-x man printf RET (new window show man, there 4 windows now).

So how force Emacs display no more that 2 windows at same time?


Perry Smith

unread,
Feb 20, 2011, 6:07:39 PM2/20/11
to Oleksandr Gavenko (aka gavenkoa), help-gn...@gnu.org

This is not exactly what you were asking for. I wanted to get emacs to
do what it was doing before. I followed the instructions but found
that it kept creating smaller and smaller windows. So, now I leave
split-height-threshold alone and do this (this is inside my
.emacs.d/init.el file.

(custom-set-variables
...
'(split-width-threshold 1600)
)

which basically says "don't split windows vertically".
Setting it to nil didn't have the effect I was looking for.

pedz


Perry Smith

unread,
Feb 21, 2011, 9:15:46 AM2/21/11
to martin rudalics, help-gn...@gnu.org

On Feb 21, 2011, at 1:47 AM, martin rudalics wrote:

> > This is not exactly what you were asking for. I wanted to get emacs to
> > do what it was doing before. I followed the instructions but found
>

> Which instructions?

The documentation for split-width-threshold, split-height-threshold, and
split-window-sensibly. In particular, split-window sensibly says:

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.

The last sentence prompted me to set split-height-threshold to 0
and that is probably why I constantly got smaller and smaller windows
instead of reusing a previous window.

>
> > that it kept creating smaller and smaller windows. So, now I leave
> > split-height-threshold alone and do this (this is inside my
> > .emacs.d/init.el file.
> >
> > (custom-set-variables
> > ...
> > '(split-width-threshold 1600)
> > )
> >
> > which basically says "don't split windows vertically".
>

> Actually it means "don't split windows horizontally" ;-)

Yea. I totally don't understand the language here. A vertically line
creating two windows is splitting it vertically in my pee sized brain.
Sorry about that.

>
> > Setting it to nil didn't have the effect I was looking for.
>

> What effect were you looking for?

What emacs use to do before split-window-sensibly.

> To avoid that `display-buffer' creates smaller and smaller windows, set
> the values of either or both `split-height-threshold' and
> `split-width-threshold' to nil or to some larger value. If this doesn't
> work for you there's a bug; so please try to tell us more precisely what
> you wanted to do and how it failed.


At the time, I concluded that it wasn't a bug in the code but just
that I misread / misunderstood the documentation. I believe I tried
setting split-width-threshold to nil and split-height-threshold (after
trying 0), I tried leaving it alone and it still didn't go back to the
old method. Setting split-width-threshold to some giant number
seems to take a different path through the code and gives me
the old behavior.

I can experiment more if you want me to and try and recreate
what I was setting.

pedz


Perry Smith

unread,
Feb 21, 2011, 12:43:55 PM2/21/11
to martin rudalics, help-gn...@gnu.org
On Feb 21, 2011, at 11:00 AM, martin rudalics wrote:

> 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.
>
> The last sentence prompted me to set split-height-threshold to 0
> and that is probably why I constantly got smaller and smaller windows
> instead of reusing a previous window.

Replacing "zero" by "a smaller value" might cause less confusion here.


>> Actually it means "don't split windows horizontally" ;-)
>
> Yea.  I totally don't understand the language here.  A vertically line
> creating two windows is splitting it vertically in my pee sized brain.
> Sorry about that.

I'm afraid every second user interprets this as you did.  Unfortunately,
it's not easy to find a less confusing term here.  We could replace
"horizontally" by "side-by-side" but I have no idea which term to use
instead of "vertically".

How about "top and bottom" ?


>> What effect were you looking for?
>
> What emacs use to do before split-window-sensibly.

Do you use wide frames so Emacs tries to split them into side-by-side
windows?  What are your frame sizes?

Yea.  My code is generally 80 columns but I have to widen my frame
extra wide to fit Ruby's error messages into one line.  At that point, emacs
started splitting my screen side-by-side which defected the
whole purpose of a wide frame.


> At the time, I concluded that it wasn't a bug in the code but just
> that I misread / misunderstood the documentation.  I believe I tried
> setting split-width-threshold to nil and split-height-threshold (after
> trying 0), I tried leaving it alone and it still didn't go back to the
> old method.  Setting split-width-threshold to some giant number
> seems to take a different path through the code and gives me
> the old behavior.

If you never want more than two windows per frame the following should
be sufficient:

(setq split-height-threshold nil)
(setq split-width-threshold nil)

Ok.  I'll try that.

Thanks,
pedz

Oleksandr Gavenko

unread,
Feb 21, 2011, 5:40:38 PM2/21/11
to help-gn...@gnu.org
On 2011-02-20 23:07, Perry Smith wrote:
> On Feb 20, 2011, at 2:52 PM, Oleksandr Gavenko (aka gavenkoa) wrote:
>> So how force Emacs display no more that 2 windows at same time?
>
> I wanted to get emacs to do what it was doing before.
I also.

> I followed the instructions but found

> that it kept creating smaller and smaller windows.

Same things!

> So, now I leave split-height-threshold alone and do this:
>
> (setq split-width-threshold 1600)


>
> which basically says "don't split windows vertically".

Nice!

> Setting it to nil didn't have the effect I was looking for.
>

Sad.

--
Best regards!


Oleksandr Gavenko

unread,
Feb 21, 2011, 5:44:51 PM2/21/11
to help-gn...@gnu.org
On 2011-02-21 17:43, Perry Smith wrote:
>>
>> (setq split-height-threshold nil)
>> (setq split-width-threshold nil)
>
> Ok. I'll try that.
>
On 4:5 (1280x1024) screen work fine.

Next week test on BAD notebook
with Debian/Emacs 23.2.1/1280x800.

--
Best regards!


martin rudalics

unread,
Feb 21, 2011, 2:46:53 AM2/21/11
to gave...@gmail.com, help-gn...@gnu.org
> How prefer horizontal splitting I know:
>
>
> (when window-system
> ;; Prefer horizontal windows splitting.
> (setq split-height-threshold 0)
> (setq split-width-threshold nil)
> )

This prefers "vertical" splitting in Emacs parlance ;-) But why do you
check for `window-system' and why do you set `split-height-threshold' to
zero?

> But how stop Emacs from splitting when already 2 windows?
> So reuse existing window.

Whenever you ask Emacs to display a buffer, it looks at the largest
window on your frame which, since you don't make side-by-side windows,
is the highest window on your frame. In `window-splittable-p' the
following happens:

(>= (window-height window)
(max split-height-threshold
(* 2 (max window-min-height
(if mode-line-format 2 1))))))))))

Since `split-height-threshold' is zero, a new window is split off
whenever the height of the largest window (the value of `window-height'
for that window) is at least as large as two times the minimum height of
the largest window (the value of `window-min-height').

Try setting `split-height-threshold' and `split-width-threshold' both to
nil. This should allow at most two windows on your frames.

martin

martin rudalics

unread,
Feb 21, 2011, 2:47:16 AM2/21/11
to ped...@gmail.com, help-gn...@gnu.org
> This is not exactly what you were asking for. I wanted to get emacs to
> do what it was doing before. I followed the instructions but found

Which instructions?

> that it kept creating smaller and smaller windows. So, now I leave
> split-height-threshold alone and do this (this is inside my
> .emacs.d/init.el file.
>
> (custom-set-variables
> ...
> '(split-width-threshold 1600)
> )
>

> which basically says "don't split windows vertically".

Actually it means "don't split windows horizontally" ;-)

> Setting it to nil didn't have the effect I was looking for.

What effect were you looking for?

To avoid that `display-buffer' creates smaller and smaller windows, set


the values of either or both `split-height-threshold' and
`split-width-threshold' to nil or to some larger value. If this doesn't
work for you there's a bug; so please try to tell us more precisely what
you wanted to do and how it failed.

Thanks, martin

martin rudalics

unread,
Feb 21, 2011, 12:00:42 PM2/21/11
to Perry Smith, help-gn...@gnu.org
> 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.
>
> The last sentence prompted me to set split-height-threshold to 0
> and that is probably why I constantly got smaller and smaller windows
> instead of reusing a previous window.

Replacing "zero" by "a smaller value" might cause less confusion here.

>> Actually it means "don't split windows horizontally" ;-)
>


> Yea. I totally don't understand the language here. A vertically line
> creating two windows is splitting it vertically in my pee sized brain.
> Sorry about that.

I'm afraid every second user interprets this as you did. Unfortunately,
it's not easy to find a less confusing term here. We could replace
"horizontally" by "side-by-side" but I have no idea which term to use
instead of "vertically".

>> What effect were you looking for?
>


> What emacs use to do before split-window-sensibly.

Do you use wide frames so Emacs tries to split them into side-by-side
windows? What are your frame sizes?

> At the time, I concluded that it wasn't a bug in the code but just


> that I misread / misunderstood the documentation. I believe I tried
> setting split-width-threshold to nil and split-height-threshold (after
> trying 0), I tried leaving it alone and it still didn't go back to the
> old method. Setting split-width-threshold to some giant number
> seems to take a different path through the code and gives me
> the old behavior.

If you never want more than two windows per frame the following should
be sufficient:

(setq split-height-threshold nil)
(setq split-width-threshold nil)

martin

martin rudalics

unread,
Feb 21, 2011, 2:03:07 PM2/21/11
to Perry Smith, help-gn...@gnu.org
> How about "top and bottom" ?

I think we could use `split-window-side-by-side' instead of
`split-window-horizontally'. But using `split-window-top-and-bottom'
instead of `split-window-vertically' doesn't sound very intuitive.

> Yea. My code is generally 80 columns but I have to widen my frame
> extra wide to fit Ruby's error messages into one line. At that point, emacs
> started splitting my screen side-by-side which defected the
> whole purpose of a wide frame.

I see. Is line wrapping for Ruby error messages bad? Where do you show
them - in a separate window?

martin

Oleksandr Gavenko

unread,
Mar 10, 2011, 7:38:28 AM3/10/11
to help-gn...@gnu.org
On 22.02.2011 0:44, Oleksandr Gavenko wrote:
> On 2011-02-21 17:43, Perry Smith wrote:
>>>
>>> (setq split-height-threshold nil)
>>> (setq split-width-threshold nil)
>>
>> Ok. I'll try that.
>>
> On 4:5 (1280x1024) screen work fine.
>
> Next week test on BAD notebook
> with Debian/Emacs 23.2.1/1280x800.
>
This work well on Emacs 22.3, 23.2.1, both Linux/Windows/Cygwin and
GUI/console.


0 new messages