hydra icon indicating copy to clipboard operation
hydra copied to clipboard

Feature Proposal: Provide hook for enter/exit hydra state

Open WolfgangRamos opened this issue 6 years ago • 2 comments

I would like to know how you would feel about introducing a hydra-state-enter-hook and hydra-state-exit-hook. The first beeing called every time a hydra is "opened" the latter every time a hydra is closed. Hence the new hooks would be very similar to :body-pre and :post, with one major difference:

If a user wants to perform some action every time a hydra is opened/closed he would have to set :body-pre and :post of each hydra. With the new hooks he could set this once for all of his hydras.

I stumbled upon this inconvenience when trying to disable key-chord-mode during my hydras. So why does onyone would want to do this you may ask. Imagine you bind the key-chord jj to some heavily used action A (because that key is so easy to reach and so uncommon in any word you usually type). Then.you bind j in a hydra to sime action B and would like jj to perform B twice, then key-chord-mode would interfere, executing action A when hitting jj fast.

If you agree that this would be useful, I (think) I could implement the new hooks. If I do, I would maybe pass the hydras generated key-map to the new hooks, so that the functions on these hooks could deactivate single key-chords conditionally if they conflict with the hydras bound keys.

WolfgangRamos avatar Jun 25 '18 07:06 WolfgangRamos

I was reluctant on adding hooks to hydra before. But since the requests keep coming up I changed my mind. Please PR.

If I do, I would maybe pass the hydras generated key-map to the new hooks, so that the functions on these hooks could deactivate single key-chords conditionally if they conflict with the hydras bound keys.

No need to do this, Emacs hooks take no arguments. A user's hook can still examine hydra-curr-map.

abo-abo avatar Jun 25 '18 15:06 abo-abo

Ok, I'll implement two standard hooks (i.e. functions on that hook will be called with no arguments). Just give me a few days, my schedule is quite full this week.

A user's hook can still examine hydra-curr-map.

I did not know that. Thank you for pointing it out.

WolfgangRamos avatar Jun 26 '18 10:06 WolfgangRamos