5.29 How do I execute (“evaluate”) a piece of Emacs Lisp code?
There are a number of ways to execute (evaluate, in Lisp lingo) an
Emacs Lisp form:
- If you want it evaluated every time you run Emacs, put it in a file
named .emacs in your home directory. This is known as “your
.emacs file,” and contains all of your personal customizations.
- You can type the form in the *scratch* buffer, and then type
LFD (or C-j) after it. The result of evaluating the form
will be inserted in the buffer.
emacs-lisp-mode, typing C-M-x evaluates a top-level form
before or around point.
- Typing C-x C-e in any buffer evaluates the Lisp form immediately
before point and prints its value in the echo area.
- Typing M-: or M-x eval-expression allows you to type a Lisp
form in the minibuffer which will be evaluated once you press RET.
- You can use M-x load-file to have Emacs evaluate all the Lisp
forms in a file. (To do this from Lisp use the function
autoload are also
useful; see Emacs Lisp documentation, if you want to learn more