1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2026-01-10 13:40:36 -08:00

Extend capabilities of use-package-ensure-function

Modify the expected API of `use-package-ensure-function' so that it is
passed three arguments: the name of the package declared in the
`use-package' form; the argument passed to `:ensure'; and the current
`state' plist created by previous handlers. (Previously, it was only
given a single argument, which was the argument passed to `:ensure',
or the name of the package declared in the `use-package' form, if the
former was `t'.

This allows for more flexibility in the capabilities of the
`use-package-ensure-function' implementation. For example, its
behavior can change depending on the values of other keywords, if
those keywords modify the `state' plist appropriately.
This commit is contained in:
Radon Rosborough 2017-03-08 11:17:33 -08:00
parent 0905a7b1c7
commit 4e6115214b

View file

@ -566,24 +566,26 @@ manually updated package."
(concat ":ensure wants an optional package name "
"(an unquoted symbol name)")))))))
(defun use-package-ensure-elpa (package &optional no-refresh)
(require 'package)
(if (package-installed-p package)
t
(if (and (not no-refresh)
(assoc package (bound-and-true-p package-pinned-packages)))
(package-read-all-archive-contents))
(if (or (assoc package package-archive-contents) no-refresh)
(package-install package)
(progn
(package-refresh-contents)
(use-package-ensure-elpa package t)))))
(defun use-package-ensure-elpa (name ensure state &optional no-refresh)
(let ((package (or (and (eq ensure t) (use-package-as-symbol name))
ensure)))
(when package
(require 'package)
(if (package-installed-p package)
t
(if (and (not no-refresh)
(assoc package (bound-and-true-p package-pinned-packages)))
(package-read-all-archive-contents))
(if (or (assoc package package-archive-contents) no-refresh)
(package-install package)
(progn
(package-refresh-contents)
(use-package-ensure-elpa name ensure state t)))))))
(defun use-package-handler/:ensure (name keyword ensure rest state)
(let* ((body (use-package-process-keywords name rest state))
(package-name (or (and (eq ensure t) (use-package-as-symbol name)) ensure))
(ensure-form (when package-name
`(,use-package-ensure-function ',package-name))))
(ensure-form `(,use-package-ensure-function
',name ',ensure ',state)))
;; We want to avoid installing packages when the `use-package'
;; macro is being macro-expanded by elisp completion (see
;; `lisp--local-variables'), but still do install packages when