jerrypnz / major-mode-hydra.el

Spacemacs-esque major mode leader key powered by Hydra

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Composing hydras / minor mode support again

caioaao opened this issue · comments

I'm trying to compose hydras based on which minor modes are active. For instance, I have this hydras for flycheck and eglot:

(pretty-hydra-define my:flycheck-hydra ()
  ("Errors"
   (("<" flycheck-previous-error "prev" :exit nil)
    (">" flycheck-next-error "next" :exit nil)
    ("l" flycheck-list-errors "list"))))

(pretty-hydra-define my:eglot-hydra ()
  ("Eglot"
     (("f" eglot-format)
      ("r" eglot-code-actions))))

And I want them both to appear if eglot is active and flycheck is active, alongside the major mode hydra. So, for example, I'd like an easy way to combine those with my python-specific hydra so that the final result is the same as using the following hydra:

(major-mode-hydra-define python-mode nil
    ("Nav"
     (("n" python-nav-forward-defun "next-defun" :exit nil)
      ("p" python-nav-backward-defun "prev-defun" :exit nil))
     "Errors"
     (("<" flycheck-previous-error "prev" :exit nil)
      (">" flycheck-next-error "next" :exit nil)
      ("l" flycheck-list-errors "list"))
     "Env"
     (("a" pipenv-activate "pipenv-activate" :exit nil)
      ("d" pipenv-deactivate "pipenv-deactivate" :exit nil)
      ("w" pyvenv-workon "workon...")
      ("s" run-python "pyshell"))
     "Tools"
     (("f" blacken-buffer "reformat")
      ("i" py-isort-buffer "sort imports"))
     "Test"
     (("t" python-pytest-popup "pytest..."))
     "Eglot"
     (("f" eglot-format)
      ("r" eglot-code-actions))))

This is exactly a use case I'd like myself. I actually created #23 for this but haven't got around to implementing it. It might not be trivial because it requires dynamically updating the definition of the hydra based on certain conditions. Unfortunately I don't have much free time nowadays but if you have some ideas a PR is more than welcome.

I don't have a lot of time right now either, but my first impression is that since we have a pretty-hydra-define+ it should be straightforward to merge two hydras during dispatch instead of stopping on the first one found for the major mode.

Anyways while I don't find time to do that I'm just adding the sub hydras dispatch in the major mode hydra for now. One more key/level to reach where I want but it's working :)

Yeah that's what I've been doing as well. I'll have a think about this when I get a chance again. It could be a fun challenge to implement this.

Any updates on this matter? Have been trying to do something similar for half an hour only to realize that it is not possible yet. (new to the world of Emacs, hence why I was stuck for that long. :s)