-
-
Notifications
You must be signed in to change notification settings - Fork 113
Conditional Hydra
Oleh Krehel edited this page Jun 24, 2015
·
1 revision
(defhydra hydra-vi (:hint nil)
"vi"
("j" next-line)
("k" previous-line)
("n" next-line)
("p" previous-line))
(setq hydra-vi/hint
'(if (evenp (line-number-at-pos))
(prog1 (eval
(hydra--format nil '(nil nil :hint nil)
"\neven: _j_ _k_\n" hydra-vi/heads))
(define-key hydra-vi/keymap "n" nil)
(define-key hydra-vi/keymap "p" nil)
(define-key hydra-vi/keymap "j" 'hydra-vi/next-line)
(define-key hydra-vi/keymap "k" 'hydra-vi/previous-line))
(prog1 (eval
(hydra--format nil '(nil nil :hint nil)
"\nodd: _n_ _p_\n" hydra-vi/heads))
(define-key hydra-vi/keymap "j" nil)
(define-key hydra-vi/keymap "k" nil)
(define-key hydra-vi/keymap "n" 'hydra-vi/next-line)
(define-key hydra-vi/keymap "p" 'hydra-vi/previous-line))))
defhydra
defines hydra-vi/hint
variable that’s evaled each time
for the hint. We re-define it to modify the hydra’s docstring and
bindings depending on the line number: on even line numbers j
and
k
will be active, with the corresponding docstring, while on odd
line numbers n
and p
will be active.
Basically we start with a single hydra template, which we modify dynamically depending on the situation.
- Binding-Styles
- Basics
- Verbosity
- Verbosity-Long-Short
- Conditional-Hydra
- defcustom
- Hydra-Colors
- internals
- Nesting-Hydras
- Prefix-map