Assume there's an interactive function foo. Assume it is bound in various keymaps and is also bound inside an hydra as a simple key, let's say "a".

How can foo's code detect that it was invoked via the hydra as opposed to any other way? I'd like foo to be able to distinguish whether it was invoked when the hydra remapping the "a" key is active or otherwise (ie, if there are other non-hydra key bindings to it).

Also assume I have full control of the definition of that hydra (ie, the defhydra code that defines that specific hydra).

  • The reason I want to know is that I want an interactive function to be available inside and outside an hydra. When invoked inside the hydra I want the function to behave differently (in one case I want the function to first close the hydra and then execute the code, but I have other cases).

1 Answer 1


I assume your last paragraph (The reason...)describe best your goals, IMHO.

To achieve that, you need to provide an optional argument to your function foo and call that function without the argument outside hydra, and with the argument inside hydra. The optional argument will be the flag to separate the operating modes/tasks of that function.

Some examples how to do that are provided in your hydra installation folder, see the file hydra-examples.el, in particular the example #12, where the interactive function org-agenda-log-mode is called in three ways.

  • That's correct. It answers my question as written. I should have identified that I wanted to be able, for the function, to not be the function directly invoked by the hydra. I really wanted to be able to determine dynamically if the hydra key map was active or not. My question was not clear enough.
    – PRouleau
    Oct 22, 2023 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.