4 ;; misc operation for toggle some style
5 ;; such as toggle line number
6 ;; windows layout restore / maximum
10 ;; package-list-p, eval-buffer
12 (defhydra hydra-helm (global-map "M-c")
14 ("j" helm-mini "helm-mini")
17 ;;** Example 1: text scale
19 (defhydra hydra-zoom (global-map "<f2>")
21 ("g" text-scale-increase "in")
22 ("l" text-scale-decrease "out"))
28 (defhydra hydra-window ()
44 ("o" delete-other-windows "one" :color blue)
45 ("a" ace-window "ace")
46 ("s" ace-swap-window "swap")
47 ("d" ace-delete-window "del")
48 ("i" ace-maximize-window "ace-one" :color blue)
49 ("b" ido-switch-buffer "buf")
50 ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo")
51 ("i" winner-undo "undo2")
54 ;; define C-space start mark
57 ;;** Example 2: move window splitter
59 (defhydra hydra-splitter (global-map "C-M-s")
61 ("h" hydra-move-splitter-left)
62 ("j" hydra-move-splitter-down)
63 ("k" hydra-move-splitter-up)
64 ("l" hydra-move-splitter-right))
66 ;;** Example 3: jump to error
68 (defhydra hydra-error (global-map "M-g")
70 ("h" first-error "first")
71 ("j" next-error "next")
72 ("k" previous-error "prev")
73 ("v" recenter-top-bottom "recenter")
78 ;;** Example 4: toggle rarely used modes
80 ; (defvar whitespace-mode nil)
83 ; (defhydra hydra-toggle-simple (:color blue)
85 ; ("a" abbrev-mode "abbrev")
86 ; ("d" toggle-debug-on-error "debug")
87 ; ("f" auto-fill-mode "fill")
88 ; ("t" toggle-truncate-lines "truncate")
89 ; ("w" whitespace-mode "whitespace")
90 ; ("q" nil "cancel")))
94 ;;** Example 5: mini-vi
95 (defun hydra-vi/pre ()
96 (set-cursor-color "#e52b50"))
98 (defun hydra-vi/post ()
99 (set-cursor-color "#ffffff"))
104 (defhydra hydra-vi (:pre hydra-vi/pre :post hydra-vi/post :color amaranth)
110 ("m" set-mark-command "mark")
111 ("a" move-beginning-of-line "beg")
112 ("e" move-end-of-line "end")
113 ("d" delete-region "del" :color blue)
114 ("y" kill-ring-save "yank" :color blue)
119 ;;** Example 6: selective global bind
121 (defhydra hydra-next-error (global-map "C-x")
123 ("`" next-error "next")
124 ("j" next-error "next" :bind nil)
125 ("k" previous-error "previous" :bind nil))
127 ;; This example will bind "C-x `" in `global-map', but it will not
128 ;; bind "C-x j" and "C-x k".
129 ;; You can still "C-x `jjk" though.
131 ;;** Example 7: toggle with Ruby-style docstring
132 (defvar whitespace-mode nil)
133 (defhydra hydra-toggle (:color pink)
135 _a_ abbrev-mode: %`abbrev-mode
136 _d_ debug-on-error: %`debug-on-error
137 _f_ auto-fill-mode: %`auto-fill-function
138 _t_ truncate-lines: %`truncate-lines
139 _w_ whitespace-mode: %`whitespace-mode
142 ("a" abbrev-mode nil)
143 ("d" toggle-debug-on-error nil)
144 ("f" auto-fill-mode nil)
145 ("t" toggle-truncate-lines nil)
146 ("w" whitespace-mode nil)
148 ;; Recommended binding:
149 ;; (global-set-key (kbd "C-c C-v") 'hydra-toggle/body)
151 ;; Here, using e.g. "_a_" translates to "a" with proper face.
152 ;; More interestingly:
154 ;; "foobar %`abbrev-mode" means roughly (format "foobar %S" abbrev-mode)
156 ;; This means that you actually see the state of the mode that you're changing.
158 ;;** Example 8: the whole menu for `Buffer-menu-mode'
159 (defhydra hydra-buffer-menu (:color pink
162 ^Mark^ ^Unmark^ ^Actions^ ^Search
163 ^^^^^^^^----------------------------------------------------------------- (__)
164 _m_: mark _u_: unmark _x_: execute _R_: re-isearch (oo)
165 _s_: save _U_: unmark up _b_: bury _I_: isearch /------\\/
166 _d_: delete ^ ^ _g_: refresh _O_: multi-occur / | ||
167 _D_: delete up ^ ^ _T_: files only: % -28`Buffer-menu-files-only^^ * /\\---/\\
168 _~_: modified ^ ^ ^ ^ ^^ ~~ ~~
170 ("m" Buffer-menu-mark)
171 ("u" Buffer-menu-unmark)
172 ("U" Buffer-menu-backup-unmark)
173 ("d" Buffer-menu-delete)
174 ("D" Buffer-menu-delete-backwards)
175 ("s" Buffer-menu-save)
176 ("~" Buffer-menu-not-modified)
177 ("x" Buffer-menu-execute)
178 ("b" Buffer-menu-bury)
180 ("T" Buffer-menu-toggle-files-only)
181 ("O" Buffer-menu-multi-occur :color blue)
182 ("I" Buffer-menu-isearch-buffers :color blue)
183 ("R" Buffer-menu-isearch-buffers-regexp :color blue)
185 ("v" Buffer-menu-select "select" :color blue)
186 ("o" Buffer-menu-other-window "other-window" :color blue)
187 ("q" quit-window "quit" :color blue))
188 ;; Recommended binding:
189 ;; (define-key Buffer-menu-mode-map "." 'hydra-buffer-menu/body)
191 ;;** Example 9: s-expressions in the docstring
192 ;; You can inline s-expresssions into the docstring like this:
193 (defvar dired-mode-map)
194 (when (bound-and-true-p hydra-examples-verbatim)
196 (defhydra hydra-marked-items (dired-mode-map "")
198 Number of marked items: %(length (dired-get-marked-files))
200 ("m" dired-mark "mark")))
202 ;; This results in the following dynamic docstring:
204 ;; (format "Number of marked items: %S\n"
205 ;; (length (dired-get-marked-files)))
207 ;; You can use `format'-style width specs, e.g. % 10(length nil).
209 ;;** Example 10: apropos family
210 (defhydra hydra-apropos (:color blue
214 _d_ocumentation _l_ibrary
215 _v_ariable _u_ser-option
218 ("d" apropos-documentation)
219 ("v" apropos-variable)
220 ("c" apropos-command)
221 ("l" apropos-library)
222 ("u" apropos-user-option)
224 ;; Recommended binding:
225 ;; (global-set-key (kbd "C-c h") 'hydra-apropos/body)
227 ;;** Example 11: rectangle-mark-mode
228 (defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1)
230 :post (deactivate-mark))
232 ^_k_^ _d_elete _s_tring
234 ^_j_^ _n_ew-copy _r_eset
235 ^^^^ _e_xchange _u_ndo
238 ("h" backward-char nil)
239 ("l" forward-char nil)
240 ("k" previous-line nil)
242 ("e" hydra-ex-point-mark nil)
243 ("n" copy-rectangle-as-kill nil)
244 ("d" delete-rectangle nil)
245 ("r" (if (region-active-p)
247 (rectangle-mark-mode 1)) nil)
248 ("y" yank-rectangle nil)
250 ("s" string-rectangle nil)
251 ("p" kill-rectangle nil)
254 ;; Recommended binding:
255 ;; (global-set-key (kbd "C-x SPC") 'hydra-rectangle/body)
260 (defun hydra-move-splitter-left (arg)
261 "Move window splitter left."
263 (if (let ((windmove-wrap-around))
264 (windmove-find-other-window 'right))
265 (shrink-window-horizontally arg)
266 (enlarge-window-horizontally arg)))
268 (defun hydra-move-splitter-right (arg)
269 "Move window splitter right."
271 (if (let ((windmove-wrap-around))
272 (windmove-find-other-window 'right))
273 (enlarge-window-horizontally arg)
274 (shrink-window-horizontally arg)))
276 (defun hydra-move-splitter-up (arg)
277 "Move window splitter up."
279 (if (let ((windmove-wrap-around))
280 (windmove-find-other-window 'up))
282 (shrink-window arg)))
284 (defun hydra-move-splitter-down (arg)
285 "Move window splitter down."
287 (if (let ((windmove-wrap-around))
288 (windmove-find-other-window 'up))
290 (enlarge-window arg)))
292 (defvar rectangle-mark-mode)
293 (defun hydra-ex-point-mark ()
294 "Exchange point and mark."
296 (if rectangle-mark-mode
297 (exchange-point-and-mark)
299 (rectangle-mark-mode 1)
302 (provide 'init-hydra)