You customize key bindings using one of three functions: define-key, global-set-key, or local-set-key. Their forms are:
(define-key keymap "keystroke" 'command-name) (global-set-key "keystroke" 'command-name) (local-set-key "keystroke" 'command-name)
Notice the double quotes around keystroke and the single quote preceding command-name. This is LISP syntax. The "keystroke" is one or more characters, either printable or special characters. Special characters, such as ESC, should be represented as shown in the table below.
Special Character | Definition |
---|---|
C-n | C-n (where n is any letter) |
C-[ or e | ESC |
C-j or | LINEFEED |
C-m or | RETURN |
C-i or T | TAB |
To set the value of a variable, use the setq function in your .emacs file, as in:
(setq auto-save-interval 800)
Although auto-save-interval takes an integer value, many Emacs variables take "true" or "false" values. In Emacs LISP, t is true and nil is false. Emacs variables can also take other types of values; here is how to specify them:
Strings of characters are surrounded by double quotes.
Characters are specified like strings but with a ? preceding them, and they are not surrounded by double quotes. Thus, ?x and ?C-c are character values x and C-c, respectively.
Symbols are specified by a single quote followed by a symbol name—for example, 'never.
A list of some useful Emacs variables with descriptions and default values follows.
Variable Default | Description |
---|---|
make-backup-files t | If t, create a backup version of the current file before saving it for the first time. |
backup-by-copying nil | If t, create backup files by copying rather than renaming the file. The default is renaming, which is more efficient. |
version-control nil | If t, create numbered versions of files as backups (with names of the form file-name~n~). If nil, only do this for files that have numbered versions already. If 'never, never make numbered versions. |
kept-new-versions 2 | Number of latest versions of a file to keep when a new numbered backup is made. |
kept-old-versions 2 | Number of oldest versions of a file to keep when a new numbered backup is made. |
delete-old-versions nil | If t, delete excess versions without first asking for confirmation. If nil, ask for confirmation. If any other value, don't delete excess versions. |
auto-save-default t | If t, auto-save every file visited. |
auto-save-visited- file-name nil | If t, auto-save to the file being visited rather than to an auto-save file. |
auto-save-interval 300 | Number of keystrokes between auto-saving; if 0, turn off auto-saving. |
auto-save-timeout 30 | Seconds of inactivity after which Emacs auto-saves. If nil or 0, turn off this feature. |
delete-auto-save-files t | Non-nil means delete auto-save files whenever the "real" file is saved. |
buffer-offer-save nil | Non-nil means offer to save the current buffer when exiting Emacs, even if the buffer is not a file. |
Variable Default | Description |
---|---|
case-fold-search t | If non-nil, treat upper- and lowercase letters as the same when searching. |
case-replace t | If non-nil, preserve the original case of letters when doing replaces (even if case-fold-search is on). |
search-upper-case `not-yanks | If non-nil, uppercase letters in search strings force search to be case-sensitive. The symbol 'not-yanks means convert uppercase letters in yanked text to lowercase. |
search-exit-option t | If non-nil, any control character other than those defined in incremental search (DEL, LINEFEED, C-q, C-r, C-s, C-w, C-y) exits search. |
search-slow-speed 1200 | If terminal is communicating at this speed or slower, use slow-style incremental search, in which a small window shows partial search results. |
search-highlight t | If non-nil, highlight partial search matches (GUI only). |
query-replace-highlight nil | If non-nil, highlight matches in query-replace mode (GUI only). |
Variable Default | Description |
---|---|
major-mode fundamental-mode | Default mode for new buffers, unless set by virtue of the filename; when setting this variable, precede the mode name with a single quote. |
left-margin 0 | Number of columns to indent when typing C-j in fundamental mode and text mode. |
indent-tabs-mode t | If non-nil, allow the use of tab characters (as well as spaces) when indenting with C-j. |
find-file-run-dired t | When visiting a file, run dired if the filename is a directory and this is non-nil. |
dired-kept-versions 2 | When cleaning a directory in Dired, keep this many versions of files. |
dired-listing-switches "-al" | Options passed to the ls command for generating Dired listings; should contain at least "-l". |
$SHELL | Filename of shell to run with functions that use one, such aslist-directory, dired, and compile; taken from value of the UNIX environment variable SHELL. |
load-path | List of directories to search for LISP packages to load; often set to LISP subdirectory of directory where Emacs source code is installed. |
Variable Default | Description |
---|---|
sentence-end-double-space t | If non-nil, do not treat single spaces after periods as ends of sentences. |
paragraph-separate "[ f]*$" | Regular expression that matches beginnings of lines that separate paragraphs. |
paragraph-start "[ f]" | Regular expression that matches beginnings oflines that start or separate paragraphs. |
page-delimiter "^f " | Regular expression that matches page breaks. |
tex-default-mode 'plain-tex-mode | Mode to invoke when creating a file that could be either TeX or LaTeX. |
tex-run-command "tex" | Character string used as a command to run TeXin a subprocess on a file in TeXmode. |
Latex-run-command "latex" | String used as a command to run LaTeX in a subprocess. |
slitex-run-command "slitex" | String used as a command to run SliTeX in a subprocess. |
tex-dvi-print-command "lpr -d" | Character string used as a command to print a file in TeXmode with C-c C-p. |
tex-dvi-view-command nil | Character string used as command to view a .dvi TeXoutput file with C-c C-v; usually set to xdvi on X Window systems. |
tex-offer-save t | If non-nil, offer to save any unsaved buffers before running TeX. |
tex-show-queue-command "lpq" | Character string used as command to show the print queue with C-c C-q in TeXmode. |
tex-directory "." | Directory for TeXto put temporary files in; default is the current directory. |
outline-regexp "[*f]+" | Regular expression that matches heading lines in outline mode. |
outline-heading-end-regexp " " | Regular expression that matches ends of heading lines in outline mode. |
selective-display-ellipses t | If t, display " . . . " in place of hidden text in outline mode; otherwise, don't display anything. |
Variable Default | Description |
---|---|
completion-auto-help t | If non-nil, provide help if a completion (via TAB or RETURN in minibuffer) is invalid or ambiguous. |
completion-ignored-extensions | List of filename suffixes Emacs ignores when completing filenames. |
completion-ignore-case nil | If non-nil, ignore case distinctions when doing completion. |
Variable Default | Description |
---|---|
kill-ring-max 30 | Keep n pieces of deleted text in the kill ring before deleting oldest kills. |
require-final-newline nil | If a file being saved is missing a final LINEFEED, nil means don't add one, t means add one automatically, and other values mean ask for confirmation. |
next-line-add-newlines t | If non-nil, next-line (C-n or down arrow) inserts newlines when at the end of the buffer, rather than signaling an error. |