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

From: Elijah Gabe Pérez <[email-masked]>
Date: Sat, 02 Aug 2025 19:42:24 -0600

Karthik Chikmagalur <[email-masked]> writes:

>>> From my POV, we can install these changes in core, assuming that
>>> you
>>> can post a patch that incorporates the relevant parts of the
>>> discussions.
>>
>> Sounds good to me, I've updated the patch for include *only* the
>> keywords that people may find useful.
>>
>> The rest can be kept in my use-package-x repository.
>
> Since support for :hook+ is being added, I have a suggestion to make
> its
> syntax more in-line with add-hook, so the user does not have to learn
> new syntax.  This might not be possible (or lead to ambiguous
> parsing),
> so feel free to ignore it if this is the case.
>
> add-hook takes the arguments (HOOK FUNCTION DEPTH LOCAL), so perhaps
> :hook+ can do the same?
>
> -------------------------------------
>
> Suggestion 1: allow many hooks to be specified in a list
>
> :hook+ (foo-mode . (bar baz quux))
>
> adds functions bar, baz and quux to foo-mode-hook.  (To disambiguate
> between a list of hook functions and a lambda, you can look at the car
> of the list maybe?)

It is not possible because (foo-mode . (bar baz quux)) is expanded as
(foo-mode bar baz quux), and this can be misinterpreted by :hook+ as a
list of hooks.

The only workaround i found is making a kind of separator (:multi),
which tells :hook+ the cdr is a list of functions, not part of a list of
hooks.

I know that :multi can look weird (even i was thinking in rename it [1]
or use a better separator), but it was the only solution i found and
worked.

> Suggestion 2: allow many hooks to be added to.  (:hook already does
> this)
>
> :hook+ ((foo-mode cor-mode) . (bar baz quux))
>
> Adds the three functions to both foo-mode-hook and cor-mode-hook.

Similar problem as previous.

> Suggestion 3: Allow DEPTH and LOCAL to be optionally specified with
> the functions,
> in the same order as add-hook.
>
> :hook+ (foo-mode . ((bar 90 t)
>                     baz
>                     (quux -30)
>                     (cor nil t))
>
> will install 
> - bar at depth 90, to be run buffer-locally when foo-mode-hook runs
> - baz without special accommodations, and
> - quux at depth -30.
> - cor buffer-locally with default depth

I like this, i think i can implement only the "local" part.
But of course, only part of :multi.

If i can get rid of `:multi` i can implement this, but it will look
somewhat ugly:

  :hook+ (foo-mode . '((bar 90 t)))

[1] Some of my alternatives were using `quote` or `list` instead of
`:multi`, and another was using `'(fn fn2 fn3)`, or even use a list
instead of a cons-cell, these actually work, but I didn't know which of
them to use.

-- 
- E.G via Gnus and Org.