File: hydra.el.html
This package can be used to tie related commands into a family of short bindings with a common prefix - a Hydra.
Once you summon the Hydra (through the prefixed binding), all the heads can be called in succession with only a short extension. The Hydra is vanquished once Hercules, any binding that isn't the Hydra's head, arrives. Note that Hercules, besides vanquishing the Hydra, will still serve his original purpose, calling his proper command. This makes the Hydra very seamless, it's like a minor mode that disables itself automagically.
Here's an example Hydra, bound in the global map (you can use any
keymap in place of global-map):
(defhydra hydra-zoom (global-map "<f2>")
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))
It allows to start a command chain either like this:
"<f2> gg4ll5g", or "<f2> lgllg".
Here's another approach, when you just want a "callable keymap":
(defhydra hydra-toggle (:color blue)
"toggle"
("a" abbrev-mode "abbrev")
("d" toggle-debug-on-error "debug")
("f" auto-fill-mode "fill")
("t" toggle-truncate-lines "truncate")
("w" whitespace-mode "whitespace")
("q" nil "cancel"))
This binds nothing so far, but if you follow up with:
(global-set-key (kbd "C-c C-v") 'hydra-toggle/body)
you will have bound "C-c C-v a", "C-c C-v d" etc.
Knowing that defhydra defines e.g. hydra-toggle/body command,
you can nest Hydras if you wish, with hydra-toggle/body possibly
becoming a blue head of another Hydra.
If you want to learn all intricacies of using defhydra without
having to figure it all out from this source code, check out the
wiki: https://github.com/abo-abo/hydra/wiki. There's a wealth of
information there. Everyone is welcome to bring the existing pages
up to date and add new ones.
Additionally, the file hydra-examples.el serves to demo most of the functionality.
Defined variables (31)
hydra--ignore | When non-nil, don’t call ‘hydra-curr-on-exit’. |
hydra--input-method-function | Store overridden ‘input-method-function’ here. |
hydra--posframe-timer | Timer for hiding posframe hint. |
hydra--work-around-dedicated | When non-nil, assume there’s no bug in ‘pop-to-buffer’. |
hydra-amaranth-warn-message | Amaranth Warning message. Shown when the user tries to press an |
hydra-base-map | Keymap that all Hydras inherit. See ‘universal-argument-map’. |
hydra-cell-format | The default format for docstring cells. |
hydra-curr-body-fn | The current hydra-.../body function. |
hydra-curr-foreign-keys | The current :foreign-keys behavior. |
hydra-curr-map | The keymap of the current Hydra called. |
hydra-curr-on-exit | The on-exit predicate for the current Hydra. |
hydra-deactivate | If a Hydra head sets this to t, exit the Hydra. |
hydra-default-hint | Default :hint property to use for heads when not specified in |
hydra-doc-format-spec | Default ‘format’-style specifier for ?a? syntax in docstrings. |
hydra-fontify-head-function | Possible replacement for ‘hydra-fontify-head-default’. |
hydra-head-format | The formatter for each head of a plain docstring. |
hydra-hint-display-alist | Store the functions for ‘hydra-hint-display-type’. |
hydra-hint-display-type | The utility to show hydra hint |
hydra-is-helpful | When t, display a hint with possible bindings in the echo area. |
hydra-key-doc-function | The function for formatting key-doc pairs. |
hydra-key-format-spec | Default ‘format’-style specifier for _a_ syntax in docstrings. |
hydra-key-regex | Regex for the key quoted in the docstring. |
hydra-look-for-remap | When non-nil, hydra binding behaves as keymap binding with [remap]. |
hydra-message-timer | Timer for the hint. |
hydra-pause-ring | Ring for paused hydras. |
hydra-posframe-show-params | List of parameters passed to ‘posframe-show’. |
hydra-repeat--command | Command to use with ‘hydra-repeat’. |
hydra-repeat--prefix-arg | Prefix arg to use with ‘hydra-repeat’. |
hydra-timeout-timer | Timer for ‘hydra-timeout’. |
hydra-verbose | When non-nil, hydra will issue some non essential style warnings. |
hydra-width-spec-regex | Regex for the width spec in keys and %‘ quoted sexps. |
Defined functions (71)
Defined faces (5)
hydra-face-amaranth | Amaranth body has red heads and warns on intercepting non-heads. Exitable only through a blue head. |
hydra-face-blue | Blue Hydra heads exit the Hydra. Every other command exits as well. |
hydra-face-pink | Pink body has red heads and runs intercepted non-heads. Exitable only through a blue head. |
hydra-face-red | Red Hydra heads don’t exit the Hydra. Every other command exits the Hydra. |
hydra-face-teal | Teal body has blue heads and warns on intercepting non-heads. Exitable only through a blue head. |