;;; Code:
+(require 'cl-lib)
(require 'up-core)
(defgroup use-package-ensure nil
(defcustom use-package-ensure-function 'use-package-ensure-elpa
"Function that ensures a package is installed.
This function is called with 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.
+package declared in the `use-package' form; the arguments passed
+to all `:ensure' keywords (always a list, even if only one); and
+the current `state' plist created by previous handlers.
Note that this function is called whenever `:ensure' is provided,
even if it is nil. It is up to the function to decide on the
t
(use-package-only-one (symbol-name keyword) args
#'(lambda (label arg)
- (if (symbolp arg)
- arg
+ (cond
+ ((symbolp arg)
+ (list arg))
+ ((and (listp arg) (cl-every #'symbolp arg))
+ arg)
+ (t
(use-package-error
(concat ":ensure wants an optional package name "
- "(an unquoted symbol name)")))))))
-
-(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)
- (unless (package-installed-p package)
- (condition-case-unless-debug err
- (progn
- (when (assoc package (bound-and-true-p
- package-pinned-packages))
- (package-read-all-archive-contents))
- (if (assoc package package-archive-contents)
- (package-install package)
- (package-refresh-contents)
+ "(an unquoted symbol name)"))))))))
+
+(defun use-package-ensure-elpa (name args state &optional no-refresh)
+ (dolist (ensure args)
+ (let ((package
+ (or (and (eq ensure t) (use-package-as-symbol name))
+ ensure)))
+ (when package
+ (require 'package)
+ (unless (package-installed-p package)
+ (condition-case-unless-debug err
+ (progn
(when (assoc package (bound-and-true-p
package-pinned-packages))
(package-read-all-archive-contents))
- (package-install package))
- t)
- (error
- (ignore
- (display-warning 'use-package
- (format "Failed to install %s: %s"
- name (error-message-string err))
- :error))))))))
+ (if (assoc package package-archive-contents)
+ (package-install package)
+ (package-refresh-contents)
+ (when (assoc package (bound-and-true-p
+ package-pinned-packages))
+ (package-read-all-archive-contents))
+ (package-install package))
+ t)
+ (error
+ (ignore
+ (display-warning 'use-package
+ (format "Failed to install %s: %s"
+ name (error-message-string err))
+ :error)))))))))
(defun use-package-handler/:ensure (name keyword ensure rest state)
(let* ((body (use-package-process-keywords name rest state)))
body))
(add-to-list 'use-package-defaults
- '(:ensure use-package-always-ensure
+ '(:ensure (list use-package-always-ensure)
(lambda (args)
(and use-package-always-ensure
(not (plist-member args :load-path))))) t)
(flet ((norm (&rest args)
(apply #'use-package-normalize/:ensure
'foopkg :ensure args)))
- (should (equal (norm '(t)) t))
- (should (equal (norm '(nil)) nil))
- (should (equal (norm '(sym)) 'sym))
+ (should (equal (norm '(t)) '(t)))
+ (should (equal (norm '(nil)) '(nil)))
+ (should (equal (norm '(sym)) '(sym)))
(should-error (norm '(1)))
(should-error (norm '("Hello")))))
(match-expansion
(use-package foo :ensure t)
`(progn
- (use-package-ensure-elpa 'foo 't 'nil)
+ (use-package-ensure-elpa 'foo '(t) 'nil)
(require 'foo nil nil)))))
(ert-deftest use-package-test/:ensure-2 ()
(match-expansion
(use-package foo :ensure t)
`(progn
- (use-package-ensure-elpa 'foo 't 'nil)
+ (use-package-ensure-elpa 'foo '(t) 'nil)
(require 'foo nil nil)))))
(ert-deftest use-package-test/:ensure-3 ()
(match-expansion
(use-package foo :ensure nil)
`(progn
- (use-package-ensure-elpa 'foo 'nil 'nil)
+ (use-package-ensure-elpa 'foo '(nil) 'nil)
(require 'foo nil nil)))))
(ert-deftest use-package-test/:ensure-4 ()
(match-expansion
(use-package foo :ensure nil)
`(progn
- (use-package-ensure-elpa 'foo 'nil 'nil)
+ (use-package-ensure-elpa 'foo '(nil) 'nil)
(require 'foo nil nil)))))
(ert-deftest use-package-test/:ensure-5 ()
(match-expansion
(use-package foo :ensure nil :load-path "foo")
`(progn
- (use-package-ensure-elpa 'foo 'nil 'nil)
+ (use-package-ensure-elpa 'foo '(nil) 'nil)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil nil)))))
(match-expansion
(use-package foo :ensure nil :load-path "foo")
`(progn
- (use-package-ensure-elpa 'foo 'nil 'nil)
+ (use-package-ensure-elpa 'foo '(nil) 'nil)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil nil)))))
(match-expansion
(use-package foo :ensure t :load-path "foo")
`(progn
- (use-package-ensure-elpa 'foo 't 'nil)
+ (use-package-ensure-elpa 'foo '(t) 'nil)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil nil)))))
(match-expansion
(use-package foo :ensure t :load-path "foo")
`(progn
- (use-package-ensure-elpa 'foo 't 'nil)
+ (use-package-ensure-elpa 'foo '(t) 'nil)
(eval-and-compile
(add-to-list 'load-path ,(pred stringp)))
(require 'foo nil nil)))))
(use-package foo :ensure t)
(should (eq tried-to-install 'foo)))))
+(ert-deftest use-package-test/:ensure-12 ()
+ (let ((use-package-always-ensure t))
+ (match-expansion
+ (use-package foo :ensure bar)
+ `(progn
+ (use-package-ensure-elpa 'foo '(bar) 'nil)
+ (require 'foo nil nil)))))
+
+(ert-deftest use-package-test/:ensure-13 ()
+ (let ((use-package-always-ensure t))
+ (match-expansion
+ (use-package foo :ensure bar :ensure quux)
+ `(progn
+ (use-package-ensure-elpa 'foo '(bar quux) 'nil)
+ (require 'foo nil nil)))))
+
+(ert-deftest use-package-test/:ensure-14 ()
+ (let ((use-package-always-ensure t))
+ (match-expansion
+ (use-package foo :ensure bar :ensure (quux bow))
+ `(progn
+ (use-package-ensure-elpa 'foo '(bar quux bow) 'nil)
+ (require 'foo nil nil)))))
+
(ert-deftest use-package-test/:if-1 ()
(match-expansion
(use-package foo :if t)
(bind-keys :package mu4e
("<f9>" . mu4e))))))
-(ert-deftest use-package-test/539 ()
- (match-expansion
- (use-package foo
- :requires bar
- :after quux
- :ensure bow)
- `(progn
- (use-package-ensure-elpa 'foo 'bow 'nil)
- (when (featurep 'bar)
- (eval-after-load 'quux
- '(require 'foo nil nil))))))
-
;; Local Variables:
;; indent-tabs-mode: nil
;; no-byte-compile: t