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

Toggle between Vertical and Horizontal Windows Splitting

463 views
Skip to first unread message

Nordlöw

unread,
Nov 14, 2008, 8:43:55 AM11/14/08
to
Requested: Function that toggles between vertical and horizontal split
layout of currently defined windows preferrably preserving splitting
ratio.

Thanks in advance,
Nordlöw

Fabrice Niessen

unread,
Nov 14, 2008, 8:54:46 AM11/14/08
to
Nordlöw,

> Requested: Function that toggles between vertical and
> horizontal split layout of currently defined windows
> preferrably preserving splitting ratio.

You can find the following:

--8<---------------cut here---------------start------------->8---
(defun my-toggle-window-split ()
"Vertical split shows more of each line, horizontal split shows
more lines. This code toggles between them. It only works for
frames with exactly two windows."
(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))))))

(global-set-key [(control c) (|)] 'my-toggle-window-split)
--8<---------------cut here---------------end--------------->8---

in my `.emacs' file (on http://www.mygooglest.com/fni/dot-emacs.html).

FYI, this has been taken from the excellent EmacsWiki:

http://www.emacswiki.org/emacs/ToggleWindowSplit

Best regards,
Fabrice

_________________________________________________________________________
Fabrice Niessen
Search the Web with "My Google Search Tools" on http://www.MyGooglest.com

Nordlöw

unread,
Nov 14, 2008, 9:42:12 AM11/14/08
to
On 14 Nov, 14:54, "Fabrice Niessen" <tdhkhcidi...@spammotel.com>
wrote:
> in my `.emacs' file (onhttp://www.mygooglest.com/fni/dot-emacs.html).

>
> FYI, this has been taken from the excellent EmacsWiki:
>
>    http://www.emacswiki.org/emacs/ToggleWindowSplit
>
> Best regards,
>   Fabrice
>
> _________________________________________________________________________
> Fabrice Niessen
> Search the Web with "My Google Search Tools" onhttp://www.MyGooglest.com

Thanks!

/Nordlöw

0 new messages