summaryrefslogtreecommitdiff
path: root/lisp/use-package/use-package.el
diff options
context:
space:
mode:
authorRadon Rosborough <radon.neon@gmail.com>2017-03-08 11:17:33 -0800
committerRadon Rosborough <radon.neon@gmail.com>2017-03-08 11:17:33 -0800
commit4e6115214b24b5e52fddcb53040045890d01f59a (patch)
tree7158e0769049ebab43d3a8a128bb72041dcb992d /lisp/use-package/use-package.el
parent0905a7b1c728612788718014458a8f265e265389 (diff)
downloademacs-4e6115214b24b5e52fddcb53040045890d01f59a.tar.gz
emacs-4e6115214b24b5e52fddcb53040045890d01f59a.tar.bz2
emacs-4e6115214b24b5e52fddcb53040045890d01f59a.zip
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.
Diffstat (limited to 'lisp/use-package/use-package.el')
-rw-r--r--lisp/use-package/use-package.el32
1 files changed, 17 insertions, 15 deletions
diff --git a/lisp/use-package/use-package.el b/lisp/use-package/use-package.el
index f933ce2d936..2ef697201f8 100644
--- a/lisp/use-package/use-package.el
+++ b/lisp/use-package/use-package.el
@@ -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