Skip to main content

Medusa - The mother of all Hydras

Bundling all Hydras into a single file to rule them all, and to use them context aware

One of the problems of all text editors is that they actually have to reconcile two different functions, capturing text, and editing of text. That we are seldom aware of how different these two tasks are is also part of the problem. Our mind tends to switch seamlessly between these two tasks.

We write a sentence, and even as we type it, we notice that after the last word it would have been better to have a comma, and that the whole paragraph might have been part of the introduction anyway, maybe as a quotation.

This way of working makes it necessary to switch between capturing and editing text at any time. Essentially, 3 approaches have prevailed. Common to all of them is that they often find the simple functions on their own keys (Delete, Tab, PageUp, etc …). For the more complicated cases we find:

  1. The menu control (eg Word) with the problem that you have to switch between the mouse and keyboard back and forth for mouse operation.
  2. A multiple assignment of the keys via ALT, CTRL, META, SUPER or HYPER keys. This is the area where Emacs is at home.
  3. A leader key, which is a key that does not appear in normal text, and therefore serves to switch to edit mode. This is the domain of VIM

   

Spacemacs and the Leaderkey

Just like for me, also for the makers of Spacemacs the idea with the Leaderkey, is the way to go. So they have adopted the concept as far as possible and put it over an existing Emacs as a configuration. The charm is that it does not affect any of the usual features in Emacs, and now both types of operation can coexist. What has unfortunately been lost in my eyes, is the more systematic structure of the functions that Emacs usually brings. The Hydras delivered by Spacemacs (a kind of visual menu guide) rarely seem useful or easy to remember in my head

Thing at point

I get, for example, always the same Hydra when I press the Leaderkey, while you can choose in Emacs countless modes of operation, each requiring completely different ways of interaction.

In a recent blog entry from Derek Feichtinger, I recently found a very elegant solution that not only can provide different Hydras for the different modes, but is also still able to determine if the cursor is in the very popular Org mode on an object (such as a link or table), and then call a Hydra specific to that object.

Fallback

The elegant thing about this solution is that on the one hand it is very easy to expand, and on the other hand it also offers the possibility to call a standard Hydra if none of the special cases are present.

In the combination of different Hydras this offers unexpected possibilities. For example, my Leaderkey is the <menu> key, which is usually to the right of the space bar, and calls the context menu on Winows. With Linux this had never been a useful feature for me anyway.

In each Hydra, I programmed the <menu> key with the most frequently used function. This allows me to press the menu button twice and - in Org Mode - do the same thing that Ctrl-C Ctrl-C does, while in Ledger Mode a new booking is created instead.

Again, as with the Spacemac solution, all of the built-in Emacs buttons continue to work as normal, I've now integrated all the Hydras that I've created so far into the Medusa project, the sources are here.

2019-05-14