reddit / emacs

Is there a way to split the *whole frame* vertically?

Jack-o-tall-tales · 2022-07-25 10:11
I have a frame with windows like this: +---------------------+ | | | a | | | +---------------------+ | | | b | | | +---------------------+ And I want this: +---------+-----------+ | | | | a | | | | | +---------+ c | | | | | b | | | | | +---------+-----------+ That is, I: * already have a top/bottom split, buffer a above b. * want to end up a right/left left split, where the left side is split in the same way as the original top/bottom split (buffer a above b). I don't mind having to switch buffers after splitting to get the right buffer at c. Is there a way to do that?
Horrih · 2022-07-25 10:26
C-x 3 to do a left right split, then go to the left window and do a top/bottom split (C-x 2). Or did i misunderstand your question ?
Jack-o-tall-tales · 2022-07-25 10:31
Thanks, but I think you've slightly misunderstood. This would be a good way to go from a frame with *no* split windows to one with the split I'm looking for. But in my question, I *already have* a top/bottom split, and I want to end up with the a right/left split, where the left window is split in the same way as the top/bottom split I started with. I've edited the question for clarity.
KuangPoulp · 2022-07-25 11:10
I still don't get it.
Jack-o-tall-tales · 2022-07-25 11:15
Hmmmm turns out I'm bad at explaing things. Try this: open a new emacs session (or a new frame in a current session) and do `split-window-below` (by default, bound to `C-x 2`). What you see now is what I'm starting with. Now do: * `delete-window` (`C-x 0`) (now you should just have one window again, filling the frame) * `split-window-left` (`C-x 3`) (now two windows side by side) * `split-window-below` (`C-x 2`) Now you should have three windows, one big one on the right, and two smaller ones on the left, one above the other. What you see now is what I want to end up with. I want to be able to get from what I started with to what I end up with *using only command*. My question is: is there a command which does this?
jctherik · 2022-07-25 11:30
Do that, record it as a macro, save macro, run macro.
TomSwirly · 2022-07-25 11:36
Yes. OP wants to go from the _first_ picture to the _second_ one directly. You are starting from some other configuration where only a is on screen in the first picture.
n-i-c-l-a-s · 2022-07-25 11:59
I use DOOM Emacs with evil-mode, so it might work differently for you, but I can use SPC-w-n for "evil-window-new" and then SPC-w-L for "evil/window-move-right" and that accomplishes what you are trying to do. Unfortunately, I have no idea how this would work without evil-mode/DOOM...
karthink · 2022-07-25 12:54
(split-window (frame-root-window) nil t nil) Make it interactive: (defun my/split-window-right (&optional arg) (interactive "P") (if arg (split-window (frame-root-window) nil t nil) (call-interactively #'split-window-right))) (defun my/split-window-below (&optional arg) (interactive "P") (if arg (split-window (frame-root-window)) (call-interactively #'split-window-below))) (define-key global-map [remap split-window-right] 'my/split-window-right) (define-key global-map [remap split-window-below] 'my/split-window-below) Now you can split the frame root when you call `C-x 2` or `C-x 3` with a prefix argument, but you lose fine grained control over the split ratio. Many users are unaware that they can control the window sizes with prefix arguments when splitting, so you may be okay with that tradeoff. ---- EDIT: [Emacs' window management system](https://www.gnu.org/software/emacs/manual/html_node/elisp/Windows-and-Frames.html) is similar to a manual tiling window manager like i3wm: windows in a frame are arranged in a tree, and the live windows are the leaves. Try runnng (window-tree) You can do any kind of window manipulation you need by walking this tree with the `window-*` functions (`window-parent`, `window-next-sibling` etc) provided by Emacs.
TheFrenchPoulp · 2022-07-25 13:10
Try this: (split-window (frame-root-window) nil 'right)
onetom · 2022-07-25 14:00
the steps given as an example doesn't retain the original content of the windows, so i think it was just a demonstration of the splits. macros might not be enough for this, so probably karthik's answer is the best.
Jack-o-tall-tales · 2022-07-25 18:47
Thanks!! This was really useful.
PBMagi · 2022-07-25 23:30
Don't know about OP, but it helped me!
HM0880 · 2022-07-30 23:06
Amazing! I've added the functions to my config. I don't use the prefix key for the split ratio, so these functions work for me as-is. Also, thanks for the mention of `(window-tree)`; it's always a good day to learn more about Emacs internals.