From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Matthew Malcomson <hardenedapple@gmail.com>
Cc: 62419@debbugs.gnu.org
Subject: bug#62419: 28.2; Elisp let-bound buffer-local variable and kill-local-variable
Date: Sun, 26 Mar 2023 11:16:44 -0400 [thread overview]
Message-ID: <jwv8rfj7dhb.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <56FDA944-04A3-4993-93BE-3E3E0F1CD227@gmail.com> (Matthew Malcomson's message of "Sun, 26 Mar 2023 16:01:22 +0100")
>>> (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.
>>
>> AFAIK the behavior is "as intended": the `let` only affects *one*
>> binding, either the global one or the buffer-local one.
>>
>
> Not going to push much on this since your suggested change to
> `newline` would fix everything to me. But the part I think is strange
> is `setq` not creating a buffer-local binding in this environment.
Hmm... maybe you're right that the (setq auto-fill-function 'other-symbol)
shouldn't set the global variable but the local one.
It might be a bug in how we check whether there's a let-binding that
should make us refrain from obeying the "automatically set buffer-locally".
Good point. I'll have to take a closer look.
> I.e. currently the behaviour of `setq` on automatic buffer-local variables is:
> - Outside `let`, always affect buffer-local (creating if necessary)
> - In `let` of global binding, affect global binding.
> - In `let` of buffer-local binding, affect buffer-local
> - In `let` of buffer-local binding but where buffer-local value has
> been killed, affect global value.
>
> I believe that last condition is strange and the behaviour of `setq` would
> be more understandable without it.
Agreed.
Stefan
next prev parent reply other threads:[~2023-03-26 15:16 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 13:37 bug#62419: 28.2; Elisp let-bound buffer-local variable and kill-local-variable Matthew Malcomson
2023-03-25 11:49 ` Eli Zaretskii
2023-03-25 16:19 ` Matthew Malcomson
2023-03-26 14:01 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-26 14:34 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-26 15:01 ` Matthew Malcomson
2023-03-26 15:16 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2023-03-26 15:30 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-03-29 10:56 ` Matthew Malcomson
2023-04-02 21:55 ` Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-09-12 0:00 ` Stefan Kangas
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwv8rfj7dhb.fsf-monnier+emacs@gnu.org \
--to=bug-gnu-emacs@gnu.org \
--cc=62419@debbugs.gnu.org \
--cc=hardenedapple@gmail.com \
--cc=monnier@iro.umontreal.ca \
/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 public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).