Skip to content

Commit 4ca646e

Browse files
committed
Allow a sexp as head's CMD paramater
* hydra.el (hydra--make-callable): New function. (defhydra): Use `hydra--make-callable'. Now, head's CMD is either: command name, nil, a sexp. In case of a sexp, it will be wrapped unevaluated in an interactive lambda. You can use a `progn' to have many statements in the sexp. Fixes #25. Example: (defhydra hydra-launcher (:color blue) "Launch" ("h" man "man") ("r" (browse-url "http://www.reddit.com/r/emacs/") "reddit") ("w" (browse-url "http://www.emacswiki.org/") "emacswiki") ("s" shell "shell") ("q" nil "cancel")) (global-set-key (kbd "C-c r") 'hydra-launcher/body)
1 parent d10c26e commit 4ca646e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

hydra.el

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
;; Author: Oleh Krehel <ohwoeowho@gmail.com>
66
;; Maintainer: Oleh Krehel <ohwoeowho@gmail.com>
77
;; URL: https://github.com/abo-abo/hydra
8-
;; Version: 0.8.1
8+
;; Version: 0.9.0
99
;; Keywords: bindings
1010
;; Package-Requires: ((cl-lib "0.5"))
1111

@@ -177,6 +177,16 @@ It's possible to set this to nil.")
177177
(and (consp x)
178178
(memq (car x) '(function quote)))))
179179

180+
(defun hydra--make-callable (x)
181+
"Generate a callable symbol from X.
182+
If X is a function symbol or a lambda, return it. Otherwise, it
183+
should be a single statement. Wrap it in an interactive lambda."
184+
(if (or (symbolp x) (functionp x))
185+
x
186+
`(lambda ()
187+
(interactive)
188+
,x)))
189+
180190
(defun hydra--head-property (h prop &optional default)
181191
"Return for Hydra head H the value of property PROP.
182192
Return DEFAULT if PROP is not in H."
@@ -412,7 +422,7 @@ except a blue head can stop the Hydra state.
412422
,@(cl-mapcar
413423
(lambda (head name)
414424
(hydra--make-defun
415-
name (cadr head) (hydra--color head body-color)
425+
name (hydra--make-callable (cadr head)) (hydra--color head body-color)
416426
(format "%s\n\nCall the head: `%S'." doc (cadr head))
417427
hint keymap
418428
body-color body-pre body-post))

0 commit comments

Comments
 (0)