GNU bug report logs - #77609
How to add multiple functions to one hook with :hook in use-package?

Previous Next

Package: emacs;

Reported by: Reuben Thomas <rrt <at> sc3d.org>

Date: Mon, 7 Apr 2025 13:46:02 UTC

Severity: normal

Done: Eli Zaretskii <eliz <at> gnu.org>

To reply to this bug, email your comments to 77609 AT debbugs.gnu.org.
There is no need to reopen the bug first.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Mon, 07 Apr 2025 13:46:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to Reuben Thomas <rrt <at> sc3d.org>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 07 Apr 2025 13:46:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: bug-emacs <bug-emacs <at> gnu.org>
Subject: How to add multiple functions to one hook with :hook in use-package?
Date: Mon, 7 Apr 2025 14:43:39 +0100
[Message part 1 (text/plain, inline)]
The manual says:

The @code{:hook} keyword allows adding functions to hooks.  It takes
@c FIXME: The actual forms accepted by :hook are different, see below!
one argument of the form @var{hooks}, specifying one or more functions
to add to one or more hooks.


The FIXME suggests that the documentation may be incorrect!

I am precisely trying to add multiple functions to one hook, and I can't
work out how to do it with a single :hook clause. Is this in fact possible?
The most obvious syntax, copying the syntax for adding a function to
multiple hooks, does not work, e.g.:

(use-package foo-mode
  :hook
  (foo-mode . (function-a function-b)))

I tried other things, and searching online, and even looking at the source
code for use-package, but I can't work it out. Hence, maybe a good chance
to fix this FIXME in the docs, and explain to users how this is done, or
state that it cannot be done, and you have to use another method to add
multiple functions to a hook.

I have to say, use-package (which I have only now looked at) is a
revelation!

-- 
https://rrt.sc3d.org
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Mon, 07 Apr 2025 13:48:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: bug-emacs <bug-emacs <at> gnu.org>
Subject: Re: How to add multiple functions to one hook with :hook in
 use-package?
Date: Mon, 7 Apr 2025 14:46:59 +0100
[Message part 1 (text/plain, inline)]
On Mon, 7 Apr 2025 at 14:43, Reuben Thomas <rrt <at> sc3d.org> wrote:

>
> I tried other things, and searching online, and even looking at the source
> code for use-package, but I can't work it out.
>

I had another look at the source code, and found this:

           (concat label " a <symbol> or (<symbol or list of symbols> .
<symbol or function>)"
                   " or list of these")

It's unfortunate that this is part of an error message, as I've never seen
the error, but I think this explains the syntax, and indeed says that you
can't add multiple functions to a single hook with one :hook line; in other
words, it would be necessary to write something like:

(use-package foo-mode
   :hook
   ((foo-mode . function-a)
   (foo-mode . function-b)))

-- 
https://rrt.sc3d.org
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Sun, 13 Apr 2025 08:50:05 GMT) Full text and rfc822 format available.

Message #11 received at 77609 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: Reuben Thomas <rrt <at> sc3d.org>, John Wiegley <johnw <at> gnu.org>
Cc: 77609 <at> debbugs.gnu.org
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook in
 use-package?
Date: Sun, 13 Apr 2025 11:49:15 +0300
> Date: Mon, 7 Apr 2025 14:46:59 +0100
> From:  Reuben Thomas via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <bug-gnu-emacs <at> gnu.org>
> 
> On Mon, 7 Apr 2025 at 14:43, Reuben Thomas <rrt <at> sc3d.org> wrote:
> 
>  I tried other things, and searching online, and even looking at the source code for use-package, but I
>  can't work it out.
> 
> I had another look at the source code, and found this:
> 
>            (concat label " a <symbol> or (<symbol or list of symbols> . <symbol or function>)"
>                    " or list of these")
> 
> It's unfortunate that this is part of an error message, as I've never seen the error, but I think this explains the
> syntax, and indeed says that you can't add multiple functions to a single hook with one :hook line; in other
> words, it would be necessary to write something like:
> 
> (use-package foo-mode
>    :hook
>    ((foo-mode . function-a)
>    (foo-mode . function-b)))

