]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow keys to be bound to nil
authorJohn Wiegley <johnw@newartisans.com>
Thu, 30 Nov 2017 05:43:52 +0000 (21:43 -0800)
committerJohn Wiegley <johnw@newartisans.com>
Thu, 30 Nov 2017 05:44:02 +0000 (21:44 -0800)
Fixes https://github.com/jwiegley/use-package/issues/525

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

index eb1ea804d2a86ba25f27714339404ea9e593f719..e5e06c7cd2a0003b3cf7456dedeaa4f4de26a535 100644 (file)
@@ -267,11 +267,12 @@ function symbol (unquoted)."
          (wrap map
                (cl-mapcan
                 (lambda (form)
-                  (if prefix-map
-                      `((bind-key ,(car form) #',(cdr form) ,prefix-map ,filter))
-                    (if (and map (not (eq map 'global-map)))
-                        `((bind-key ,(car form) #',(cdr form) ,map ,filter))
-                      `((bind-key ,(car form) #',(cdr form) nil ,filter)))))
+                  (let ((fun (and (cdr form) (list 'function (cdr form)))))
+                    (if prefix-map
+                        `((bind-key ,(car form) ,fun ,prefix-map ,filter))
+                      (if (and map (not (eq map 'global-map)))
+                          `((bind-key ,(car form) ,fun ,map ,filter))
+                        `((bind-key ,(car form) ,fun nil ,filter))))))
                 first))
          (when next
            (bind-keys-form
index 2b8daae009d5c4edf21ce4225e4948ff142f6432..bc8dd70609ff8d7c84f4159ff0ee0d68d5632b92 100644 (file)
@@ -1014,6 +1014,7 @@ If RECURSED is non-nil, recurse into sublists."
 
 (defun use-package--recognize-function (v &optional additional-pred)
   "A predicate that recognizes functional constructions:
+  nil
   sym
   'sym
   (quote sym)
@@ -1025,11 +1026,10 @@ If RECURSED is non-nil, recurse into sublists."
   #'(lambda () ...)
   (function (lambda () ...))"
   (pcase v
-    ((pred use-package--non-nil-symbolp) t)
+    ((pred symbolp) t)
     (`(,(or `quote `function)
-       ,(pred use-package--non-nil-symbolp)) t)
-    ((pred functionp) t)
-    (`(function (lambda . ,_)) t)
+       ,(pred symbolp)) t)
+    ((pred commandp) t)
     (_ (and additional-pred
             (funcall additional-pred v)))))
 
@@ -1038,9 +1038,9 @@ If RECURSED is non-nil, recurse into sublists."
   sym
   #'(lambda () ...)"
   (pcase v
-    ((pred use-package--non-nil-symbolp) v)
+    ((pred symbolp) v)
     (`(,(or `quote `function)
-       ,(and sym (pred use-package--non-nil-symbolp))) sym)
+       ,(and sym (pred symbolp))) sym)
     (`(lambda . ,_) v)
     (`(quote ,(and lam `(lambda . ,_))) lam)
     (`(function ,(and lam `(lambda . ,_))) lam)
@@ -1057,10 +1057,12 @@ representing symbols (that may need to be autloaded)."
                               (use-package--normalize-function (cdr x)))
                       x)) args)))
     (cons nargs
-          (delete nil (mapcar #'(lambda (x)
-                                  (and (consp x)
-                                       (use-package--non-nil-symbolp (cdr x))
-                                       (cdr x))) nargs)))))
+          (delete
+           nil (mapcar
+                #'(lambda (x)
+                    (and (consp x)
+                         (use-package--non-nil-symbolp (cdr x))
+                         (cdr x))) nargs)))))
 
 (defun use-package-normalize-binder (name keyword args)
   (use-package-as-one (symbol-name keyword) args
@@ -1500,11 +1502,12 @@ representing symbols (that may need to be autloaded)."
       (lambda (def)
         (let ((syms (car def))
               (fun (cdr def)))
-          (mapcar
-           #'(lambda (sym)
-               `(add-hook (quote ,(intern (format "%s-hook" sym)))
-                          (function ,fun)))
-           (if (use-package--non-nil-symbolp syms) (list syms) syms))))
+          (when fun
+            (mapcar
+             #'(lambda (sym)
+                 `(add-hook (quote ,(intern (format "%s-hook" sym)))
+                            (function ,fun)))
+             (if (use-package--non-nil-symbolp syms) (list syms) syms)))))
       nargs))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;