Two new Hydra colors - pink and teal19 Feb 2015
Two new colors are being added up to a total of five: red, blue, amaranth, pink and teal. I should carefully restate what they do to avoid confusion.
The three rules of Hydratics
1. A hydra may not injure a human being or, through inaction, allow a human being to come to harm.
Seriously though, see below.
Rule 1: Hydra heads are either red or blue
Once you're in a Hydra state:
- calling a red head will call the command and continue the state
- calling a blue head will call the command and stop the state
They may have a reddish or a bluish face that isn't exactly red or blue, but that's what they are underneath. I hope you get what I mean.
Rule 2: red or blue is inherited from the body color
This is merely a convenience, you can still explicitly override each head to be blue or red:
- if the body is red, amaranth or pink, the heads inherit red
- if the body is blue or teal, the heads inherit blue
When you call a binding which isn't a head:
- amaranth, teal and pink Hydras will intercept it
- red and blue Hydras will quit and let Emacs execute your binding
Finally, on intercepting a non-head, amaranth and teal will issue a warning and do nothing without quitting. And pink will try to call the intercepted command without quitting. Currently only non-prefix bindings can be called, since I haven't figured out how to do it for prefixes.
A nice table to sum things up
Thanks to @kaushalmodi for pointing me in this direction:
|----------+-----------+-----------------------+-----------------| | Body | Head | Executing NON-HEADS | Executing HEADS | | Color | Inherited | | | | | Color | | | |----------+-----------+-----------------------+-----------------| | amaranth | red | Disallow and Continue | Continue | | teal | blue | Disallow and Continue | Quit | | pink | red | Allow and Continue | Continue | | red | red | Allow and Quit | Continue | | blue | blue | Allow and Quit | Quit | |----------+-----------+-----------------------+-----------------|
The extra-awesome Ruby-style Hydra docstrings
How it works:
(defhydra hydra-toggle (:color pink) " _a_ abbrev-mode: %`abbrev-mode _d_ debug-on-error: %`debug-on-error _f_ auto-fill-mode: %`auto-fill-function _g_ golden-ratio-mode: %`golden-ratio-mode _t_ truncate-lines: %`truncate-lines _w_ whitespace-mode: %`whitespace-mode " ("a" abbrev-mode nil) ("d" toggle-debug-on-error nil) ("f" auto-fill-mode nil) ("g" golden-ratio-mode nil) ("t" toggle-truncate-lines nil) ("w" whitespace-mode nil) ("q" nil "cancel")) (global-set-key (kbd "C-c C-v") 'hydra-toggle/body)
Here, using e.g.
"_a_" translates to
"a" with proper face. More
translates roughly to
(format "foobar %S" abbrev-mode)
This means that you actually see the state of the mode that you're
changing. The escape syntax was chosen with another intent in mind:
because of the backquote, if you have
company-mode on, you can
complete the symbols while in string.
See how it looks like in action:
Small note on pink Hydras
It's useful for instance it the above example, when I don't care about self-inserting, but I still want to do navigation. Basically pink Hydra is the closest thing to an actual minor mode. Thanks to @angelic-sedition for the idea.
Small note on teal Hydras
It provides an interface similar to
magit dispatch: pressing
appropriate keys does things and pressing the wrong keys issues a
warning. The only difference between teal and amaranth is the color
inheritance, otherwise they behave exactly the same. This means that
if you want a non-quitting Hydra that will end up with more blue
heads, start with teal, otherwise, start with amaranth.
Thanks to @ffevotte for the idea.
It feels like things are finally falling into place with this package. I hope that you like the new changes and find new cool uses for the added abilities. Happy hacking!