(socket_status): New function.
[bpt/emacs.git] / man / major.texi
CommitLineData
6bf7aab6
DL
1@c This is part of the Emacs manual.
2@c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997 Free Software Foundation, Inc.
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
34 The major modes fall into three major groups. Lisp mode (which has
35several variants), C mode, Fortran mode and others are for specific
36programming languages. Text mode, Nroff mode, @TeX{} mode and Outline
37mode are for editing English text. The remaining major modes are not
38intended for use on users' files; they are used in buffers created for
39specific purposes by Emacs, such as Dired mode for buffers made by Dired
40(@pxref{Dired}), Mail mode for buffers made by @kbd{C-x m}
41(@pxref{Sending Mail}), and Shell mode for buffers used for
42communicating with an inferior shell process (@pxref{Interactive
43Shell}).
44
45 Most programming-language major modes specify that only blank lines
46separate paragraphs. This is to make the paragraph commands useful.
47(@xref{Paragraphs}.) They also cause Auto Fill mode to use the
48definition of @key{TAB} to indent the new lines it creates. This is
49because most lines in a program are usually indented.
50(@xref{Indentation}.)
51
52@menu
53* Choosing Modes:: How major modes are specified or chosen.
54@end menu
55
56@node Choosing Modes,,Major Modes,Major Modes
57@section How Major Modes are Chosen
58
59@cindex choosing a major mode
60 You can select a major mode explicitly for the current buffer, but
61most of the time Emacs determines which mode to use based on the file
62name or on special text in the file.
63
64 Explicit selection of a new major mode is done with a @kbd{M-x} command.
65From the name of a major mode, add @code{-mode} to get the name of a
66command to select that mode. Thus, you can enter Lisp mode by executing
67@kbd{M-x lisp-mode}.
68
69@vindex auto-mode-alist
70 When you visit a file, Emacs usually chooses the right major mode based
71on the file's name. For example, files whose names end in @samp{.c} are
72edited in C mode. The correspondence between file names and major modes is
73controlled by the variable @code{auto-mode-alist}. Its value is a list in
74which each element has this form,
75
76@example
77(@var{regexp} . @var{mode-function})
78@end example
79
80@noindent
81or this form,
82
83@example
84(@var{regexp} @var{mode-function} @var{flag})
85@end example
86
87@noindent
88For example, one element normally found in the list has the form
89@code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C
90mode for files whose names end in @file{.c}. (Note that @samp{\\} is
91needed in Lisp syntax to include a @samp{\} in the string, which is
92needed to suppress the special meaning of @samp{.} in regexps.) If the
93element has the form @code{(@var{regexp} @var{mode-function}
94@var{flag})} and @var{flag} is non-@code{nil}, then after calling
95@var{function}, the suffix that matched @var{regexp} is discarded and
96the list is searched again for another match.
97
98 You can specify which major mode should be used for editing a certain
99file by a special sort of text in the first nonblank line of the file. The
100mode name should appear in this line both preceded and followed by
101@samp{-*-}. Other text may appear on the line as well. For example,
102
103@example
104;-*-Lisp-*-
105@end example
106
107@noindent
108tells Emacs to use Lisp mode. Such an explicit specification overrides
109any defaulting based on the file name. Note how the semicolon is used
110to make Lisp treat this line as a comment.
111
112 Another format of mode specification is
113
114@example
115-*- mode: @var{modename};-*-
116@end example
117
118@noindent
119which allows you to specify local variables as well, like this:
120
121@example
122-*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*-
123@end example
124
125@noindent
126@xref{File Variables}, for more information about this.
127
128@vindex interpreter-mode-alist
129 When a file's contents begin with @samp{#!}, it can serve as an
130executable shell command, which works by running an interpreter named on
131the file's first line. The rest of the file is used as input to the
132interpreter.
133
134 When you visit such a file in Emacs, if the file's name does not
135specify a major mode, Emacs uses the interpreter name on the first line
136to choose a mode. If the first line is the name of a recognized
137interpreter program, such as @samp{perl} or @samp{tcl}, Emacs uses a
138mode appropriate for programs for that interpreter. The variable
139@code{interpreter-mode-alist} specifies the correspondence between
140interpreter program names and major modes.
141
142 When the first line starts with @samp{#!}, you cannot (on many
143systems) use the @samp{-*-} feature on the first line, because the
144system would get confused when running the interpreter. So Emacs looks
145for @samp{-*-} on the second line in such files as well as on the
146first line.
147
148@vindex default-major-mode
149 When you visit a file that does not specify a major mode to use, or
150when you create a new buffer with @kbd{C-x b}, the variable
151@code{default-major-mode} specifies which major mode to use. Normally
152its value is the symbol @code{fundamental-mode}, which specifies
153Fundamental mode. If @code{default-major-mode} is @code{nil}, the major
154mode is taken from the previously selected buffer.
155
156@findex normal-mode
157 If you change the major mode of a buffer, you can go back to the major
158mode Emacs would choose automatically: use the command @kbd{M-x
159normal-mode} to do this. This is the same function that
160@code{find-file} calls to choose the major mode. It also processes
161the file's local variables list if any.
162
163@vindex change-major-mode-with-file-name
164 The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to
165a new major mode if the new file name implies a mode (@pxref{Saving}).
166However, this does not happen if the buffer contents specify a major
167mode, and certain ``special'' major modes do not allow the mode to
168change. You can turn off this mode-changing feature by setting
169@code{change-major-mode-with-file-name} to @code{nil}.