[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Toggle between Vertical and Horizontal Windows Splitting
From: |
Fabrice Niessen |
Subject: |
Re: Toggle between Vertical and Horizontal Windows Splitting |
Date: |
Fri, 14 Nov 2008 14:54:46 +0100 |
User-agent: |
Gnus/5.110009 (No Gnus v0.9) Emacs/23.0.60 (gnu/linux) |
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