How to Evaluate Emacs Lisp Code

By Xah Lee. Date: . Last updated: .

To evaluate a single lisp expression, move your cursor to the right of the last closing parenthesis, and call eval-last-sexpCtrl+x Ctrl+e】.

To evaluate all elisp code in a text selection, call eval-region.

eval emacs lisp basics 2015-09-17
eval emacs lisp code basics. 〔in elisp, char is just integer. So, the paren shows octal, hex, and char notation for an integer〕

Here's ways to eval elisp code, roughly in order of usefulness:

methods of evaluating emacs lisp code
Command NameActing AreaKey
eval-last-sexpthe complete lisp expression to the left of cursorCtrl+x Ctrl+e
eval-defunthe function definition block (defun) the cursor is in.
(the elisp code must be well-indended, otherwise emacs may have problem finding function.)
Ctrl+Alt+x
(only when in lisp modes)
eval-regiontext selection
eval-bufferwhole file in current window
load-fileprompts you for a file nameL】 in dired.
eval-expressionprompts you to type codeAlt+:】 or 【Esc :

Emacs Lisp Command Line Interface (REPL)

Emacs has a interactive emacs lisp shell. Call ielm to start.

emacs lisp interactive command line interface REPL ielm
emacs lisp interactive command line interface (REPL) ielm

I recommend working in a buffer instead of REPL.

Working in a buffer (sometimes called notebook inteface) allows you to use full editing power, and eval any expression, in any order, anytime, anywhere.

Like it? Buy Xah Emacs Tutorial. Thanks.

or, buy something from Best Keyboard for Emacs