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 2017 01 04
eval emacs lisp code basics.

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.)
(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 【Escape :

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. Emacs Lisp Basics
  2. Overview of Text-Processing in Emacs Lisp
  3. Emacs Lisp Examples
  4. Evaluate Emacs Lisp Code
  5. Elisp: Documentation Lookup
  6. Elisp: Search Documentation
  7. Emacs: How to Edit Lisp Code
Patreon me $5 patreon

Or Buy Xah Emacs Tutorial

Or buy a nice keyboard: Best Keyboard for Emacs

If you have a question, put $5 at patreon and message me.