3

I need a hydra with four "heads", each of should exit the hydra when its function is executed. The hydra intended to be used in dired-mode and direx:direx-mode and pop-up when O pressed. This is what I got so far:

(defhydra dired-open (dired-mode-map "O" :exit t)
        "dired-open"
        ("j" dired-find-file-other-window-below "below")
        ("k" dired-find-file-other-window-above "above")
        ("h" dired-find-file-other-windowd-left "left")
        ("l" dired-find-file-other-window-right "left”))

it kinda works, but:

  • it's a bit ugly - I would like to learn how to make "proper" hydras, like in magit

  • it works only dired mode, I don't know how to properly bind it for both modes

upd: apparently Spacemacs has builtin function for introducing transient states. I'm gonna add Spacemacs tag, since I'm using it

iLemming
  • 1,223
  • 9
  • 14
  • 3
    Magit's windows are not [hydras](https://github.com/abo-abo/hydra); they are created using the [`magit-popup`](https://magit.vc/manual/magit-popup.html) package. – Tianxiang Xiong Nov 14 '16 at 17:05

1 Answers1

3

Oh. wow. Spacemacs's define-transient-state is really nice:

(spacemacs|define-transient-state dired-open-item-other-window
  :title "Open item in other window"
  :doc
  "\n[_j_/_k_] down/up [_h_/_l_] left/right [_q_] quit"
  :bindings
  ("j" dired-find-file-other-window-below :exit t)
  ("k" dired-find-file-other-window-above :exit t)
  ("h" dired-find-file-other-window-left :exit t)
  ("l" dired-find-file-other-window-right :exit t)
  ("q" nil :exit t))

(evil-define-key 'normal dired-mode-map "O"
   'spacemacs/dired-open-item-other-window-transient-state/body)
iLemming
  • 1,223
  • 9
  • 14