Customization
Home : Emacs tips :
Customization
[this section is under construction. it's well-covered in the emacs
texinfo doc, though, so i may decide not to finish it. -- rgr,
22-May-00.]
There are many ways to customise emacs, including the following, from
simplest to most complicated:
- Setting variables.
- Rebinding keys.
- Writing keyboard macros.
- Defining hook functions.
- Writing emacs lisp code.
All of these can be put in your .emacs file so that they
persist from session to session.
The .emacs file
emacs loads the .emacs file from your home directory every time
you start emacs. This file should contain a series of emacs lisp
expressions
(also known as forms or, more obscurely, symbolic
expressions or sexps), each of which is evaluated in
turn. Each expression is of the form:
- a self-defining constant (integer, floating point number, or
string surrounded by double quotes);
- [finish]
Setting variables
Variables may be set with the M-x set-variable command,
which prompts for the variable name, and then a value.
Rebinding keys
(global-set-key "\C-cb" 'bury-buffer)
or, for a keybinding that is specific to mail-mode:
(define-key mail-mode-map "\C-cb" 'bury-buffer)
Writing keyboard macros
Since you can bind a string of characters that invoke commands to a key,
the way to save a keyboard macro is like this:
(global-set-key "\C-cf" "This is some inserted text.
It occupies two lines\n")
Remember that ordinary characters are commands that insert themselves.
Defining hook functions
Writing emacs lisp code
If you've been keeping up with the preceding discussion, then you're
already reading emacs lisp code.
The minimum command would look like this:
(defun foo-command ()
(interactive)
(insert "This is some inserted text.
It occupies two lines\n"))
(global-set-key "\C-cf" 'foo-command)
You could then invoke foo-command by typing "C-c f", in
any buffer.
Bob Rogers
<rogers@rgrjr.dyndns.org>
Last modified: Sun Jun 18 22:33:41 EDT 2000