John, can you please help in understanding how the documentation could
be clarified in this regard?




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Fri, 25 Apr 2025 01:11:02 GMT) Full text and rfc822 format available.

Message #14 received at 77609 <at> debbugs.gnu.org (full text, mbox):

From: John Wiegley <johnw <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 77609 <at> debbugs.gnu.org, Reuben Thomas <rrt <at> sc3d.org>
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook
 in use-package?
Date: Thu, 24 Apr 2025 18:10:32 -0700
>>>>> Eli Zaretskii <eliz <at> gnu.org> writes:

>> It's unfortunate that this is part of an error message, as I've never seen the error, but I think this explains the
>> syntax, and indeed says that you can't add multiple functions to a single hook with one :hook line; in other
>> words, it would be necessary to write something like:
>> 
>> (use-package foo-mode
>> :hook
>> ((foo-mode . function-a)
>> (foo-mode . function-b)))

> John, can you please help in understanding how the documentation could be
> clarified in this regard?

I mean, there’s no reason it could be extended to support a list, like:

  (foo-mode . (function-a function b))

So do we want to document the restriction, or relax it?

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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Fri, 25 Apr 2025 07:29:02 GMT) Full text and rfc822 format available.

Message #17 received at 77609 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: John Wiegley <johnw <at> gnu.org>
Cc: 77609 <at> debbugs.gnu.org, rrt <at> sc3d.org
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook
 in use-package?
Date: Fri, 25 Apr 2025 10:28:32 +0300
> From: John Wiegley <johnw <at> gnu.org>
> Cc: Reuben Thomas <rrt <at> sc3d.org>,  77609 <at> debbugs.gnu.org
> Date: Thu, 24 Apr 2025 18:10:32 -0700
> 
> >>>>> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> >> It's unfortunate that this is part of an error message, as I've never seen the error, but I think this explains the
> >> syntax, and indeed says that you can't add multiple functions to a single hook with one :hook line; in other
> >> words, it would be necessary to write something like:
> >> 
> >> (use-package foo-mode
> >> :hook
> >> ((foo-mode . function-a)
> >> (foo-mode . function-b)))
> 
> > John, can you please help in understanding how the documentation could be
> > clarified in this regard?
> 
> I mean, there’s no reason it could be extended to support a list, like:
> 
>   (foo-mode . (function-a function b))
> 
> So do we want to document the restriction, or relax it?

The latter, I guess, assuming it isn't too complicated.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Sat, 10 May 2025 09:24:02 GMT) Full text and rfc822 format available.

Message #20 received at 77609 <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: johnw <at> gnu.org
Cc: 77609 <at> debbugs.gnu.org, rrt <at> sc3d.org
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook in
 use-package?
Date: Sat, 10 May 2025 12:23:12 +0300
Ping! How can we make any further progress here?

> Cc: 77609 <at> debbugs.gnu.org, rrt <at> sc3d.org
> Date: Fri, 25 Apr 2025 10:28:32 +0300
> From: Eli Zaretskii <eliz <at> gnu.org>
> 
> > From: John Wiegley <johnw <at> gnu.org>
> > Cc: Reuben Thomas <rrt <at> sc3d.org>,  77609 <at> debbugs.gnu.org
> > Date: Thu, 24 Apr 2025 18:10:32 -0700
> > 
> > >>>>> Eli Zaretskii <eliz <at> gnu.org> writes:
> > 
> > >> It's unfortunate that this is part of an error message, as I've never seen the error, but I think this explains the
> > >> syntax, and indeed says that you can't add multiple functions to a single hook with one :hook line; in other
> > >> words, it would be necessary to write something like:
> > >> 
> > >> (use-package foo-mode
> > >> :hook
> > >> ((foo-mode . function-a)
> > >> (foo-mode . function-b)))
> > 
> > > John, can you please help in understanding how the documentation could be
> > > clarified in this regard?
> > 
> > I mean, there’s no reason it could be extended to support a list, like:
> > 
> >   (foo-mode . (function-a function b))
> > 
> > So do we want to document the restriction, or relax it?
> 
> The latter, I guess, assuming it isn't too complicated.
> 
> 
> 
> 




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Thu, 22 May 2025 06:21:02 GMT) Full text and rfc822 format available.

