aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-07-10 00:05:33 -0400
committerChong Yidong2011-07-10 00:05:33 -0400
commit8875da1e9284e108386c4e58c638b483f4ced9b5 (patch)
tree82b3a15e339697ada5ddadf39fd7a722179a971c
parent6cfd0fa2de12047b5f29963ae5c7dc2ea481100d (diff)
downloademacs-8875da1e9284e108386c4e58c638b483f4ced9b5.tar.gz
emacs-8875da1e9284e108386c4e58c638b483f4ced9b5.zip
Move Minor Modes node of Emacs manual next to the Major Modes node
and out of the Customizations chapter. * doc/emacs/modes.texi: Rename from major.texi. (Modes): New node. Make Major Modes and Minor Modes subsections of this. All callers changed. * doc/emacs/custom.texi (Minor Modes): Move to modes.texi.
-rw-r--r--doc/emacs/ChangeLog8
-rw-r--r--doc/emacs/Makefile.in2
-rw-r--r--doc/emacs/custom.texi151
-rw-r--r--doc/emacs/emacs.texi13
-rw-r--r--doc/emacs/indent.texi2
-rw-r--r--doc/emacs/major.texi236
-rw-r--r--doc/emacs/modes.texi410
-rw-r--r--doc/emacs/mule.texi2
8 files changed, 428 insertions, 396 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index 1b2588fec58..6bc8c7312db 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,5 +1,13 @@
12011-07-10 Chong Yidong <cyd@stupidchicken.com> 12011-07-10 Chong Yidong <cyd@stupidchicken.com>
2 2
3 * modes.texi: Rename from major.texi.
4 (Modes): New node. Make Major Modes and Minor Modes subsections
5 of this. All callers changed.
6
7 * custom.texi (Minor Modes): Move to modes.texi.
8
92011-07-10 Chong Yidong <cyd@stupidchicken.com>
10
3 * custom.texi (Syntax): Node deleted. 11 * custom.texi (Syntax): Node deleted.
4 12
5 * help.texi (Help Summary): 13 * help.texi (Help Summary):
diff --git a/doc/emacs/Makefile.in b/doc/emacs/Makefile.in
index aca17ce817d..9465c726eba 100644
--- a/doc/emacs/Makefile.in
+++ b/doc/emacs/Makefile.in
@@ -84,7 +84,7 @@ EMACSSOURCES= \
84 ${srcdir}/windows.texi \ 84 ${srcdir}/windows.texi \
85 ${srcdir}/frames.texi \ 85 ${srcdir}/frames.texi \
86 ${srcdir}/mule.texi \ 86 ${srcdir}/mule.texi \
87 ${srcdir}/major.texi \ 87 ${srcdir}/modes.texi \
88 ${srcdir}/indent.texi \ 88 ${srcdir}/indent.texi \
89 ${srcdir}/text.texi \ 89 ${srcdir}/text.texi \
90 ${srcdir}/programs.texi \ 90 ${srcdir}/programs.texi \
diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi
index 4ecbb0c42cc..8465dd93519 100644
--- a/doc/emacs/custom.texi
+++ b/doc/emacs/custom.texi
@@ -23,8 +23,6 @@ Reference Manual}.
23@end ifnottex 23@end ifnottex
24 24
25@menu 25@menu
26* Minor Modes:: Each minor mode is a feature you can turn on
27 independently of any others.
28* Easy Customization:: Convenient way to browse and change settings. 26* Easy Customization:: Convenient way to browse and change settings.
29* Variables:: Many Emacs commands examine Emacs variables 27* Variables:: Many Emacs commands examine Emacs variables
30 to decide what to do; by setting variables, 28 to decide what to do; by setting variables,
@@ -35,155 +33,6 @@ Reference Manual}.
35 @file{.emacs} file. 33 @file{.emacs} file.
36@end menu 34@end menu
37 35
38@node Minor Modes
39@section Minor Modes
40@cindex minor modes
41@cindex mode, minor
42
43 Minor modes are optional features which you can turn on or off. For
44example, Auto Fill mode is a minor mode in which @key{SPC} breaks
45lines between words as you type. Minor modes are independent of one
46another and of the selected major mode. Most minor modes say in the
47mode line when they are enabled; for example, @samp{Fill} in the mode
48line means that Auto Fill mode is enabled.
49
50 Each minor mode is associated with a command, called the @dfn{mode
51command}, which turns it on or off. The name of this command consists
52of the name of the minor mode, followed by @samp{-mode}; for instance,
53the mode command for Auto Fill mode is @code{auto-fill-mode}. Calling
54the minor mode command with no prefix argument @dfn{toggles} the mode,
55turning it on if it was off, and off if it was on. A positive
56argument always turns the mode on, and a zero or negative argument
57always turns it off. Mode commands are usually invoked with
58@kbd{M-x}, but you can bind keys to them if you wish (@pxref{Key
59Bindings}).
60
61 Most minor modes also have a @dfn{mode variable}, with the same name
62as the mode command. Its value is non-@code{nil} if the mode is
63enabled, and @code{nil} if it is disabled. In some minor modes---but
64not all---the value of the variable alone determines whether the mode
65is active: the mode command works simply by setting the variable, and
66changing the value of the variable has the same effect as calling the
67mode command. Because not all minor modes work this way, we recommend
68that you avoid changing the mode variables directly; use the mode
69commands instead.
70
71 Some minor modes are @dfn{buffer-local}: they apply only to the
72current buffer, so you can enable the mode in certain buffers and not
73others. Other minor modes are @dfn{global}: while enabled, they
74affect everything you do in the Emacs session, in all buffers. Some
75global minor modes are enabled by default.
76
77 The following is a list of some buffer-local minor modes:
78
79@itemize @bullet
80@item
81Abbrev mode automatically expands text based on pre-defined
82abbreviation definitions. @xref{Abbrevs}.
83
84@item
85Auto Fill mode inserts newlines as you type to prevent lines from
86becoming too long. @xref{Filling}.
87
88@item
89Auto Save mode saves the buffer contents periodically to reduce the
90amount of work you can lose in case of a crash. @xref{Auto Save}.
91
92@item
93Enriched mode enables editing and saving of formatted text.
94@xref{Formatted Text}.
95
96@item
97Flyspell mode automatically highlights misspelled words.
98@xref{Spelling}.
99
100@item
101Font-Lock mode automatically highlights certain textual units found in
102programs. It is enabled globally by default, but you can disable it
103in individual buffers. @xref{Faces}.
104
105@findex linum-mode
106@cindex Linum mode
107@item
108Linum mode displays each line's line number in the window's left
109margin. Its mode command is @code{linum-mode}.
110
111@item
112Outline minor mode provides similar facilities to the major mode
113called Outline mode. @xref{Outline Mode}.
114
115@cindex Overwrite mode
116@cindex mode, Overwrite
117@findex overwrite-mode
118@kindex INSERT
119@item
120Overwrite mode causes ordinary printing characters to replace existing
121text instead of shoving it to the right. For example, if point is in
122front of the @samp{B} in @samp{FOOBAR}, then in Overwrite mode typing
123a @kbd{G} changes it to @samp{FOOGAR}, instead of producing
124@samp{FOOGBAR} as usual. In Overwrite mode, the command @kbd{C-q}
125inserts the next character whatever it may be, even if it is a
126digit---this gives you a way to insert a character instead of
127replacing an existing character. The mode command,
128@code{overwrite-mode}, is bound to the @key{Insert} key.
129
130@findex binary-overwrite-mode
131@item
132Binary Overwrite mode is a variant of Overwrite mode for editing
133binary files; it treats newlines and tabs like other characters, so
134that they overwrite other characters and can be overwritten by them.
135In Binary Overwrite mode, digits after @kbd{C-q} specify an octal
136character code, as usual.
137
138@item
139Visual Line mode performs ``word wrapping'', causing long lines to be
140wrapped at word boundaries. @xref{Visual Line Mode}.
141@end itemize
142
143 Here are some useful global minor modes. Since Line Number mode and
144Transient Mark mode can be enabled or disabled just by setting the
145value of the minor mode variable, you @emph{can} set them differently
146for particular buffers, by explicitly making the corresponding
147variable local in those buffers. @xref{Locals}.
148
149@itemize @bullet
150@item
151Column Number mode enables display of the current column number in the
152mode line. @xref{Mode Line}.
153
154@item
155Delete Selection mode causes text insertion to first delete the text
156in the region, if the region is active. @xref{Using Region}.
157
158@item
159Icomplete mode displays an indication of available completions when
160you are in the minibuffer and completion is active. @xref{Completion
161Options}.
162
163@item
164Line Number mode enables display of the current line number in the
165mode line. It is enabled by default. @xref{Mode Line}.
166
167@item
168Menu Bar mode gives each frame a menu bar. It is enabled by default.
169@xref{Menu Bars}.
170
171@item
172Scroll Bar mode gives each window a scroll bar. It is enabled by
173default, but the scroll bar is only displayed on graphical terminals.
174@xref{Scroll Bars}.
175
176@item
177Tool Bar mode gives each frame a tool bar. It is enabled by default,
178but the tool bar is only displayed on graphical terminals. @xref{Tool
179Bars}.
180
181@item
182Transient Mark mode highlights the region, and makes many Emacs
183commands operate on the region when the mark is active. It is enabled
184by default. @xref{Mark}.
185@end itemize
186
187@node Easy Customization 36@node Easy Customization
188@section Easy Customization Interface 37@section Easy Customization Interface
189 38
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi
index c0f1712bada..902de8318b8 100644
--- a/doc/emacs/emacs.texi
+++ b/doc/emacs/emacs.texi
@@ -184,7 +184,7 @@ Major Structures of Emacs
184* International:: Using non-@acronym{ASCII} character sets. 184* International:: Using non-@acronym{ASCII} character sets.
185 185
186Advanced Features 186Advanced Features
187* Major Modes:: Text mode vs. Lisp mode vs. C mode... 187* Modes:: Major and minor modes alter Emacs' basic behavior.
188* Indentation:: Editing the white space at the beginnings of lines. 188* Indentation:: Editing the white space at the beginnings of lines.
189* Text:: Commands and modes for editing English. 189* Text:: Commands and modes for editing English.
190* Programs:: Commands and modes for editing programs. 190* Programs:: Commands and modes for editing programs.
@@ -549,9 +549,12 @@ International Character Set Support
549 to use without multibyte characters. 549 to use without multibyte characters.
550* Charsets:: How Emacs groups its internal character codes. 550* Charsets:: How Emacs groups its internal character codes.
551 551
552Major Modes 552Modes
553 553
554* Choosing Modes:: How major modes are specified or chosen. 554* Major Modes:: Text mode vs. Lisp mode vs. C mode...
555* Minor Modes:: Each minor mode is a feature you can turn on
556 independently of any others.
557* Choosing Modes:: How modes are chosen when visiting files.
555 558
556Indentation 559Indentation
557 560
@@ -1058,8 +1061,6 @@ Hyperlinking and Navigation Features
1058 1061
1059Customization 1062Customization
1060 1063
1061* Minor Modes:: Each minor mode is a feature you can turn on
1062 independently of any others.
1063* Easy Customization:: Convenient way to browse and change settings. 1064* Easy Customization:: Convenient way to browse and change settings.
1064* Variables:: Many Emacs commands examine Emacs variables 1065* Variables:: Many Emacs commands examine Emacs variables
1065 to decide what to do; by setting variables, 1066 to decide what to do; by setting variables,
@@ -1485,7 +1486,7 @@ Lisp programming.
1485@include windows.texi 1486@include windows.texi
1486@include frames.texi 1487@include frames.texi
1487@include mule.texi 1488@include mule.texi
1488@include major.texi 1489@include modes.texi
1489@include indent.texi 1490@include indent.texi
1490@include text.texi 1491@include text.texi
1491@c Includes fortran-xtra. 1492@c Includes fortran-xtra.
diff --git a/doc/emacs/indent.texi b/doc/emacs/indent.texi
index c4ef4781aaf..e13b2808f09 100644
--- a/doc/emacs/indent.texi
+++ b/doc/emacs/indent.texi
@@ -2,7 +2,7 @@
2@c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2011 2@c Copyright (C) 1985-1987, 1993-1995, 1997, 2001-2011
3@c Free Software Foundation, Inc. 3@c Free Software Foundation, Inc.
4@c See file emacs.texi for copying conditions. 4@c See file emacs.texi for copying conditions.
5@node Indentation, Text, Major Modes, Top 5@node Indentation, Text, Modes, Top
6@chapter Indentation 6@chapter Indentation
7@cindex indentation 7@cindex indentation
8@cindex tabs 8@cindex tabs
diff --git a/doc/emacs/major.texi b/doc/emacs/major.texi
deleted file mode 100644
index ff73e568311..00000000000
--- a/doc/emacs/major.texi
+++ /dev/null
@@ -1,236 +0,0 @@
1@c This is part of the Emacs manual.
2@c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011
3@c Free Software Foundation, Inc.
4@c See file emacs.texi for copying conditions.
5@node Major Modes, Indentation, International, Top
6@chapter Major Modes
7@cindex major modes
8@cindex mode, major
9@kindex TAB @r{(and major modes)}
10@kindex DEL @r{(and major modes)}
11@kindex C-j @r{(and major modes)}
12
13 Emacs provides many alternative @dfn{major modes}, each of which
14customizes Emacs for editing text of a particular sort. The major modes
15are mutually exclusive, and each buffer has one major mode at any time.
16The mode line normally shows the name of the current major mode, in
17parentheses (@pxref{Mode Line}).
18
19 The least specialized major mode is called @dfn{Fundamental mode}.
20This mode has no mode-specific redefinitions or variable settings, so
21that each Emacs command behaves in its most general manner, and each
22user option variable is in its default state. For editing text of a
23specific type that Emacs knows about, such as Lisp code or English
24text, you should switch to the appropriate major mode, such as Lisp
25mode or Text mode.
26
27 Selecting a major mode changes the meanings of a few keys to become
28more specifically adapted to the language being edited. The ones that
29are changed frequently are @key{TAB}, @key{DEL}, and @kbd{C-j}. The
30prefix key @kbd{C-c} normally contains mode-specific commands. In
31addition, the commands which handle comments use the mode to determine
32how comments are to be delimited. Many major modes redefine the
33syntactical properties of characters appearing in the buffer.
34
35 The major modes fall into three major groups. The first group
36contains modes for normal text, either plain or with mark-up. It
37includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline
38mode. The second group contains modes for specific programming
39languages. These include Lisp mode (which has several variants), C
40mode, Fortran mode, and others. The remaining major modes are not
41intended for use on users' files; they are used in buffers created for
42specific purposes by Emacs, such as Dired mode for buffers made by
43Dired (@pxref{Dired}), Message mode for buffers made by @kbd{C-x m}
44(@pxref{Sending Mail}), and Shell mode for buffers used for
45communicating with an inferior shell process (@pxref{Interactive
46Shell}).
47
48 Most programming-language major modes specify that only blank lines
49separate paragraphs. This is to make the paragraph commands useful.
50(@xref{Paragraphs}.) They also cause Auto Fill mode to use the
51definition of @key{TAB} to indent the new lines it creates. This is
52because most lines in a program are usually indented
53(@pxref{Indentation}).
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
64most of the time Emacs determines which mode to use based on the file
65name or on special text in the file.
66
67 To explicitly select a new major, you use an @kbd{M-x} command.
68Take the name of a major mode and add @code{-mode} to get the name of
69the command to select that mode. Thus, you can enter Lisp mode by
70executing @kbd{M-x lisp-mode}.
71
72@vindex auto-mode-alist
73 When you visit a file, Emacs usually chooses the right major mode
74automatically. Normally, it makes the choice based on the file
75name---for example, files whose names end in @samp{.c} are normally
76edited in C mode---but sometimes it chooses the major mode based on
77the contents of the file. Here is the exact procedure:
78
79 First, Emacs checks whether the file contains a file-local variable
80that specifies the major mode. If so, it uses that major mode,
81ignoring all other criteria. @xref{File Variables}. There are
82several methods to specify a major mode using a file-local variable;
83the simplest is to put the mode name in the first nonblank line,
84preceded and followed by @samp{-*-}. Other text may appear on the
85line as well. For example,
86
87@example
88; -*-Lisp-*-
89@end example
90
91@noindent
92tells Emacs to use Lisp mode. Note how the semicolon is used to make
93Lisp treat this line as a comment. Alternatively, you could write
94
95@example
96; -*- mode: Lisp;-*-
97@end example
98
99@noindent
100The latter format allows you to specify local variables as well, like
101this:
102
103@example
104; -*- mode: Lisp; tab-width: 4; -*-
105@end example
106
107@vindex interpreter-mode-alist
108 Second, Emacs checks whether the file's contents begin with
109@samp{#!}. If so, that indicates that the file can serve as an
110executable shell command, which works by running an interpreter named
111on the file's first line (the rest of the file is used as input to the
112interpreter). Therefore, Emacs tries to use the interpreter name to
113choose a mode. For instance, a file that begins with
114@samp{#!/usr/bin/perl} is opened in Perl mode. The variable
115@code{interpreter-mode-alist} specifies the correspondence between
116interpreter program names and major modes.
117
118 When the first line starts with @samp{#!}, you usually cannot use
119the @samp{-*-} feature on the first line, because the system would get
120confused when running the interpreter. So Emacs looks for @samp{-*-}
121on the second line in such files as well as on the first line. The
122same is true for man pages which start with the magic string
123@samp{'\"} to specify a list of troff preprocessors.
124
125@vindex magic-mode-alist
126 Third, Emacs tries to determine the major mode by looking at the
127text at the start of the buffer, based on the variable
128@code{magic-mode-alist}. By default, this variable is @code{nil} (an
129empty list), so Emacs skips this step; however, you can customize it
130in your init file (@pxref{Init File}). The value should be a list of
131elements of the form
132
133@example
134(@var{regexp} . @var{mode-function})
135@end example
136
137@noindent
138where @var{regexp} is a regular expression (@pxref{Regexps}), and
139@var{mode-function} is a Lisp function that toggles a major mode. If
140the text at the beginning of the file matches @var{regexp}, Emacs
141chooses the major mode specified by @var{mode-function}.
142
143Alternatively, an element of @code{magic-mode-alist} may have the form
144
145@example
146(@var{match-function} . @var{mode-function})
147@end example
148
149@noindent
150where @var{match-function} is a Lisp function that is called at the
151beginning of the buffer; if the function returns non-@code{nil}, Emacs
152set the major mode wit @var{mode-function}.
153
154 Fourth---if Emacs still hasn't found a suitable major mode---it
155looks at the file's name. The correspondence between file names and
156major modes is controlled by the variable @code{auto-mode-alist}. Its
157value is a list in which each element has this form,
158
159@example
160(@var{regexp} . @var{mode-function})
161@end example
162
163@noindent
164or this form,
165
166@example
167(@var{regexp} @var{mode-function} @var{flag})
168@end example
169
170@noindent
171For example, one element normally found in the list has the form
172@code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C
173mode for files whose names end in @file{.c}. (Note that @samp{\\} is
174needed in Lisp syntax to include a @samp{\} in the string, which must
175be used to suppress the special meaning of @samp{.} in regexps.) If
176the element has the form @code{(@var{regexp} @var{mode-function}
177@var{flag})} and @var{flag} is non-@code{nil}, then after calling
178@var{mode-function}, Emacs discards the suffix that matched
179@var{regexp} and searches the list again for another match.
180
181@vindex auto-mode-case-fold
182 On systems with case-insensitive file names, such as Microsoft
183Windows, Emacs performs a single case-insensitive search through
184@code{auto-mode-alist}. On other systems, Emacs normally performs a
185single case-sensitive search through the alist. However, if you
186change the variable @code{auto-mode-case-fold} to @code{t}, Emacs
187performs a second case-insensitive search if the first search fails.
188
189@vindex magic-fallback-mode-alist
190 Finally, if Emacs @emph{still} hasn't found a major mode to use, it
191compares the text at the start of the buffer to the variable
192@code{magic-fallback-mode-alist}. This variable works like
193@code{magic-mode-alist}, described above, except that is consulted
194only after @code{auto-mode-alist}. By default,
195@code{magic-fallback-mode-alist} contains forms that check for image
196files, HTML/XML/SGML files, and Postscript files.
197
198@vindex major-mode
199 Once a major mode is chosen, Emacs sets the value of the variable
200@code{major-mode} to the symbol for that major mode (e.g.,
201@code{text-mode} for Text mode). This is a per-buffer variable
202(@pxref{Locals}); its buffer-local value is set automatically, and you
203should not change it yourself.
204
205 The default value of @code{major-mode} determines the major mode to
206use for files that do not specify a major mode, and for new buffers
207created with @kbd{C-x b}. Normally, this default value is the symbol
208@code{fundamental-mode}, which specifies Fundamental mode. You can
209change it via the Customization interface (@pxref{Easy
210Customization}), or by adding a line like this to your init file
211(@pxref{Init File}):
212
213@smallexample
214(setq-default major-mode 'text-mode)
215@end smallexample
216
217@noindent
218If the default value of @code{major-mode} is @code{nil}, the major
219mode is taken from the previously current buffer.
220
221@findex normal-mode
222 If you have changed the major mode of a buffer, you can return to
223the major mode Emacs would have chosen automatically, by typing
224@kbd{M-x normal-mode}. This is the same function that
225@code{find-file} calls to choose the major mode. It also processes
226the file's @samp{-*-} line or local variables list (if any).
227@xref{File Variables}.
228
229@vindex change-major-mode-with-file-name
230 The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to
231a new major mode if the new file name implies a mode (@pxref{Saving}).
232(@kbd{C-x C-s} does this too, if the buffer wasn't visiting a file.)
233However, this does not happen if the buffer contents specify a major
234mode, and certain ``special'' major modes do not allow the mode to
235change. You can turn off this mode-changing feature by setting
236@code{change-major-mode-with-file-name} to @code{nil}.
diff --git a/doc/emacs/modes.texi b/doc/emacs/modes.texi
new file mode 100644
index 00000000000..314d5d4347e
--- /dev/null
+++ b/doc/emacs/modes.texi
@@ -0,0 +1,410 @@
1@c This is part of the Emacs manual.
2@c Copyright (C) 1985-1987, 1993-1995, 1997, 2000-2011
3@c Free Software Foundation, Inc.
4@c See file emacs.texi for copying conditions.
5@node Modes, Indentation, International, Top
6@chapter Editing Modes
7
8 Emacs contains many @dfn{editing modes}, each of which alters its
9basic behavior in useful ways. These are divided into @dfn{major
10modes} and @dfn{minor modes}.
11
12 Major modes provide specialized facilities for working on a
13particular file type, such as a C source file (@pxref{Programs}), or a
14particular type of non-file buffer, such as a shell buffer
15(@pxref{Shell}). Major modes are mutually exclusive; each buffer has
16one and only one major mode at any time.
17
18 Minor modes are optional features which you can turn on or off, not
19necessarily specific to a type of file or buffer. For example, Auto
20Fill mode is a minor mode in which @key{SPC} breaks lines between
21words as you type (@pxref{Auto Fill}). Minor modes are independent of
22one another, and of the selected major mode.
23
24@menu
25* Major Modes:: Text mode vs. Lisp mode vs. C mode...
26* Minor Modes:: Each minor mode is a feature you can turn on
27 independently of any others.
28* Choosing Modes:: How modes are chosen when visiting files.
29@end menu
30
31@node Major Modes
32@section Major Modes
33@cindex major modes
34@cindex mode, major
35@kindex TAB @r{(and major modes)}
36@kindex DEL @r{(and major modes)}
37@kindex C-j @r{(and major modes)}
38
39 Every buffer possesses a major mode, which determines the editing
40behavior of Emacs while that buffer is current. The mode line
41normally shows the name of the current major mode, in parentheses.
42@xref{Mode Line}.
43
44 Usually, the major mode is automatically set by Emacs, when you
45first visit a file or create a buffer. @xref{Choosing Modes}. You
46can explicitly select a new major mode by using an @kbd{M-x} command.
47Take the name of the mode and add @code{-mode} to get the name of the
48command to select that mode. Thus, you can enter Lisp mode with
49@kbd{M-x lisp-mode}.
50
51 The least specialized major mode is called @dfn{Fundamental mode}.
52This mode has no mode-specific redefinitions or variable settings, so
53that each Emacs command behaves in its most general manner, and each
54user option variable is in its default state.
55
56 For editing text of a specific type that Emacs knows about, such as
57Lisp code or English text, you typically use a more specialized major
58mode, such as Lisp mode or Text mode. Such major modes change the
59meanings of some keys to become more specifically adapted to the
60language being edited. The ones that are commonly changed are
61@key{TAB}, @key{DEL}, and @kbd{C-j}. The prefix key @kbd{C-c}
62normally contains mode-specific commands. In addition, the commands
63which handle comments use the mode to determine how comments are to be
64delimited. Many major modes redefine the syntactical properties of
65characters appearing in the buffer.
66
67 The major modes fall into three major groups. The first group
68contains modes for normal text, either plain or with mark-up. It
69includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline
70mode. The second group contains modes for specific programming
71languages. These include Lisp mode (which has several variants), C
72mode, Fortran mode, and others. The remaining major modes are not
73intended for use on users' files; they are used in buffers created for
74specific purposes by Emacs, such as Dired mode for buffers made by
75Dired (@pxref{Dired}), Message mode for buffers made by @kbd{C-x m}
76(@pxref{Sending Mail}), and Shell mode for buffers used for
77communicating with an inferior shell process (@pxref{Interactive
78Shell}).
79
80 Most programming-language major modes specify that only blank lines
81separate paragraphs. This is to make the paragraph commands useful.
82(@xref{Paragraphs}.) They also cause Auto Fill mode to use the
83definition of @key{TAB} to indent the new lines it creates. This is
84because most lines in a program are usually indented
85(@pxref{Indentation}).
86
87@node Minor Modes
88@section Minor Modes
89@cindex minor modes
90@cindex mode, minor
91
92 A minor mode is an optional editing modes that alters the behavior
93of Emacs in some well-defined way. Unlike major modes, any number of
94minor modes can be in effect at any time. Some minor modes are
95@dfn{buffer-local}: they apply only to the current buffer, so you can
96enable the mode in certain buffers and not others. Other minor modes
97are @dfn{global}: while enabled, they affect everything you do in the
98Emacs session, in all buffers. Some global minor modes are enabled by
99default.
100
101 Most minor modes say in the mode line when they are enabled, just
102after the major mode indicator. For example, @samp{Fill} in the mode
103line means that Auto Fill mode is enabled. @xref{Mode Line}.
104
105 Each minor mode is associated with a command, called the @dfn{mode
106command}, which turns it on or off. The name of this command consists
107of the name of the minor mode, followed by @samp{-mode}; for instance,
108the mode command for Auto Fill mode is @code{auto-fill-mode}. Calling
109the minor mode command with no prefix argument @dfn{toggles} the mode,
110turning it on if it was off, and off if it was on. A positive
111argument always turns the mode on, and a zero or negative argument
112always turns it off. Mode commands are usually invoked with
113@kbd{M-x}, but you can bind keys to them if you wish (@pxref{Key
114Bindings}).
115
116 Most minor modes also have a @dfn{mode variable}, with the same name
117as the mode command. Its value is non-@code{nil} if the mode is
118enabled, and @code{nil} if it is disabled. In some minor modes---but
119not all---the value of the variable alone determines whether the mode
120is active: the mode command works simply by setting the variable, and
121changing the value of the variable has the same effect as calling the
122mode command. Because not all minor modes work this way, we recommend
123that you avoid changing the mode variables directly; use the mode
124commands instead.
125
126 The following is a list of some buffer-local minor modes:
127
128@itemize @bullet
129@item
130Abbrev mode automatically expands text based on pre-defined
131abbreviation definitions. @xref{Abbrevs}.
132
133@item
134Auto Fill mode inserts newlines as you type to prevent lines from
135becoming too long. @xref{Filling}.
136
137@item
138Auto Save mode saves the buffer contents periodically to reduce the
139amount of work you can lose in case of a crash. @xref{Auto Save}.
140
141@item
142Enriched mode enables editing and saving of formatted text.
143@xref{Formatted Text}.
144
145@item
146Flyspell mode automatically highlights misspelled words.
147@xref{Spelling}.
148
149@item
150Font-Lock mode automatically highlights certain textual units found in
151programs. It is enabled globally by default, but you can disable it
152in individual buffers. @xref{Faces}.
153
154@findex linum-mode
155@cindex Linum mode
156@item
157Linum mode displays each line's line number in the window's left
158margin. Its mode command is @code{linum-mode}.
159
160@item
161Outline minor mode provides similar facilities to the major mode
162called Outline mode. @xref{Outline Mode}.
163
164@cindex Overwrite mode
165@cindex mode, Overwrite
166@findex overwrite-mode
167@kindex INSERT
168@item
169Overwrite mode causes ordinary printing characters to replace existing
170text instead of shoving it to the right. For example, if point is in
171front of the @samp{B} in @samp{FOOBAR}, then in Overwrite mode typing
172a @kbd{G} changes it to @samp{FOOGAR}, instead of producing
173@samp{FOOGBAR} as usual. In Overwrite mode, the command @kbd{C-q}
174inserts the next character whatever it may be, even if it is a
175digit---this gives you a way to insert a character instead of
176replacing an existing character. The mode command,
177@code{overwrite-mode}, is bound to the @key{Insert} key.
178
179@findex binary-overwrite-mode
180@item
181Binary Overwrite mode is a variant of Overwrite mode for editing
182binary files; it treats newlines and tabs like other characters, so
183that they overwrite other characters and can be overwritten by them.
184In Binary Overwrite mode, digits after @kbd{C-q} specify an octal
185character code, as usual.
186
187@item
188Visual Line mode performs ``word wrapping'', causing long lines to be
189wrapped at word boundaries. @xref{Visual Line Mode}.
190@end itemize
191
192 Here are some useful global minor modes. Since Line Number mode and
193Transient Mark mode can be enabled or disabled just by setting the
194value of the minor mode variable, you @emph{can} set them differently
195for particular buffers, by explicitly making the corresponding
196variable local in those buffers. @xref{Locals}.
197
198@itemize @bullet
199@item
200Column Number mode enables display of the current column number in the
201mode line. @xref{Mode Line}.
202
203@item
204Delete Selection mode causes text insertion to first delete the text
205in the region, if the region is active. @xref{Using Region}.
206
207@item
208Icomplete mode displays an indication of available completions when
209you are in the minibuffer and completion is active. @xref{Completion
210Options}.
211
212@item
213Line Number mode enables display of the current line number in the
214mode line. It is enabled by default. @xref{Mode Line}.
215
216@item
217Menu Bar mode gives each frame a menu bar. It is enabled by default.
218@xref{Menu Bars}.
219
220@item
221Scroll Bar mode gives each window a scroll bar. It is enabled by
222default, but the scroll bar is only displayed on graphical terminals.
223@xref{Scroll Bars}.
224
225@item
226Tool Bar mode gives each frame a tool bar. It is enabled by default,
227but the tool bar is only displayed on graphical terminals. @xref{Tool
228Bars}.
229
230@item
231Transient Mark mode highlights the region, and makes many Emacs
232commands operate on the region when the mark is active. It is enabled
233by default. @xref{Mark}.
234@end itemize
235
236@node Choosing Modes
237@section Choosing File Modes
238
239@cindex choosing a major mode
240@cindex choosing a minor mode
241@vindex auto-mode-alist
242 When you visit a file, Emacs chooses a major mode automatically.
243Normally, it makes the choice based on the file name---for example,
244files whose names end in @samp{.c} are normally edited in C mode---but
245sometimes it chooses the major mode based on special text in the file.
246This special text can also be used to enable buffer-local minor modes.
247
248 Here is the exact procedure:
249
250 First, Emacs checks whether the file contains file-local mode
251variables. @xref{File Variables}. If there is a file-local variable
252that specifies a major mode, then Emacs uses that major mode, ignoring
253all other criteria. There are several methods to specify a major mode
254using a file-local variable; the simplest is to put the mode name in
255the first nonblank line, preceded and followed by @samp{-*-}. Other
256text may appear on the line as well. For example,
257
258@example
259; -*-Lisp-*-
260@end example
261
262@noindent
263tells Emacs to use Lisp mode. Note how the semicolon is used to make
264Lisp treat this line as a comment. Alternatively, you could write
265
266@example
267; -*- mode: Lisp;-*-
268@end example
269
270@noindent
271The latter format allows you to specify local variables as well, like
272this:
273
274@example
275; -*- mode: Lisp; tab-width: 4; -*-
276@end example
277
278 If a file variable specifies a buffer-local minor mode, Emacs
279enables that minor mode in the buffer.
280
281@vindex interpreter-mode-alist
282 Second, if there is no file variable specifying a major mode, Emacs
283checks whether the file's contents begin with @samp{#!}. If so, that
284indicates that the file can serve as an executable shell command,
285which works by running an interpreter named on the file's first line
286(the rest of the file is used as input to the interpreter).
287Therefore, Emacs tries to use the interpreter name to choose a mode.
288For instance, a file that begins with @samp{#!/usr/bin/perl} is opened
289in Perl mode. The variable @code{interpreter-mode-alist} specifies
290the correspondence between interpreter program names and major modes.
291
292 When the first line starts with @samp{#!}, you usually cannot use
293the @samp{-*-} feature on the first line, because the system would get
294confused when running the interpreter. So Emacs looks for @samp{-*-}
295on the second line in such files as well as on the first line. The
296same is true for man pages which start with the magic string
297@samp{'\"} to specify a list of troff preprocessors.
298
299@vindex magic-mode-alist
300 Third, Emacs tries to determine the major mode by looking at the
301text at the start of the buffer, based on the variable
302@code{magic-mode-alist}. By default, this variable is @code{nil} (an
303empty list), so Emacs skips this step; however, you can customize it
304in your init file (@pxref{Init File}). The value should be a list of
305elements of the form
306
307@example
308(@var{regexp} . @var{mode-function})
309@end example
310
311@noindent
312where @var{regexp} is a regular expression (@pxref{Regexps}), and
313@var{mode-function} is a Lisp function that toggles a major mode. If
314the text at the beginning of the file matches @var{regexp}, Emacs
315chooses the major mode specified by @var{mode-function}.
316
317Alternatively, an element of @code{magic-mode-alist} may have the form
318
319@example
320(@var{match-function} . @var{mode-function})
321@end example
322
323@noindent
324where @var{match-function} is a Lisp function that is called at the
325beginning of the buffer; if the function returns non-@code{nil}, Emacs
326set the major mode wit @var{mode-function}.
327
328 Fourth---if Emacs still hasn't found a suitable major mode---it
329looks at the file's name. The correspondence between file names and
330major modes is controlled by the variable @code{auto-mode-alist}. Its
331value is a list in which each element has this form,
332
333@example
334(@var{regexp} . @var{mode-function})
335@end example
336
337@noindent
338or this form,
339
340@example
341(@var{regexp} @var{mode-function} @var{flag})
342@end example
343
344@noindent
345For example, one element normally found in the list has the form
346@code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C
347mode for files whose names end in @file{.c}. (Note that @samp{\\} is
348needed in Lisp syntax to include a @samp{\} in the string, which must
349be used to suppress the special meaning of @samp{.} in regexps.) If
350the element has the form @code{(@var{regexp} @var{mode-function}
351@var{flag})} and @var{flag} is non-@code{nil}, then after calling
352@var{mode-function}, Emacs discards the suffix that matched
353@var{regexp} and searches the list again for another match.
354
355@vindex auto-mode-case-fold
356 On systems with case-insensitive file names, such as Microsoft
357Windows, Emacs performs a single case-insensitive search through
358@code{auto-mode-alist}. On other systems, Emacs normally performs a
359single case-sensitive search through the alist. However, if you
360change the variable @code{auto-mode-case-fold} to @code{t}, Emacs
361performs a second case-insensitive search if the first search fails.
362
363@vindex magic-fallback-mode-alist
364 Finally, if Emacs @emph{still} hasn't found a major mode to use, it
365compares the text at the start of the buffer to the variable
366@code{magic-fallback-mode-alist}. This variable works like
367@code{magic-mode-alist}, described above, except that is consulted
368only after @code{auto-mode-alist}. By default,
369@code{magic-fallback-mode-alist} contains forms that check for image
370files, HTML/XML/SGML files, and Postscript files.
371
372@vindex major-mode
373 Once a major mode is chosen, Emacs sets the value of the variable
374@code{major-mode} to the symbol for that major mode (e.g.,
375@code{text-mode} for Text mode). This is a per-buffer variable
376(@pxref{Locals}); its buffer-local value is set automatically, and you
377should not change it yourself.
378
379 The default value of @code{major-mode} determines the major mode to
380use for files that do not specify a major mode, and for new buffers
381created with @kbd{C-x b}. Normally, this default value is the symbol
382@code{fundamental-mode}, which specifies Fundamental mode. You can
383change it via the Customization interface (@pxref{Easy
384Customization}), or by adding a line like this to your init file
385(@pxref{Init File}):
386
387@smallexample
388(setq-default major-mode 'text-mode)
389@end smallexample
390
391@noindent
392If the default value of @code{major-mode} is @code{nil}, the major
393mode is taken from the previously current buffer.
394
395@findex normal-mode
396 If you have changed the major mode of a buffer, you can return to
397the major mode Emacs would have chosen automatically, by typing
398@kbd{M-x normal-mode}. This is the same function that
399@code{find-file} calls to choose the major mode. It also processes
400the file's @samp{-*-} line or local variables list (if any).
401@xref{File Variables}.
402
403@vindex change-major-mode-with-file-name
404 The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to
405a new major mode if the new file name implies a mode (@pxref{Saving}).
406(@kbd{C-x C-s} does this too, if the buffer wasn't visiting a file.)
407However, this does not happen if the buffer contents specify a major
408mode, and certain ``special'' major modes do not allow the mode to
409change. You can turn off this mode-changing feature by setting
410@code{change-major-mode-with-file-name} to @code{nil}.
diff --git a/doc/emacs/mule.texi b/doc/emacs/mule.texi
index 3f3da503769..3c970ecb12c 100644
--- a/doc/emacs/mule.texi
+++ b/doc/emacs/mule.texi
@@ -1,7 +1,7 @@
1@c This is part of the Emacs manual. 1@c This is part of the Emacs manual.
2@c Copyright (C) 1997, 1999-2011 Free Software Foundation, Inc. 2@c Copyright (C) 1997, 1999-2011 Free Software Foundation, Inc.
3@c See file emacs.texi for copying conditions. 3@c See file emacs.texi for copying conditions.
4@node International, Major Modes, Frames, Top 4@node International, Modes, Frames, Top
5@chapter International Character Set Support 5@chapter International Character Set Support
6@c This node is referenced in the tutorial. When renaming or deleting 6@c This node is referenced in the tutorial. When renaming or deleting
7@c it, the tutorial needs to be adjusted. (TUTORIAL.de) 7@c it, the tutorial needs to be adjusted. (TUTORIAL.de)