In Emacs Lisp, is there a function to get the initial value of a symbol initilized by defvar
? Like the some-function
shown below:
(defvar var "initial value")
(setq var "changed value")
(some-function 'var)
=> "inital value"
In Emacs Lisp, is there a function to get the initial value of a symbol initilized by defvar
? Like the some-function
shown below:
(defvar var "initial value")
(setq var "changed value")
(some-function 'var)
=> "inital value"
If the variable is set up to have buffer local values or frame local values, try:
(default-value 'var)
Though, if someone has used setq-default
to change the default, you'll get the new one, and not the original that was set up via defvar
. From the documentation:
This function returns symbol's default value. This is the value that is seen in buffers and frames that do not have their own values for this variable. If symbol is not buffer-local, this is equivalent to symbol-value (see Accessing Variables).
Emacs doesn't remember the initial value. If you evaluate
(defvar var "initial value")
(setq var "changed value")
in the *scratch*
buffer, "initial value"
is no longer available, full stop.
If the defvar
was performed in a loaded file, Emacs remembers where it's loaded from; (symbol-file var 'defvar)
returns the file name, and you can get an the original expression that the variable was initialized with (but not the original value), assuming the file is still around. This is also available via the command M-x find-variable.