Subject: Re: bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`

From: Michael Heerdegen <[email-masked]>
Date: Sun, 04 Jul 2021 02:31:45 +0200

Lars Ingebrigtsen <[email-masked]> writes:

> 1) Should `add/remove-hook' even attempt to do uniqueness checks when
> adding/removing things that aren't symbols (or more generally, eq-able
> things), and
>
> 2) Should `add-hook' disallow adding such things?

That would be going too far.  It's perfectly ok to add an anonymous
function to a hook and keep a reference to it to remove it later.

`eq' testing is ok in my eyes - `equal' might be too much.  Are there
any reasonable use cases for that?

> Today, it's super common for people to say
>
> (add-hook 'some-hook (lambda () ...))
>
> [...]
>
> So I'm not sure I see any way forward with this.  Would adding a new
> pair of functions (that are `eq' only) help in any way?

If you ask me: that problem exists mainly for end users and their init
files, it's not that we have a problem in Emacs.  Instead we should try
to provide a better tool for users to add stuff to hooks conveniently.

Since the problem of identification is not trivial - how about forcing
the user to specify a name?  How about a macro like

(user-add-hook foo-hook my-configure-foo-keybindings
   code...) ?

Here `my-configure-foo-keybindings' would be the unique name (the
uniqueness of the name could easily be tested by the byte compiler).
The name would be used to avoid multiple adding (a second evaluation
could just remove the old version from the code before adding the new,
so that changing the CODE... would work).

Michael.