ErgoEmacsEmacsLispBlogEmacsLispBuy Tutorial
Web Hosting by 1&1

Emacs: How to Evaluate Emacs Lisp Code

Xah Lee, , …,

This page shows you how to evaluate emacs lisp code.

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 a text selection, call eval-region.

Here's a list of other ways, roughly in order of usefulness (to me):

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.
(your cursor needs to be near top level.)
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 codeMeta+:】 or 【Esc :

For commands that do not have a key, you can assign them a key, or you can give them a alias for convenience, ⁖ “eb” for eval-buffer.

Interactive Command Line Interfaces

Also, emacs has a interactive emacs lisp shell. Call ielm to start.

I never liked programing in a shell interface, so i never used ielm. I prefer a notebook-style interface. With notebook interface, as in emacs buffer, you can use the full power of editor to edit any part of your code, and evaluate any part you want dynamically, with many different ways to evaluate them.

blog comments powered by Disqus