From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Newsgroups: gmane.emacs.bugs Subject: bug#46407: 27.1; Hooks with permanent-local-hook are not cleared of lambdas Date: Tue, 25 May 2021 09:10:43 +0200 Message-ID: <87r1hv2sr0.fsf@miha-pc> References: <87im7182fn.fsf@miha-pc> <87eedvajan.fsf@gnus.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34972"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 46407@debbugs.gnu.org To: Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue May 25 09:06:43 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llR9G-0008tX-Ri for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 May 2021 09:06:42 +0200 Original-Received: from localhost ([::1]:33816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llR9F-0002V0-8d for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 25 May 2021 03:06:41 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34998) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1llR8c-0002Uj-UT for bug-gnu-emacs@gnu.org; Tue, 25 May 2021 03:06:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:32993) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1llR8c-00079V-FN for bug-gnu-emacs@gnu.org; Tue, 25 May 2021 03:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1llR8c-0000be-9u for bug-gnu-emacs@gnu.org; Tue, 25 May 2021 03:06:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 25 May 2021 07:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 46407 X-GNU-PR-Package: emacs Original-Received: via spool by 46407-submit@debbugs.gnu.org id=B46407.16219263262286 (code B ref 46407); Tue, 25 May 2021 07:06:02 +0000 Original-Received: (at 46407) by debbugs.gnu.org; 25 May 2021 07:05:26 +0000 Original-Received: from localhost ([127.0.0.1]:44539 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llR82-0000ao-EA for submit@debbugs.gnu.org; Tue, 25 May 2021 03:05:26 -0400 Original-Received: from chiru.no ([142.4.209.132]:45358) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1llR7z-0000ae-2a for 46407@debbugs.gnu.org; Tue, 25 May 2021 03:05:24 -0400 Original-Received: from localhost (BSN-77-156-43.static.siol.net [193.77.156.43]) by chiru.no (Postfix) with ESMTPSA id 8541E128001B; Tue, 25 May 2021 07:05:20 +0000 (UTC) In-Reply-To: <87eedvajan.fsf@gnus.org> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:207172 Archived-At: Lars Ingebrigtsen writes: > jakanakaevangeli 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 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.