Created
July 16, 2013 13:45
-
-
Save bamanzi/6008825 to your computer and use it in GitHub Desktop.
[emacs] Toggle window split direction
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defun window-toggle-split-direction () | |
| "Switch window split from horizontally to vertically, or vice versa. | |
| i.e. change right window to bottom, or change bottom window to right." | |
| (interactive) | |
| (require 'windmove) | |
| (let ((done)) | |
| (dolist (dirs '((right . down) (down . right))) | |
| (unless done | |
| (let* ((win (selected-window)) | |
| (nextdir (car dirs)) | |
| (neighbour-dir (cdr dirs)) | |
| (next-win (windmove-find-other-window nextdir win)) | |
| (neighbour1 (windmove-find-other-window neighbour-dir win)) | |
| (neighbour2 (if next-win (with-selected-window next-win | |
| (windmove-find-other-window neighbour-dir next-win))))) | |
| ;;(message "win: %s\nnext-win: %s\nneighbour1: %s\nneighbour2:%s" win next-win neighbour1 neighbour2) | |
| (setq done (and (eq neighbour1 neighbour2) | |
| (not (eq (minibuffer-window) next-win)))) | |
| (if done | |
| (let* ((other-buf (window-buffer next-win))) | |
| (delete-window next-win) | |
| (if (eq nextdir 'right) | |
| (split-window-vertically) | |
| (split-window-horizontally)) | |
| (set-window-buffer (windmove-find-other-window neighbour-dir) other-buf)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment