Emacs window detection is already split

How do I know if 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 characters.

Each time I change my .emacs file and I want to reload it in place, so I run Mx load-file in my .emacs file, and this window that I am in gets re-split.

Is there some kind of command that I can call to check if the frame has already been split and only call (split-window-horizontally) if it doesn't? Sort of:

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

or

 (when (not (window-is-already-split)) (split-window-horizontally)) 
+6
source share
2 answers

window-list will return you a list of windows (for the current frame) so you can:

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

Check out the related documentation for windows .

+10
source

These are pointless questions; windows don't break.

Yes, there are functions called split-window ... but what they do is simply reduce the window size and create a new one in the freed space.

You cannot just use (= 1 (length (window-list))), since you have at least one window per frame (not counting the sim-windows of the minibuffer).

You may try:

 (< (length (frame-list)) (length (window-list))) 

but it doesn’t tell you if there are several windows in the selected frame, what are you really asking, since obviously it could be another frame containing several windows.

So, if you ask the question CORRECTLY, β€œhow can I find out if 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)))))) 
-3
source

Source: https://habr.com/ru/post/918021/


All Articles