From 5f2b0cbe8fd7e4293357fb4788afb5ea41e58779 Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Wed, 29 Nov 2017 21:43:52 -0800 Subject: [PATCH] Allow keys to be bound to nil Fixes https://github.com/jwiegley/use-package/issues/525 --- lisp/use-package/bind-key.el | 11 ++++++----- lisp/use-package/use-package.el | 33 ++++++++++++++++++--------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el index eb1ea804d2a..e5e06c7cd2a 100644 --- a/lisp/use-package/bind-key.el +++ b/lisp/use-package/bind-key.el @@ -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 diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el index 2b8daae009d..bc8dd70609f 100644 --- a/lisp/use-package/use-package.el +++ b/lisp/use-package/use-package.el @@ -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)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -- 2.39.2