branch: master commit 4ca646ed1b10a5a1c1be4843cfd41be7797d9db1 Author: Oleh Krehel <ohwoeo...@gmail.com> Commit: Oleh Krehel <ohwoeo...@gmail.com>
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) --- hydra.el | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/hydra.el b/hydra.el index dd0e098..2770fbc 100644 --- a/hydra.el +++ b/hydra.el @@ -5,7 +5,7 @@ ;; Author: Oleh Krehel <ohwoeo...@gmail.com> ;; Maintainer: Oleh Krehel <ohwoeo...@gmail.com> ;; URL: https://github.com/abo-abo/hydra -;; Version: 0.8.1 +;; Version: 0.9.0 ;; Keywords: bindings ;; Package-Requires: ((cl-lib "0.5")) @@ -177,6 +177,16 @@ It's possible to set this to nil.") (and (consp x) (memq (car x) '(function quote))))) +(defun hydra--make-callable (x) + "Generate a callable symbol from X. +If X is a function symbol or a lambda, return it. Otherwise, it +should be a single statement. Wrap it in an interactive lambda." + (if (or (symbolp x) (functionp x)) + x + `(lambda () + (interactive) + ,x))) + (defun hydra--head-property (h prop &optional default) "Return for Hydra head H the value of property PROP. Return DEFAULT if PROP is not in H." @@ -412,7 +422,7 @@ except a blue head can stop the Hydra state. ,@(cl-mapcar (lambda (head name) (hydra--make-defun - name (cadr head) (hydra--color head body-color) + name (hydra--make-callable (cadr head)) (hydra--color head body-color) (format "%s\n\nCall the head: `%S'." doc (cadr head)) hint keymap body-color body-pre body-post))