Emacs: How to Evaluate Emacs Lisp Code
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-sexp 【Ctrl+x Ctrl+e】.
To evaluate all elisp code in a text selection, call
Here's a list of other ways, roughly in order of usefulness:
|Command Name||Acting Area||Key|
|the complete lisp expression to the left of cursor||【Ctrl+x Ctrl+e】|
|the 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)
|whole file in current window||◇|
|prompts you for a file name||【L】 in dired.|
|prompts you to type code||【Alt+:】 or 【Esc :】|
If a command does not have key, you can give it a key. 〔➤see Emacs: How to Define Keys〕 Or you can give them a alias for convenience, ➢ for example: “eb” for
eval-buffer. 〔➤see Emacs: Use Alias for Fast M-x〕
Interactive Command Line Interfaces
Emacs has a interactive emacs lisp shell. Call
ielm to start.
Note: coding lisp in a command line interface may not be the most convenient. I recommend you work in a buffer instead. That way, you can use the full power of emacs to edit any part of your code, and evaluate any part you want.
or, buy something from my keyboard store.