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 ("w" 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")
53 ;(defun pl-last-winner ()
56 ;; define C-space start mark
59 ;;** Example 2: move window splitter
61 (defhydra hydra-splitter (global-map "C-M-s")
63 ("h" hydra-move-splitter-left)
64 ("j" hydra-move-splitter-down)
65 ("k" hydra-move-splitter-up)
66 ("l" hydra-move-splitter-right))
68 ;;** Example 3: jump to error
70 (defhydra hydra-error (global-map "M-g")
72 ("h" first-error "first")
73 ("j" next-error "next")
74 ("k" previous-error "prev")
75 ("v" recenter-top-bottom "recenter")
80 ;;** Example 4: toggle rarely used modes
82 ; (defvar whitespace-mode nil)
85 ; (defhydra hydra-toggle-simple (:color blue)
87 ; ("a" abbrev-mode "abbrev")
88 ; ("d" toggle-debug-on-error "debug")
89 ; ("f" auto-fill-mode "fill")
90 ; ("t" toggle-truncate-lines "truncate")
91 ; ("w" whitespace-mode "whitespace")
92 ; ("q" nil "cancel")))
96 ;;** Example 5: mini-vi
97 (defun hydra-vi/pre ()
98 (set-cursor-color "#e52b50"))
100 (defun hydra-vi/post ()
101 (set-cursor-color "#ffffff"))
106 (defhydra hydra-vi (:pre hydra-vi/pre :post hydra-vi/post :color amaranth)
112 ("m" set-mark-command "mark")
113 ("a" move-beginning-of-line "beg")
114 ("e" move-end-of-line "end")
115 ("d" delete-region "del" :color blue)
116 ("y" kill-ring-save "yank" :color blue)
121 ;;** Example 6: selective global bind
123 (defhydra hydra-next-error (global-map "C-x")
125 ("`" next-error "next")
126 ("j" next-error "next" :bind nil)
127 ("k" previous-error "previous" :bind nil))
129 ;; This example will bind "C-x `" in `global-map', but it will not
130 ;; bind "C-x j" and "C-x k".
131 ;; You can still "C-x `jjk" though.
133 ;;** Example 7: toggle with Ruby-style docstring
134 (defvar whitespace-mode nil)
135 (defhydra hydra-toggle (:color pink)
137 _a_ abbrev-mode: %`abbrev-mode
138 _d_ debug-on-error: %`debug-on-error
139 _f_ auto-fill-mode: %`auto-fill-function
140 _t_ truncate-lines: %`truncate-lines
141 _w_ whitespace-mode: %`whitespace-mode
144 ("a" abbrev-mode nil)
145 ("d" toggle-debug-on-error nil)
146 ("f" auto-fill-mode nil)
147 ("t" toggle-truncate-lines nil)
148 ("w" whitespace-mode nil)
150 ;; Recommended binding:
151 ;; (global-set-key (kbd "C-c C-v") 'hydra-toggle/body)
153 ;; Here, using e.g. "_a_" translates to "a" with proper face.
154 ;; More interestingly:
156 ;; "foobar %`abbrev-mode" means roughly (format "foobar %S" abbrev-mode)
158 ;; This means that you actually see the state of the mode that you're changing.
160 ;;** Example 8: the whole menu for `Buffer-menu-mode'
161 (defhydra hydra-buffer-menu (:color pink
164 ^Mark^ ^Unmark^ ^Actions^ ^Search
165 ^^^^^^^^----------------------------------------------------------------- (__)
166 _m_: mark _u_: unmark _x_: execute _R_: re-isearch (oo)
167 _s_: save _U_: unmark up _b_: bury _I_: isearch /------\\/
168 _d_: delete ^ ^ _g_: refresh _O_: multi-occur / | ||
169 _D_: delete up ^ ^ _T_: files only: % -28`Buffer-menu-files-only^^ * /\\---/\\
170 _~_: modified ^ ^ ^ ^ ^^ ~~ ~~
172 ("m" Buffer-menu-mark)
173 ("u" Buffer-menu-unmark)
174 ("U" Buffer-menu-backup-unmark)
175 ("d" Buffer-menu-delete)
176 ("D" Buffer-menu-delete-backwards)
177 ("s" Buffer-menu-save)
178 ("~" Buffer-menu-not-modified)
179 ("x" Buffer-menu-execute)
180 ("b" Buffer-menu-bury)
182 ("T" Buffer-menu-toggle-files-only)
183 ("O" Buffer-menu-multi-occur :color blue)
184 ("I" Buffer-menu-isearch-buffers :color blue)
185 ("R" Buffer-menu-isearch-buffers-regexp :color blue)
187 ("v" Buffer-menu-select "select" :color blue)
188 ("o" Buffer-menu-other-window "other-window" :color blue)
189 ("q" quit-window "quit" :color blue))
190 ;; Recommended binding:
191 ;; (define-key Buffer-menu-mode-map "." 'hydra-buffer-menu/body)
193 ;;** Example 9: s-expressions in the docstring
194 ;; You can inline s-expresssions into the docstring like this:
195 (defvar dired-mode-map)
196 (when (bound-and-true-p hydra-examples-verbatim)
198 (defhydra hydra-marked-items (dired-mode-map "")
200 Number of marked items: %(length (dired-get-marked-files))
202 ("m" dired-mark "mark")))
204 ;; This results in the following dynamic docstring:
206 ;; (format "Number of marked items: %S\n"
207 ;; (length (dired-get-marked-files)))
209 ;; You can use `format'-style width specs, e.g. % 10(length nil).
211 ;;** Example 10: apropos family
212 (defhydra hydra-apropos (:color blue
216 _d_ocumentation _l_ibrary
217 _v_ariable _u_ser-option
220 ("d" apropos-documentation)
221 ("v" apropos-variable)
222 ("c" apropos-command)
223 ("l" apropos-library)
224 ("u" apropos-user-option)
226 ;; Recommended binding:
227 ;; (global-set-key (kbd "C-c h") 'hydra-apropos/body)
229 ;;** Example 11: rectangle-mark-mode
230 (defhydra hydra-rectangle (:body-pre (rectangle-mark-mode 1)
232 :post (deactivate-mark))
234 ^_k_^ _d_elete _s_tring
236 ^_j_^ _n_ew-copy _r_eset
237 ^^^^ _e_xchange _u_ndo
240 ("h" backward-char nil)
241 ("l" forward-char nil)
242 ("k" previous-line nil)
244 ("e" hydra-ex-point-mark nil)
245 ("n" copy-rectangle-as-kill nil)
246 ("d" delete-rectangle nil)
247 ("r" (if (region-active-p)
249 (rectangle-mark-mode 1)) nil)
250 ("y" yank-rectangle nil)
252 ("s" string-rectangle nil)
253 ("p" kill-rectangle nil)
256 ;; Recommended binding:
257 ;; (global-set-key (kbd "C-x SPC") 'hydra-rectangle/body)
262 (defun hydra-move-splitter-left (arg)
263 "Move window splitter left."
265 (if (let ((windmove-wrap-around))
266 (windmove-find-other-window 'right))
267 (shrink-window-horizontally arg)
268 (enlarge-window-horizontally arg)))
270 (defun hydra-move-splitter-right (arg)
271 "Move window splitter right."
273 (if (let ((windmove-wrap-around))
274 (windmove-find-other-window 'right))
275 (enlarge-window-horizontally arg)
276 (shrink-window-horizontally arg)))
278 (defun hydra-move-splitter-up (arg)
279 "Move window splitter up."
281 (if (let ((windmove-wrap-around))
282 (windmove-find-other-window 'up))
284 (shrink-window arg)))
286 (defun hydra-move-splitter-down (arg)
287 "Move window splitter down."
289 (if (let ((windmove-wrap-around))
290 (windmove-find-other-window 'up))
292 (enlarge-window arg)))
294 (defvar rectangle-mark-mode)
295 (defun hydra-ex-point-mark ()
296 "Exchange point and mark."
298 (if rectangle-mark-mode
299 (exchange-point-and-mark)
301 (rectangle-mark-mode 1)
304 (provide 'init-hydra)