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