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