(lispref.info)Major Modes

Next: Minor Modes Prev: Modes Up: Modes

Major Modes

   Major modes specialize Emacs for editing particular kinds of text.
Each buffer has only one major mode at a time.

   The least specialized major mode is called "Fundamental mode".  This
mode has no mode-specific definitions or variable settings, so each
Emacs command behaves in its default manner, and each option is in its
default state.  All other major modes redefine various keys and options.
For example, Lisp Interaction mode provides special key bindings for
LFD (`eval-print-last-sexp'), TAB (`lisp-indent-line'), and other keys.

   When you need to write several editing commands to help you perform a
specialized editing task, creating a new major mode is usually a good
idea.  In practice, writing a major mode is easy (in contrast to
writing a minor mode, which is often difficult).

   If the new mode is similar to an old one, it is often unwise to
modify the old one to serve two purposes, since it may become harder to
use and maintain.  Instead, copy and rename an existing major mode
definition and alter it for its new function.  For example, Rmail Edit
mode, which is in `emacs/lisp/rmailedit.el', is a major mode that is
very similar to Text mode except that it provides three additional
commands.  Its definition is distinct from that of Text mode, but was
derived from it.

   Rmail Edit mode is an example of a case where one piece of text is
put temporarily into a different major mode so it can be edited in a
different way (with ordinary Emacs commands rather than Rmail).  In such
cases, the temporary major mode usually has a command to switch back to
the buffer's usual mode (Rmail mode, in this case).  You might be
tempted to present the temporary redefinitions inside a recursive edit
and restore the usual ones when the user exits; but this is a bad idea
because it constrains the user's options when it is done in more than
one buffer: recursive edits must be exited most-recently-entered first.
Using alternative major modes avoids this limitation.  Note: Recursive

   The standard GNU Emacs Lisp library directory contains the code for
several major modes, in files including `text-mode.el', `texinfo.el',
`lisp-mode.el', `c-mode.el', and `rmail.el'.  You can look at these
libraries to see how modes are written.  Text mode is perhaps the
simplest major mode aside from Fundamental mode.  Rmail mode is a
rather complicated, full-featured mode.

* Major Mode Conventions
Coding conventions for keymaps, etc.
* Example Major Modes
Text mode and Lisp modes.
* Auto Major Mode
How Emacs chooses the major mode automatically.
* Mode Help
Finding out how to use a mode.

automatically generated by info2www