Emacs: How to Evaluate Emacs Lisp Code

Advertise Here

, , …,

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:

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-filepromps you for a file name
eval-expressionpromps you to type code

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

Also, emacs has a interactive emacs lisp shell: 【Alt+x ielm】. You might find it useful. I never liked programing in a shell interface, so i never used ielm. I prefer a notebook-style interface, i always code elisp in a new empty file.

blog comments powered by Disqus