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


17.4.1 Evaluating Expressions in Lisp-Mode

sexp

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.

eval-last-sexp

[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)
eval-defun

C-M-x

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.

eval-expression

M-:

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)
eval-region

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.

describe-variable

C-h v

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

set-variable

M-x set-variable

Set user options.