1

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

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

(defhydra hydra-b (:color teal)
  "b"
  ("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.

bertfred
  • 1,699
  • 1
  • 11
  • 23

2 Answers2

3

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 ()
  (interactive)    
  (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-b/body)
        (hydra-push '(hydra-a/body)))
      "visit hydra-b")

and in hydra b defining quit to pop the stack:

 ("q" hydra-pop "exit")
glucas
  • 20,175
  • 1
  • 51
  • 83
  • 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 03 '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 03 '17 at 14:23
  • Thanks. I will wait if abo-abo answers, else I will open an issue. – bertfred Nov 03 '17 at 14:32
1

That's what I actually wanted:

(defhydra hydra-b (:color teal)
  "b"
   ("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.

bertfred
  • 1,699
  • 1
  • 11
  • 23