GNU bug report logs - #47992
27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`

Previous Next

Package: emacs;

Reported by: Daniel Mendler <mail <at> daniel-mendler.de>

Date: Sat, 24 Apr 2021 12:12:01 UTC

Severity: normal

Tags: fixed

Fixed in version 28.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Michael Heerdegen <michael_heerdegen <at> web.de>
To: Lars Ingebrigtsen <larsi <at> gnus.org>
Cc: Daniel Mendler <mail <at> daniel-mendler.de>, jakanakaevangeli <at> chiru.no, monnier <at> iro.umontreal.ca, 47992 <at> debbugs.gnu.org
Subject: bug#47992: 27; 28; Phase out use of `equal` in `add-hook`, `remove-hook`
Date: Sun, 04 Jul 2021 02:31:45 +0200
Lars Ingebrigtsen <larsi <at> gnus.org> 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.




This bug report was last modified 3 years and 323 days ago.

Previous Next


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