Hydra 0.9.0 is out08 Feb 2015
I'll just list the new features from the release notes here.
hydra-keyboard-quit set to
"C-g" means that it's possible to quit an amaranth Hydra
with C-g. You can customize this variable.
:pre keys in the body
PLIST can be either a single
sexp or a function name. The function doesn't need to be interactive.
Support for local Hydra heads via
(defhydra hydra-next-error (global-map "C-x") "next-error" ("`" next-error "next") ("j" next-error "next" :bind nil) ("k" previous-error "previous" :bind nil))
What it does:
- binds C-x ` to
- does not bind C-x j and C-x k
- you can still do C-x `jjkk
:bind property in Hydra body
The body, like the heads will recognize the
:bind property in
The heads will inherit it, just like they do with
:bind property can be nil or a lambda of
(defhydra hydra-goto (global-map "M-g" :bind (lambda (key cmd) (bind-key key cmd))) ("g" goto-line "goto-line" :bind global-set-key) ("c" goto-char "goto-char"))
bind-key will be used to bind
goto-char to M-g c,
since c head has inherited body's
:bind property. Note
bind-key is a macro, it was necessary to wrap it in a
global-set-key will be used to bind
goto-line to M-g g, this
was overridden in the g head.
Since this commit, it's not possible to pass a lambda instead of the
BODY argument, as was advertised before. Just put it on
hydra/body will pass the initial
(global-set-key (kbd "C-z") (defhydra hydra-vi () "vi" ("l" forward-char) ("q" nil "quit")))
Now, C-u C-z l will result in
(forward-char 4). All the other l
will normally call
(forward-char 1), unless an additional prefix is given. The previous
behavior allowed only for C-z C-u l to get
Allow a sexp as head's CMD parameter
(defhydra hydra-launcher (:color blue) "Launch" ("h" man "man") ("r" (browse-url "http://www.reddit.com/r/emacs/") "reddit") ("w" (browse-url "http://www.emacswiki.org/") "emacswiki") ("s" shell "shell") ("q" nil "cancel")) (global-set-key (kbd "C-c r") 'hydra-launcher/body)
Here, r and w heads are using this feature. Here's what will be generated, if you're interested:
(defun hydra-launcher/lambda-w nil "Create a hydra with no body and the heads: \"h\": `man', \"r\": `(browse-url \"http://www.reddit.com/r/emacs/\")', \"w\": `(browse-url \"http://www.emacswiki.org/\")', \"s\": `shell', \"q\": `nil' The body can be accessed via `hydra-launcher/body'. Call the head: `(browse-url \"http://www.emacswiki.org/\")'." (interactive) (hydra-disable) (catch (quote hydra-disable) (call-interactively (function (lambda nil (interactive) (browse-url "http://www.emacswiki.org/"))))))
hydra-create and all old examples in hydra-examples.el are now obsolete.
You can still use them for a short while, but they will be removed soon.
You should take the time to switch from
defhydra. All the old examples
are provided in the new style in hydra-examples.el. However, they will not be evaluated
(require 'hydra-examples) unless you
(setq hydra-examples-verbatim t)
beforehand. This is because I have no idea what kind of bindings will work for you, you
should decide yourself. But I am providing you with a template. The number of examples
has also grown to six.