[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 64e5b91 22/27: Avoid evaling METHOD.

From: Oleh Krehel
Subject: [elpa] master 64e5b91 22/27: Avoid evaling METHOD.
Date: Sat, 24 Jan 2015 20:36:36 +0000

branch: master
commit 64e5b9129fcc61b18ca194af6e512cbe91122155
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Avoid evaling METHOD.
    * hydra.el (hydra-create): Update.
    METHOD doesn't need to be evaled: it's either nil, a lambda, or assume
    that it's a valid keymap without evaling. This will prevent eager
    macroexpansion failure for this argument.
    There still is a problem with eager macroexpansion failure in HEADS
    Re #9
 hydra.el |   38 ++++++++++++++++++++++----------------
 1 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/hydra.el b/hydra.el
index 932cea2..4ef966c 100644
--- a/hydra.el
+++ b/hydra.el
@@ -112,20 +112,7 @@ When `(keymapp METHOD)`, it becomes:
                 (lambda (x)
                   (format "\"%s\":    `%S'" (car x) (cadr x)))
-                heads ",\n")))
-         map
-         (method
-          (cond ((null method)
-                 (unless (keymapp (global-key-binding (kbd body)))
-                   (global-set-key (kbd body) nil))
-                 'global-set-key)
-                ((keymapp (setq map (eval method)))
-                 (unless (keymapp (lookup-key map (kbd body)))
-                   (define-key map (kbd body) nil))
-                 `(lambda (key command)
-                    (define-key ,method key command)))
-                (t
-                 method))))
+                heads ",\n"))))
           (lambda (head name)
@@ -137,7 +124,8 @@ When `(keymapp METHOD)`, it becomes:
                      `((call-interactively #',(cadr head))
                        (when hydra-is-helpful
                          (message ,hint))
-                       (setq hydra-last (hydra-set-transient-map ',keymap 
+                       (setq hydra-last
+                             (hydra-set-transient-map ',keymap t))))))
           heads names)
        (defun ,(intern (format "hydra-%s-body" body)) ()
@@ -145,9 +133,27 @@ When `(keymapp METHOD)`, it becomes:
          (when hydra-is-helpful
            (message ,hint))
          (setq hydra-last (hydra-set-transient-map ',keymap t)))
+       ,@(cond ((null method)
+                `((unless (keymapp (global-key-binding (kbd ,body)))
+                    (global-set-key (kbd ,body) nil))))
+               ((or (functionp method)
+                    (and (consp method)
+                         (memq (car method) '(function quote))))
+                nil)
+               (t
+                `((unless (keymapp (lookup-key ,method (kbd ,body)))
+                    (define-key ,method (kbd ,body) nil)))))
           (lambda (head name)
-            `(,method ,(vconcat (kbd body) (kbd (car head))) #',name))
+            `(,@(cond ((null method)
+                      (list 'global-set-key))
+                      ((or (functionp method)
+                           (and (consp method)
+                                (memq (car method) '(function quote))))
+                      (list 'funcall method))
+                     (t
+                      (list 'define-key method)))
+                ,(vconcat (kbd body) (kbd (car head))) #',name))
           heads names))))
 (provide 'hydra)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]