GNU bug report logs - #46407
27.1; Hooks with permanent-local-hook are not cleared of lambdas

Previous Next

Package: emacs;

Reported by: jakanakaevangeli <jakanakaevangeli <at> chiru.no>

Date: Tue, 9 Feb 2021 20:01:01 UTC

Severity: normal

Tags: patch

Found in version 27.1

Fixed in version 28.1

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

Bug is archived. No further changes may be made.

Full log


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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: jakanakaevangeli <jakanakaevangeli <at> chiru.no>
Cc: 46407 <at> debbugs.gnu.org
Subject: Re: bug#46407: 27.1; Hooks with permanent-local-hook are not
 cleared of lambdas
Date: Mon, 24 May 2021 23:55:28 +0200
jakanakaevangeli <jakanakaevangeli <at> chiru.no> writes:

> When kill-all-local-variables encounters a hook variable with its
> 'permanent-local property set to 'permanent-local-hook, it removes from
> its value every element except for t, functions with
> 'permanent-local-hook property and anything that isn't a symbol
> (see the comment at src/buffer.c:1072).
>
> This means that, for the following code
>
>      (defvar   'some-hook nil)
>      (add-hook 'some-hook #'some-fun         nil t)
>      (add-hook 'some-hook (lambda () (test)) nil t)
>
> whether some-fun is removed depends on some-fun's permanent-local-hook
> property, which is expected. As for the anonymous lambda function, it is
> not predictable, whether it will be kept or removed. In fact, it depends
> on some-fun's permanent-local-hook property.

Well, it depends on the hook's permanent-local-hook property, but it's
true that add-hook will automatically set that for you if you pass in a
symbol with that property set.

So, yes, that's a strange side effect of this interface, but I'm not
sure anything could be done about it at this stage (it was introduced in
this form almost two decades ago).

jakanakaevangeli <jakanakaevangeli <at> chiru.no> writes:

> Also one more thing:
>
>     (defvar some-hook nil)
>     (add-hook 'some-hook #'some-fun nil t)
>     (put 'some-fun 'permanent-local-hook t)
>
> If we mark a function as permanent-local-hook only after adding it to a
> hook, the hook symbol will not have its permanent-local property set to
> 'permanent-local-hook, so some-fun will not be kept on removal of local
> variables.
>
> This can be a real non-theoretical problem when adding an autoloaded
> function to a hook.

You mean if the property isn't part of the autoloaded signature?  Yes,
that's true.

As far as I can tell, this permanent-local-hook stuff isn't used
anywhere in the Emacs tree, and it seems like a pretty odd and (as this
bug report shows) inconsistent interface.  I'm not sure whether it's
worth trying to fix, or we should just document that it's iffy.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




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

Previous Next


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