]> code.delx.au - gnu-emacs-elpa/commitdiff
hydra.el (hydra--make-funcall): Add
authorOleh Krehel <ohwoeowho@gmail.com>
Sat, 28 Mar 2015 13:26:26 +0000 (14:26 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Sat, 28 Mar 2015 13:28:30 +0000 (14:28 +0100)
* hydra-test.el (hydra--make-funcall): Add test.

hydra-test.el
hydra.el

index 86aa2fbf4d491713c8d3e9f062ded3a9be95d29e..155c047e8aaa25e44b7c4fa2bc7a472b6cbb1d7c 100644 (file)
@@ -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
index a1fee76c859807e111db10096a7ff0421795f2e0..cc7ac6583c8ff1ba3fa11327de662e7b05f3f07c 100644 (file)
--- 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.