Last active
August 29, 2015 14:16
-
-
Save TauPan/513a529281ff98e406b2 to your computer and use it in GitHub Desktop.
The fearsome hydra for managing emacs windows
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
;;; from http://www.emacswiki.org/emacs/ToggleWindowSplit (last example as of 2015-02-19) | |
(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)))))))) | |
;; current versions that work for me: | |
;; - ace-window 20150217.650 (from melpa) | |
;; - hydra 20150224.302 (from melpa) | |
;; - key-chord 0.5.20080915 (from marmalade) | |
;; - transpose-frame 20131221.1542 (from melpa) | |
(use-package ace-window | |
;; from http://sachachua.com/blog/2015/01/emacs-microhabit-switching-windows-windmove-ace-window-ace-jump/ | |
;; extended by http://oremacs.com/2015/01/29/more-hydra-goodness/ | |
;; :ensure t ;; only in melpa :( | |
:config | |
(progn | |
(use-package hydra | |
:ensure t | |
:config | |
(use-package transpose-frame | |
:ensure t | |
:config | |
(progn | |
(require 'hydra-examples) | |
(defun hydra-universal-argument (arg) | |
(interactive "P") | |
(setq prefix-arg (if (consp arg) | |
(list (* 4 (car arg))) | |
(if (eq arg '-) | |
(list -4) | |
'(4))))) | |
(lexical-let ((hydra-lv nil) ;; does not work with lv, | |
;; because lv creates an extra window | |
(hydra-key-format-spec nil)) | |
(defhydra hydra-window (global-map "C-M-o") | |
" | |
Window Manager: | |
Move Point ^^^^ Move Splitter ^Ace ^^Split ^^Transpose | |
^^^^^^^^^^------------------------------------------------------------------------------------------------------------------ | |
_w_, _<up>_ Shift + Move _C-a_: ace-window _2_: split-window-below _1_: transpose-frame | |
_a_, _<left>_ _C-s_: ace-swap-window _3_: split-window-right _e_: rotate-frame-clockwise | |
_s_, _<down>_ _C-d_: ace-delete-window _<_: toggle-split-direction _y_: flip-frame vertically | |
_d_, _<right>_ _C-m_: ace-maximize-window ^ ^ _c_: flop-frame horizontally | |
You can use arrow-keys or WASD. | |
" | |
("2" split-window-below nil) | |
("3" split-window-right nil) | |
("a" windmove-left nil) | |
("s" windmove-down nil) | |
("w" windmove-up nil) | |
("d" windmove-right nil) | |
("A" hydra-move-splitter-left nil) | |
("S" hydra-move-splitter-down nil) | |
("W" hydra-move-splitter-up nil) | |
("D" hydra-move-splitter-right nil) | |
("<left>" windmove-left nil) | |
("<down>" windmove-down nil) | |
("<up>" windmove-up nil) | |
("<right>" windmove-right nil) | |
("<S-left>" hydra-move-splitter-left nil) | |
("<S-down>" hydra-move-splitter-down nil) | |
("<S-up>" hydra-move-splitter-up nil) | |
("<S-right>" hydra-move-splitter-right nil) | |
("C-a" ace-window nil) | |
("u" hydra-universal-argument nil) | |
("C-s" ace-swap-window nil) | |
("C-d" ace-delete-window nil) | |
("C-m" ace-maximize-window nil) | |
("<" window-toggle-split-direction nil) | |
("1" transpose-frame nil) | |
("e" rotate-frame-clockwise nil) | |
("y" flip-frame nil) | |
("c" flop-frame nil) | |
("b" ido-switch-buffer "switch-buffer") | |
("k" ido-kill-buffer "kill-buffer") | |
("f" ido-find-file "find-file") | |
("q" nil "quit"))) | |
(use-package key-chord | |
:ensure t | |
:config | |
(progn | |
(key-chord-mode 1) | |
(key-chord-define-global "yy" 'hydra-window/body)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment