Xah Lee, 2007-12, …, 2010-08-13
This page shows you how to evaluate a emacs lisp expression, and how to find the function you want, and how to lookup function's documentation.
To evaluate a single lisp expression, move your cursor to the right of the last closing parenthesis, and type 【Ctrl+x Ctrl+e】 (eval-last-sexp).
To evaluate a text selection, call “eval-region”.
Here's a list of other ways, roughly in order of usefulness:
| Command Name | Acting Area | Shortcut |
|---|---|---|
| eval-last-sexp | the complete lisp expression to the left of cursor | 【Ctrl+x Ctrl+e】 |
| eval-defun | the function definition block (defun) the cursor is in | ◇ |
| eval-region | text selection | ◇ |
| eval-buffer | whole file in current window | ◇ |
| load-file | promps you for a file name | ◇ |
| eval-expression | promps you to type code | ◇ |
For commands that do not have a shortcut, you can assign them a shortcut, or you can give them a alias. For example, i have the following aliases defined:
(defalias 'eb 'eval-buffer) (defalias 'er 'eval-region) (defalias 'ed 'eval-defun) (defalias 'ee 'eval-expression) (defalias 'elm 'emacs-lisp-mode)
Also, emacs has a interactive emacs lisp shell: 【Alt+x ielm】.
Type 【Ctrl+h f】 (describe-function), then type the function name. If the word the cursor is on is a valid elisp function name, emacs will use that by default.
Type 【Ctrl+h v】 (describe-variable).
If you are using emacs 23, you can use the asterisk “*” as a wildcard when looking up function or variable doc. For example, type 【Ctrl+h f *file Tab】 and emacs will list all functions whose name ends in “file”.
Once the function's inline doc string page comes up, you can jump to the function's location in source code by clicking on underlined file name (or move your cursor there and press Enter).
To search command names using a regex, type 【Ctrl+h a】 (apropos-command).
To search both function and command name spaces, call apropos-command with a empty argument, like this: 【Ctrl+u Ctrl+h a】.
(Commands are a subset of functions. Commands are functions that can be called interactively, meanig that you can call them by typing 【Alt+x ‹name›】. A function is a command when its definition contains the (interactive …) clause.)
To search all symbols space (commands, functions, variables), type 【Alt+x apropos】.
Use “elisp-index-search” to find a function's documentation in the emacs lisp manual. For emacs manual, use “emacs-index-search”.
If you use elisp-index-search often, you can assign it a alias.
(defalias 'eis 'elisp-index-search)blog comments powered by Disqus