Reputation: 6387
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))
Upvotes: 7
Views: 657
Reputation: 256
This is a meaningless questions, windows are not split.
Yes, there are functions named split-window..., but what they do is merely to reduce the size of the window, and create a new one in the space thus freed.
You cannot just use (= 1 (length (window-list))) since you have at least one window per frame (not counting the simili-window of the minibuffer).
You could try:
(< (length (frame-list)) (length (window-list)))
but that doesn't tell you if there are several windows in the selected frame, which is what you are actually asking, since obviously it could be another frame that contains several windows.
So if you ask the question CORRECTLY, "how can I know whether the selected frame contains more than one window", you can easily find the answer:
(require 'cl)
(defun complement (fun)
(byte-compile `(lambda (&rest args) (not (apply ',fun args)))))
(defun* more-than-one-window-in-frame-p (&optional (frame (selected-frame)))
(< 1 (length (remove* frame (window-list)
:key (function window-frame)
:test (complement (function eql))))))
Upvotes: -3
Reputation: 74480
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.
Upvotes: 11