[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4ca646e 15/17: Allow a sexp as head's CMD paramater
From: |
Oleh Krehel |
Subject: |
[elpa] master 4ca646e 15/17: Allow a sexp as head's CMD paramater |
Date: |
Tue, 10 Feb 2015 07:13:28 +0000 |
branch: master
commit 4ca646ed1b10a5a1c1be4843cfd41be7797d9db1
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
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 <address@hidden>
;; Maintainer: Oleh Krehel <address@hidden>
;; 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))
- [elpa] master 1b1d31d 07/17: Support local hydra heads, (continued)
- [elpa] master 1b1d31d 07/17: Support local hydra heads, Oleh Krehel, 2015/02/10
- [elpa] master 9a8e2f1 04/17: hydra.el (hydra-keyboard-quit): New custom var, Oleh Krehel, 2015/02/10
- [elpa] master 9b31ead 08/17: Update semantics for local heads to `:bind nil', Oleh Krehel, 2015/02/10
- [elpa] master 969fa66 10/17: fix typo - single not singe, Oleh Krehel, 2015/02/10
- [elpa] master d41be74 11/17: `hydra/body' will pass the initial `current-prefix-arg' along, Oleh Krehel, 2015/02/10
- [elpa] master ad771a4 03/17: Move defun-creating code into a defun, Oleh Krehel, 2015/02/10
- [elpa] master 763bb2a 13/17: Allow lambda :bind property for body and heads, Oleh Krehel, 2015/02/10
- [elpa] master 0712a43 12/17: README.md: update, Oleh Krehel, 2015/02/10
- [elpa] master d10c26e 14/17: Update comments and mark the old examples obsolete, Oleh Krehel, 2015/02/10
- [elpa] master 0c08964 16/17: README.md: update, Oleh Krehel, 2015/02/10
- [elpa] master 4ca646e 15/17: Allow a sexp as head's CMD paramater,
Oleh Krehel <=
- [elpa] master bb01930 09/17: Fix "catch 'hydra-disable", Oleh Krehel, 2015/02/10
- [elpa] master 11b130e 17/17: Merge commit '0c08964462812942db51d177e6ea922b26019e65' from hydra, Oleh Krehel, 2015/02/10