From: Jean Louis <bugs@gnu.support>
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 10:31:55 +0300 [thread overview]
Message-ID: <Z1qRa6F-6hnYi5T4@lco2> (raw)
In-Reply-To: <CADZEZBZbKRo7uHpqjOBTADhQcUG5U=H+RuZOOwd7DRdtLE_s5A@mail.gmail.com>
* Patrick Nicodemus <gadget142@gmail.com> [2024-12-11 16:59]:
> 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 have just checked it, try doing it this way:
(defvar-local abc 123)
save the buffer, and verify the abc is still there.
This way, it doesn't work, variable must be symbol, not string:
(make-variable-buffer-local "abc")
You can try this way too:
- open new buffer ~/tmp/new2 which shall look as file
- (setq-local def 123)
- save buffer
- evaluate def -> 123
It worked that way. And it works this way:
- open new buffer ~/tmp/new4 which shall look as file
- (defvar-local def 123)
- save buffer
- evaluate def -> 123
And also it works this way:
- C-x b RET WriteAnyNameOfBuffer
- (defvar-local def 123)
- save buffer as any other name
- evaluate def -> 123
But if you try it this way:
(make-variable-buffer-local 'abcde)
(setq abcde 4)
After saving, the variable could lose the value.
Then you must consider what documentation says:
make-variable-buffer-local is an interactive primitive-function in ‘C
source code’.
(make-variable-buffer-local VARIABLE)
Make VARIABLE become buffer-local whenever it is set.
At any time, the value for the current buffer is in effect,
unless the variable has never been set in this buffer,
in which case the default value is in effect.
Note that binding the variable with ‘let’, or setting it while
a ‘let’-style binding made in this buffer is in effect,
does not make the variable buffer-local. Return VARIABLE.
Unless the variable has never been set in this buffer... it becomes default.
So that may be the reason of such behavior, and you may be right something is wrong with that function, and myself I do not know if it is.
But the way how I have shown you works well that buffer-local variable remains buffer local even after saving.
--
Jean Louis
next prev parent reply other threads:[~2024-12-12 7:31 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 [this message]
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
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=Z1qRa6F-6hnYi5T4@lco2 \
--to=bugs@gnu.support \
--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).