dotfiles/private_dot_emacs.d/org/hydra.org
2020-11-01 02:56:34 +01:00

2.5 KiB

Hydra

Base

  (defhydra magic_rb/hydra-base (:color red :body-pre (setq hydra-stack nil))
    ("w" (progn
    (magic_rb/hydra-window-sub/body)
    (hydra-push '(magic_rb/hydra-launcher)))
"visit magic_rb/hydra-window-sub" :color teal)
    ("s" treemacs-switch-workspace)
    ("S" treemacs-edit-workspaces)
    ("t" treemacs-select-window)
    ("T" treemacs)
    ("v" vterm)
    ("m" magit)
    ("RET" (progn (setq hydra-stack nil)) "Cancel" :color blue)
    ("SPC" (progn (setq hydra-stack nil)) "Cancel" :color blue))

  (defhydra magic_rb/hydra-rust (:color red :inherit (magic_rb/hydra-base/heads))
    ("r" (progn
    (magic_rb/hydra-rust-sub/body)
    (hydra-push '(magic_rb/hydra-launcher)))
"visit magic_rb/hydra-rust-sub" :color teal)
    ("e" lsp-execute-code-action))

  (defhydra magic_rb/hydra-lsp (:color red :inherit (magic_rb/hydra-base/heads))
("e" lsp-execute-code-action))

Subs

Window

  (defhydra magic_rb/hydra-window-sub (:color red)
("a" ace-window)
("j" windmove-left)
("k" windmove-up)
("l" windmove-down)
(";" windmove-right)
("x" delete-window)
("RET" hydra-pop "exit" :color blue)
("SPC" hydra-pop "exit" :color blue)
("q" (progn (setq hydra-stack nil)) "Cancel" :color blue))

Rust

  (defhydra magic_rb/hydra-rust-sub ()
("b" rustic-cargo-build)
("r" rustic-cargo-run)
("t" rustic-cargo-test)
("f" rustic-format-buffer)
("RET" hydra-pop "exit" :color blue)
("SPC" hydra-pop "exit" :color blue)
("q" (progn (setq hydra-stack nil)) "Cancel" :color blue))

LSP

  (use-package hydra
    :ensure t
    :after (vterm magit treemacs lsp-mode rustic)
    :config
    (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))))


    (defun magic_rb/hydra-launcher ()
"A launcher for hydras based on current context."
(interactive)
(cl-case major-mode
 ('rustic-mode (magic_rb/hydra-rust/body))
 ('lsp-mode (magic_rb/hydra-rust/body))
 (t (magic_rb/hydra-base/body)))
)

    <<hydra-base>>

    <<hydra-window>> 

    <<hydra-rust>>

    :bind (("C-'" . magic_rb/hydra-launcher)))