Hydra

about | blog | config | notes | github

1. Make Emacs Bindings that Stick Around

hydra_and_hercules.png

Hydra & Hercules by Unknown

Once you summon the Hydra through the prefixed binding (the body + any one head), all heads can be called in succession with only a short extension.

The Hydra is vanquished once Hercules, any binding that isn't the Hydra's head, arrives. Note that Hercules, besides vanquishing the Hydra, will still serve his original purpose, calling his proper command. This makes the Hydra very seamless, it's like a minor mode that disables itself auto-magically.

hydra is simply a package that provides lets us create configurable menus for quick access to commands for GNU/Emacs

2. Configuration

2.1. Package Install

Load up the hydra package.

(use-package hydra)

2.2. Text Scale Example Function

Here is a simple hydra function for scaling text.

(defhydra hydra-text-scale (:timeout 4)
  "scale text"
  ("j" zamlz/increase-font-size "in")
  ("k" zamlz/decrease-font-size "out")
  ("h" zamlz/reset-font-size "reset")
  ("f" nil "finished" :exit t))

We can add this hydra function to our General Leader Keybindings Definer for easy access.

(require 'init-general)
(zamlz/leader-keys
  "ts" '(hydra-text-scale/body :which-key "scale text"))

2.3. Feature Provider

Make sure to provide the feature.

(provide 'init-hydra)

Created: 2021-11-13

Emacs 26.1 (Org mode 9.5)