The global value of a variable with buffer-local bindings is also called the default value, because it is the value that is in effect except when specifically overridden.
The functions default-value
and setq-default
access and
change a variable's default value regardless of whether the current
buffer has a buffer-local binding. For example, you could use
setq-default
to change the default setting of
paragraph-start
for most buffers; and this would work even when
you are in a C or Lisp mode buffer that has a buffer-local value for
this variable.
The special forms defvar
and defconst
also set the
default value (if they set the variable at all), rather than any local
value.
symbol-value
(see section Accessing Variable Values).
default-boundp
tells you whether symbol's
default value is nonvoid. If (default-boundp 'foo)
returns
nil
, then (default-value 'foo)
would get an error.
default-boundp
is to default-value
as boundp
is to
symbol-value
.
setq-default
form is value.
If a symbol is not buffer-local for the current buffer, and is not
marked automatically buffer-local, setq-default
has the same
effect as setq
. If symbol is buffer-local for the current
buffer, then this changes the value that other buffers will see (as long
as they don't have a buffer-local value), but not the value that the
current buffer sees.
;; In buffer `foo': (make-local-variable 'local) => local (setq local 'value-in-foo) => value-in-foo (setq-default local 'new-default) => new-default local => value-in-foo (default-value 'local) => new-default ;; In (the new) buffer `bar': local => new-default (default-value 'local) => new-default (setq local 'another-default) => another-default (default-value 'local) => another-default ;; Back in buffer `foo': local => value-in-foo (default-value 'local) => another-default
setq-default
, except that symbol is
evaluated.
(set-default (car '(a b c)) 23) => 23 (default-value 'a) => 23
Go to the first, previous, next, last section, table of contents.