Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

rotate split windows

8 views
Skip to first unread message

wim yedema

unread,
Dec 4, 2006, 8:33:23 AM12/4/06
to help-gn...@gnu.org
Hi,

I would like to be able to "rotate" the split between windows, eg: from (A, B) vertical to (A, B) horizonal, to (B, A) vertical, to (B, A) horizontal, and the other way around. Can anyone tell me how to do this?

Thanks,
Wim Yedema

Markus Triska

unread,
Dec 4, 2006, 2:54:37 PM12/4/06
to
"wim yedema" <wim.y...@gmail.com> writes:


Add this to your .emacs:


(defun rotate-split ()
(interactive)
(let ((root (car (window-tree))))
(if (listp root)
(let* ((w1 (nth 2 root))
(w2 (nth 3 root))
(b1 (window-buffer w1))
(b2 (window-buffer w2)))
(cond ((car root) ; currently vertically split
(delete-window w2)
(set-window-buffer (split-window-horizontally) b2))
(t ; currently horizontally split
(delete-window w1)
(set-window-buffer (split-window-vertically) b1))))
(message "Root window not split"))))

and invoke it with M-x rotate-split.

You can add this:

(global-set-key [f9] 'rotate-split)

to bind it to the function key F9 (for example).

The clockwise direction is analogous.


All the best,
Markus Triska

Dieter Wilhelm

unread,
Dec 4, 2006, 4:22:50 PM12/4/06
to wim yedema, help-gn...@gnu.org
"wim yedema" <wim.y...@gmail.com> writes:

> Hi,


> I would like to be able to "rotate" the split between windows,
> eg: from (A, B) vertical to (A, B) horizonal, to (B, A) vertical, to
> (B, A) horizontal, and the other way around. Can anyone tell me how

Can I assume that there are only two windows (A,B) in your Emacs
frame?

--
Best wishes

H. Dieter Wilhelm
Darmstadt, Germany


Marco Wahl

unread,
Dec 5, 2006, 5:09:28 AM12/5/06
to
Markus Triska <tri...@gmx.at> writes:

> Add this to your .emacs:
>
>
> (defun rotate-split ()
> (interactive)
> (let ((root (car (window-tree))))

> [...]

Calling the function gives

car: Symbol's function definition is void: window-tree

Is there an alternative for

$ emacs --version
GNU Emacs 21.3.1

?


TIA
--
Marco Wahl
http://visenso.com

Chris Menzel

unread,
Dec 5, 2006, 4:03:06 PM12/5/06
to
On 05 Dec 2006 11:09:28 +0100, Marco Wahl <m...@visenso.de> said:
> Markus Triska <tri...@gmx.at> writes:
>
>> Add this to your .emacs:
>>
>>
>> (defun rotate-split ()
>> (interactive)
>> (let ((root (car (window-tree))))
>> [...]
>
> Calling the function gives
>
> car: Symbol's function definition is void: window-tree
>
> Is there an alternative for
>
> $ emacs --version
> GNU Emacs 21.3.1

Give this a try:

(defun rotate-window-buffers()
(interactive)
(let* ((windows (window-list))
(buffers (mapcar #'window-buffer windows))
(wpoints (mapcar #'window-point windows))
(w (pop windows)))
(setq windows (append windows `(,w)))
(mapc (lambda(w)
(let ((b (pop buffers))
(p (pop wpoints)))
(set-window-buffer w b)
(set-window-point w p)))
windows)))

(define-key global-map [f7] 'rotate-window-buffers)

Markus Triska

unread,
Dec 6, 2006, 1:12:28 PM12/6/06
to
Marco Wahl <m...@visenso.de> writes:

> alternative for [...] GNU Emacs 21.3.1

No nice one (you can calculate the split using `window-egdes'):

Primitives to look inside of window configurations would make sense,
but none are implemented.


The code posted by Chris only rotates the buffers and doesn't flip the
split as requested; a more concise version:

(defun rotate-window-buffers ()
(interactive)
(let* ((ws (window-list))
(bs (mapcar 'window-buffer ws))
(ps (mapcar 'window-point ws))
(w (pop ws)))
(dolist (v (append ws `(,w)))
(set-window-buffer v (pop bs))
(set-window-point v (pop ps)))))

Chris Menzel

unread,
Dec 6, 2006, 4:34:56 PM12/6/06
to
On Wed, 06 Dec 2006 19:12:28 +0100, Markus Triska <tri...@gmx.at> said:
> Marco Wahl <m...@visenso.de> writes:
>
> The code posted by Chris only rotates the buffers and doesn't flip the
> split as requested;

Whoops, missed that feature request. :-)

wim yedema

unread,
Dec 7, 2006, 3:34:54 AM12/7/06
to Markus Triska, help-gn...@gnu.org
> Marco Wahl <m...@visenso.de> writes:
>
> > alternative for [...] GNU Emacs 21.3.1
>
> No nice one (you can calculate the split using `window-egdes'):
Unfortunately I also have version 21.3.1.
I think it's safe to say that no one is going to make this for me?

What version of emacs should I use to get the window-tree?

Wim


Markus Triska

unread,
Dec 7, 2006, 12:35:53 PM12/7/06
to
"wim yedema" <wim.y...@gmail.com> writes:

> What version of emacs should I use to get the window-tree?

Try CVS trunk.

0 new messages