1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-15 10:30:25 -08:00

Support :ensure (pkg :pin archive)

Fixes https://github.com/jwiegley/use-package/issues/506
This commit is contained in:
John Wiegley 2017-12-04 15:39:31 -08:00
parent e34fdb580a
commit 62d33b2143
3 changed files with 61 additions and 30 deletions

View file

@ -50,6 +50,26 @@
for use by extension packages, indicates keywords that, if used without
`:demand`, cause deferred loading (as if `:defer t` had been specified).
- The `:ensure` keyword now accepts a specific pinning sub-keyword. For
example:
``` elisp
(use-package foo
:pin "elpa")
```
This ensure the package `foo` is installed from `"elpa"`.
``` elisp
(use-package foo
:ensure bar
:ensure (quux :pin "melpa"))
```
This says that `foo` ensures that `bar` is installed, as well as `quux` from
`"melpa"`. It does *not* ensure that `foo` is installed, because explicit
`:ensure` keywords were given.
- New `:hook` keyword.
- New `:catch` keyword. If `t` or `nil`, it enables (the default, see

View file

@ -137,15 +137,17 @@ manually updated package."
t
(use-package-only-one (symbol-name keyword) args
#'(lambda (label 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)"))))))))
(pcase arg
((pred symbolp)
(list arg))
(`(,(and pkg (pred symbolp))
:pin ,(and repo (or (pred stringp)
(pred symbolp))))
(list (cons pkg repo)))
(_
(use-package-error
(concat ":ensure wants an optional package name "
"(an unquoted symbol name), or (<symbol> :pin <string>)"))))))))
(defun use-package-ensure-elpa (name args state &optional no-refresh)
(dolist (ensure args)
@ -154,6 +156,9 @@ manually updated package."
ensure)))
(when package
(require 'package)
(when (consp package)
(use-package-pin-package (car package) (cdr package))
(setq package (car package)))
(unless (package-installed-p package)
(condition-case-unless-debug err
(progn

View file

@ -343,11 +343,33 @@
(require 'foo nil nil)))))
(ert-deftest use-package-test/:ensure-14 ()
(match-expansion
(use-package ess-site
:ensure ess1
:ensure ess2
:ensure (ess3 :pin "melpa-unstable")
:pin melpa-stable)
`(progn
(use-package-pin-package 'ess-site "melpa-stable")
(use-package-ensure-elpa 'ess-site
'(ess1 ess2
(ess3 . "melpa-unstable"))
'nil)
(require 'ess-site nil nil))))
(ert-deftest use-package-test/:ensure-15 ()
(let ((use-package-always-ensure t))
(match-expansion
(use-package foo :ensure bar :ensure (quux bow))
(use-package foo
:pin "elpa"
:ensure bar
:ensure (quux :pin "melpa"))
`(progn
(use-package-ensure-elpa 'foo '(bar quux bow) 'nil)
(use-package-pin-package 'foo "elpa")
(use-package-ensure-elpa 'foo
'(bar
(quux . "melpa"))
'nil)
(require 'foo nil nil)))))
(ert-deftest use-package-test/:if-1 ()
@ -1431,18 +1453,6 @@
(bind-key "f" #'w3m-lnum-print-this-url w3m-y-prefix-map nil)
(bind-key "t" #'w3m-print-this-url w3m-y-prefix-map nil)))))
(ert-deftest use-package-test/506 ()
(match-expansion
(use-package ess-site
:ensure ess
:pin melpa-stable)
`(progn
(use-package-pin-package 'ess-site "melpa-stable")
(use-package-ensure-elpa 'ess-site
'(ess)
'nil)
(require 'ess-site nil nil))))
(ert-deftest use-package-test/538 ()
(match-expansion
(use-package mu4e
@ -1452,16 +1462,12 @@
:config
(config))
`(progn
(unless
(fboundp 'mu4e)
(unless (fboundp 'mu4e)
(autoload #'mu4e "mu4e" nil t))
(eval-after-load 'mu4e
'(progn
(config)
t))
'(progn (config) t))
(ignore
(bind-keys :package mu4e
("<f9>" . mu4e))))))
(bind-keys :package mu4e ("<f9>" . mu4e))))))
;; Local Variables:
;; indent-tabs-mode: nil