[Next] [Previous] [Up] [Top] [Contents]

CHAPTER 10 Editors

10.2 Configuring Your emacs Session

Configuring the emacs environment amounts to making calls to LISP functions. Emacs is infinitely customizable by means of emacs variables and built-in functions and by using Emacs LISP programming. Settings can be specified from the minibuffer (or command line) during an emacs session. Alternatively, frequently used settings can be established automatically when emacs is invoked, by use of a .emacs file. Though a discussion of Emacs LISP is beyond the scope of this document, a few examples of common emacs configurations follow.

To set or toggle emacs variables, or to use emacs built-in functions, use the <escape> key ("Meta" is how emacs refers to it), followed by the letter x, then by the variable or function and its arguments.

M-x what-line what line is the cursor on?

M-x auto-fill-mode turn on word-wrap

M-x auto-fill-mode turn off word-wrap

M-x set-variable<return>

fill-column<return> set line-length to

45 45 characters

M-x set-variable<return>

auto-save-interval<return> save the file automatically after every

300 300 keystrokes

M-x goto-line<return>16 move the cursor to line 16

M-x help-for-help invoke emacs help when C-h has been bound to the backspace key

The following is a sample .emacs file:

(message "Loading ~/.emacs...")

; Comments begin with semi-colons and continue to the end of the line.

(setq text-mode-hook 'turn-on-auto-fill) ;turn on word-wrap

(setq fill-column 45) ;line-length=45 chars

(setq auto-save-interval 300) ;save after every 300 keystrokes

; Bind (or map) the rubout (control-h) function to the backspace key

(global-set-key "\C-h" 'backward-delete-char-untabify)

; Bind the emacs help function to the keystroke sequence "C-x ?".

(global-set-key "\C-x?" 'help-for-help)

; To jump to line 16, type M-#<return>16

(global-set-key "\M-#" 'goto-line)

; To find out what line you are on, type M-n

(global-set-key "\M-n" 'what-line)

(message "~/.emacs loaded.")

(message "")

Introduction to Unix - 14 AUG 1996
[Next] [Previous] [Up] [Top] [Contents]