all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Persistent buffer local variables?
@ 2010-07-13 17:57 Elena
  2010-07-14  7:45 ` Elena
  0 siblings, 1 reply; 2+ messages in thread
From: Elena @ 2010-07-13 17:57 UTC (permalink / raw
  To: help-gnu-emacs

Hello,

I need to attach a some values to a buffer for later use. I have tried
using buffer local variables, but it seems they are forgotten as soon
as I switch major mode. How could I work around that? Here is my test
code:


(defvar my-var nil)
(make-variable-buffer-local 'my-var)

(defun my-set-var ()
	(interactive)
	(switch-to-buffer (get-buffer-create "*test*"))
	(setq my-var "test")
	;; (text-mode) ;; If I uncomment this line, variable is forgotten.
)

(defun my-show-var ()
	(interactive)
	(message "my-var is: %s" my-var))

Thanks.


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Persistent buffer local variables?
  2010-07-13 17:57 Persistent buffer local variables? Elena
@ 2010-07-14  7:45 ` Elena
  0 siblings, 0 replies; 2+ messages in thread
From: Elena @ 2010-07-14  7:45 UTC (permalink / raw
  To: help-gnu-emacs

According to the manual, this behavior is expected, since major modes
start by calling `kill-all-local-variables'. I needed to write:

(put 'my-var 'permanent-local t)

to keep the variable alive.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-07-14  7:45 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-13 17:57 Persistent buffer local variables? Elena
2010-07-14  7:45 ` Elena

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.