Next: File Variables Prev: Hooks Up: Variables
`M-x make-local-variable RET VAR RET'
Make variable VAR have a local value in the current buffer.
`M-x kill-local-variable RET VAR RET'
Make variable VAR use its global value in the current buffer.
`M-x make-variable-buffer-local RET VAR RET'
Mark variable VAR so that setting it will make it local to the
buffer that is current at that time.
Any variable can be made "local" to a specific Emacs buffer. This
means that its value in that buffer is independent of its value in other
buffers. A few variables are always local in every buffer. Every other
Emacs variable has a "global" value which is in effect in all buffers
that have not made the variable local.
`M-x make-local-variable' reads the name of a variable and makes it
local to the current buffer. Further changes in this buffer will not
affect others, and further changes in the global value will not affect
`M-x make-variable-buffer-local' reads the name of a variable and
changes the future behavior of the variable so that it will become local
automatically when it is set. More precisely, once a variable has been
marked in this way, the usual ways of setting the variable automatically
do `make-local-variable' first. We call such variables "per-buffer"
Major modes (Note: Major Modes.) always make the variables they set
local to the buffer. This is why changing major modes in one buffer has
no effect on other buffers. Minor modes also work by setting
variables--normally, each minor mode has one controlling variable which
is non-`nil' when the mode is enabled (Note: Minor Modes.). For most
minor modes, the controlling variable is per buffer.
Emacs contains a number of variables that are always per-buffer.
These include `abbrev-mode', `auto-fill-function', `case-fold-search',
`comment-column', `ctl-arrow', `fill-column', `fill-prefix',
`indent-tabs-mode', `left-margin', `mode-line-format', `overwrite-mode',
`selective-display-ellipses', `selective-display', `tab-width', and
`truncate-lines'. Some other variables are always local in every
buffer, but they are used for internal purposes.
`M-x kill-local-variable' reads the name of a variable and makes it
cease to be local to the current buffer. The global value of the
variable henceforth is in effect in this buffer. Setting the major
mode kills all the local variables of the buffer except for a few
specially marked variables that are "permanent locals".
To set the global value of a variable, regardless of whether the
variable has a local value in the current buffer, you can use the Lisp
function `setq-default'. It works like `setq'. If there is a local
value in the current buffer, the local value is not affected by
`setq-default'; thus, the new global value may not be visible until you
switch to another buffer. For example,
(setq-default fill-column 75)
`setq-default' is the only way to set the global value of a variable
that has been marked with `make-variable-buffer-local'.
Lisp programs can look at a variable's default value with
`default-value'. This function takes a symbol as argument and returns
its default value. The argument is evaluated; usually you must quote
it explicitly. For example,
automatically generated by info2www