From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 03:12:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: 44733@debbugs.gnu.org X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.160575547123165 (code B ref -1); Thu, 19 Nov 2020 03:12:02 +0000 Received: (at submit) by debbugs.gnu.org; 19 Nov 2020 03:11:11 +0000 Received: from localhost ([127.0.0.1]:37379 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfaLm-00061Y-Nb for submit@debbugs.gnu.org; Wed, 18 Nov 2020 22:11:10 -0500 Received: from lists.gnu.org ([209.51.188.17]:35096) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfaLi-00061O-Ca for submit@debbugs.gnu.org; Wed, 18 Nov 2020 22:11:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60532) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfaLi-0006Kk-64 for bug-gnu-emacs@gnu.org; Wed, 18 Nov 2020 22:11:06 -0500 Received: from venus.catern.com ([68.183.49.163]:53478) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kfaLd-00053t-K2 for bug-gnu-emacs@gnu.org; Wed, 18 Nov 2020 22:11:05 -0500 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1605755460; bh=AW7z8z3lQojjDru6NnQA2rYdfA8lRVxBvPgtCGoY2TE=; h=From:To:Subject:Date; b=h3PHhJpyMjq+KTqBPmBB9vgZS1jK8XcynG5nnvMopdmnbieiWcPyw/4h5Gff9+/J4 cZfVRKhSvmCgQbzMkSqXmc+r8rKZoqBHESaNF1CxqjaTpBPrc2HsJIQNces+HSWoZe Wbecu3QRfcsuQlWgYguItTQ4Md+JBOeMJ/8YthnA= Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id 5737D2DD885 for ; Thu, 19 Nov 2020 03:11:00 +0000 (UTC) From: Spencer Baugh Date: Wed, 18 Nov 2020 22:11:00 -0500 Message-ID: <877dqikpmj.fsf@catern.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: pass client-ip=68.183.49.163; envelope-from=sbaugh@catern.com; helo=venus.catern.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/11/18 22:11:00 X-ACL-Warn: Detected OS = Linux 3.11 and newer X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) The problem is with variables defined in C by DEFVAR_PER_BUFFER. These are Lisp variables with special Lisp_Object slots in struct buffer. These variables can be let-bound. When these variable are let-bound when the variable is not buffer-local in the current buffer, the default value for the variable is changed (which affects all buffers which don't have a buffer-local value for the variable). In the C code, this is a SPECPDL_LET_DEFAULT binding. If a DEFVAR_PER_BUFFER variable is set with setq inside such a SPECPDL_LET_DEFAULT binding, the resulting situation is somewhat unusual: The variable is set to the specified value only for the current buffer, and other buffers keep their old values for the variable, but the variable does not become buffer-local - e.g. local-variable-p returns nil. This situation is unusual and undocumented, but not necessarily buggy. This is somewhat normal. However, more buggy is what happens when these let bindings are nested. If we do first SPECPDL_LET_DEFAULT, then setq, then a second nested SPECPDL_LET_DEFAULT, when the second nested let binding is unwound, the default value for variable is set to the pseudo-buffer-local value that was active in (current-buffer) when the nested let was entered. See the below code example (left-margin is chosen as an arbitrary DEFVAR_PER_BUFFER variable): (let ((left-margin 1)) ;; Set this variable "pseudo-locally", inside a SPECPDL_LET_DEFAULT binding. (setq left-margin 123) (assert (eq left-margin 123)) ;; Note, it's not a local variable. (assert (not (local-variable-p 'left-margin))) ;; The default value doesn't change. (assert (eq (default-value 'left-margin) 1)) (with-temp-buffer (assert (eq left-margin 1))) ;; Perform a seemingly unrelated do-nothing let-binding of left-margin. (let ((left-margin 2))) ;; !! The default value of left-margin has changed to 123. (assert (eq (default-value 'left-margin) 123)) (with-temp-buffer (assert (eq left-margin 123))) ;; Emacs used (current-buffer)'s value for left-margin, 123, instead of ;; the actual default value, 1, when storing the old value for left-margin. ;; So when it unwound the let, it set the default value to 123! ) This seems unexpected. I ran into this while working on a patch-set to optimize DEFVAR_PER_BUFFER. This current unwinding behavior is pretty clearly a bug in C, so maybe we don't need to preserve it, which hopefully might allow for an easier implementation of an optimized DEFVAR_PER_BUFFER, if behavior will change anyway. (Although I can't say yet exactly what might be the best change...) From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Eli Zaretskii Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 14:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Spencer Baugh Cc: 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.16057950507515 (code B ref 44733); Thu, 19 Nov 2020 14:11:02 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 14:10:50 +0000 Received: from localhost ([127.0.0.1]:38579 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfke9-0001x8-Uz for submit@debbugs.gnu.org; Thu, 19 Nov 2020 09:10:50 -0500 Received: from eggs.gnu.org ([209.51.188.92]:43288) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfke8-0001wq-7j for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 09:10:48 -0500 Received: from fencepost.gnu.org ([2001:470:142:3::e]:52523) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kfke2-00009G-Tl; Thu, 19 Nov 2020 09:10:42 -0500 Received: from [176.228.60.248] (port=4957 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1kfke1-0000OF-S2; Thu, 19 Nov 2020 09:10:42 -0500 Date: Thu, 19 Nov 2020 16:10:27 +0200 Message-Id: <834kllphd8.fsf@gnu.org> From: Eli Zaretskii In-Reply-To: <877dqikpmj.fsf@catern.com> (message from Spencer Baugh on Wed, 18 Nov 2020 22:11:00 -0500) References: <877dqikpmj.fsf@catern.com> MIME-version: 1.0 Content-type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) > From: Spencer Baugh > Date: Wed, 18 Nov 2020 22:11:00 -0500 > > However, more buggy is what happens when these let bindings are nested. > If we do first SPECPDL_LET_DEFAULT, then setq, then a second nested > SPECPDL_LET_DEFAULT, when the second nested let binding is unwound, the > default value for variable is set to the pseudo-buffer-local value that > was active in (current-buffer) when the nested let was entered. > > See the below code example (left-margin is chosen as an arbitrary > DEFVAR_PER_BUFFER variable): > > (let ((left-margin 1)) > ;; Set this variable "pseudo-locally", inside a SPECPDL_LET_DEFAULT binding. > (setq left-margin 123) > (assert (eq left-margin 123)) > ;; Note, it's not a local variable. > (assert (not (local-variable-p 'left-margin))) > ;; The default value doesn't change. > (assert (eq (default-value 'left-margin) 1)) > (with-temp-buffer (assert (eq left-margin 1))) > ;; Perform a seemingly unrelated do-nothing let-binding of left-margin. > (let ((left-margin 2))) > ;; !! The default value of left-margin has changed to 123. > (assert (eq (default-value 'left-margin) 123)) > (with-temp-buffer (assert (eq left-margin 123))) > ;; Emacs used (current-buffer)'s value for left-margin, 123, instead of > ;; the actual default value, 1, when storing the old value for left-margin. > ;; So when it unwound the let, it set the default value to 123! > ) > > This seems unexpected. Why did you think this is a bug? The ELisp manual seems to document what you see: A variable can have more than one local binding at a time (e.g., if there are nested ‘let’ forms that bind the variable). The “current binding” is the local binding that is actually in effect. It determines the value returned by evaluating the variable symbol, and it is the binding acted on by ‘setq’. Or did I misunderstand what you found unexpected? From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 14:23:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.16057957318676 (code B ref 44733); Thu, 19 Nov 2020 14:23:02 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 14:22:11 +0000 Received: from localhost ([127.0.0.1]:38598 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfkp8-0002Fs-QF for submit@debbugs.gnu.org; Thu, 19 Nov 2020 09:22:11 -0500 Received: from venus.catern.com ([68.183.49.163]:52154) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfkp7-0002Ff-70 for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 09:22:10 -0500 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1605795728; bh=9EhhG/syizb191S+q6O44kkUSyMUjKOY+W/Ue6WHAys=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=BfjuqfMwfdmX3UQl4hGCzgGuilkP/ciQTnYc3CXzB2bd0EcQy8xIU7SqyzIfTYbBQ lmbbNQjXZaOBDB3Db+YG+2HkmDY4jp0DQutA5rqgEV8D75UJeRNPqA3SOYVvg8pmNZ I92h3EfHo/+BHoRBv6igLk1fidS3QW5Aks9rzjJ0= Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id 4EB1B2DDA20; Thu, 19 Nov 2020 14:22:08 +0000 (UTC) From: Spencer Baugh In-Reply-To: <834kllphd8.fsf@gnu.org> References: <877dqikpmj.fsf@catern.com> <834kllphd8.fsf@gnu.org> Date: Thu, 19 Nov 2020 09:22:07 -0500 Message-ID: <874klll94g.fsf@catern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Eli Zaretskii writes: > Why did you think this is a bug? The ELisp manual seems to document > what you see: > > A variable can have more than one local binding at a time (e.g., if > there are nested =E2=80=98let=E2=80=99 forms that bind the variable). = The =E2=80=9Ccurrent > binding=E2=80=9D is the local binding that is actually in effect. It d= etermines > the value returned by evaluating the variable symbol, and it is the > binding acted on by =E2=80=98setq=E2=80=99. > > Or did I misunderstand what you found unexpected? I mentioned two unexpected things, but I don't think that parapgrah describes either of them. First was the behavior that when you setq within a let_default binding, the binding does not appear local when queried with local-variable-p. That's relatively minor. It doesn't seem to me that that paragraph says anything about "You can have local bindings which don't appear local when queried with local-variable-p". Second, and the more important bug, which my code example was about, is "the default value is set to whatever your current binding is, if you enter and then exit a nested let-binding". That seems definitely uncovered by that paragraph, or any documentation. From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 18:19:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Eli Zaretskii Cc: Spencer Baugh , 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.160580988225359 (code B ref 44733); Thu, 19 Nov 2020 18:19:01 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 18:18:02 +0000 Received: from localhost ([127.0.0.1]:40887 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfoVN-0006an-NU for submit@debbugs.gnu.org; Thu, 19 Nov 2020 13:18:01 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:34280) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfoVL-0006aQ-M5 for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 13:18:00 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 224FD8025A; Thu, 19 Nov 2020 13:17:54 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id A47748009B; Thu, 19 Nov 2020 13:17:52 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1605809872; bh=F7UPJysp1jpFNzlB+9KGROOY3p589/aNNk+/aWLy/so=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=jB7tffIuKbVcP/zMU6aEvZ78pfGW1rdxTHtWxV1D/68gBjPgqAoDfAwjVYnVoE0u9 F2Nrx/RfoAufj5uh8rQ6N2fKvjMMIjbNHQoSCYt6aJN9oVqef+0iDguIlXmAVdiK67 WB2ygSxhrHURQ+AeiMJtSipG0cqJ09JLSxxwgi09Th9FNJC/OMRUKgnUAXXnN6N6f8 WNsmh/NLxt7MOUbBX8xcvmknbAk81RlaTYrvECRTIJLKfefoNOYi8DcInARjI+7oSL 2zAIBYIM94Hxaw56zwhIncAKqzG0wbDABKbHQa/dtMmnpcAnVX4nMeoWJvMyoBKc78 OuTUah1FrKWcQ== Received: from alfajor (unknown [157.52.9.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 77A6A120310; Thu, 19 Nov 2020 13:17:52 -0500 (EST) From: Stefan Monnier Message-ID: References: <877dqikpmj.fsf@catern.com> <834kllphd8.fsf@gnu.org> Date: Thu, 19 Nov 2020 13:17:51 -0500 In-Reply-To: <834kllphd8.fsf@gnu.org> (Eli Zaretskii's message of "Thu, 19 Nov 2020 16:10:27 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.076 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> (let ((left-margin 1)) >> ;; Set this variable "pseudo-locally", inside a SPECPDL_LET_DEFAULT binding. >> (setq left-margin 123) >> (assert (eq left-margin 123)) >> ;; Note, it's not a local variable. >> (assert (not (local-variable-p 'left-margin))) >> ;; The default value doesn't change. >> (assert (eq (default-value 'left-margin) 1)) This is a bug, indeed. It should be 123 at this point. >> (with-temp-buffer (assert (eq left-margin 1))) Same here, it should be 123. Stefan From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 19:22:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier , Eli Zaretskii Cc: 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.160581368031211 (code B ref 44733); Thu, 19 Nov 2020 19:22:02 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 19:21:20 +0000 Received: from localhost ([127.0.0.1]:40930 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfpUd-00087L-UZ for submit@debbugs.gnu.org; Thu, 19 Nov 2020 14:21:20 -0500 Received: from venus.catern.com ([68.183.49.163]:52836) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfpUb-00087D-Ro for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 14:21:18 -0500 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1605813676; bh=320klxXAYUzgr05IDtnAVeoqS1K7+NfTLVrSZha/vrU=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=K4rPNYsKT74MaTbzxTgIMv8pG83tgxAt0PgtJZ739So2aOKHRuVqv8cI+kxTn3Zb8 zkTGL+Kk2vHfPcE6E3Yeptl3KCgFPG37exV8J5XZn17LtOyaPFH70KTWiOSXZkfyTu pm1iYc94oxlpfZ86eMX9Ev9rE6MpooZb6G7KFJfk= Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id CF90E2DDB27; Thu, 19 Nov 2020 19:21:16 +0000 (UTC) From: Spencer Baugh In-Reply-To: References: <877dqikpmj.fsf@catern.com> <834kllphd8.fsf@gnu.org> Date: Thu, 19 Nov 2020 14:21:16 -0500 Message-ID: <87y2ixjgpf.fsf@catern.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Stefan Monnier writes: >>> (let ((left-margin 1)) >>> ;; Set this variable "pseudo-locally", inside a SPECPDL_LET_DEFAULT binding. >>> (setq left-margin 123) >>> (assert (eq left-margin 123)) >>> ;; Note, it's not a local variable. >>> (assert (not (local-variable-p 'left-margin))) >>> ;; The default value doesn't change. >>> (assert (eq (default-value 'left-margin) 1)) > > This is a bug, indeed. It should be 123 at this point. That's one perspective, but it seems less consistent with the documentation and with expected behavior. The documentation for these variables says: Automatically becomes buffer-local when set. and here, we are setting it, with setq. It would seem that it should become buffer-local, then. Indeed, that's the current behavior, that it becomes "pseudo-buffer-local", in that the value is different in this buffer from every other buffer. (But local-variable-p returns nil, which is the only indication that something weird is going on.) From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 20:24:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Spencer Baugh Cc: Eli Zaretskii , 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.160581743820739 (code B ref 44733); Thu, 19 Nov 2020 20:24:01 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 20:23:58 +0000 Received: from localhost ([127.0.0.1]:40997 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfqTG-0005OR-Hu for submit@debbugs.gnu.org; Thu, 19 Nov 2020 15:23:58 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:15479) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfqTE-0005OB-Fl for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 15:23:56 -0500 Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 019638005E; Thu, 19 Nov 2020 15:23:51 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 46A2B80055; Thu, 19 Nov 2020 15:23:47 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1605817427; bh=eleUub42MSbyb82tovmGw5Gz3uTwBMkzG0/w0zFA5OU=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=f1qwwqkkJI3PG40RvuxA3HHo2ob6RaPx92nhdO20MOvpR9X4ZPEKm2v1zkAqexyWt NyVmgyBusDVD5r+IfO/gaIKLlzDtWYE29F7YZboa1s56h10eFm7EqtQ8himuLM8BAQ o+70cGXFELO26g8OgCmfpicdjhqTE2Vf7LJyh6EHs5U94BpkVs16tNM+CbXps9nvxR cxXCcjv2EHMo58iEXdWQEDW2LLw5PQh9/pMZTSlet2cKVDqlnthzxXh7nv64/CKVlx wtDApHdLuYflmsjbpugL8T0l+RpqQ93bVpKZ50vnxIAd1N8wwplEZRmyuKJw2ijM0s 7mb20MbuGixFg== Received: from alfajor (unknown [157.52.9.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id C9659120323; Thu, 19 Nov 2020 15:23:46 -0500 (EST) From: Stefan Monnier Message-ID: References: <877dqikpmj.fsf@catern.com> <834kllphd8.fsf@gnu.org> <87y2ixjgpf.fsf@catern.com> Date: Thu, 19 Nov 2020 15:23:45 -0500 In-Reply-To: <87y2ixjgpf.fsf@catern.com> (Spencer Baugh's message of "Thu, 19 Nov 2020 14:21:16 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.075 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) >> This is a bug, indeed. It should be 123 at this point. > That's one perspective, but it seems less consistent with the > documentation and with expected behavior. That's the way all other variables behave: (defvar-local sm-foo 1) (let ((sm-foo 23)) (setq sm-foo 45) (list sm-foo (with-temp-buffer sm-foo))) and I think it's asking for trouble if (let ((sm-foo 23)) ...) behaves differently from (let (sm-foo) (setq sm-foo 23) ...) > and here, we are setting it, with setq. It would seem that it should > become buffer-local, then. Indeed, that's the current behavior, that it > becomes "pseudo-buffer-local", in that the value is different in this > buffer from every other buffer. (But local-variable-p returns nil, > which is the only indication that something weird is going on.) Indeed the current behavior is clearly buggy. Historically, the behavior of PER_BUFFER variables has been even more unlike that of `make-variable-buffer-local` but over the years, I've made efforts to make them behave the same. Clearly, I missed this spot. Stefan From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Spencer Baugh Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 20:57:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: Eli Zaretskii , 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.160581941724071 (code B ref 44733); Thu, 19 Nov 2020 20:57:01 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 20:56:57 +0000 Received: from localhost ([127.0.0.1]:41141 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfqzB-0006GB-0P for submit@debbugs.gnu.org; Thu, 19 Nov 2020 15:56:57 -0500 Received: from venus.catern.com ([68.183.49.163]:53014) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfqz9-0006G3-2b for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 15:56:55 -0500 Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=98.7.229.235; helo=localhost; envelope-from=sbaugh@catern.com; receiver= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=catern.com; s=mail; t=1605819414; bh=x/ePQV3/vnjXsFgWyvmP4B6ztm9/1l8Y8FK1p+/0llw=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=PY3OwxaRcyyYR91C6ThxOgyfzKEOXbd6cGlD7Cn+Hyv6fF4f//wffHW5puqU9JYdk +r068PMOWCF03H7MbkYT2ZsKLBWPjFZXbVegAhI2Vyb4BB0CDsfrsYCVQ8pIBBulaY ACYmmljcqtNLLhdzlv5vsta6fDDaqhpiaJH9sfNI= Received: from localhost (cpe-98-7-229-235.nyc.res.rr.com [98.7.229.235]) by venus.catern.com (Postfix) with ESMTPSA id 63C232DD8A0; Thu, 19 Nov 2020 20:56:54 +0000 (UTC) From: Spencer Baugh In-Reply-To: References: <877dqikpmj.fsf@catern.com> <834kllphd8.fsf@gnu.org> <87y2ixjgpf.fsf@catern.com> Date: Thu, 19 Nov 2020 15:56:54 -0500 Message-ID: <87tutljca1.fsf@catern.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Score: 0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) Stefan Monnier writes: >>> This is a bug, indeed. It should be 123 at this point. >> That's one perspective, but it seems less consistent with the >> documentation and with expected behavior. > > That's the way all other variables behave: > > (defvar-local sm-foo 1) > (let ((sm-foo 23)) > (setq sm-foo 45) > (list sm-foo > (with-temp-buffer sm-foo))) Aha, okay, I certainly can't argue with that. DEFVAR_PER_BUFFER variables should match that behavior. I'll update my patch series to match. > and I think it's asking for trouble if > > (let ((sm-foo 23)) > ...) > > behaves differently from > > (let (sm-foo) > (setq sm-foo 23) > ...) Ah, this example is persuasive to me. I see also that there is at least some documentation of this behavior, in the make-variable-buffer-local documentation in variables.texi, which I missed: A peculiar wrinkle of this feature is that binding the variable (with @code{let} or other binding constructs) does not create a buffer-local binding for it. Only setting the variable (with @code{set} or @code{setq}), while the variable does not have a @code{let}-style binding that was made in the current buffer, does so. From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Nov 2020 22:15:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Spencer Baugh Cc: 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.16058240516848 (code B ref 44733); Thu, 19 Nov 2020 22:15:02 +0000 Received: (at 44733) by debbugs.gnu.org; 19 Nov 2020 22:14:11 +0000 Received: from localhost ([127.0.0.1]:41219 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfsBv-0001mO-FX for submit@debbugs.gnu.org; Thu, 19 Nov 2020 17:14:11 -0500 Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:50523) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kfsBu-0001m6-7B for 44733@debbugs.gnu.org; Thu, 19 Nov 2020 17:14:10 -0500 Received: from pmg3.iro.umontreal.ca (localhost [127.0.0.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id CC2D9441580; Thu, 19 Nov 2020 17:14:04 -0500 (EST) Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg3.iro.umontreal.ca (Proxmox) with ESMTP id 6D93344155F; Thu, 19 Nov 2020 17:14:03 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1605824043; bh=pqUIq4u7rRxlDaHGy9ChauC/ReLyulk58U6Pw25PBAw=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=gzd+q3SeSZSwAb/NmBY8JE/47cduvIR3edBfzRRUQyJrp4t8DmkXsiuTkJG4GsPFr vM7jHY2LCxxAeEwChAA2cVjp7Ngq9OrMO3c6GnqVqUlhFaeDIk3SMi1DbDk3VjzHHg wHO6Q0jdrTwGDjRfu6UfF1fodDLdCPLfFdQsbyAbmKfFamfXE6l5LXbfViryL/uUXn xbTl7My/E34kgkwIQUCrdZ/15N4O0LJZIjFlW0VB9sOQydWSYFfE0rQC1Zad38Ov+n FHYGfeiiQKbLvLhYo2pucIel3Q7SnqEh/XkF7htsuE5FNPzCL+Z67gJadoyAQrcmm5 leuvYnFfyxxBA== Received: from alfajor (unknown [157.52.9.240]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 28B2B120310; Thu, 19 Nov 2020 17:14:03 -0500 (EST) From: Stefan Monnier Message-ID: References: <877dqikpmj.fsf@catern.com> Date: Thu, 19 Nov 2020 17:14:01 -0500 In-Reply-To: <877dqikpmj.fsf@catern.com> (Spencer Baugh's message of "Wed, 18 Nov 2020 22:11:00 -0500") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SPAM-INFO: Spam detection results: 0 ALL_TRUSTED -1 Passed through trusted hosts only via SMTP AWL -0.074 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain X-SPAM-LEVEL: X-Spam-Score: -2.3 (--) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) I just pushed a fix for that, along with the corresponding test case, Stefan From unknown Mon Aug 18 14:20:02 2025 X-Loop: help-debbugs@gnu.org Subject: bug#44733: Nested let bindings for non-local DEFVAR_PER_BUFFER variables unwind wrong Resent-From: Stefan Kangas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 23 Oct 2021 10:20:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 44733 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: To: Stefan Monnier Cc: Spencer Baugh , 44733@debbugs.gnu.org Received: via spool by 44733-submit@debbugs.gnu.org id=B44733.163498439118127 (code B ref 44733); Sat, 23 Oct 2021 10:20:02 +0000 Received: (at 44733) by debbugs.gnu.org; 23 Oct 2021 10:19:51 +0000 Received: from localhost ([127.0.0.1]:34444 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meE7y-0004iF-LK for submit@debbugs.gnu.org; Sat, 23 Oct 2021 06:19:50 -0400 Received: from mail-pf1-f174.google.com ([209.85.210.174]:33639) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1meE7w-0004hz-Gh for 44733@debbugs.gnu.org; Sat, 23 Oct 2021 06:19:48 -0400 Received: by mail-pf1-f174.google.com with SMTP id t184so5944349pfd.0 for <44733@debbugs.gnu.org>; Sat, 23 Oct 2021 03:19:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:in-reply-to:references:user-agent :mime-version:date:message-id:subject:to:cc; bh=36CbIRY1Xn8SF1JplOkYIKIlSyHXXfPCftorCPWUOgc=; b=NGWK50ka169hz6VMISpYUUZHeEgiswdKXPuUdZ3WJOUnmlibEMF1yFx+Z89XJf1C+9 3HwLksDVBlhA7H8B0i2q8MoZlqHaPu3onQEvWde2dAj5fMtwW6fb59YP7asRJjCBolr8 D0/LwWokx8uivb63z2ra8ikrex6c28bS5uzS4MQzt2oBrYZIYYy36XKp3mffLqfqnYCF sNbTWnHXoEzSh7e/ssTcq0WtBYSY3Uv1QNLpHtTib5lIpLyVtNtuHcpI+56uTwy/JF3X Hl7sgsNy09yUkqUo2nRUL7NWZb+mrfSCt1w4Wugo/v0mpQmm+irVoHPoWrY50A2iAj3C Wb+w== X-Gm-Message-State: AOAM532q1iO6mUbwCiiGa3qyxfRdjGjdL34fHcMimVUps+KNFFYqNqZt UNPUeQKqW69sBPLUWKXX2x246/yCbL/017eJF09skrMuZTk= X-Google-Smtp-Source: ABdhPJw7WmDkA4NzzkMzsU2GEmfsbsEJCi206ZjB93y59RtkWzwrCrddqq04kWIGp+v3EXG0MpWJhR6uoh19YY64+7Q= X-Received: by 2002:a63:81c2:: with SMTP id t185mr4091852pgd.114.1634984382701; Sat, 23 Oct 2021 03:19:42 -0700 (PDT) Received: from 753933720722 named unknown by gmailapi.google.com with HTTPREST; Sat, 23 Oct 2021 03:19:42 -0700 From: Stefan Kangas In-Reply-To: (Stefan Monnier's message of "Thu, 19 Nov 2020 17:14:01 -0500") References: <877dqikpmj.fsf@catern.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) MIME-Version: 1.0 Date: Sat, 23 Oct 2021 03:19:42 -0700 Message-ID: Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.5 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -0.5 (/) close 44733 28.1 thanks Stefan Monnier writes: > I just pushed a fix for that, along with the corresponding test case, It seems like this was fixed but never closed, so I'm closing it now. commit 8fac2444641567b10f4c38b599636aeae0478e68 Author: Stefan Monnier Date: Thu Nov 19 17:13:04 2020 -0500 * src/data.c (set_internal): Fix bug#44733 Set the default value when `set` encounters a PER_BUFFER variable which has been let-bound globally, to match the behavior seen with `make-variable-buffer-local`. * test/src/data-tests.el (binding-test--let-buffer-local): Add corresponding test. (data-tests--set-default-per-buffer): Add tentative test for the performance problem encountered in bug#41029.