dotfiles/.emacs.d/org/hydra.org
2020-12-11 17:48:47 +01:00

3.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)
    ("d" (progn
    (magic_rb/hydra-digraph-sub/body)
    (hydra-push '(magic_rb/hydra-launcher)))
     "visit magic_rb/hydra-window-sub" :color teal)
    ("a" org-agenda :color teal)
    ("f" org-roam-find-file :color teal)
    ("c" org-roam-capture :color teal)
    ("r" org-roam :color teal)
    ("s" treemacs-switch-workspace)
    ("S" treemacs-edit-workspaces :color teal)
    ("t" treemacs-select-window)
    ("T" treemacs)
    ("v" vterm)
    ("m" magit :color teal)
    ("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))

  (defhydra magic_rb/hydra-org (:color red :inherit (magic_rb/hydra-base/heads))
    ("'" org-cycle-agenda-files :color blue))

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))

Window

  (defmacro create-digraph (char keyseq)
(list `(char (lambda () (interactive) (insert keyseq)))))

  (macroexpand '(create-digraph "a" "aa"))

  (defhydra magic_rb/hydra-digraph-sub (:color red)
(create-digraph "()" "◊")
("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
:straight t
; :after (vterm magit treemacs lsp-mode) ; rustic
:config
(defvar hydra-stack nil)
:bind (("C-'" . magic_rb/hydra-launcher)
    :map org-mode-map
    ("C-'" . magic_rb/hydra-launcher)))

  (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))
('org-mode (magic_rb/hydra-org/body))
(t (magic_rb/hydra-base/body))))

  <<digraph>>

  <<hydra-base>>

  <<hydra-window>> 

  <<hydra-rust>>