(lispref.info)Default Value

Prev: Creating Buffer-Local Up: Buffer-Local Variables

The Default Value of a Buffer-Local Variable

   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' allow you to access
and change the 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 which
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.

 - Function: default-value SYMBOL
     This function returns SYMBOL's default value.  This is the value
     that is seen in buffers that do not have their own values for this
     variable.  If SYMBOL is not buffer-local, this is equivalent to
     `symbol-value' (Note: Accessing Variables.).

 - Function: default-boundp VARIABLE
     The function `default-boundp' tells you whether VARIABLE'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

 - Special Form: setq-default SYMBOL VALUE
     This sets the default value of SYMBOL to VALUE.  SYMBOL is not
     evaluated, but VALUE is.  The value of the `setq-default' form is

     If a SYMBOL is not buffer-local for the current buffer, and is not
     marked automatically buffer-local, this 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
               => value-in-foo
          (default-value 'local)
               => new-default
          ;; In (the new) buffer `bar':
               => new-default
          (default-value 'local)
               => new-default
          (setq local 'another-default)
               => another-default
          (default-value 'local)
               => another-default
          ;; Back in buffer `foo':
               => value-in-foo
          (default-value 'local)
               => another-default

 - Function: set-default SYMBOL VALUE
     This function is like `setq-default', except that SYMBOL is

          (set-default (car '(a b c)) 23)
               => 23
          (default-value 'a)
               => 23

automatically generated by info2www