From: Michael Heerdegen <michael_heerdegen@web.de>
To: Patrick Nicodemus <gadget142@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: Why does saving a buffer to a new file clear local variables?
Date: Thu, 12 Dec 2024 13:50:14 +0100 [thread overview]
Message-ID: <875xnp83qx.fsf@web.de> (raw)
In-Reply-To: <CADZEZBZbKRo7uHpqjOBTADhQcUG5U=H+RuZOOwd7DRdtLE_s5A@mail.gmail.com> (Patrick Nicodemus's message of "Tue, 10 Dec 2024 23:05:00 -0500")
Patrick Nicodemus <gadget142@gmail.com> writes:
> If I create a new buffer like (get-buffer-create "tmpbuf"),
> switch to the buffer, and execute the commands
> (make-variable-buffer-local "abc")
> (setq abc 3)
> and then save the buffer to, say, "tmpbuf", then abc becomes nil.
> Why is this the case?
> Is this behavior documented anywhere?
> I checked that it doesn't change the major mode. It is "Fundamental" before
> and after saving.
I recall we had a very similar question not long ago. I think Eli gave
an answer, and it was like that this situation counts as visiting a
file, and visiting a file by default clears all local bindings via
`normal-mode'.
There are ways to modify this behavior - in your scenario, turning
`change-major-mode-with-file-name' off prevents losing your local
binding.
Giving a variable a non-nil `permanent-local' property also would have
this effect - see `kill-all-local-variables's docstring. But the
details depend on the use case.
Michael.
prev parent reply other threads:[~2024-12-12 12:50 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-11 4:05 Why does saving a buffer to a new file clear local variables? Patrick Nicodemus
2024-12-12 7:31 ` Jean Louis
2024-12-12 11:32 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-12-12 12:41 ` Jean Louis
2024-12-12 13:01 ` Michael Heerdegen via Users list for the GNU Emacs text editor
2024-12-12 18:31 ` Jean Louis
2024-12-12 12:50 ` Michael Heerdegen [this message]
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=875xnp83qx.fsf@web.de \
--to=michael_heerdegen@web.de \
--cc=gadget142@gmail.com \
--cc=help-gnu-emacs@gnu.org \
/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.
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).