(or emacs irrelevant)

Hydra 0.9.0 is out

I'll just list the new features from the release notes here.

Keyboard quit

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 and :post refinement

:post and :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 :bind property

Example:

(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 next-error.
  • does not bind C-x j and C-x k
  • you can still do C-x `jjkk

Thanks, @ffevotte.

Support for :bind property in Hydra body

The body, like the heads will recognize the :bind property in PLIST. The heads will inherit it, just like they do with :color. The :bind property can be nil or a lambda of global-set-key format.

Example:

(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"))

Here, bind-key will be used to bind goto-char to M-g c, since c head has inherited body's :bind property. Note that since bind-key is a macro, it was necessary to wrap it in a lambda.

However, global-set-key will be used to bind goto-line to M-g g, this :bind property was overridden in the g head.

Since this commit, it's not possible to pass a lambda instead of the whole BODY argument, as was advertised before. Just put it on :bind now.

hydra/body will pass the initial current-prefix-arg along

Example:

(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 (forward-char 4).

Allow a sexp as head's CMD parameter

Example:

(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/"))))))

Obsolete declarations

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 hydra-create to defhydra. All the old examples are provided in the new style in hydra-examples.el. However, they will not be evaluated through (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.