Function: eval-buffer

eval-buffer is an interactive function defined in lread.c.

Signature

(eval-buffer &optional BUFFER PRINTFLAG FILENAME UNIBYTE DO-ALLOW-PRINT)

Documentation

Execute the accessible portion of current buffer as Lisp code.

You can use C-x n n (narrow-to-region) to limit the part of buffer to be evaluated. When called from a Lisp program (i.e., not interactively), this function accepts up to five optional arguments: BUFFER is the buffer to evaluate (nil means use current buffer),
 or a name of a buffer (a string).
PRINTFLAG controls printing of output by any output functions in the
 evaluated code, such as print, princ, and prin1:
  a value of nil means discard it; anything else is the stream to print to.
  See Info node (elisp)Output Streams for details on streams.
FILENAME specifies the file name to use for load-history. UNIBYTE, if non-nil, specifies load-convert-to-unibyte for this
 invocation.
DO-ALLOW-PRINT, if non-nil, specifies that output functions in the
 evaluated code should work normally even if PRINTFLAG is nil, in
 which case the output is displayed in the echo area.

This function ignores the current value of the lexical-binding variable. Instead it will heed any
  -*- lexical-binding: t -*-
settings in the buffer, and if there is no such setting, the buffer will be evaluated without lexical binding.

This function preserves the position of point.

Key Bindings

Source Code

// Defined in /usr/src/emacs/src/lread.c
{
  ptrdiff_t count = SPECPDL_INDEX ();
  Lisp_Object tem, buf;

  if (NILP (buffer))
    buf = Fcurrent_buffer ();
  else
    buf = Fget_buffer (buffer);
  if (NILP (buf))
    error ("No such buffer");

  if (NILP (printflag) && NILP (do_allow_print))
    tem = Qsymbolp;
  else
    tem = printflag;

  if (NILP (filename))
    filename = BVAR (XBUFFER (buf), filename);

  specbind (Qeval_buffer_list, Fcons (buf, Veval_buffer_list));
  specbind (Qstandard_output, tem);
  record_unwind_protect_excursion ();
  BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
  specbind (Qlexical_binding, lisp_file_lexically_bound_p (buf) ? Qt : Qnil);
  BUF_TEMP_SET_PT (XBUFFER (buf), BUF_BEGV (XBUFFER (buf)));
  readevalloop (buf, 0, filename,
		!NILP (printflag), unibyte, Qnil, Qnil, Qnil);
  return unbind_to (count, Qnil);
}