1
0
mirror of https://git.savannah.gnu.org/git/emacs.git synced 2024-11-27 07:37:33 +00:00

All the second argument in use-package-defaults lists to be a function

Address the question raised in https://github.com/jwiegley/use-package/issues/591
This commit is contained in:
John Wiegley 2017-12-15 22:48:42 -08:00
parent 51eceb4238
commit 2d226310f1
2 changed files with 37 additions and 12 deletions

View File

@ -159,21 +159,30 @@ See also `use-package-defaults', which uses this value."
(not (plist-member args :defer))
(not (plist-member args :demand))))))
"Default values for specified `use-package' keywords.
Each entry in the alist is a list of three elements. The first
element is the `use-package' keyword and the second is a form
that can be evaluated to get the default value. The third element
is a form that can be evaluated to determine whether or not to
assign a default value; if it evaluates to nil, then the default
value is not assigned even if the keyword is not present in the
`use-package' form. This third element may also be a function, in
which case it receives the name of the package (as a symbol) and
a list of keywords (in normalized form). It should return nil or
t according to whether defaulting should be attempted."
Each entry in the alist is a list of three elements:
The first element is the `use-package' keyword.
The second is a form that can be evaluated to get the default
value. It can also be a function that will receive the name of
the use-package declaration and the keyword plist given to
`use-package', in normalized form. The value it returns should
also be in normalized form (which is sometimes *not* what one
would normally write in a `use-package' declaration, so use
caution).
The third element is a form that can be evaluated to determine
whether or not to assign a default value; if it evaluates to nil,
then the default value is not assigned even if the keyword is not
present in the `use-package' form. This third element may also be
a function, in which case it receives the name of the package (as
a symbol) and a list of keywords (in normalized form). It should
return nil or non-nil depending on whether defaulting should be
attempted."
:type `(repeat
(list (choice :tag "Keyword"
,@(mapcar #'(lambda (k) (list 'const k))
use-package-keywords))
(choice :tag "Default value" sexp)
(choice :tag "Default value" sexp function)
(choice :tag "Enable if non-nil" sexp function)))
:group 'use-package)
@ -564,7 +573,11 @@ extending any keys already present."
(funcall func name args)
(eval func)))
(setq args (use-package-plist-maybe-put
args (nth 0 spec) (eval (nth 1 spec))))))
args (nth 0 spec)
(let ((func (nth 1 spec)))
(if (and func (functionp func))
(funcall func name args)
(eval func)))))))
;; Determine any autoloads implied by the keywords used.
(let ((iargs args)

View File

@ -1862,6 +1862,18 @@
(string-match ":defer wants exactly one argument"
(car warnings))) 44))))))
(ert-deftest use-package-test/591 ()
(let ((use-package-defaults
(cons '(:if (lambda (name _) `(locate-library ,name)) t)
use-package-defaults)))
(match-expansion
(use-package nonexistent
:hook lisp-mode)
`(when (locate-library nonexistent)
(unless (fboundp 'nonexistent)
(autoload #'nonexistent "nonexistent" nil t))
(add-hook 'lisp-mode-hook #'nonexistent)))))
(ert-deftest bind-key/:prefix-map ()
(match-expansion
(bind-keys :prefix "<f1>"