1.11. Customizing Emacs

1.11.1. Keyboard Customization

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.

1.11.1.1. Special character conventions
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

1.11.2. Emacs Variables

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.

1.11.2.1. Backups and auto-save
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.

1.11.2.2. Search and replace
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).

1.11.2.3. Display
Variable Default Description
next-screen-context-lines 2 Retain this many lines when scrolling forward or backward by C-v or ESC-v.
scroll-step 0 When moving the cursor vertically, scroll this many lines forward or backward.
scroll-step 0 When moving the cursor horizontally, scroll this many columns left or right.
tab-width 8 Width of tab stops; local to the current buffer.
truncate-lines nil If non-nil, truncate long lines and use $ to show that the line continues off-screen.
truncate-partial-width-windows t If non-nil, truncate long lines (as above) in all windows that are not the full width of the display.
window-min-height 4 Minimum allowable height of windows (in lines).
window-min-width 10 Minimum allowable width of vertically split windows (in columns).
split-window-keep-point t When splitting windows, non-nil means keep point at same place in both new windows. If nil, choose new location of point to minimize redrawing (good for slow displays).
resize-minibuffer-mode nil If non-nil, allow minibuffer to increase height to fit its contents.
resize-minibuffer-window-exactly t Change size of minibuffer window dynamically so that it is exactly large enough to display its messages.
resize-minibuffer-frame nil If non-nil, allow minibuffer frame (in GUI systems) to change height.
resize-minibuffer-frame-exactly t Change size of the minibuffer frame (in GUI systems) dynamically so that it is exactly large enough to display its messages.
resize-minibuffer-window-max-height nil Maximum size the minibuffer can grow to in resize-minibuffer-mode; in GUIs, if less than 1 or not a number, the limit is the height of the minibuffer frame.
ctl-arrow t Non-nil means display control characters using ^X, where X is the letter being "controlled." Otherwise, use octal (base 8) ASCII notation for display—for example, C-h appears as 10 in octal.
display-time-day-and-date nil If non-nil, ESC x display-time RETURN also shows day and date.
line-number-mode t If non-nil, display line number on mode line.
line-number-display-limit 1,000,000 Maximum size of buffer (in characters) for which line numbers should be displayed.
column-number-mode nil If non-nil, display the column number on the mode line.
visible-bell nil If non-nil, "flash" the screen instead of beeping when necessary.
track-eol nil If non-nil, whenever the cursor is at the end of the line, "stick" to the end of the line when moving the cursor up or down; otherwise, stay in the column where the cursor is.
blink-matching-paren t If non-nil, blink matching open parenthesis character when a closing parenthesis is typed.
blink-matching-paren-distance 25,600 Maximum number of characters to search through to find a matching open parenthesis character when a close parenthesis is typed.
blink-matching-delay 1 Number of seconds to pause when blinking a matching parenthesis.
echo-keystrokes 1 Echo prefixes for unfinished commands (e.g., ESC-) in minibuffer after user pauses for this many seconds; 0 means don't do echoing at all.
insert-default-directory t If non-nil, insert the current directory in the minibuffer when asking for a filename.
inverse-video nil If non-nil, use reverse video for the entire display (normal video for mode lines).
mode-line-inverse-video t Non-nil means use reverse video for mode lines.
highlight-nonselected-windows nil If non-nil, highlight regions in windows other than the one currently selected (GUI only).
mouse-scroll-delay 0.25 Delay, in seconds, between screen scrolls when mouse is clicked and dragged from inside a window to beyond its borders. 0 means scroll as fast as possible.
mouse-scroll-min-lines 1 Scroll at least this many lines when mouse is dragged up or down beyond a window.

1.11.2.4. Modes
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.

1.11.2.5. Mail
Variable Default Description
mail-self-blind nil If non-nil, automatically insert your own name in the BCC (blind copy) field to ensure that you save a copy of your mail.
rmail-mail-new-frame nil If non-nil, create a new frame for creating outgoing mail messages (GUI only).
mail-default-reply-to nil Character string to insert in Reply-to: field of mail messages by default.
mail-use-rfc822 nil If non-nil, use the full RFC822 parser on mail addresses (takes longer but increases odds that complex addresses are parsed correctly).
mail-host-address nil Name of your machine; can be used for constructing user-mail-address.
user-mail-address "your email address" Your full email address.
rmail-primary-inbox-list nil List of files containing incoming (unread) mail; if nil, use value of $MAIL environment variable, or, if that doesn't exist, use this path: /usr/spool/mail/yourname.
rmail-file-name "~/RMAIL" File where RMAIL puts mail messages.
mail-archive-file-name nil Character string used as name of the file to save all outgoing messages in; ifnil, don't save all outgoing messages.
mail-personal-alias-file "~/.mailrc" Name of the file in which to store mail aliases; RMAIL mail mode uses the same format for aliases as the standard UNIX mail and mailx programs.
mail-signature nil Text to insert at end of outgoing mail messages.
rmail-dont-reply-to-names nil Regular expression specifying names to omit when constructing lists of addresses to reply to; if nil, omit yourself from reply list.
rmail-displayed-headers nil Regular expression specifying which message header fields to display; if nil, display all headers except those included in rmail-ignored-headers.
rmail-ignored-headers Regular expression specifying which message header fields not to display.
rmail-highlighted-headers "^From:\|^Subject:" Regular expression specifying message headers to highlight (GUI only).
rmail-delete-after-output nil If non-nil, automatically delete a message if it is saved in a file.
mail-from-style 'angles Format of usernames in From: fields; if nil, include mail address only. If 'angles, enclose mail address in angle brackets. If 'parens, enclose it in parentheses.

1.11.2.6. Text editing
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.

1.11.2.7. Completion
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.

1.11.2.8. Miscellaneous
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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset