Next: Default Value Prev: Intro to Buffer-Local Up: Buffer-Local Variables
Creating and Destroying Buffer-local Bindings
- Command: make-local-variable VARIABLE
This function creates a buffer-local binding in the current buffer
for VARIABLE (a symbol). Other buffers are not affected. The
value returned is VARIABLE.
The buffer-local value of VARIABLE starts out as the same value
VARIABLE previously had. If VARIABLE was void, it remains void.
;; In buffer `b1':
(setq foo 5) ; Affects all buffers.
(make-local-variable 'foo) ; Now it is local in `b1'.
foo ; That did not change
=> 5 ; the value.
(setq foo 6) ; Change the value
=> 6 ; in `b1'.
;; In buffer `b2', the value hasn't changed.
- Command: make-variable-buffer-local VARIABLE
This function marks VARIABLE (a symbol) automatically
buffer-local, so that any attempt to set it will make it local to
the current buffer at the time.
The value returned is VARIABLE.
- Function: buffer-local-variables &optional BUFFER
This function tells you what the buffer-local variables are in
buffer BUFFER. It returns an association list (Note: Association
Lists.) in which each association contains one buffer-local
variable and its value. When a buffer-local variable is void in
BUFFER, then it appears directly in the resulting list. If BUFFER
is omitted, the current buffer is used.
(setq bind-me 69)
(setq lcl (buffer-local-variables))
;; First, built-in variables local in all buffers:
=> ((mark-active . nil)
(mode-name . "Fundamental")
;; Next, non-built-in local variables.
;; This one is local and void:
;; This one is local and nonvoid:
(bind-me . 69))
Note that storing new values into the CDRs of cons cells in this
list does *not* change the local values of the variables.
- Command: kill-local-variable VARIABLE
This function deletes the buffer-local binding (if any) for
VARIABLE (a symbol) in the current buffer. As a result, the
global (default) binding of VARIABLE becomes visible in this
buffer. Usually this results in a change in the value of
VARIABLE, since the global value is usually different from the
buffer-local value just eliminated.
It is possible to kill the local binding of a variable that
automatically becomes local when set. This causes the variable to
show its global value in the current buffer. However, if you set
the variable again, this will once again create a local value.
`kill-local-variable' returns VARIABLE.
- Function: kill-all-local-variables
This function eliminates all the buffer-local variable bindings of
the current buffer except for variables marker as "permanent". As
a result, the buffer will see the default values of most variables.
This function also resets certain other information pertaining to
the buffer: its local keymap is set to `nil', its syntax table is
set to the value of `standard-syntax-table', and its abbrev table
is set to the value of `fundamental-mode-abbrev-table'.
Every major mode command begins by calling this function, which
has the effect of switching to Fundamental mode and erasing most
of the effects of the previous major mode. To ensure that this
does its job, the variables that major modes set should not be
`kill-all-local-variables' returns `nil'.
A local variable is "permanent" if the variable name (a symbol) has a
`permanent-local' property that is non-`nil'. Permanent locals are
appropriate for data pertaining to where the file came from or how to
save it, rather than with how to edit the contents.
automatically generated by info2www