From: Eli Zaretskii <eliz@gnu.org>
To: Matthew Malcomson <hardenedapple@gmail.com>,
Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 62419@debbugs.gnu.org
Subject: bug#62419: 28.2; Elisp let-bound buffer-local variable and kill-local-variable
Date: Sat, 25 Mar 2023 14:49:54 +0300 [thread overview]
Message-ID: <83v8ipcaot.fsf@gnu.org> (raw)
In-Reply-To: <19A857D6-D071-44DE-AF89-539A563FD782@gmail.com> (message from Matthew Malcomson on Fri, 24 Mar 2023 13:37:57 +0000)
> From: Matthew Malcomson <hardenedapple@gmail.com>
> 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?
next prev parent reply other threads:[~2023-03-25 11:49 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 [this message]
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
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=83v8ipcaot.fsf@gnu.org \
--to=eliz@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).