simple useful functions from Tak Ota
[elbb.git] / code / manipulating_windows.el
bloba18a08135c3de8005cf97f47c421462a7deaefb8
1 ;; Source: http://www.emacswiki.org/cgi-bin/wiki/ToggleWindowSplit
3 ;; Vertical split shows more of each line, horizontal split shows
4 ;; more lines. This code toggles between them. It only works for
5 ;; frames with exactly two windows. The top window goes to the left
6 ;; or vice-versa. I was motivated by ediff-toggle-split and helped
7 ;; by TransposeWindows. There may well be better ways to write this.
9 (defun toggle-window-split ()
10 (interactive)
11 (if (= (count-windows) 2)
12 (let* ((this-win-buffer (window-buffer))
13 (next-win-buffer (window-buffer (next-window)))
14 (this-win-edges (window-edges (selected-window)))
15 (next-win-edges (window-edges (next-window)))
16 (this-win-2nd (not (and (<= (car this-win-edges)
17 (car next-win-edges))
18 (<= (cadr this-win-edges)
19 (cadr next-win-edges)))))
20 (splitter
21 (if (= (car this-win-edges)
22 (car (window-edges (next-window))))
23 'split-window-horizontally
24 'split-window-vertically)))
25 (delete-other-windows)
26 (let ((first-win (selected-window)))
27 (funcall splitter)
28 (if this-win-2nd (other-window 1))
29 (set-window-buffer (selected-window) this-win-buffer)
30 (set-window-buffer (next-window) next-win-buffer)
31 (select-window first-win)
32 (if this-win-2nd (other-window 1))))))
34 ;; (define-key ctl-x-4-map "t" 'toggle-window-split)