]> git.eshelyaron.com Git - emacs.git/commitdiff
Support multiples uses of :map with :bind
authorJohn Wiegley <johnw@newartisans.com>
Thu, 25 Feb 2016 23:57:50 +0000 (15:57 -0800)
committerJohn Wiegley <johnw@newartisans.com>
Thu, 25 Feb 2016 23:57:50 +0000 (15:57 -0800)
GitHub-reference: fixes https://github.com/jwiegley/use-package/issues/121

lisp/use-package/bind-key.el
lisp/use-package/use-package.el

index 65f40f7901a953ab151cf22f5ba56a85346184ff..c74e7b6a75356e53fae9051d81dfc629fd84a6c6 100644 (file)
@@ -190,8 +190,7 @@ See `bind-key' for more details."
   "Similar to `bind-key', but overrides any mode-specific bindings."
   `(bind-key ,key-name ,command override-global-map ,predicate))
 
-;;;###autoload
-(defmacro bind-keys (&rest args)
+(defun bind-keys-form (args)
   "Bind multiple keys at once.
 
 Accepts keyword arguments:
@@ -223,33 +222,64 @@ function symbol (unquoted)."
       (error "Both :prefix-map and :prefix must be supplied"))
     (when (and menu-name (not prefix))
       (error "If :menu-name is supplied, :prefix must be too"))
-    (macroexp-progn
-     (append
-      (when prefix-map
-        `((defvar ,prefix-map)
-          ,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
-          ,@(if menu-name
-                `((define-prefix-command ',prefix-map nil ,menu-name))
-              `((define-prefix-command ',prefix-map)))
-          ,@(if maps
+    (let ((args key-bindings)
+          first next)
+      (while args
+        (if (keywordp (car args))
+            (progn
+              (setq next args)
+              (setq args nil))
+          (if first
+              (nconc first (list (car args)))
+            (setq first (list (car args))))
+          (setq args (cdr args))))
+      (append
+       (when prefix-map
+         `((defvar ,prefix-map)
+           ,@(when doc `((put ',prefix-map 'variable-documentation ,doc)))
+           ,@(if menu-name
+                 `((define-prefix-command ',prefix-map nil ,menu-name))
+               `((define-prefix-command ',prefix-map)))
+           ,@(if maps
+                 (mapcar
+                  #'(lambda (m)
+                      `(bind-key ,prefix ',prefix-map ,m ,filter)) maps)
+               `((bind-key ,prefix ',prefix-map nil ,filter)))))
+       (cl-mapcan
+        (lambda (form)
+          (if prefix-map
+              `((bind-key ,(car form) ',(cdr form) ,prefix-map ,filter))
+            (if maps
                 (mapcar
                  #'(lambda (m)
-                     `(bind-key ,prefix ',prefix-map ,m ,filter)) maps)
-              `((bind-key ,prefix ',prefix-map nil ,filter)))))
-      (cl-mapcan
-       (lambda (form)
-         (if prefix-map
-             `((bind-key ,(car form) ',(cdr form) ,prefix-map ,filter))
-           (if maps
-               (mapcar
-                #'(lambda (m)
-                    `(bind-key ,(car form) ',(cdr form) ,m ,filter)) maps)
-             `((bind-key ,(car form) ',(cdr form) nil ,filter)))))
-       key-bindings)))))
+                     `(bind-key ,(car form) ',(cdr form) ,m ,filter)) maps)
+              `((bind-key ,(car form) ',(cdr form) nil ,filter)))))
+        first)
+       (when next
+         (bind-keys-form next))))))
+
+;;;###autoload
+(defmacro bind-keys (&rest args)
+  "Bind multiple keys at once.
+
+Accepts keyword arguments:
+:map MAP               - a keymap into which the keybindings should be
+                         added
+:prefix KEY            - prefix key for these bindings
+:prefix-map MAP        - name of the prefix map that should be created
+                         for these bindings
+:prefix-docstring STR  - docstring for the prefix-map variable
+:menu-name NAME        - optional menu string for prefix map
+:filter FORM           - optional form to determine when bindings apply
+
+The rest of the arguments are conses of keybinding string and a
+function symbol (unquoted)."
+  (macroexp-progn (bind-keys-form args)))
 
 ;;;###autoload
 (defmacro bind-keys* (&rest args)
-  `(bind-keys :map override-global-map ,@args))
+  (macroexp-progn
+   (bind-keys-form (cons :map (cons override-global-map args)))))
 
 (defun get-binding-description (elem)
   (cond
index baa50b0270f8b5c245d0fb0473efc68fac0f51e0..15da2452f1af222c3a55633b1c41e2ec5a18ace6 100644 (file)
@@ -698,7 +698,9 @@ may also be a string, as accepted by `define-key'."
        (use-package-sort-keywords
         (use-package-plist-maybe-put rest :defer t))
        (use-package-plist-append state :commands commands))
-     `((ignore (,(if bind-macro bind-macro 'bind-keys) ,@arg))))))
+     `((ignore
+        ,(macroexpand
+          `(,(if bind-macro bind-macro 'bind-keys) ,@arg)))))))
 
 (defun use-package-handler/:bind* (name keyword arg rest state)
   (use-package-handler/:bind name keyword arg rest state 'bind-keys*))