Message #23 received at 77609 <at> debbugs.gnu.org (full text, mbox):

From: John Wiegley <johnw <at> gnu.org>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: 77609 <at> debbugs.gnu.org, rrt <at> sc3d.org
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook
 in use-package?
Date: Wed, 21 May 2025 23:20:32 -0700
>>>>> Eli Zaretskii <eliz <at> gnu.org> writes:

> Ping! How can we make any further progress here?

So, I dug into ‘use-package-normalize/:hook’ to see how hard it would be and…
it’s unreasonably hard. Accepting a list of functions in this way is just not
something the code was designed to do in its current form.

So rather than risk breaking lots of things, I think the user just has to
expand:

  :hook (foo a b)
  :hook (foo . (a b))

into

  :hook
  (foo . a)
  (foo . b)

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




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#77609; Package emacs. (Thu, 22 May 2025 07:56:02 GMT) Full text and rfc822 format available.

Message #26 received at 77609 <at> debbugs.gnu.org (full text, mbox):

From: Reuben Thomas <rrt <at> sc3d.org>
To: John Wiegley <johnw <at> gnu.org>
Cc: Eli Zaretskii <eliz <at> gnu.org>, 77609 <at> debbugs.gnu.org
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook
 in use-package?
Date: Thu, 22 May 2025 08:54:47 +0100
[Message part 1 (text/plain, inline)]
On Thu, 22 May 2025 at 07:20, John Wiegley <johnw <at> gnu.org> wrote:

> >>>>> Eli Zaretskii <eliz <at> gnu.org> writes:
>
> > Ping! How can we make any further progress here?
>
> So, I dug into ‘use-package-normalize/:hook’ to see how hard it would be
> and…
> it’s unreasonably hard. Accepting a list of functions in this way is just
> not
> something the code was designed to do in its current form.
>

Thanks for looking into this.

-- 
https://rrt.sc3d.org
[Message part 2 (text/html, inline)]

Reply sent to Eli Zaretskii <eliz <at> gnu.org>:
You have taken responsibility. (Sat, 24 May 2025 09:59:01 GMT) Full text and rfc822 format available.

Notification sent to Reuben Thomas <rrt <at> sc3d.org>:
bug acknowledged by developer. (Sat, 24 May 2025 09:59:02 GMT) Full text and rfc822 format available.

Message #31 received at 77609-done <at> debbugs.gnu.org (full text, mbox):

From: Eli Zaretskii <eliz <at> gnu.org>
To: John Wiegley <johnw <at> gnu.org>
Cc: 77609-done <at> debbugs.gnu.org, rrt <at> sc3d.org
Subject: Re: bug#77609: How to add multiple functions to one hook with :hook
 in use-package?
Date: Sat, 24 May 2025 12:58:10 +0300
> From: John Wiegley <johnw <at> gnu.org>
> Cc: 77609 <at> debbugs.gnu.org,  rrt <at> sc3d.org
> Date: Wed, 21 May 2025 23:20:32 -0700
> 
> >>>>> Eli Zaretskii <eliz <at> gnu.org> writes:
> 
> > Ping! How can we make any further progress here?
> 
> So, I dug into ‘use-package-normalize/:hook’ to see how hard it would be and…
> it’s unreasonably hard. Accepting a list of functions in this way is just not
> something the code was designed to do in its current form.
> 
> So rather than risk breaking lots of things, I think the user just has to
> expand:
> 
>   :hook (foo a b)
>   :hook (foo . (a b))
> 
> into
> 
>   :hook
>   (foo . a)
>   (foo . b)

Thanks, I've now updated the manual with this information, and I'm
therefore closing this bug.




This bug report was last modified 20 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.