Function: make-variable-buffer-local
make-variable-buffer-local is an interactive function defined in
data.c.
Signature
(make-variable-buffer-local VARIABLE)
Documentation
Make VARIABLE become buffer-local whenever it is set.
At any time, the value for the current buffer is in effect,
unless the variable has never been set in this buffer,
in which case the default value is in effect.
Note that binding the variable with let, or setting it while
a let-style binding made in this buffer is in effect,
does not make the variable buffer-local. Return VARIABLE.
This globally affects all uses of this variable, so it belongs together with
the variable declaration, rather than with its uses (if you just want to make
a variable local to the current buffer for one particular use, use
make-local-variable). Buffer-local bindings are normally cleared
while setting up a new major mode, unless they have a permanent-local
property.
The function default-value gets the default value and set-default sets it.
See also defvar-local.
Probably introduced at or before Emacs version 18.
Key Bindings
Source Code
// Defined in /usr/src/emacs/src/data.c
{
struct Lisp_Symbol *sym;
struct Lisp_Buffer_Local_Value *blv = NULL;
union Lisp_Val_Fwd valcontents UNINIT;
bool forwarded UNINIT;
CHECK_SYMBOL (variable);
sym = XSYMBOL (variable);
start:
switch (sym->u.s.redirect)
{
case SYMBOL_VARALIAS: sym = SYMBOL_ALIAS (sym); goto start;
case SYMBOL_PLAINVAL:
forwarded = 0; valcontents.value = SYMBOL_VAL (sym);
if (BASE_EQ (valcontents.value, Qunbound))
valcontents.value = Qnil;
break;
case SYMBOL_LOCALIZED:
blv = SYMBOL_BLV (sym);
break;
case SYMBOL_FORWARDED:
forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym);
if (KBOARD_OBJFWDP (valcontents.fwd))
error ("Symbol %s may not be buffer-local",
SDATA (SYMBOL_NAME (variable)));
else if (BUFFER_OBJFWDP (valcontents.fwd))
return variable;
break;
default: emacs_abort ();
}
if (SYMBOL_CONSTANT_P (variable))
xsignal1 (Qsetting_constant, variable);
if (!blv)
{
blv = make_blv (sym, forwarded, valcontents);
sym->u.s.redirect = SYMBOL_LOCALIZED;
SET_SYMBOL_BLV (sym, blv);
}
blv->local_if_set = 1;
return variable;
}