Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs rearrange split panes

Tags:

emacs

If I'm working in (terminal) Emacs and have 2 buffers on screen using a horizontal split:

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

Then I decide to open the slime repl, Emacs will split one of those horizontal panes vertically:

+--------------------------+
|                          |
|                          |
|                          |
|                          |
+-------------+------------+
|             |            |
|             |  slime     |
|             |            |
|             |            |
+-------------+------------+

But what I want is to have slime on the right, using the full height of the window:

+-------------+------------+
|             |            |
|             |            |
|             |            |
|             |            |
+-------------+  slime     |
|             |            |
|             |            |
|             |            |
|             |            |
+-------------+------------+

Is there any easy way to get from the arrangement Emacs automatically gave me, to the one I want (e.g. a rotate arrangement), or do I explicitly close and re-split the windows myself?

EDIT | Also curious if I can directly open a full vertical split if I'm currently using a full horizontal split, or if it's effectively impossible.

like image 220
d11wtq Avatar asked Jul 01 '13 23:07

d11wtq


2 Answers

If you like pre-set window configurations, take a look at the "workspace management" pakages:

  • Perspective gives you named workspaces
  • Equilibrium Emacs Window Manager is similar but more sophisticated tool which allows to configure popup placement, window configuraion, buffers, fonts and keybindings.

There is more on the project management page on EmacsWiki.

To your second question, here is what I have in my configuration to flip horizontal/vertical splits (credit: https://github.com/yyr/emacs.d):

(defun split-window-func-with-other-buffer (split-function)
  (lexical-let ((s-f split-function))
    (lambda ()
      (interactive)
      (funcall s-f)
      (set-window-buffer (next-window) (other-buffer)))))

(defun split-window-horizontally-instead ()
  (interactive)
  (save-excursion
    (delete-other-windows)
    (funcall (split-window-func-with-other-buffer 'split-window-horizontally))))

(defun split-window-vertically-instead ()
  (interactive)
  (save-excursion
    (delete-other-windows)
    (funcall (split-window-func-with-other-buffer 'split-window-vertically))))

(global-set-key "\C-x|" 'split-window-horizontally-instead)
(global-set-key "\C-x_" 'split-window-vertically-instead)
like image 53
Alex Vorobiev Avatar answered Sep 25 '22 15:09

Alex Vorobiev


There are certainly libraries for transforming a frame's window configuration (flip, rotate, etc...), and other libraries for rotating the visible buffers through the available windows. Combining those would achieve your aim.

I like TransposeFrame for the former, and I can see at least a couple of options for the latter:

  • https://github.com/banister/window-rotate-for-emacs
  • http://www.emacswiki.org/emacs/TransposeWindows

In general, CategoryWindows on the Wiki should be useful to you.

Note that the window configuration transforms do need to delete and re-create the splits, so the original window objects do not all survive the process. In that respect, it's not actually possible to do what you're asking; but for most purposes, 'faking it' is sufficient.

like image 23
phils Avatar answered Sep 23 '22 15:09

phils