(or emacs irrelevant)

One Hydra Two Hydra Red Hydra Blue Hydra

Hydra evolution picks up the pace with hydra 0.6.1. This version adds prefix arguments to all Hydras.

Some Examples

Look ma, no modifiers!

Now it's possible to write this:

(global-set-key
 (kbd "C-z")
 (defhydra hydra-vi ()
   "vi"
   ("l" forward-char)
   ("h" backward-char)
   ("j" next-line)
   ("k" previous-line)))

And now C-z 5j7l will move 5 lines down and 7 characters left, still with the option to press h, j, k, l some more.

Additionally C-z C-u C-u C-u k will move 64 lines up, since C-u multiplies its argument by 4 each time.

The good-old zoom

If you remember, this was the original Hydra:

(defhydra hydra-zoom (global-map "<f2>")
  "zoom"
  ("g" text-scale-increase "in")
  ("l" text-scale-decrease "out"))

Now, <f2> g 4g 2l will zoom in 5 times, and zoom out 2 times for a total of +3 zoom.

The good-old move-splitter

(defhydra hydra-splitter (global-map "C-M-s")
  "splitter"
  ("h" hydra-move-splitter-left)
  ("j" hydra-move-splitter-down)
  ("k" hydra-move-splitter-up)
  ("l" hydra-move-splitter-right))

This Hydra can benefit from numeric arguments as well: C-M-s l 40l will quickly make the right window a lot smaller.

If I wanted to type C-M-s 40 l, I would have to use this definition instead:

(global-set-key
 (kbd "C-M-s")
 (defhydra hydra-splitter ()
   "splitter"
   ("h" hydra-move-splitter-left)
   ("j" hydra-move-splitter-down)
   ("k" hydra-move-splitter-up)
   ("l" hydra-move-splitter-right)))

For that case, I would get the hint immediately after C-M-s and would be able to give the numeric argument immediately, but I wouldn't be able to bind anything else on C-M-s as a prefix, e.g.:

(global-set-key (kbd "C-M-s z") 'recenter-top-bottom)

The code above would give the error "Key sequence C-M-s z starts with non-prefix key C-M-s". So you can pick the method that you prefer, the choice is there.

The ultimate window switching setup

(global-set-key
 (kbd "C-M-o")
 (defhydra hydra-window ()
   "window"
   ("h" windmove-left)
   ("j" windmove-down)
   ("k" windmove-up)
   ("l" windmove-right)
   ("a" (lambda ()
          (interactive)
          (ace-window 1)
          (add-hook 'ace-window-end-once-hook
                    'hydra-window/body))
        "ace")
   ("v" (lambda ()
          (interactive)
          (split-window-right)
          (windmove-right))
        "vert")
   ("x" (lambda ()
          (interactive)
          (split-window-below)
          (windmove-down))
        "horz")
   ("s" (lambda ()
          (interactive)
          (ace-window 4)
          (add-hook 'ace-window-end-once-hook
                    'hydra-window/body))
        "swap")
   ("d" (lambda ()
          (interactive)
          (ace-window 16)
          (add-hook 'ace-window-end-once-hook
                    'hydra-window/body))
        "del")
   ("o" delete-other-windows "1" :color blue)
   ("i" ace-maximize-window "a1" :color blue)
   ("q" nil "cancel")))

The credit for this monster goes to bcarell, I just refined his approach with making ace-window not quit the hydra-window Hydra. This setup needs the latest ace-window.

Here's the result of C-M-o xvxv starting from a single window:

hydra-window

From here, I can quickly maximize the current window with o while simultaneously quitting the Hydra; i will maximize a window as well, but it will select it with ace-window, instead of maximizing the current one.

Note that, since numerical arguments are working now, 4a is the same as s (swap) and 16a or C-u C-u a is the same as d (delete).