Subject: bug#79106: [PATCH] Add new optional keywords to use-package

From: John Wiegley <[email-masked]>
Date: Wed, 30 Jul 2025 11:07:44 -0700

>>>>> Stéphane Marks <[email-masked]> writes:

> I tend to agree with Karthik, and would not use any of the new
> keywords in my configuration.  I suspect it will encourage lack of
> understanding, and increase support burden.  e.g., for sufficiently
> sophisticated users that need to specify hook depth, they're likely
> also providing their own functions and those have to be defined
> somewhere (and lambdas are discouraged in hooks, right?).  In my
> configuration, I tend to pair `remove-hook` and `advice-remove`
> calls, which I comment out, to facilitate testing and comparison of
> results from unadvised functions, and to make it easy to remove a
> named hook also for the same reasons.  These keywords will discourage
> learning Elisp programming, which even the most minor of function
> advices requires to foster a mental model.

I must say that I respectfully disagree with Karthik’s reasoning here. I don’t
think it’s a good design principle to remove functionality from the hands of
everyone, only for the sake of those who would not fully understand it — and
thus, who probably wouldn’t have used it in the first place.

If we take this logic to the extreme, there would be no reason for use-package
at all, because in the end it’s just Elisp that you can write yourself. The
main reason I created it is to codify best practices that I didn’t want to
have to repeat.

Take :hook for example. It codifies this pattern:

  If :demand is being used (or is implied), it’s just add-hook with the tiny
  syntactic convenience of not needed to put `-hook` at the end of the symbol
  name, or the ability to just say `SYM` and have the hook name inferred.

  If :demand is not being used (or is not implied), then it additionally
  declares an autoload for the function being added to the hook. This autoload
  is probably already being defined by the package, so doubtful it’s needed.

Is it really better to say:

  (use-package foo :hook bar)

Than just:

  (add-hook 'bar-hook #'foo-mode)

Probably not really. The former hides a bit of logic — and thus, opens the
door to confusion — while the second always works as intended and can be
separately evaluated, etc. But the point is: *the first form is what I want to
write, as an Emacs user who does understand what’s going on*.

Adding :hook+ would allow me to additionally specify depth, which at the
moment I cannot do, requiring me to undo the declarative form and use the
procedural form in order to pass a depth argument.

Lastly, use-package-x (and family?) is *opt-in*. If people want to post their
use of it online, and others want to copy&paste it, that’s on them. I wouldn’t
try to prevent them from having easy access to those features simply because
some third party might try to join in the fun and not fully understand what’s
going on.

--
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2

Sponsor my open source on github.com/sponsors/jwiegley or patreon.com/jwiegley