* hydra.el (hydra--callablep): New function.
(hydra-create): Write down in terms of `defhydra'.
(defhydra): New macro.
`defhydra' uses more parameters than `hydra-create' and looks more like
a `defun':
(defhydra hydra-windmove (global-map "C-M-o")
"windmove"
("h" windmove-left)
("j" windmove-down)
("k" windmove-up)
("l" windmove-right)
("o"))
(defhydra hydra-zoom (global-map "<f2>")
"zoom"
("g" text-scale-increase "in")
("l" text-scale-decrease "out"))
(defhydra lispy-knight ()
"knight"
("j" lispy-knight-down)
("k" lispy-knight-up)
("z"))
Important advantages:
- Hydra body can be omitted. If you do this, you can bind the functions
that `defhydra' produced (in the example above, `lispy-knight/body')
yourself. It can be useful e.g. if you want to call these functions
conditionally.
- Each Hydra gets a nice name, like `hydra-windmove/windmove-left'
instead of the old `hydra-C-M-o-windmove-left'.
- Hydra hint (base) can now be customized.
* hydra.el (hydra-create): Update.
METHOD doesn't need to be evaled: it's either nil, a lambda, or assume
that it's a valid keymap without evaling. This will prevent eager
macroexpansion failure for this argument.
There still is a problem with eager macroexpansion failure in HEADS
argument.
Re #9
* hydra.el (hydra-create): Update.
Basically the same fix as before, only for bindings relating to a map.
Now this will work:
(hydra-create "C-y"
'(("l" forward-char)
("h" backward-char)
("j" next-line)
("k" previous-line)
("z"))
lispy-mode-map)
even though "C-y" is bound to a command in `lispy-mode-map'. The
previous binding will be undefined.
Re #4.
* hydra.el (hydra-create): Update.
Before, this would result in a disaster - all bindings of "C-x" would be
cleared:
(hydra-create "C-x" hydra-example-move-window-splitter)
Now this should be OK. Fixes#4.
* hydra.el (hydra-create): Update.
In order to bind hydras in `lispy', I need a way to split the body from
the heads. Now, this is possible:
(hydra-create "C-z"
'(("l" forward-char)
("h" backward-char)
("j" next-line)
("k" previous-line)
("z"))
lispy-mode-map)
(lispy-define-key lispy-mode-map "z" 'hydra-C-z-body)
* hydra.el (hydra-last): Store the lambda to disable the Hydra.
(hydra-create): Update.
Sometimes, I have nothing particualr on my mind to do, but I want to
stop the Hydra. I could just type "C-g", but it's possible to have
something more convenient. For instance:
(hydra-create "C-z"
'(("l" forward-char)
("h" backward-char)
("j" next-line)
("k" previous-line)
("z")))
* hydra.el (hydra-create): Expects a lists of lists for HEADS, instead
of list of cons cells. The optional thrid element of each list is the
hint.
* hydra-examples.el: Update the examples.
* README.md: Update.
Re #2
* hydra.el (hydra-create): Add a third optional argument. When it's not
supplied, the behavior should remain the same. Otherwise, it's a
lambda that's used instead of `global-set-key', with the same semantics.
* README.md: Update.
re #1