From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#62419: 28.2; Elisp let-bound buffer-local variable and kill-local-variable Date: Sat, 25 Mar 2023 14:49:54 +0300 Message-ID: <83v8ipcaot.fsf@gnu.org> References: <19A857D6-D071-44DE-AF89-539A563FD782@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18084"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 62419@debbugs.gnu.org To: Matthew Malcomson , Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Mar 25 12:56:00 2023 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 1pg2V4-0004Nw-7j for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 25 Mar 2023 12:55:58 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pg2UD-0000K8-8o; Sat, 25 Mar 2023 07:55:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pg2UA-0000J4-TM for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 07:55:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pg2UA-0008Km-JP for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 07:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pg2UA-0003yS-ER for bug-gnu-emacs@gnu.org; Sat, 25 Mar 2023 07:55:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 25 Mar 2023 11:55:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62419 X-GNU-PR-Package: emacs Original-Received: via spool by 62419-submit@debbugs.gnu.org id=B62419.167974527615242 (code B ref 62419); Sat, 25 Mar 2023 11:55:02 +0000 Original-Received: (at 62419) by debbugs.gnu.org; 25 Mar 2023 11:54:36 +0000 Original-Received: from localhost ([127.0.0.1]:41905 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pg2Tj-0003xm-Hk for submit@debbugs.gnu.org; Sat, 25 Mar 2023 07:54:36 -0400 Original-Received: from eggs.gnu.org ([209.51.188.92]:42836) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pg2Th-0003xV-Ae for 62419@debbugs.gnu.org; Sat, 25 Mar 2023 07:54:33 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pg2PH-00079L-5f; Sat, 25 Mar 2023 07:49:59 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-version:References:Subject:In-Reply-To:To:From: Date; bh=xwECM2Do3qNFNOx9BhQzVqfohdy4ldtn8/bn4M/iREA=; b=BDMe7p8MljkPlUB48kkz KTT8lfEf6vs6oqMPPtrx79dXHuVApgHhbO3b4N/NXaOaZtfiv6OYvzwmbC6amd1QXCnS5RyOK0Ews SLEIAYQ4kPkd87/ihoATCjszcIOkZmt2H4yepHxej5DpckJ/kCQt/hgHwTTy2hCGQ9Gr4Chgqzc8/ pXc+u5zckfZRQrMAyPKx0AXeEbjiWwR2hbRikDjjOJXjH1siefclhZYF+DUqWmqW8fiKkuOAaBzw3 1o4lzMvSn5IkJYSHD29rIUrPGSn2tkVAoeUI8Q35Jrfc8VahoYzMpE0Lp0RRBgq1oqvtZp/4Bf5+A wr6YRtJSzyuPZw==; Original-Received: from [87.69.77.57] (helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pg2PG-0000iw-JO; Sat, 25 Mar 2023 07:49:58 -0400 In-Reply-To: <19A857D6-D071-44DE-AF89-539A563FD782@gmail.com> (message from Matthew Malcomson on Fri, 24 Mar 2023 13:37:57 +0000) 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-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:258542 Archived-At: > From: Matthew Malcomson > Date: Fri, 24 Mar 2023 13:37:57 +0000 > > I’m inlining some elisp which has behaviour I find unintuitive. > To view the bug I would run each top-level form with C-x C-e in turn in an elisp buffer. > This behaviour may be expected — the manual mentions something related — but I believe this is an unintended edge-case. > N.b. the use of `auto-fill-function’ is just for a variable which turns buffer-local when set, not as anything related to this particular symbol. > FWIW I believe this behaviour to be the root cause of https://github.com/joaotavora/yasnippet/issues/919 (which was closed due to not being able to reproduce it). > > ————— > ;; Ensure that `auto-fill-function' has a buffer-local version and a global > ;; version. > (setq auto-fill-function 'local-symbol) > (describe-variable 'auto-fill-function) > ;; `auto-fill-function' is let-bound in the buffer scope > (let ((auto-fill-function 'temp-symbol)) > ;; Now there is no buffer-local variable for `auto-fill-function', but the > ;; `let' unwrapping info is still there. > (kill-local-variable 'auto-fill-function) > ;; Since the check in the emacs source is > ;; a) Is there a buffer-local variable. > ;; b) Is there a let-binding shadowing the current variable. > ;; Then this `setq' sets the *global* variable. > (setq auto-fill-function 'other-symbol)) > ;; Exiting the `let' has special handling to avoid resetting a local variable > ;; when the local variable was `let' bound, which means that overall the `setq' > ;; set the global variable and the `let' has been lost. > (describe-variable 'auto-fill-function) > ————— > > > I think the final state after having done the above should be: > 1) Global value has not changed. > 2) Local value has not changed. > > While the observed state after the above is: > 1) Global value has been set to `other-symbol'. > 2) Local value has been removed. > > - The `setq` inside the `let` sets the *global* value rather than creating a buffer-local variable. > - The `let` on the buffer-local version of the variable is lost. What is the purpose of doing this? what are you trying to accomplish, and why? > The manual for `make-variable-buffer-local` — in `(elisp) Creating Buffer-Local` — does mention that if a variable is in a `let` binding then a `setq` does not create a buffer-local version. > That said, I’m guessing the intention of this behaviour is so a `let` binding on a global variable is modified rather than bypassed by a `setq`. > I’d suggest that is not relevant to the above code since the use of `kill-local-variable` means the `let` is effectively lost already (e.g. it does not get “reset” on an unwind). Did you also read about default-toplevel-value and set-default-toplevel-value (in the "Default Value" node of the ELisp manual)? > I’m not proposing this as a change, just including it for extra context about the cause. > I *believe* that the form of the C code around here looks like the special case of a forwarded variable not having a buffer-local value but having a buffer-local `let` binding could easily have been an oversight rather than intention. Stefan, any comments?