Skip to content

Instantly share code, notes, and snippets.

@wrightmikea
Last active March 23, 2021 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrightmikea/31536eefe20b444f492aea7a31c9497a to your computer and use it in GitHub Desktop.
Save wrightmikea/31536eefe20b444f492aea7a31c9497a to your computer and use it in GitHub Desktop.
Elisp related to 2021 March 5 Emacs-SF Demo of Nested Hydra Menus by Mike Wright
;;; demo-nested-hydra-menus.el --- Emacs SF hydra gist -*- lexical-binding: t; -*-
;; Elisp related to 2021 March 5 Emacs-SF Demo of Nested Hydra Menus by Mike Wright
;;
;; (use-package hydra :ensure t)
;;
(progn
(require 'hydra)
(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 hydra-reset ()
"Reset the stack to empty."
(interactive)
(setq hydra-stack '()))
(defhydra hydra-low (:color amaranth)
"low"
("e" (message "do something else") "demo something else")
("i" (message "do it") "demo it")
("p" show-paren-mode "toggle paren matching")
("s" (message "do something") "demo something")
("w" whitespace-mode "toggle whitespace")
("+" text-scale-increase "bigger text")
("-" text-scale-decrease "smaller text")
("b" hydra-pop "back" :color blue )
("q" hydra-reset "quit" :exit t))
(defhydra hydra-mid (:color teal)
"mid"
("l" (progn
(hydra-low/body)
(hydra-push '(hydra-mid/body))) "low")
("b" hydra-pop "back" :color blue)
("q" hydra-reset "quit" :exit t))
(defhydra hydra-high (:color teal)
"high"
("m" (progn
(hydra-mid/body)
(hydra-push '(hydra-high/body)))
"middle")
("q" hydra-reset "quit" :exit t))
(global-set-key (kbd "s-1") 'hydra-high/body))
@wrightmikea
Copy link
Author

The actual elisp code I demoed was much larger (multiple files) and coupled to a lot of non-hydra code. To simplify things, I created this self-contained demo file.

Also, the code I demoed on March 5th had a bug that prevented returning from nested menus, so this code has a fix for that.

@wrightmikea
Copy link
Author

I also demoed something very similar to this on 3/19 using yasnippets.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment