GNU bug report logs -
#53885
Autoload package-installed-p
Previous Next
Reported by: Corwin Brust <corwin <at> bru.st>
Date: Tue, 8 Feb 2022 23:56:02 UTC
Severity: normal
Done: Eli Zaretskii <eliz <at> gnu.org>
Bug is archived. No further changes may be made.
Full log
Message #17 received at 53885 <at> debbugs.gnu.org (full text, mbox):
On Tue, 8 Feb 2022 at 23:39, Corwin Brust <corwin <at> bru.st> wrote:
> Corrected reproducer:
>
> (progn
> (setq package-user-dir "~/elpa")
> (setq package-archives
> '(("MELPA" .
> "https://melpa.org/packages/")))
> (unless (package-installed-p 'use-package)
> (package-install 'use-package)))
By the way, there are two issues with this code snippet. First, you
should call '(package-refresh-contents)' to make sure you have the
package list from MELPA.
Second, and more subtly, calling package install during init time
doesn't add the package to the list of selected packages, so
'use-package' would be subject to removal by 'package-autoremove'. To
fix this, something like
(add-hook 'after-init-hook
(lambda () (package--update-selected-packages '(use-package) nil)))
is needed.
I think a more user-friendly 'package-ensure-installed' function is in
order here. I believe the use-package package provides some
functionality for this, but there is no good built-in equivalent (which
is needed even by use-package users).
This bug report was last modified 3 years and 103 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.