]> code.delx.au - gnu-emacs-elpa/commitdiff
Don't undefine BODY's map binding when it's a prefix
authorOleh Krehel <ohwoeowho@gmail.com>
Wed, 21 Jan 2015 16:43:33 +0000 (17:43 +0100)
committerOleh Krehel <ohwoeowho@gmail.com>
Wed, 21 Jan 2015 16:45:54 +0000 (17:45 +0100)
* 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

index 39ff68bc609da8fb72d691337c1220537f5ac326..fa27904e8b5f4a4e92caf6cf94532be211a879d1 100644 (file)
--- 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 ()