Emacs Lisp mode is the major mode for editing Emacs Lisp. Its mode command is M-x emacs-lisp-mode.
Emacs provides several commands for evaluating Emacs Lisp expressions. You can use these commands in Emacs Lisp mode, to test your Emacs Lisp code as it is being written. For example, after re-writing a function, you can evaluate the function definition to make it take effect for subsequent function calls. These commands are also available globally, and can be used outside Emacs Lisp mode.
eval-expression) reads an expression using the
minibuffer, and evaluates it. (Before evaluating the expression, the
current buffer switches back to the buffer that was current when you
typed M-:, not the minibuffer into which you typed the
The command C-x C-e (
eval-last-sexp) evaluates the
Emacs Lisp expression preceding point in the buffer, and displays the
value in the echo area. When the result of an evaluation is an
integer, you can type C-x C-e a second time to display the value
of the integer result in additional formats (octal, hexadecimal, and
If M-: or C-x C-e is given a prefix argument, it inserts the value into the current buffer at point, rather than displaying it in the echo area. The argument's value does not matter.
eval-defun command is bound to C-M-x in Emacs Lisp
mode. It evaluates the top-level Lisp expression containing or
following point, and prints the value in the echo area. In this
context, a top-level expression is referred to as a “defun”, but it
need not be an actual
defun (function definition). In
particular, this command treats
defvar expressions specially.
Normally, evaluating a
defvar expression does nothing if the
variable it defines already has a value. But this command
unconditionally resets the variable to the initial value specified by
defvar; this is convenient for debugging Emacs Lisp
defface expressions are treated
similarly. Note that the other commands documented in this section do
not have this special feature.
With a prefix argument, C-M-x instruments the function definition for Edebug, the Emacs Lisp Debugger. See Instrumenting for Edebug.
The command M-x eval-region parses the text of the region as one or more Lisp expressions, evaluating them one by one. M-x eval-buffer is similar but evaluates the entire buffer.
eval-expression-print-length control the maximum depth and
length of lists to print in the result of the evaluation commands
before abbreviating them.
controls whether evaluation errors invoke the debugger when these
commands are used; its default is