annotate man/xemacs/major.texi @ 391:e50d8e68d7a5

Added tag r21-2-10 for changeset c6012109f545
author cvs
date Mon, 13 Aug 2007 11:10:04 +0200
parents e45d5e7c476e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 0
diff changeset
2 @node Major Modes, Indentation, Mule, Top
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 @chapter Major Modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 @cindex major modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 @kindex TAB
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 @kindex DEL
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 @kindex LFD
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Emacs has many different @dfn{major modes}, each of which customizes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 Emacs for editing text of a particular sort. The major modes are mutually
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 exclusive; at any time, each buffer has one major mode. The mode line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 normally contains the name of the current major mode in parentheses.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 @xref{Mode Line}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 The least specialized major mode is called @dfn{Fundamental mode}. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 mode has no mode-specific redefinitions or variable settings. Each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 Emacs command behaves in its most general manner, and each option is in its
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 default state. For editing any specific type of text, such as Lisp code or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 English text, you should switch to the appropriate major mode, such as Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 mode or Text mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 Selecting a major mode changes the meanings of a few keys to become
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 more specifically adapted to the language being edited. @key{TAB},
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 @key{DEL}, and @key{LFD} are changed frequently. In addition, commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 which handle comments use the mode to determine how to delimit comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 Many major modes redefine the syntactical properties of characters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 appearing in the buffer. @xref{Syntax}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 The major modes fall into three major groups. Lisp mode (which has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 several variants), C mode, and Muddle mode are for specific programming
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 languages. Text mode, Nroff mode, @TeX{} mode, and Outline mode are for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 editing English text. The remaining major modes are not intended for use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 on users' files; they are used in buffers created by Emacs for specific
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 purposes and include Dired mode for buffers made by Dired (@pxref{Dired}),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 Mail mode for buffers made by @kbd{C-x m} (@pxref{Sending Mail}), and Shell
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 mode for buffers used for communicating with an inferior shell process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 (@pxref{Interactive Shell}).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 Most programming language major modes specify that only blank lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 separate paragraphs. This is so that the paragraph commands remain useful.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 @xref{Paragraphs}. They also cause Auto Fill mode to use the definition of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 @key{TAB} to indent the new lines it creates. This is because most lines
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 in a program are usually indented. @xref{Indentation}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 @menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 * Choosing Modes:: How major modes are specified or chosen.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 @end menu
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 @node Choosing Modes,,Major Modes,Major Modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 @section Choosing Major Modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 You can select a major mode explicitly for the current buffer, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 most of the time Emacs determines which mode to use based on the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 name or some text in the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 Use a @kbd{M-x} command to explicitly select a new major mode. Add
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 @code{-mode} to the name of a major mode to get the name of a command to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 select that mode. For example, to enter Lisp mode, execute @kbd{M-x
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 lisp-mode}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 @vindex auto-mode-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 When you visit a file, Emacs usually chooses the right major mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 based on the file's name. For example, files whose names end in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 @code{.c} are edited in C mode. The variable @code{auto-mode-alist}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 controls the correspondence between file names and major mode. Its value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 is a list in which each element has the form:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (@var{regexp} . @var{mode-function})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 For example, one element normally found in the list has the form
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 @code{(@t{"\\.c$"} . c-mode)}. It is responsible for selecting C mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 for files whose names end in @file{.c}. (Note that @samp{\\} is needed in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 Lisp syntax to include a @samp{\} in the string, which is needed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 suppress the special meaning of @samp{.} in regexps.) The only practical
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 way to change this variable is with Lisp code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 You can specify which major mode should be used for editing a certain
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 file by a special sort of text in the first non-blank line of the file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 The mode name should appear in this line both preceded and followed by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 @samp{-*-}. Other text may appear on the line as well. For example,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;-*-Lisp-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 tells Emacs to use Lisp mode. Note how the semicolon is used to make Lisp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 treat this line as a comment. Such an explicit specification overrides any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 default mode based on the file name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 Another format of mode specification is:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 @example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 -*-Mode: @var{modename};-*-
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 @end example
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 @noindent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 which allows other things besides the major mode name to be specified.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 However, Emacs does not look for anything except the mode name.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 The major mode can also be specified in a local variables list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 @xref{File Variables}.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 @vindex default-major-mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 When you visit a file that does not specify a major mode to use, or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 when you create a new buffer with @kbd{C-x b}, Emacs uses the major mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 specified by the variable @code{default-major-mode}. Normally this
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 value is the symbol @code{fundamental-mode}, which specifies Fundamental
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 mode. If @code{default-major-mode} is @code{nil}, the major mode is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 taken from the previously selected buffer.