Files
emacs/config/hydra.org
2025-10-30 13:49:55 -05:00

2.8 KiB

Hail Hydra?!

I find that Hydra is great for providing visual menus for tasks that might otherwise be fairly unwieldy. I use them hydra's for windows, tabs, and a few other things in the future perhaps.

Tabs

Pretty simple tab hydra. Handles opening, closing, and simple navigation.

  (defhydra hydra-tab (:color red :hint nil)
    "
Movement^^    ^Modifier^
----------------------------------------------------------------
_h_ ←        _n_ ew
_l_ →        _c_ lose
"
    ("h" tab-previous)
    ("l" tab-next)
    ("n" tab-new)
    ("c" tab-close)
    ("SPC" nil))
  (global-set-key (kbd "C-c t") 'hydra-tab/body)

Windows

Quite a helpful window hydra. I cannot take credit for this. I copied it from somewhere. When I find the link I'll add it here.

  (defhydra hydra-window (:color red :hint nil)
    "
Movement^^        ^Split^         ^Switch^		^Resize^
----------------------------------------------------------------
_h_ ←       	_v_ertical    	_b_uffer		_q_ X←
_j_ ↓        	_x_ horizontal	_f_ind files	_w_ X↓
_k_ ↑        	_z_ undo      	_a_ce 1		_e_ X↑
_l_ →        	_Z_ reset      	_s_wap		_r_ X→
_F_ollow		_D_lt Other   	_S_ave		max_i_mize
_SPC_ cancel	_o_nly this   	_d_elete
"
    ("h" windmove-left )
    ("j" windmove-down )
    ("k" windmove-up )
    ("l" windmove-right )
    ("q" hydra-move-splitter-left)
    ("w" hydra-move-splitter-down)
    ("e" hydra-move-splitter-up)
    ("r" hydra-move-splitter-right)
    ("b" consult-buffer)
    ("f" consult-fd)
    ("F" follow-mode)
    ("a" (lambda ()
           (interactive)
           (ace-window 1)
           (add-hook 'ace-window-end-once-hook
                     'hydra-window/body))
     )
    ("v" (lambda ()
           (interactive)
           (split-window-right)
           (windmove-right))
     )
    ("x" (lambda ()
           (interactive)
           (split-window-below)
           (windmove-down))
     )
    ("s" (lambda ()
           (interactive)
           (ace-window 4)
           (add-hook 'ace-window-end-once-hook
                     'hydra-window/body)))
    ("S" save-buffer)
    ("d" delete-window)
    ("D" (lambda ()
           (interactive)
           (ace-window 16)
           (add-hook 'ace-window-end-once-hook
                     'hydra-window/body))
     )
    ("o" delete-other-windows)
    ("i" ace-maximize-window)
    ("z" (progn
           (winner-undo)
           (setq this-command 'winner-undo))
     )
    ("Z" winner-redo)
    ("SPC" nil))
  (global-set-key (kbd "C-c w") 'hydra-window/body)

Pulling it all together

(use-package hydra
	:demand t
  :config
  <<tab-hydra>>
  <<window-hydra>>)