Emacs: toggle window split.

master
Ambrevar 2012-12-07 14:34:39 +01:00
parent 7e218708ee
commit 0bcc773ff1
1 changed files with 33 additions and 0 deletions

View File

@ -23,6 +23,39 @@
((shell-command (echo blah)))
)
;;==============================================================================
;; Toggle window split
;;==============================================================================
(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)
;;==============================================================================
;; Duplicate line
;;==============================================================================