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--ignoreWhen non-nil, don’t call ‘hydra-curr-on-exit’.
hydra--input-method-functionStore overridden ‘input-method-function’ here.
hydra--posframe-timerTimer for hiding posframe hint.
hydra--work-around-dedicatedWhen non-nil, assume there’s no bug in ‘pop-to-buffer’.
hydra-amaranth-warn-messageAmaranth Warning message. Shown when the user tries to press an
hydra-base-mapKeymap that all Hydras inherit. See ‘universal-argument-map’.
hydra-cell-formatThe default format for docstring cells.
hydra-curr-body-fnThe current hydra-.../body function.
hydra-curr-foreign-keysThe current :foreign-keys behavior.
hydra-curr-mapThe keymap of the current Hydra called.
hydra-curr-on-exitThe on-exit predicate for the current Hydra.
hydra-deactivateIf a Hydra head sets this to t, exit the Hydra.
hydra-default-hintDefault :hint property to use for heads when not specified in
hydra-doc-format-specDefault ‘format’-style specifier for ?a? syntax in docstrings.
hydra-fontify-head-functionPossible replacement for ‘hydra-fontify-head-default’.
hydra-head-formatThe formatter for each head of a plain docstring.
hydra-hint-display-alistStore the functions for ‘hydra-hint-display-type’.
hydra-hint-display-typeThe utility to show hydra hint
hydra-is-helpfulWhen t, display a hint with possible bindings in the echo area.
hydra-key-doc-functionThe function for formatting key-doc pairs.
hydra-key-format-specDefault ‘format’-style specifier for _a_ syntax in docstrings.
hydra-key-regexRegex for the key quoted in the docstring.
hydra-look-for-remapWhen non-nil, hydra binding behaves as keymap binding with [remap].
hydra-message-timerTimer for the hint.
hydra-pause-ringRing for paused hydras.
hydra-posframe-show-paramsList of parameters passed to ‘posframe-show’.
hydra-repeat--commandCommand to use with ‘hydra-repeat’.
hydra-repeat--prefix-argPrefix arg to use with ‘hydra-repeat’.
hydra-timeout-timerTimer for ‘hydra-timeout’.
hydra-verboseWhen non-nil, hydra will issue some non essential style warnings.
hydra-width-spec-regexRegex for the width spec in keys and %‘ quoted sexps.

Defined functions (71)

defhydra(NAME BODY &optional DOCSTRING &rest HEADS)
defhydra+(NAME BODY &optional DOCSTRING &rest HEADS)
defhydradio(NAME BODY &rest HEADS)
hydra--body-exit(BODY)
hydra--body-foreign-keys(BODY)
hydra--call-interactively(CMD NAME)
hydra--call-interactively-remap-maybe(CMD)
hydra--callablep(X)
hydra--cell(FSTR NAMES)
hydra--clearfun()
hydra--complain(FORMAT-STRING &rest ARGS)
hydra--cycle-radio(SYM)
hydra--delete-duplicates(HEADS)
hydra--describe-key()
hydra--digit-argument(ARG)
hydra--doc(BODY-KEY BODY-NAME HEADS)
hydra--eval-and-format(X)
hydra--format(NAME BODY DOCSTRING HEADS)
hydra--format-1(DOCSTRING REST VARLIST)
hydra--generate-matrix(HEADS-GROUPS)
hydra--head-has-property(H PROP)
hydra--head-name(H NAME)
hydra--head-property(H PROP &optional DEFAULT)
hydra--head-set-property(H PROP VALUE)
hydra--hint(BODY HEADS)
hydra--hint-from-matrix(BODY HEADS-MATRIX)
hydra--hint-from-matrix-1(BODY HEADS-MATRIX)
hydra--hint-heads-wocol(BODY HEADS)
hydra--hint-row(HEADS BODY)
hydra--imf(&rest OBJECTS)
hydra--make-callable(X)
hydra--make-defun(NAME BODY DOC HEAD KEYMAP BODY-PRE BODY-BEFORE-EXIT &optional BODY-AFTER-EXIT)
hydra--make-funcall(SYM)
hydra--matrix(LST ROWS COLS)
hydra--negative-argument(ARG)
hydra--normalize-body(BODY)
hydra--normalize-heads(HEADS)
hydra--pad(LST N)
hydra--pad-heads(HEADS-GROUPS PADDING-HEAD)
hydra--prop(NAME PROP-NAME)
hydra--quote-maybe(X)
hydra--radio(PARENT HEAD)
hydra--sort-heads(NORMALIZED-HEADS)
hydra--strip-align-markers(STR)
hydra--table(NAMES ROWS COLS &optional CELL-FORMATS)
hydra--to-string(X)
hydra--universal-argument(ARG)
hydra--vconcat(STRS &optional JOINER)
hydra-add-font-lock()
hydra-add-imenu()
hydra-amaranth-warn()
hydra-default-pre()
hydra-disable()
hydra-fontify-head(HEAD BODY)
hydra-fontify-head-default(HEAD BODY)
hydra-fontify-head-greyscale(HEAD BODY)
hydra-get-property(NAME KEY)
hydra-idle-message(SECS HINT NAME)
hydra-interpose(X LST)
hydra-key-doc-function-default(KEY KEY-WIDTH DOC DOC-WIDTH)
hydra-keyboard-quit()
hydra-multipop(LST N)
hydra-pause-resume()
hydra-plist-get-default(PLIST PROP DEFAULT)
hydra-posframe-show(STR)
hydra-repeat(&optional ARG)
hydra-reset-radios(NAMES)
hydra-set-property(NAME KEY VAL)
hydra-set-transient-map(KEYMAP ON-EXIT &optional FOREIGN-KEYS)
hydra-show-hint(HINT CALLER)
hydra-timeout(SECS &optional FUNCTION)

Defined faces (5)

hydra-face-amaranthAmaranth body has red heads and warns on intercepting non-heads. Exitable only through a blue head.
hydra-face-blueBlue Hydra heads exit the Hydra. Every other command exits as well.
hydra-face-pinkPink body has red heads and runs intercepted non-heads. Exitable only through a blue head.
hydra-face-redRed Hydra heads don’t exit the Hydra. Every other command exits the Hydra.
hydra-face-tealTeal body has blue heads and warns on intercepting non-heads. Exitable only through a blue head.