[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 7843563 14/18: hydra.el (hydra--make-funcall): Add
From: |
Oleh Krehel |
Subject: |
[elpa] master 7843563 14/18: hydra.el (hydra--make-funcall): Add |
Date: |
Sat, 28 Mar 2015 15:04:28 +0000 |
branch: master
commit 784356366768cd713af1a2b389a37c59c04491c7
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>
hydra.el (hydra--make-funcall): Add
* hydra-test.el (hydra--make-funcall): Add test.
---
hydra-test.el | 6 ++++++
hydra.el | 18 +++++++++---------
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/hydra-test.el b/hydra-test.el
index 86aa2fb..155c047 100644
--- a/hydra-test.el
+++ b/hydra-test.el
@@ -1193,6 +1193,12 @@ _r_ Commander William Riker: % -8`hydra-tng/riker^
_t_ Deanna Troi:
_d_ Lieutenant Commander Data: % -8`hydra-tng/data^^ _c_ Doctor Beverly
Crusher: % -8`hydra-tng/dr-crusher
_w_ Worf: % -8`hydra-tng/worf^^ _h_ Set phasers to
% -8`hydra-tng/phaser^^^^" 1)))))
+(ert-deftest hydra--make-funcall ()
+ (should (equal (let ((body-pre 'foo))
+ (hydra--make-funcall body-pre)
+ body-pre)
+ '(funcall (function foo)))))
+
(provide 'hydra-test)
;;; hydra-test.el ends here
diff --git a/hydra.el b/hydra.el
index a1fee76..cc7ac65 100644
--- a/hydra.el
+++ b/hydra.el
@@ -664,8 +664,7 @@ NAME, BODY and HEADS are parameters to `defhydra'."
(let ((body-color (hydra--body-color body))
(body-post (plist-get (cddr body) :post)))
(if body-post
- (when (symbolp body-post)
- (setq body-post `(funcall #',body-post)))
+ (hydra--make-funcall body-post)
(when hydra-keyboard-quit
(define-key keymap hydra-keyboard-quit #'hydra-keyboard-quit)))
(when (memq body-color '(amaranth pink teal))
@@ -826,7 +825,6 @@ Cancel the previous `hydra-timeout'."
(timer-activate hydra-timer))
;;* Macros
-;;** defhydra
;;;###autoload
(defmacro defhydra (name body &optional docstring &rest heads)
"Create a Hydra - a family of functions with prefix NAME.
@@ -896,8 +894,7 @@ result of `defhydra'."
(method (or (plist-get body :bind)
(car body))))
(when body-post
- (when (symbolp body-post)
- (setq body-post `(funcall #',body-post)))
+ (hydra--make-funcall body-post)
(setq heads (cons (list hydra-keyboard-quit #'hydra-keyboard-quit nil
:exit t)
heads)))
(dolist (h heads)
@@ -928,10 +925,8 @@ result of `defhydra'."
(define-key keymap (kbd (car x))
(plist-get (cl-cdddr x) :cmd-name)))
heads)
- (when (and body-pre (symbolp body-pre))
- (setq body-pre `(funcall #',body-pre)))
- (when (and body-body-pre (symbolp body-body-pre))
- (setq body-body-pre `(funcall #',body-body-pre)))
+ (hydra--make-funcall body-pre)
+ (hydra--make-funcall body-body-pre)
(hydra--handle-nonhead keymap name body heads)
`(progn
,@(mapcar
@@ -983,6 +978,11 @@ result of `defhydra'."
(or body-body-pre body-pre) body-post
'(setq prefix-arg current-prefix-arg))))))
+(defmacro hydra--make-funcall (sym)
+ "Transform SYM into a `funcall' that calls it."
+ `(when (and ,sym (symbolp ,sym))
+ (setq ,sym `(funcall #',,sym))))
+
(defmacro defhydradio (name _body &rest heads)
"Create radios with prefix NAME.
_BODY specifies the options; there are none currently.
- [elpa] master 71491b9 04/18: Fix argument to `replace-match', (continued)
- [elpa] master 71491b9 04/18: Fix argument to `replace-match', Oleh Krehel, 2015/03/28
- [elpa] master f6697f3 02/18: Allow for the "%s`foo" spec., Oleh Krehel, 2015/03/28
- [elpa] master 5c3ab46 08/18: hydra.el (hydra--format): Amend regex, Oleh Krehel, 2015/03/28
- [elpa] master 1bad0c4 09/18: hydra.el (hydra--format): Update regex order, Oleh Krehel, 2015/03/28
- [elpa] master 03771f4 01/18: hydra.el: Turn on lexical-binding, Oleh Krehel, 2015/03/28
- [elpa] master fe1cfee 10/18: hydra-examples.el (hydra-rectangle): Update, Oleh Krehel, 2015/03/28
- [elpa] master c8c6b8c 03/18: Fix blue/red heads with same cmd, Oleh Krehel, 2015/03/28
- [elpa] master 1290237 12/18: Disable key-chord for the duration of the hydra, Oleh Krehel, 2015/03/28
- [elpa] master cb4b78a 11/18: hydra-test.el (hydra-format-4): Add test, Oleh Krehel, 2015/03/28
- [elpa] master 640af46 13/18: hydra.el (defhydra): Improve docstring, Oleh Krehel, 2015/03/28
- [elpa] master 7843563 14/18: hydra.el (hydra--make-funcall): Add,
Oleh Krehel <=
- [elpa] master e403363 16/18: hydra.el (defhydra): Avoid eager macroexpansion failure, Oleh Krehel, 2015/03/28
- [elpa] master 5032ec7 15/18: hydra.el (defhydra): Simplify and improve the key binding code, Oleh Krehel, 2015/03/28
- [elpa] master 4a6a31d 17/18: hydra.el: Bump version, Oleh Krehel, 2015/03/28
- [elpa] master da45e68 18/18: Merge commit '4a6a31d6d4d479720f4b66091892b0cda2377346' from hydra, Oleh Krehel, 2015/03/28