Emacs Hydra for Music ControlTue, Sep 15, 2015
Hydra is a hugely powerful framework for setting up key bindings in Emacs. When I first learned of it, I didn’t really understand the use case, but after having built a few hydras to manage daily tasks, it’s starting to sink in. A hydra is basically an ephemeral key mapping with pre-defined conditions for termination. For example, one key might execute a command, but retain the key mapping, while another is designed to execute it’s command and restore the previous key mapping. I use Hydra to manage all my programming and project key accelerators, but it’s also great for quick tasks that can come up at any time, like controlling music. Here’s a hydra to manage Bongo, my preferred music player.
(defhydra hydra-bongo (:color blue :hint nil) " Bongo control _l_: library _p_: pause/resume _s_: stop _b_: back 10s ^^_f_: fwd 10s _B_: back 60s ^^_F_: fwd " ("b" bongo-seek-backward-10 :color red) ("f" bongo-seek-forward-10 :color red) ("B" bongo-seek-backward-60 :color red) ("F" bongo-seek-forward-60 :color red) ("l" bongo) ("p" bongo-pause/resume) ("s" bongo-stop) ("q" nil "cancel")) (global-set-key (kbd "C-c b") 'hydra-bongo/body)
The default keybinds for library, pausing and stopping are all terminal (blue) heads, while the commands to seek forward and backward are non-terminal (red) heads. Why use Bongo instead of a regular desktop music player? Partly because manipulating libraries, playlists and music playback is much easier and more customizable from within Emacs!
One of the things that makes Emacs so unique and powerful is that workflows like this are easy to create, and make working a pleasure, instead of a chore, since everything you use often can be accomplished with such ease. It’s a lot of fun.