Emacs: Evaluate Elisp 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 Alt+x eval-last-sexpCtrl+x Ctrl+e】.

To evaluate all elisp code in a text selection, Alt+x eval-region.

emacs lisp eval 2018-12-20 f4da8
eval emacs lisp code basics.

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

  1. eval-last-sexp → eval lisp expression to the left of cursor.
  2. eval-region → eval text selection.
  3. eval-buffer → eval whole buffer.
  4. load-file → eval a file. It prompts.
  5. eval-defun → eval function definition block the cursor is in. (the elisp code must be well-indended, otherwise emacs may have problem finding function.) [see Emacs: narrow-to-defun, eval-defun, bug]
  6. eval-expression → prompts you to type code.

Emacs Lisp Command Line Interface (REPL)

Alt+x ielm to start emacs interactive emacs lisp shell.

emacs elisp REPL ielm 2017 01 04
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.

Emacs Lisp Basics

  1. Elisp Basics
  2. ELisp Text-Processing Overview
  3. Elisp Examples
  4. Evaluate Elisp Code
  5. Doc Lookup
  6. Search Doc
  7. How to Edit Lisp Code

If you have a question, put $5 at patreon and message me.
Or Buy Xah Emacs Tutorial
Or buy a nice keyboard: Best Keyboards for Emacs


Emacs Lisp