From: <jakanakaevangeli@chiru.no>
To: Lars Ingebrigtsen <larsi@gnus.org>
Cc: 46407@debbugs.gnu.org
Subject: bug#46407: 27.1; Hooks with permanent-local-hook are not cleared of lambdas
Date: Tue, 25 May 2021 09:10:43 +0200 [thread overview]
Message-ID: <87r1hv2sr0.fsf@miha-pc> (raw)
In-Reply-To: <87eedvajan.fsf@gnus.org>
Lars Ingebrigtsen <larsi@gnus.org> writes:
> jakanakaevangeli <jakanakaevangeli@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).
On the other hand, this side effect is so undocumented and
undiscoverable (and most probably not really of any use as well), that I
highly doubt there is even a single instance of anyone relying in it
deliberately. I may be wrong though.
>
> jakanakaevangeli <jakanakaevangeli@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.
Whoops, I forgot that one can simply put an autoload cookie on the
(put ...) form as well. Please ignore my second post.
> 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.
I'm personally in favour of fixing the `kill-all-local-variables'
inconsistency (patch follows).
If not, then yes, we should document it in add-hook and fix the info
node I mentioned. Though that would leave virtually every local addition
of a lambda to a hook invalid and a possible bug (a quick grep reveals
that there are at least three such usages in Emacs itself).
diff --git a/src/buffer.c b/src/buffer.c
index 565577e75a..6933f89bd4 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -1079,9 +1079,9 @@ reset_buffer_local_variables (struct buffer *b, bool permanent_too)
/* Preserve element ELT if it's t,
if it is a function with a `permanent-local-hook' property,
or if it's not a symbol. */
- if (! SYMBOLP (elt)
- || EQ (elt, Qt)
- || !NILP (Fget (elt, Qpermanent_local_hook)))
+ if (EQ (elt, Qt)
+ || (SYMBOLP (elt)
+ && !NILP (Fget (elt, Qpermanent_local_hook))))
newlist = Fcons (elt, newlist);
}
newlist = Fnreverse (newlist);
> --
> (domestic pets only, the antidote for overdose, milk.)
> bloggy blog: http://lars.ingebrigtsen.no
Best regards.
next prev parent reply other threads:[~2021-05-25 7:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-09 19:29 bug#46407: 27.1; Hooks with permanent-local-hook are not cleared of lambdas jakanakaevangeli
2021-02-09 21:38 ` jakanakaevangeli
2021-05-21 12:56 ` jakanakaevangeli
2021-05-24 21:55 ` Lars Ingebrigtsen
2021-05-25 7:10 ` jakanakaevangeli [this message]
2021-05-25 19:10 ` Lars Ingebrigtsen
2021-07-20 14:31 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87r1hv2sr0.fsf@miha-pc \
--to=jakanakaevangeli@chiru.no \
--cc=46407@debbugs.gnu.org \
--cc=larsi@gnus.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.