emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: emacs-29 acd462b0306: ; Improve the use-package manual


From: Stefan Monnier
Subject: Re: emacs-29 acd462b0306: ; Improve the use-package manual
Date: Sat, 10 Dec 2022 11:20:14 -0500
User-agent: Gnus/5.13 (Gnus v5.13)

> The answer to your first question is yes: the macro-expansion of
>
>     (use-package foo)
>
> is just
>
>     (require 'foo nil nil)

BTW, I can't resist mentioning that `require`ing a file like that should
be extremely rarely needed in an init file.  There's a good reason for
that: by convention, the mere act of loading a file should not affect
Emacs behavior very much, if at all, so those `require` will usually
just slow down startup for no good reason.

I think this part of `use-package` is a result of its having been
designed before things like `package.el` became common practice (the
main effect of which (in this respect) has been to make `;;;###autoload`
cookies usable in all packages without any extra work on the package's
author's side).

(A similar "old style" thingy is that (use-package foo-mode :mode
".bar\\'") will setup an autoload for the `foo-mode` function, whereas
that autoload should have already been setup by the package's own
installation).

It would be nice to try and evolve `use-package` towards a default
behavior that's more aligned with current best practices rather than
what was done back when installing a package meant reading the
"Commentary:" section and copying a chunk of ELisp code into your
init file.

> The last two examples, using package-installed-p and locate-library, are
> more important to keep, as users have reported issues specifically
> related to not knowing what the difference is between them, for example:
>
>     https://github.com/jwiegley/use-package/issues/693

I think in most cases, neither of them are good choices.
Instead better choices will usually look like `:if (fboundp '...)`
(which should be a lot faster than `locate-library` and doesn't care
how the package was installed).

Also, the wording in that paragraph is weird:

    This example loads a package only when the @samp{foo} package
    is installed.

since users should rarely care about "loading" (since, as
mentioned earlier, this should have mostly no visible effect).
`use-package` should be about configuring packages, not about loading
them (the `;;;###autoload` cookies should take care of the loading part
already).

> Alternatively, we could perhaps consider changing the docstring of
> `package-installed-p' to just let people know of `locate-library' (and
> maybe even when to use it).

This doesn't sound right since those two are only distantly related.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]