I have the following code in the file1.el:
(with-current-buffer (get-buffer-create "TestBuffer")
(read-only-mode -1)
(erase-buffer)
(make-local-variable 'source)
(setq source (get-source-language))
(my-package-insert text))
In the file2.el:
(with-current-buffer "TestBuffer"
(message "Source: %s" (buffer-local-value 'source (get-buffer "TestBuffer"))))
First executes the code from file1.el and then from file2.el.
I expect that the source
will be retrieved from the buffer "TestBuffer" but I get the error:
Symbol's value as variable is void: source
Why that happens so? How could I retrieve the variable from the buffer? I can declare that variable by means of defvar
but I don't want to hold temporal variable just for such a little need. Is it possible to avoid additional variable declaration?
my-package-insert
there is a call which turns on major-mode. I didn't know that that kills local variables! After I placed variable assignment after the major mode activation I can get local variable in the file2.el. Thank you very much! – Andriy Tykhonov Jan 15 '15 at 10:51Creating Buffer-Local
in the Elisp manual. Look forkill-all-local-variables
and this paragraph: "Every major mode command begins by calling this function, which has the effect of switching to Fundamental mode and erasing most of the effects of the previous major mode. To ensure that this does its job, the variables that major modes set should not be marked permanent.". – Drew Jan 15 '15 at 16:48M-x report-emacs-bug
- and it is for enhancement requests too. – Drew Jan 15 '15 at 21:48