Mercurial > emacs
annotate man/major.texi @ 60496:3a569489ffdb
(Single Shell, Shell Options): Fix previous change.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Tue, 08 Mar 2005 02:57:30 +0000 |
parents | b38fabf04e70 |
children | 9cc4be7413fb 7e3f621f1dd4 |
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 | |
59798
0816b427495a
Don't say just "option" when talking about variables.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
21 user option variable is in its default state. For editing text of a |
0816b427495a
Don't say just "option" when talking about variables.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
22 specific type that Emacs knows about, such as Lisp code or English |
0816b427495a
Don't say just "option" when talking about variables.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
23 text, you should switch to the appropriate major mode, such as Lisp |
0816b427495a
Don't say just "option" when talking about variables.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
24 mode or Text mode. |
25829 | 25 |
26 Selecting a major mode changes the meanings of a few keys to become | |
27 more specifically adapted to the language being edited. The ones that | |
28 are changed frequently are @key{TAB}, @key{DEL}, and @kbd{C-j}. The | |
29 prefix key @kbd{C-c} normally contains mode-specific commands. In | |
30 addition, the commands which handle comments use the mode to determine | |
31 how comments are to be delimited. Many major modes redefine the | |
32 syntactical properties of characters appearing in the buffer. | |
33 @xref{Syntax}. | |
34 | |
38461
23f63206a867
Proofreading fixes from Chris Green <chris_e_green@yahoo.com>.
Eli Zaretskii <eliz@gnu.org>
parents:
37986
diff
changeset
|
35 The major modes fall into three major groups. The first group |
38745 | 36 contains modes for normal text, either plain or with mark-up. It |
37 includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline | |
38 mode. The second group contains modes for specific programming | |
39 languages. These include Lisp mode (which has several variants), C | |
40 mode, Fortran mode, and others. The remaining major modes are not | |
41 intended for use on users' files; they are used in buffers created for | |
42 specific purposes by Emacs, such as Dired mode for buffers made by | |
43 Dired (@pxref{Dired}), Mail mode for buffers made by @kbd{C-x m} | |
44 (@pxref{Sending Mail}), and Shell mode for buffers used for | |
45 communicating with an inferior shell process (@pxref{Interactive | |
46 Shell}). | |
25829 | 47 |
48 Most programming-language major modes specify that only blank lines | |
49 separate paragraphs. This is to make the paragraph commands useful. | |
50 (@xref{Paragraphs}.) They also cause Auto Fill mode to use the | |
51 definition of @key{TAB} to indent the new lines it creates. This is | |
28550 | 52 because most lines in a program are usually indented |
53 (@pxref{Indentation}). | |
25829 | 54 |
55 @menu | |
56 * Choosing Modes:: How major modes are specified or chosen. | |
57 @end menu | |
58 | |
59 @node Choosing Modes,,Major Modes,Major Modes | |
60 @section How Major Modes are Chosen | |
61 | |
62 @cindex choosing a major mode | |
63 You can select a major mode explicitly for the current buffer, but | |
64 most of the time Emacs determines which mode to use based on the file | |
65 name or on special text in the file. | |
66 | |
67 Explicit selection of a new major mode is done with a @kbd{M-x} command. | |
68 From the name of a major mode, add @code{-mode} to get the name of a | |
69 command to select that mode. Thus, you can enter Lisp mode by executing | |
70 @kbd{M-x lisp-mode}. | |
71 | |
72 @vindex auto-mode-alist | |
73 When you visit a file, Emacs usually chooses the right major mode based | |
74 on the file's name. For example, files whose names end in @samp{.c} are | |
75 edited in C mode. The correspondence between file names and major modes is | |
76 controlled by the variable @code{auto-mode-alist}. Its value is a list in | |
77 which each element has this form, | |
78 | |
79 @example | |
80 (@var{regexp} . @var{mode-function}) | |
81 @end example | |
82 | |
83 @noindent | |
84 or this form, | |
85 | |
86 @example | |
87 (@var{regexp} @var{mode-function} @var{flag}) | |
88 @end example | |
89 | |
90 @noindent | |
91 For example, one element normally found in the list has the form | |
92 @code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C | |
93 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
|
94 needed in Lisp syntax to include a @samp{\} in the string, which must |
60109
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
95 be used to suppress the special meaning of @samp{.} in regexps.) If |
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
96 the element has the form @code{(@var{regexp} @var{mode-function} |
25829 | 97 @var{flag})} and @var{flag} is non-@code{nil}, then after calling |
60109
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
98 @var{mode-function}, Emacs discards the suffix that matched |
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
99 @var{regexp} and searches the list again for another match. |
25829 | 100 |
60109
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
101 You can specify the major mode to use for editing a certain file by |
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
102 special text in the first nonblank line of the file. The |
25829 | 103 mode name should appear in this line both preceded and followed by |
104 @samp{-*-}. Other text may appear on the line as well. For example, | |
105 | |
106 @example | |
107 ;-*-Lisp-*- | |
108 @end example | |
109 | |
110 @noindent | |
111 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
|
112 any defaults based on the file name. Note how the semicolon is used |
25829 | 113 to make Lisp treat this line as a comment. |
114 | |
115 Another format of mode specification is | |
116 | |
117 @example | |
118 -*- mode: @var{modename};-*- | |
119 @end example | |
120 | |
121 @noindent | |
122 which allows you to specify local variables as well, like this: | |
123 | |
124 @example | |
125 -*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*- | |
126 @end example | |
127 | |
128 @noindent | |
129 @xref{File Variables}, for more information about this. | |
130 | |
131 @vindex interpreter-mode-alist | |
132 When a file's contents begin with @samp{#!}, it can serve as an | |
133 executable shell command, which works by running an interpreter named on | |
134 the file's first line. The rest of the file is used as input to the | |
135 interpreter. | |
136 | |
137 When you visit such a file in Emacs, if the file's name does not | |
138 specify a major mode, Emacs uses the interpreter name on the first line | |
139 to choose a mode. If the first line is the name of a recognized | |
140 interpreter program, such as @samp{perl} or @samp{tcl}, Emacs uses a | |
141 mode appropriate for programs for that interpreter. The variable | |
142 @code{interpreter-mode-alist} specifies the correspondence between | |
143 interpreter program names and major modes. | |
144 | |
145 When the first line starts with @samp{#!}, you cannot (on many | |
146 systems) use the @samp{-*-} feature on the first line, because the | |
147 system would get confused when running the interpreter. So Emacs looks | |
148 for @samp{-*-} on the second line in such files as well as on the | |
149 first line. | |
150 | |
151 @vindex default-major-mode | |
152 When you visit a file that does not specify a major mode to use, or | |
153 when you create a new buffer with @kbd{C-x b}, the variable | |
154 @code{default-major-mode} specifies which major mode to use. Normally | |
155 its value is the symbol @code{fundamental-mode}, which specifies | |
156 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
|
157 mode is taken from the previously current buffer. |
25829 | 158 |
159 @findex normal-mode | |
160 If you change the major mode of a buffer, you can go back to the major | |
161 mode Emacs would choose automatically: use the command @kbd{M-x | |
162 normal-mode} to do this. This is the same function that | |
163 @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
|
164 the file's local variables list (if any). |
25829 | 165 |
166 @vindex change-major-mode-with-file-name | |
167 The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to | |
168 a new major mode if the new file name implies a mode (@pxref{Saving}). | |
60109
b38fabf04e70
(Choosing Modes): Clarify.
Richard M. Stallman <rms@gnu.org>
parents:
59798
diff
changeset
|
169 (@kbd{C-x C-s} does this too, if the buffer wasn't visiting a file.) |
25829 | 170 However, this does not happen if the buffer contents specify a major |
171 mode, and certain ``special'' major modes do not allow the mode to | |
172 change. You can turn off this mode-changing feature by setting | |
173 @code{change-major-mode-with-file-name} to @code{nil}. | |
52401 | 174 |
175 @ignore | |
176 arch-tag: f2558800-cf32-4839-8acb-7d3b4df2a155 | |
177 @end ignore |