Sublime Forum

Implemation idea for a Hydra plugin similar to Emacs Hydra

#1

I come from an Emacs background and I used the Hydra package a lot.

That’s a pretty cool package to bind shortcuts together and provide them in a menu kind of way. Because I haven’t found a similar plugin I want to write one. :slight_smile:

I am still a Sublime Text newbie and therefore would like to ask beforehand if it would possible? I guess so. I have a little bit of plugin development experience and I already built a small helper package called Yet Another Launcher.

Hydras have usually colors to show different behaviour therefore it would be good if I could show my hydra text with different highlighting. Probably as html or so.

My main question is what would be the best way / function to display the hydra text (popup or outputpanel) and would it be possible to capture there input?

0 Likes

#2

Taking a look at Hydra from the Git page, this might be a little tough to do. Some of the things you can do in Emacs with keybindings requires direct access to the keystream. In Sublime Text, we are well downstream of the direct keystream so creating on-the-fly behavior can be kind of tough. I ran into some of this with trying to emulate some of the stutter typing shortcuts from an Emacs language mode. In one case I was able to do that with a look-behind context, but the others I simply couldn’t do in any reasonable way.

Not to dissuade you in any manner, but just a caveat because I’ve been down this road with adapting Sublime to Emacs. However it does look like everything is predefined in Hydra, so in that case, you might have a way to leverage that into behavior that you want.

0 Likes

#3

Now I think what you mean.

show_popup() could create a view that emulate the look of an hydra.

But I haven’t figured out to listen for keystrokes while the popup is active. I need a way to keystrokes, and I need only one, while the popup is active. That stroke shouldn’t be typed in the active view. Any idea? Is that possible?

0 Likes

#4

Not sure. Even keystrokes while a popup is active is actually a filtered keystream. For example you can bind ctrl+g to the hide_panel command (See Emacs Pro Essentials) and that will get rid of your popup I believe.

To my knowledge, packages are pretty far downstream of the input buffer, and keys have already been filtered by existing keybinds. Maybe I’m getting the wrong end of the stick with Hydra, but isn’t it trying to create some shortcut amalgamation of keybinds so that you can execute them rapidly without their usual keybind?

Actually you know what this kind of feels like, less like Emacs and more like vi/vim. You are trying to create a command mode! A keybind to enter this Hydra command mode, and then a new set of keybindings that are shortcut maps to commands. Since there is a vi emulation package, maybe there’s a way to handle this, but I don’t know anything about it – haven’t ever used that.

1 Like