]> git.eshelyaron.com Git - emacs.git/commitdiff
Extend capabilities of use-package-ensure-function
authorRadon Rosborough <radon.neon@gmail.com>
Wed, 8 Mar 2017 19:17:33 +0000 (11:17 -0800)
committerRadon Rosborough <radon.neon@gmail.com>
Wed, 8 Mar 2017 19:17:33 +0000 (11:17 -0800)
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

index f933ce2d936c2427c19bbecb47e38f45fcdd5a57..2ef697201f8eb056d3181e80e3d8b82d120fdc74 100644 (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