Oleh Krehel [Sun, 8 Feb 2015 14:07:12 +0000 (15:07 +0100)]
Allow a sexp as head's CMD paramater
* hydra.el (hydra--make-callable): New function.
(defhydra): Use `hydra--make-callable'. Now, head's CMD is either:
command name, nil, a sexp. In case of a sexp, it will be wrapped
unevaluated in an interactive lambda. You can use a `progn' to have many
statements in the sexp.
Oleh Krehel [Sat, 7 Feb 2015 21:00:56 +0000 (22:00 +0100)]
Allow lambda :bind property for body and heads
* hydra.el (hydra--head-property): Clean up doc.
(hydra--make-defun): Clean up doc.
(defhydra): Improve doc.
Both body and heads recognize :bind property in their plist.
It can be either nil or a lambda of `global-set-key' format.
Here, `global-set-key' will be used to bind `goto-line' to "M-g g".
And `bind-key' will be used to bind `goto-char' to "M-g c".
Note that since `bind-key' is a macro, it was necessary to wrap it
in a lambda.
Since this commit, it's not possible to pass a lambda instead of
the whole BODY arg, as was advertised before. Just put it on
:bind now.
Oleh Krehel [Fri, 6 Feb 2015 17:13:16 +0000 (18:13 +0100)]
`hydra/body' will pass the initial `current-prefix-arg' along
* hydra.el (hydra--make-defun): Take an additional arg to paste as the
last statement.
(defhydra): Set `hydra-foo/body' last statement to
`(setq prefix-arg current-prefix-arg)'.
Oleh Krehel [Fri, 6 Feb 2015 09:31:33 +0000 (10:31 +0100)]
Fix "catch 'hydra-disable"
* hydra.el (hydra--make-defun): `(catch 'hydra-disable ...)' should
extend thoughout the whole defun. The scope was reduced by mistake
earlier, now restoring.
Oleh Krehel [Fri, 6 Feb 2015 09:04:54 +0000 (10:04 +0100)]
Update semantics for local heads to `:bind nil'
* hydra.el (hydra--head-property): Accept an optional DEFAULT arg.
(defhydra): A head will not be bound in the body map when it has `:bind
nil' in its plist.
Oleh Krehel [Thu, 5 Feb 2015 14:19:17 +0000 (15:19 +0100)]
Update :post for amaranth Hydras
* hydra.el (defhydra): Since the transient map isn't technically going
away when a foreign key binding is pressed, don't call :post in that
case. This means that only blue heads will call :post for Hydras with
amaranth body.
Oleh Krehel [Thu, 5 Feb 2015 12:09:05 +0000 (13:09 +0100)]
Add amaranth (immortal) Hydras
* hydra.el (hydra-face-amaranth): New face.
(hydra--face): Update.
(defhydra): If the body color is amaranth, it's only possible to exit
this Hydra through a blue head. None of the other key bindings, even
"C-g" will work. There's a check in place that the current Hydra should
have at least one blue head.
Oleh Krehel [Wed, 4 Feb 2015 15:28:40 +0000 (16:28 +0100)]
Add :pre and :post clauses to Hydra body
* hydra.el (defhydra): the PLIST part of BODY argument now recognizes
:pre and :post keys. These should be single Elisp statements,
wrappable in a lambda. When you need more than one statement, use a
`progn'.
:pre will be called by `hydra-foo/body', as well as by all heads.
:post will be called by the blue heads, as well as on Hydra termination
by a command that isn't a head.
Oleh Krehel [Tue, 3 Feb 2015 13:38:44 +0000 (14:38 +0100)]
hydra-examples.el: splitters take numeric argument
* hydra-examples.el (hydra-move-splitter-left): Take ARG.
(hydra-move-splitter-right): Take ARG.
(hydra-move-splitter-up): Take ARG.
(hydra-move-splitter-down): Take ARG.
Oleh Krehel [Tue, 3 Feb 2015 12:27:37 +0000 (13:27 +0100)]
Add support for `universal-argument' and `digit-argument'
* hydra.el (hydra-base-map): Model after `universal-argument-map'; all
Hydra keymaps will inherit from this one.
(hydra-curr-map): Current Hydra keymap. This is necessary for
e.g. `hydra--digit-argument' to return to the orignial keymap.
(hydra--universal-argument): New function.
(hydra--digit-argument): New function.
(hydra--negative-argument): New function.
(hydra--hint): Fix dangling `body-color'.
(defhydra): keymap will inherit `hydra-base-map'.
`hydra-current-map' will be set by red heads. In red heads, make the
function call after `set-transient-map' so that e.g. "Beginning of
buffer" error will not exit the Hydra.
Oleh Krehel [Sun, 1 Feb 2015 17:43:44 +0000 (18:43 +0100)]
Distinguish red and blue hydra heads
* hydra.el (hydra-face-red): New face.
(hydra-face-blue): New face.
(hydra--color): Each head now has a color: red is persistent, blue is
single-use. Head color inherits body color if it's not explicitly
overridden. Body color is red unless explicitly stated.
(hydra--face): Return face that corresponds to color.
(hydra--hint): New function, moved out of `defhydra'.
(hydra-disable): New function, moved out of `defhydra'.
(hydra--doc): New function, moved out of `defhydra'.
(defhydra): Commands that will vanquish the Hydra should be colored with
`hydra-face-blue'. The ones that will make the Hydra persist should be
colored with `hydra-face-red'.
Add autoload, move some code outside, Test HEAD's second element with
`null' instead of `functionp'.
* hydra-test.el (defhydra-red-error): Rename from `defhydra'.
(hydra-blue-toggle): Add test.
- 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'.
Oleh Krehel [Thu, 22 Jan 2015 12:11:05 +0000 (13:11 +0100)]
Avoid evaling METHOD.
* 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.
Oleh Krehel [Tue, 20 Jan 2015 22:31:55 +0000 (23:31 +0100)]
Allow to add one head that disables the Hydra
* 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:
Oleh Krehel [Tue, 20 Jan 2015 16:46:48 +0000 (17:46 +0100)]
Allow to use minor-mode-maps and more
* 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.