Subject: Re: bug#53885: Autoload package-installed-p

From: Augusto Stoffel <[email-masked]>
Date: Thu, 10 Feb 2022 09:42:41 +0100

Hi Corwin,

On Wed,  9 Feb 2022 at 09:39, Corwin Brust <[email-masked]> wrote:

> Hi Augusto!
>
> On Wed, Feb 9, 2022, 08:39 Augusto Stoffel <[email-masked]> wrote:
>
>  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.
>
> I believe this was changed with the implementation of "early-init".  We don't need to expressly call
> `package-refresh-contents' since Emacs 27, see:
> https://github.com/emacs-mirror/emacs/blob/master/etc/NEWS.27#L227

This is a different matter.  What I was saying is, you need to download
the package list from MELPA before trying to install a missing package.

If you delete ~/.emacs.d/elpa, your configuration as you showed it won't
be able to bootstrap.

>  '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 wasn't aware of this idiosyncrasy. I will look at package.el further  FTR, in my own configuration I
> expressly set-up package-selected-packages.
>
> In any case, this bug report stems from a Reddit user's perception of breakage with the Emacs 28
> pre-release binaries recently added to alpha.  I simply created a minimal reproducer from that
> person's use/expectations.
>
> Do you agree the (corrected) reproducer given should be sufficient to demonstrate the change
> provided by adding the autoload, if the patch is applied?
>
> As things stand presently, I'm having trouble thinking of use-cases for package-installed-p that
> would not start with (require 'package).
>
>  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).
>
> I love this idea.  Would you be interested to open a new bug report for this feature request, perhaps
> offering a patch if you are so inclined?

I recall Philip giving a similar suggestion on the mailing list but I
can't find that thread anymore.  So I added him to this message.

> FWIW, I agree that ,if/when something more robust is added expressly to support the batch
> installation of packages, the need for this autoload (and perhaps all user-facing use-cases for
> package-installed-p) may be greatly reduced.

Autoloading 'package-installed-p' wouldn't cause any harm, but it also
doesn't solve any problems, so why bother?

> That said, it's not clear to me whether general consensus will be to support a "default automation"
> function (or functions) for this, or that what we have is "enough" for each of us to do things as we
> wish.  It might make sense to open a discussion on the development list to discuss this potential
> improvement.
>
> Finally, in case it may help, here is a formula I have often used to 'bootstrap' a batch install of
> packages:
>
> (setq package-selected-packages '(foo bar baz))
> (mapc (lambda(pkg) (when (not (require pkg nil t) (package-install pkg))
> package-selected-packages)
>
> For myself, I'm not using `package-autoremove'.  I typically remove (actually rename, usually) my
> ELPA folder and then relaunch Emacs.  My configuration (just like the user on behalf of whom I
> reported this "bug"), will then install the features I'm (still) using. I'm glad you are watching out for
> people who do use the auto-remove package feature.
>
> Regards,
> Corwin