(calc-get-operator): Remove extra format
[bpt/emacs.git] / man / major.texi
CommitLineData
6bf7aab6 1@c This is part of the Emacs manual.
d94888e3 2@c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 2000 Free Software Foundation, Inc.
6bf7aab6
DL
3@c See file emacs.texi for copying conditions.
4@node Major Modes, Indentation, International, Top
5@chapter Major Modes
6@cindex major modes
7@cindex mode, major
8@kindex TAB @r{(and major modes)}
9@kindex DEL @r{(and major modes)}
10@kindex C-j @r{(and major modes)}
11
12 Emacs provides many alternative @dfn{major modes}, each of which
13customizes Emacs for editing text of a particular sort. The major modes
14are mutually exclusive, and each buffer has one major mode at any time.
15The mode line normally shows the name of the current major mode, in
16parentheses (@pxref{Mode Line}).
17
18 The least specialized major mode is called @dfn{Fundamental mode}.
19This mode has no mode-specific redefinitions or variable settings, so
20that each Emacs command behaves in its most general manner, and each
21option is in its default state. For editing text of a specific type
22that Emacs knows about, such as Lisp code or English text, you should
23switch to the appropriate major mode, such as Lisp mode or Text mode.
24
25 Selecting a major mode changes the meanings of a few keys to become
26more specifically adapted to the language being edited. The ones that
27are changed frequently are @key{TAB}, @key{DEL}, and @kbd{C-j}. The
28prefix key @kbd{C-c} normally contains mode-specific commands. In
29addition, the commands which handle comments use the mode to determine
30how comments are to be delimited. Many major modes redefine the
31syntactical properties of characters appearing in the buffer.
32@xref{Syntax}.
33
58fa012d 34 The major modes fall into three major groups. The first group
0ec1f115
RS
35contains modes for normal text, either plain or with mark-up. It
36includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline
37mode. The second group contains modes for specific programming
38languages. These include Lisp mode (which has several variants), C
39mode, Fortran mode, and others. The remaining major modes are not
40intended for use on users' files; they are used in buffers created for
41specific purposes by Emacs, such as Dired mode for buffers made by
42Dired (@pxref{Dired}), Mail mode for buffers made by @kbd{C-x m}
43(@pxref{Sending Mail}), and Shell mode for buffers used for
44communicating with an inferior shell process (@pxref{Interactive
45Shell}).
6bf7aab6
DL
46
47 Most programming-language major modes specify that only blank lines
48separate paragraphs. This is to make the paragraph commands useful.
49(@xref{Paragraphs}.) They also cause Auto Fill mode to use the
50definition of @key{TAB} to indent the new lines it creates. This is
d94888e3
DL
51because most lines in a program are usually indented
52(@pxref{Indentation}).
6bf7aab6
DL
53
54@menu
55* Choosing Modes:: How major modes are specified or chosen.
56@end menu
57
58@node Choosing Modes,,Major Modes,Major Modes
59@section How Major Modes are Chosen
60
61@cindex choosing a major mode
62 You can select a major mode explicitly for the current buffer, but
63most of the time Emacs determines which mode to use based on the file
64name or on special text in the file.
65
66 Explicit selection of a new major mode is done with a @kbd{M-x} command.
67From the name of a major mode, add @code{-mode} to get the name of a
68command to select that mode. Thus, you can enter Lisp mode by executing
69@kbd{M-x lisp-mode}.
70
71@vindex auto-mode-alist
72 When you visit a file, Emacs usually chooses the right major mode based
73on the file's name. For example, files whose names end in @samp{.c} are
74edited in C mode. The correspondence between file names and major modes is
75controlled by the variable @code{auto-mode-alist}. Its value is a list in
76which each element has this form,
77
78@example
79(@var{regexp} . @var{mode-function})
80@end example
81
82@noindent
83or this form,
84
85@example
86(@var{regexp} @var{mode-function} @var{flag})
87@end example
88
89@noindent
90For example, one element normally found in the list has the form
91@code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C
92mode for files whose names end in @file{.c}. (Note that @samp{\\} is
58fa012d
EZ
93needed in Lisp syntax to include a @samp{\} in the string, which must
94be used to suppress the special meaning of @samp{.} in regexps.) If the
6bf7aab6
DL
95element has the form @code{(@var{regexp} @var{mode-function}
96@var{flag})} and @var{flag} is non-@code{nil}, then after calling
72cc9b56
RS
97@var{mode-function}, the suffix that matched @var{regexp} is discarded
98and the list is searched again for another match.
6bf7aab6
DL
99
100 You can specify which major mode should be used for editing a certain
101file by a special sort of text in the first nonblank line of the file. The
102mode name should appear in this line both preceded and followed by
103@samp{-*-}. Other text may appear on the line as well. For example,
104
105@example
106;-*-Lisp-*-
107@end example
108
109@noindent
110tells Emacs to use Lisp mode. Such an explicit specification overrides
58fa012d 111any defaults based on the file name. Note how the semicolon is used
6bf7aab6
DL
112to make Lisp treat this line as a comment.
113
114 Another format of mode specification is
115
116@example
117-*- mode: @var{modename};-*-
118@end example
119
120@noindent
121which allows you to specify local variables as well, like this:
122
123@example
124-*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*-
125@end example
126
127@noindent
128@xref{File Variables}, for more information about this.
129
130@vindex interpreter-mode-alist
131 When a file's contents begin with @samp{#!}, it can serve as an
132executable shell command, which works by running an interpreter named on
133the file's first line. The rest of the file is used as input to the
134interpreter.
135
136 When you visit such a file in Emacs, if the file's name does not
137specify a major mode, Emacs uses the interpreter name on the first line
138to choose a mode. If the first line is the name of a recognized
139interpreter program, such as @samp{perl} or @samp{tcl}, Emacs uses a
140mode appropriate for programs for that interpreter. The variable
141@code{interpreter-mode-alist} specifies the correspondence between
142interpreter program names and major modes.
143
144 When the first line starts with @samp{#!}, you cannot (on many
145systems) use the @samp{-*-} feature on the first line, because the
146system would get confused when running the interpreter. So Emacs looks
147for @samp{-*-} on the second line in such files as well as on the
148first line.
149
150@vindex default-major-mode
151 When you visit a file that does not specify a major mode to use, or
152when you create a new buffer with @kbd{C-x b}, the variable
153@code{default-major-mode} specifies which major mode to use. Normally
154its value is the symbol @code{fundamental-mode}, which specifies
155Fundamental mode. If @code{default-major-mode} is @code{nil}, the major
66e46e19 156mode is taken from the previously current buffer.
6bf7aab6
DL
157
158@findex normal-mode
159 If you change the major mode of a buffer, you can go back to the major
160mode Emacs would choose automatically: use the command @kbd{M-x
161normal-mode} to do this. This is the same function that
162@code{find-file} calls to choose the major mode. It also processes
58fa012d 163the file's local variables list (if any).
6bf7aab6
DL
164
165@vindex change-major-mode-with-file-name
166 The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to
167a new major mode if the new file name implies a mode (@pxref{Saving}).
168However, this does not happen if the buffer contents specify a major
169mode, and certain ``special'' major modes do not allow the mode to
170change. You can turn off this mode-changing feature by setting
171@code{change-major-mode-with-file-name} to @code{nil}.
ab5796a9
MB
172
173@ignore
174 arch-tag: f2558800-cf32-4839-8acb-7d3b4df2a155
175@end ignore