annotate man/major.texi @ 33970:670b73b06a0d EMACS_PRETEST_21_0_92

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