Next: , Up: Lisp-Mode   [Contents][Index]

17.4.1 Evaluating Expressions in Lisp-Mode


any readable Lisp expression — code enclosed in parentheses, a string enclosed in double quotes, a variable name, a quoted expression, a numeral, and so on.


[C-u] C-x C-e

This prints the value of the immediately-preceding sexp in the echo area. Using a prefix argument ‘C-u’ will insert the result of an evaluation into the current buffer at point.

To make ‘C-x C-e’ pretty-print:

(global-set-key [remap eval-last-sexp] 'pp-eval-last-sexp)


This evaluates the defun at point. If the cursor is inside or immediately after a variable declaration, then this function, unlike ‘C-x C-e’, resets the variable to the value contained in the declaration.



runs the command eval-expression. Evaluate EXP and print value in the echo area. When called interactively, read an Emacs Lisp expression and evaluate it. This is especially useful when you are coding and testing. It lets you quickly invoke non-interactive functions (non-commands).

To make ‘M-:’ pretty-print:

(global-set-key [remap eval-expression] 'pp-eval-expression)

M-x eval-region

This evaluates the EmacsLisp code in the region. To evaluate all of the code in the current buffer, mark it using ‘C-x h’ first.


C-h v

Checks the current value of a variable. This prints the variable’s doc string and value.


M-x set-variable

Set user options.