5

Following scenario: 1) I start emacs and the initial frame is as follow:

+---------------+
|               |
|               |
|               |
|               |
|               |
+---------------+

1) I split the window horizontally (C-x 2).

+---------------+
|               |
|               |
+---------------+
|               |
|               |
+---------------+

2) now I would like to have one third window, which stretches over the two horizontal ones, resulting in a layout as follow:

+----------+----+
|          |    |
|          |    |
+----------+    +
|          |    |
|          |    |
+----------+----+

How can I achieve this easily without deleting one window (C-x 0), splitting vertically (C-x 3) and then splitting each window horizontally again (C-x 2) ?

My real setup is obviously much more complex, and I resort at the moment to creating a second frame which I would like to avoid.

The same question can be asked for horizontal.

1 Answer 1

8

It is possible to split the frame's root window which encompasses both of your windows, thereby allowing you to add a third window at any side. There is no built-in command to do that though, so here's some example code to define commands for this particular task:

(defun my-split-root-window (size direction)
  (split-window (frame-root-window)
                (and size (prefix-numeric-value size))
                direction))

(defun my-split-root-window-below (&optional size)
  (interactive "P")
  (my-split-root-window size 'below))

(defun my-split-root-window-right (&optional size)
  (interactive "P")
  (my-split-root-window size 'right))
6
  • Thanks - works perfectly. I'll add it to my emacs.el file.
    – Rainer
    Mar 13, 2015 at 10:39
  • Just one question - what does the "P" in (interactive "P") mean?
    – Rainer
    Mar 13, 2015 at 10:50
  • It tells Emacs to read in the prefix value in raw form in case the command is executed interactively. So, if you're invoking the command with a M-9, it would pass a value of (9) which is turned into 9 and tells the command to use such a size when splitting. Passing nothing would give it nil which would be ignored. The usual "p" form would interpret no prefix argument as 1, that's why I'm going the extra mile here.
    – wasamasa
    Mar 13, 2015 at 11:10
  • Thanks. Makes sense. To bind it to a global key, (global-set-key (kbd "C-x 6") 'my-split-root-window-below) does not work as I have to specify a value - how can I do this apart from f=defining a helper function?
    – Rainer
    Mar 13, 2015 at 11:31
  • Works just fine here, thanks to the interactive form which reads in the argument when using the command interactively. The argument shouldn't even need to be specified when using the command programmatically because it's marked as optional.
    – wasamasa
    Mar 13, 2015 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.