Function: set-buffer-local-toplevel-value

set-buffer-local-toplevel-value is a function defined in eval.c.

Signature

(set-buffer-local-toplevel-value SYMBOL VALUE &optional BUFFER)

Documentation

Set SYMBOL's toplevel buffer-local value in BUFFER to VALUE.

"Toplevel" means outside of any let-binding.
BUFFER defaults to the current buffer. Makes SYMBOL buffer-local in BUFFER if it was not already.

View in manual

Probably introduced at or before Emacs version 31.1.

Source Code

// Defined in /usr/src/emacs/src/eval.c
{
  Lisp_Object buf = !NILP (buffer) ? buffer : Fcurrent_buffer ();
  union specbinding *binding = local_toplevel_binding (symbol, buf);

  if (binding)
    set_specpdl_old_value (binding, value);
  else if (NILP (buffer))
    Fset (Fmake_local_variable (symbol), value);
  else
    {
      specpdl_ref count = SPECPDL_INDEX ();
      record_unwind_current_buffer ();
      Fset_buffer (buffer);
      Fset (Fmake_local_variable (symbol), value);
      unbind_to (count, Qnil);
    }

  return Qnil;
}