emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 8884698 17/27: Don't undefine BODY's map binding when it's


From: Oleh Krehel
Subject: [elpa] master 8884698 17/27: Don't undefine BODY's map binding when it's a prefix
Date: Sat, 24 Jan 2015 20:36:34 +0000

branch: master
commit 88846985d87391dab6aea029d660de83df148b74
Author: Oleh Krehel <address@hidden>
Commit: Oleh Krehel <address@hidden>

    Don't undefine BODY's map binding when it's a prefix
    
    * hydra.el (hydra-create): Update.
    
    Basically the same fix as before, only for bindings relating to a map.
    
    Now this will work:
    
        (hydra-create "C-y"
          '(("l" forward-char)
            ("h" backward-char)
            ("j" next-line)
            ("k" previous-line)
            ("z"))
          lispy-mode-map)
    
    even though "C-y" is bound to a command in `lispy-mode-map'. The
    previous binding will be undefined.
    
    Re #4.
---
 hydra.el |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/hydra.el b/hydra.el
index 39ff68b..fa27904 100644
--- a/hydra.el
+++ b/hydra.el
@@ -90,13 +90,6 @@ When `(keymapp METHOD)`, it becomes:
                    (define-key keymap (kbd (car x))
                      (intern (format "hydra-%s-%S" body (cadr x)))))
                  heads))
-         (method (cond ((null method)
-                        'global-set-key)
-                       ((keymapp (eval method))
-                        `(lambda (key command)
-                           (define-key ,method key command)))
-                       (t
-                        method)))
          (hint (concat "hydra: "
                        (mapconcat
                         (lambda (h)
@@ -114,11 +107,21 @@ When `(keymapp METHOD)`, it becomes:
                (mapconcat
                 (lambda (x)
                   (format "\"%s\":    `%S'" (car x) (cadr x)))
-                heads ",\n"))))
+                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))))
     `(progn
-       (when (eq ',method 'global-set-key)
-         (unless (keymapp (global-key-binding ,(kbd body)))
-           (global-set-key ,(kbd body) nil)))
        ,@(cl-mapcar
           (lambda (head name)
             `(defun ,name ()



reply via email to

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