Oleh Krehel [Fri, 27 Feb 2015 18:05:43 +0000 (19:05 +0100)]
Add some features for generating tables
* hydra.el (hydra--pad): New defun.
(hydra--matrix): New defun.
(hydra--cell): New defun.
(hydra--vconcat): New defun.
(hydra-cell-format): New defcustom.
(hydra--table): New defun.
(hydra-reset-radios): New defun.
(defhydra): Allow docstring to be eval-able.
(defhydradio): Don't define `.../reset-radios', instead define
`.../names' that can be passed to `hydra-reset-radios'.
(hydra-multipop): New defmacro.
(hydra--radio): Update the order - the docstring is now a mandatory
second arg, value is the optional third.
Oleh Krehel [Tue, 24 Feb 2015 14:50:49 +0000 (15:50 +0100)]
Don't bind nil heads in outside keymaps
* hydra.el (hydra-exit): New command to be used for nil heads.
(hydra--delete-duplicates): Update for `hydra-exit'.
(defhydra): Don't bind `hydra-exit' in outside keymaps.
Oleh Krehel [Tue, 24 Feb 2015 14:31:46 +0000 (15:31 +0100)]
Improve handling of heads with duplicate cmd
hydra.el (hydra--delete-duplicates): Modify :cmd-name property of
duplicate head to to name of the head that it duplicates.
Heads are considered duplicate if their CMD and COLOR is the same.
The first of the duplicates gets a defun, the rest call it.
* hydra.el (defhydra): Bring heads into a uniform notation. If a
docstring is missing, set it to "". Set :cmd-name property to the
head's name.
Oleh Krehel [Tue, 24 Feb 2015 10:42:00 +0000 (11:42 +0100)]
Simplify the hint part of each head
* hydra.el (defhydra): All heads that don't have a hint, will get "" as
hint. The behavior will remain the same.
(hydra--head-property): Simplify, since plist is now always `cdddr'.
(hydra--hint): Simplify, heads always have length at least 3. Simplify,
third element is always a string or nil.
Oleh Krehel [Mon, 23 Feb 2015 14:12:17 +0000 (15:12 +0100)]
Avoid generating multiple defuns with same name
* hydra.el (hydra--head-name): New defun.
(hydra--delete-duplicates): New defun.
(defhydra): Update to use `hydra--delete-duplicates' and `hydra--head-name'.
Oleh Krehel [Fri, 20 Feb 2015 16:51:52 +0000 (17:51 +0100)]
Improve compatibility for Emacs <= 24.3
* hydra.el (hydra-set-transient-map): Always take 3 arguments.
(hydra--pred): New defun.
(hydra-disable): Update, `overriding-terminal-local-map' is actually
also bound in 24.3.
Oleh Krehel [Fri, 20 Feb 2015 14:41:32 +0000 (15:41 +0100)]
Add an option to fontify heads in a custom way
* hydra.el (hydra--hint): Forward to `hydra-fontify-head'.
(hydra-fontify-head-function): New defvar.
(hydra-fontify-head-default): New defun that represents the classic
fontification behavior.
(hydra-fontify-head): Fontification dispatch - use
`hydra-fontify-head-default'
unless `hydra-fontify-head-function' is set.
(hydra--format): Forward to `hydra-fontify-head'.
Example:
(setq hydra-fontify-head-function
(lambda (head body)
(let ((color (hydra--head-color head body)))
(format
(if (eq color 'blue)
"[%s]"
"{%s}") (car head)))))
Here, ^^^ represent empty characters used to compensate for the fact
that the lengths of variable symbols are different.
You can choose not to use them. The result will be the same, but your
code will look misaligned.
Oleh Krehel [Thu, 19 Feb 2015 14:56:17 +0000 (15:56 +0100)]
Add teal body color
* hydra.el (hydra-face-teal): New face.
(hydra--face): Update.
(defhydra): Teal color is the same as amaranth, except the heas inherit
blue instead of red.
Oleh Krehel [Thu, 19 Feb 2015 14:48:41 +0000 (15:48 +0100)]
Update faces
* hydra.el (hydra-face-red): Set default to actual color red.
(hydra-face-blue): Set default to actual color blue.
(hydra-face-amaranth): Explain better in the doc.
(hydra-face-pink): Explain better in the doc.
Oleh Krehel [Thu, 19 Feb 2015 14:02:11 +0000 (15:02 +0100)]
Minor refactoring
* hydra.el (hydra--head-color): Rename from `hydra--color'.
(hydra--body-color): New defun.
(hydra--message): First arg isn't pre-processed by `hydra--hint'.
(defhydra): Update call to `hydra-message'.
Oleh Krehel [Thu, 19 Feb 2015 13:19:18 +0000 (14:19 +0100)]
Allow for Ruby-style Hydra docstrings
* hydra.el (hydra--unalias-var): New defun.
(hydra--format): New defun.
(hydra--message): Use `hydra-format' instead of a static string.
Update signature.
(defhydra): Add a warning the pink Hydras can't yet handle unbound
prefix, e.g. "C-x". Update arguments given to `hydra--message'.
* hydra-test.el: Update tests, only hint functions were slightly
affected.
Oleh Krehel [Thu, 19 Feb 2015 08:34:29 +0000 (09:34 +0100)]
Add pink body color
* hydra.el (hydra-face-pink): New face.
(hydra--face): Update.
(defhydra): Pink is a variation on amaranth. It still intercepts all
bindings, but will call the intercepted bindings if they're valid.
Oleh Krehel [Tue, 17 Feb 2015 14:30:09 +0000 (15:30 +0100)]
Don't clutter Echo Area
* lv.el (lv-wnd): New variable.
(lv-window): New defun to get a window similar in properties to Echo Area.
(lv-message): New defun, a replacement for `message', that writes to `lv-window'.
* hydra.el (hydra-lv): New defcustom. If nil, use the Echo Area,
otherwise, use LV.
(hydra-disable): Add optional arg KILL-LV.
(hydra--message): New defun to dispatch on `hydra-lv'.
(hydra--make-defun): Prematurely disable with LV only for blue heads,
since regenerating LV window would cause screen tearing. No need for
timeouts between `message' when using LV. HINT argument is now a
function symbol that returns a string, instead of a plain string.
(defhydra): Generate a new defun with name `NAME/hint'.
Oleh Krehel [Fri, 13 Feb 2015 16:10:14 +0000 (17:10 +0100)]
Warn about explict red heads on amaranth body
* hydra.el (defhydra): With amaranth body, all heads that aren't blue
become amaranth. Specifying red explicitly does nothing. Add a check and
warn when this happens.
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.