From 4e6115214b24b5e52fddcb53040045890d01f59a Mon Sep 17 00:00:00 2001 From: Radon Rosborough Date: Wed, 8 Mar 2017 11:17:33 -0800 Subject: [PATCH] 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. --- lisp/use-package/use-package.el | 32 +++++++++++++++++--------------- 1 file 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 -- 2.39.2