I'm looking for a way to return to the parent hydra after using certain commands. In this example

(defhydra hydra-a (:color teal)
  ("b" (progn
         (hydra-push '(hydra-a/body)))
   "visit hydra-b")
  ("q" hydra-pop "exit"))

(defhydra hydra-b (:color teal)
  ("i" forward-line :exit nil)    
  ("q" hydra-pop "exit"))

I need some kind of keyword instead of exit for this line ("i" forward-line :exit nil). If I use :exit t the parent hydra is also closed.


You can do this by maintaining a stack of hydras, as described on the hydra wiki page Nesting Hydras.

The basic mechanism described there is to add your own push/pop commands. See the full example for details, but here are the key pieces:

(defvar hydra-stack nil)

(defun hydra-push (expr)
  (push `(lambda () ,expr) hydra-stack))

(defun hydra-pop ()
  (let ((x (pop hydra-stack)))
    (when x
      (funcall x))))

Then wiring this in to your hydra definitions, e.g. define an entry in hydra a that will push on to the stack and switch to hydra b:

"b" (progn
        (hydra-push '(hydra-a/body)))
      "visit hydra-b")

and in hydra b defining quit to pop the stack:

 ("q" hydra-pop "exit")
  • But then I still have to pop manually if I understand correctly. I want this to happen automatically for some commands similiar to :exit t. Something like :pop-or-exit t. – bertfred Nov 3 '17 at 14:22
  • 1
    You would bind hydra-pop to your exit keys, instead of :exit t. I suppose the difference is if you want to be able to use your hydra both as a nested one and as a top-level one? I don't believe what you're asking for is currently supported, so you may want to enter a feature request on GitHub. Another thing to play with might be hydra-pause-resume, which is a built-in stack but with a different intended use case.... – glucas Nov 3 '17 at 14:23
  • Thanks. I will wait if abo-abo answers, else I will open an issue. – bertfred Nov 3 '17 at 14:32

That's what I actually wanted:

(defhydra hydra-b (:color teal)
   ("1" (and (call-interactively 'ace-window) (hydra-pop)))
   ("q" hydra-pop "exit"))

I simply have to pop the child hydra after the command in order to return to the parent hydra.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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