Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting Emacs window is already split

How do I detect that an Emacs window has already been split?

In my .emacs file, I have:

(when (display-graphic-p)
  (set-frame-size (selected-frame) 166 85)
  (split-window-horizontally))

which allows me to have two buffers side-by-side, each exactly 80 chars wide.

Every once in a while I change my .emacs file and want to reload it in place, so I run M-x load-file on my .emacs file and that window I'm in gets re-split.

Is there some sort of command I can call to check if the frame has already been split and only call (split-window-horizontally) if it hasn't? Something like:

(when (window-is-root)
  (split-window-horizontally))

or

(when (not (window-is-already-split))
  (split-window-horizontally))
like image 571
sligocki Avatar asked Jun 13 '12 19:06

sligocki


1 Answers

window-list will return you a list of the windows (for the current frame), so you should be able to do:

(when (= (length (window-list)) 1)
  (split-window-horizontally))

Check out the relevant documentation for windows.

like image 128
Trey Jackson Avatar answered Sep 22 '22 14:09

Trey Jackson