annotate man/xemacs/major.texi @ 981:0205cafe98ff

[xemacs-hg @ 2002-08-30 08:25:48 by youngs] Don't look now, but 21.5.9 is on its way out the door! Don't forget what good 'ol Ma used to say... "Eat your brussels sprouts, little Johnny, so you can grow up big and strong."
author youngs
date Fri, 30 Aug 2002 08:26:22 +0000
parents 3ecd8885ac67
children 52dc9b940348
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @node Major Modes, Indentation, Mule, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 @chapter Major Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @cindex major modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @kindex TAB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @kindex DEL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @kindex LFD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Emacs has many different @dfn{major modes}, each of which customizes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Emacs for editing text of a particular sort. The major modes are mutually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 exclusive; at any time, each buffer has one major mode. The mode line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 normally contains the name of the current major mode in parentheses.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 @xref{Mode Line}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 The least specialized major mode is called @dfn{Fundamental mode}. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 mode has no mode-specific redefinitions or variable settings. Each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 Emacs command behaves in its most general manner, and each option is in its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 default state. For editing any specific type of text, such as Lisp code or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 English text, you should switch to the appropriate major mode, such as Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 mode or Text mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Selecting a major mode changes the meanings of a few keys to become
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 more specifically adapted to the language being edited. @key{TAB},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 @key{DEL}, and @key{LFD} are changed frequently. In addition, commands
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 which handle comments use the mode to determine how to delimit comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 Many major modes redefine the syntactical properties of characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 appearing in the buffer. @xref{Syntax}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 The major modes fall into three major groups. Lisp mode (which has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 several variants), C mode, and Muddle mode are for specific programming
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 languages. Text mode, Nroff mode, @TeX{} mode, and Outline mode are for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 editing English text. The remaining major modes are not intended for use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 on users' files; they are used in buffers created by Emacs for specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 purposes and include Dired mode for buffers made by Dired (@pxref{Dired}),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 Mail mode for buffers made by @kbd{C-x m} (@pxref{Sending Mail}), and Shell
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 mode for buffers used for communicating with an inferior shell process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 (@pxref{Interactive Shell}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 Most programming language major modes specify that only blank lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 separate paragraphs. This is so that the paragraph commands remain useful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 @xref{Paragraphs}. They also cause Auto Fill mode to use the definition of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 @key{TAB} to indent the new lines it creates. This is because most lines
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 in a program are usually indented. @xref{Indentation}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 * Choosing Modes:: How major modes are specified or chosen.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 @node Choosing Modes,,Major Modes,Major Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 @section Choosing Major Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 You can select a major mode explicitly for the current buffer, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 most of the time Emacs determines which mode to use based on the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 name or some text in the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Use a @kbd{M-x} command to explicitly select a new major mode. Add
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 @code{-mode} to the name of a major mode to get the name of a command to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 select that mode. For example, to enter Lisp mode, execute @kbd{M-x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 lisp-mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 @vindex auto-mode-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 When you visit a file, Emacs usually chooses the right major mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 based on the file's name. For example, files whose names end in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 @code{.c} are edited in C mode. The variable @code{auto-mode-alist}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 controls the correspondence between file names and major mode. Its value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 is a list in which each element has the form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 (@var{regexp} . @var{mode-function})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 For example, one element normally found in the list has the form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 @code{(@t{"\\.c$"} . c-mode)}. It is responsible for selecting C mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 for files whose names end in @file{.c}. (Note that @samp{\\} is needed in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 Lisp syntax to include a @samp{\} in the string, which is needed to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 suppress the special meaning of @samp{.} in regexps.) The only practical
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 way to change this variable is with Lisp code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 You can specify which major mode should be used for editing a certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 file by a special sort of text in the first non-blank line of the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 The mode name should appear in this line both preceded and followed by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 @samp{-*-}. Other text may appear on the line as well. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 ;-*-Lisp-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 tells Emacs to use Lisp mode. Note how the semicolon is used to make Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 treat this line as a comment. Such an explicit specification overrides any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 default mode based on the file name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Another format of mode specification is:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 -*-Mode: @var{modename};-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 which allows other things besides the major mode name to be specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 However, Emacs does not look for anything except the mode name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 The major mode can also be specified in a local variables list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 @xref{File Variables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 @vindex default-major-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 When you visit a file that does not specify a major mode to use, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 when you create a new buffer with @kbd{C-x b}, Emacs uses the major mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 specified by the variable @code{default-major-mode}. Normally this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 value is the symbol @code{fundamental-mode}, which specifies Fundamental
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 mode. If @code{default-major-mode} is @code{nil}, the major mode is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 taken from the previously selected buffer.