51: 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.
* In Emacs-Lisp mode, typing M-C-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-ESC or M-x eval-expression allows you to type a Lisp form in
the minibuffer which will be evaluated.
* 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 "load" instead.)
These functions are also useful (see question 16 if you want to learn
more about them):
load-library, eval-region, eval-current-buffer, require, autoload