David Zureick-Brown
David Zureick-Brown

Reputation: 715

Is there a way to retile buffer windows in Emacs?

I have two buffer windows open in emacs, arranged vertically. Is there a command that rearranges them horizontally?

Upvotes: 9

Views: 920

Answers (3)

Grzegorz Rożniecki
Grzegorz Rożniecki

Reputation: 28015

I use following snippet taken from Emacs wiki:

(defun toggle-window-split ()
  (interactive)
  (if (= (count-windows) 2)
      (let* ((this-win-buffer (window-buffer))
         (next-win-buffer (window-buffer (next-window)))
         (this-win-edges (window-edges (selected-window)))
         (next-win-edges (window-edges (next-window)))
         (this-win-2nd (not (and (<= (car this-win-edges)
                     (car next-win-edges))
                     (<= (cadr this-win-edges)
                     (cadr next-win-edges)))))
         (splitter
          (if (= (car this-win-edges)
             (car (window-edges (next-window))))
          'split-window-horizontally
        'split-window-vertically)))
    (delete-other-windows)
    (let ((first-win (selected-window)))
      (funcall splitter)
      (if this-win-2nd (other-window 1))
      (set-window-buffer (selected-window) this-win-buffer)
      (set-window-buffer (next-window) next-win-buffer)
      (select-window first-win)
      (if this-win-2nd (other-window 1))))))

(define-key ctl-x-4-map "t" 'toggle-window-split)

Just put this into init.el and use Ctrl-x 4 t.

Upvotes: 4

phils
phils

Reputation: 73334

The Transpose Frame library provides an excellent set of functionality for manipulating the windows in a frame (any of transpose-frame, rotate-frame-clockwise, or rotate-frame-anti-clockwise would suffice for your particular example).

There are other alternatives, but I find this library fairly comprehensive. See the Wiki page (or the Commentary in the code) for ascii drawings of what each function does.

Upvotes: 8

Drew
Drew

Reputation: 30708

You asked about tiling windows in a frame. Others will answer you directly about that (C-x 3 is a start). But you might also want to know that you can use separate frames and tile the frames across or down your display.

Upvotes: 3

Related Questions