1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
|
@c =============================================================
@c = $B85(B $BK](B $BLu(B: $BNkLZ1Y;R!wDEED=NBg3X(B
@c = $B2CI.=$@5(B: $BBgLZFXM:!wBgDM(B.$BC^GHBg3X(B = 1998/11/25
@c = 20.4$B2~D{(B: $BBgLZFXM:!wBgDM(B.$BC^GHBg3X(B = 1999/09/12
@c =============================================================
@c This is part of the Emacs manual.
@c Copyright (C) 1985, 86, 87, 93, 94, 95, 1997 Free Software Foundation, Inc.
@c See file emacs.texi for copying conditions.
@node Major Modes, Indentation, International, Top
@c @chapter Major Modes
@c @cindex major modes
@c @cindex mode, major
@chapter $B%a%8%c!<%b!<%I(B
@cindex $B%a%8%c!<%b!<%I(B
@cindex $B%b!<%I!"%a%8%c!<(B
@c @kindex TAB @r{(and major modes)}
@c @kindex DEL @r{(and major modes)}
@c @kindex C-j @r{(and major modes)}
@kindex TAB @r{$B!J$H%a%8%c!<%b!<%I!K(B}
@kindex DEL @r{$B!J$H%a%8%c!<%b!<%I!K(B}
@kindex C-j @r{$B!J$H%a%8%c!<%b!<%I!K(B}
@c Emacs provides many alternative @dfn{major modes}, each of which
@c customizes Emacs for editing text of a particular sort. The major modes
@c are mutually exclusive, and each buffer has one major mode at any time.
@c The mode line normally shows the name of the current major mode, in
@c parentheses (@pxref{Mode Line}).
Emacs$B$K$O!"B??t$NA*Br$G$-$k(B@dfn{$B%a%8%c!<%b!<%I(B}$B!J(Bmajor mode$B!K$,$"$j!"(B
$B3F%b!<%I$OFCDj$N<oN`$N%F%-%9%H$rJT=8$9$k$?$a$K(BEmacs$B$r%+%9%?%^%$%:$7$^$9!#(B
$B%a%8%c!<%b!<%I$OAj8_$KGSB>E*$G!"(B
$B3F%P%C%U%!$O$$$D$G$b(B1$B$D$N%a%8%c!<%b!<%I$@$1$r;}$A$^$9!#(B
$B%b!<%I9T$O!"DL>o!"8=9T$N%a%8%c!<%b!<%I$NL>A0$r3g8L$NCf$KI=<($7$^$9(B
$B!J(B@pxref{Mode Line}$B!K!#(B
@c The least specialized major mode is called @dfn{Fundamental mode}.
@c This mode has no mode-specific redefinitions or variable settings, so
@c that each Emacs command behaves in its most general manner, and each
@c option is in its default state. For editing text of a specific type
@c that Emacs knows about, such as Lisp code or English text, you should
@c switch to the appropriate major mode, such as Lisp mode or Text mode.
$B$b$C$H$bFC<l2=$5$l$F$$$J$$%a%8%c!<%b!<%I$O!"(B
@dfn{$B4pK\!J(Bfundamental$B!K%b!<%I(B}$B$H8F$P$l$^$9!#(B
$B$3$N%b!<%I$K$O!"%b!<%IFH<+$N:FDj5A$dJQ?t@_Dj$,$J$/!"(B
$B3F(BEmacs$B%3%^%s%I$O$b$C$H$b0lHLE*$J$U$k$^$$$r$7$F!"(B
$B3F%*%W%7%g%s$O%G%U%)%k%H$N>uBV$K$J$C$F$$$^$9!#(B
Lisp$B$d1QJ8$N$h$&$K!"(BEmacs$B$,CN$C$F$$$kFCDj$N<oN`$N%F%-%9%H$rJT=8$9$k$K$O!"(B
Lisp$B%b!<%I$d!"%F%-%9%H!J(Btext$B!K%b!<%I$N$h$&$J(B
$BE,@Z$J%a%8%c!<%b!<%I$K@Z$jBX$($k$Y$-$G$9!#(B
@c Selecting a major mode changes the meanings of a few keys to become
@c more specifically adapted to the language being edited. The ones that
@c are changed frequently are @key{TAB}, @key{DEL}, and @kbd{C-j}. The
@c prefix key @kbd{C-c} normally contains mode-specific commands. In
@c addition, the commands which handle comments use the mode to determine
@c how comments are to be delimited. Many major modes redefine the
@c syntactical properties of characters appearing in the buffer.
@c @xref{Syntax}.
$B%a%8%c!<%b!<%I$rA*Br$9$k$3$H$O!"(B
$BJT=8BP>]$N8@8l$K$h$jL@3N$KE,1~$9$k$h$&$K%-!<$N0UL#$rB?>/JQ99$9$k$3$H$G$9!#(B
$B$h$/JQ99$5$l$k%-!<$O(B@key{TAB}$B!"(B@key{DEL}$B!"(B@kbd{C-j}$B$G$9!#(B
$B%W%l%U%#%C%/%9%-!<(B@kbd{C-c}$B$O!"%b!<%IFCM-$N%3%^%s%I$r4^$_$^$9!#(B
$B$5$i$K!"%3%a%s%H$r07$&%3%^%s%I$O!"(B
$B%b!<%I$r;H$C$F%3%a%s%H$N6h@Z$jJ}$r7hDj$7$^$9!#(B
$BB?$/$N%a%8%c!<%b!<%I$G$O!"(B
$B%P%C%U%!Fb$K8=$l$kJ8;z$N9=J8>e$NB0@-$r:FDj5A$7$F$$$^$9!#(B
@xref{Syntax}$B!#(B
@c The major modes fall into three major groups. Lisp mode (which has
@c several variants), C mode, Fortran mode and others are for specific
@c programming languages. Text mode, Nroff mode, @TeX{} mode and Outline
@c mode are for editing English text. The remaining major modes are not
@c intended for use on users' files; they are used in buffers created for
@c specific purposes by Emacs, such as Dired mode for buffers made by Dired
@c (@pxref{Dired}), Mail mode for buffers made by @kbd{C-x m}
@c (@pxref{Sending Mail}), and Shell mode for buffers used for
@c communicating with an inferior shell process (@pxref{Interactive
@c Shell}).
$B%a%8%c!<%b!<%I$O(B3$B$D$N%0%k!<%W$KJ,$1$i$l$^$9!#(B
$B!J$$$/$D$+$NJQ<o$rM-$9$k!K(BLisp$B%b!<%I!"(BC$B%b!<%I!"(BFortran$B%b!<%I!"(B
$B$=$NB>$N%W%m%0%i%`8@8lFCM-$N%b!<%I$N%0%k!<%W$,$"$j$^$9!#(B
$B%F%-%9%H!J(Btext$B!K%b!<%I!"(Bnroff$B%b!<%I!"(B
@TeX{}$B$H%"%&%H%i%$%s!J(Boutline$B!K%b!<%I$J$I(B
$B1QJ8$rJT=8$9$k$?$a$N$b$N$,$"$j$^$9!#(B
$B;D$j$N%a%8%c!<%b!<%I$O!"%f!<%6!<$N%U%!%$%k$K;H$&$?$a$N$b$N$G$O$"$j$^$;$s!#(B
Emacs$B$,FCJL$NL\E*$N$?$a$K:n$k%P%C%U%!$G;H$o$l$^$9!#(B
dired$B!J(B@pxref{Dired}$B!K$,:n$k%P%C%U%!8~$1$N(Bdired$B%b!<%I!J(B@pxref{Dired}$B!K!"(B
@kbd{C-x m}$B$G:n$i$l$k%P%C%U%!8~$1$N(B
$B%a%$%k!J(Bmail$B!K%b!<%I!J(B@pxref{Sending Mail}$B!K!"(B
$B2<0L$N%7%'%k%W%m%;%9$H$NDL?.MQ$N%P%C%U%!8~$1$N%7%'%k!J(Bshell$B!K%b!<%I(B
$B!J(B@pxref{Interactive Shell}$B!K$J$I$G$9!#(B
@c Most programming-language major modes specify that only blank lines
@c separate paragraphs. This is to make the paragraph commands useful.
@c (@xref{Paragraphs}.) They also cause Auto Fill mode to use the
@c definition of @key{TAB} to indent the new lines it creates. This is
@c because most lines in a program are usually indented.
@c (@xref{Indentation}.)
$B$[$H$s$I$N%W%m%0%i%`8@8lMQ$N%a%8%c!<%b!<%I$G$O!"(B
$BCJMn$N6h@Z$j$O6u9T$@$1$G$9!#(B
$B$3$l$O!"CJMn%3%^%s%I$rLrN)$D$h$&$K$9$k$?$a$G$9!#(B
$B!J(B@pxref{Paragraphs}$B!#!K(B
$B$^$?!"$3$l$i$N%b!<%I$G$O!"(B
$B<+F05M$a9~$_!J(Bauto-fill$B!K%b!<%I$K$*$$$F!"(B
$B?7$?$K:n$C$?9T$r;z2<$2$9$k$h$&$K(B@key{TAB}$B$rDj5A$7$^$9!#(B
$B$H$$$&$N$O!"%W%m%0%i%`Cf$N$[$H$s$I$N9T$ODL>o;z2<$2$5$l$k$+$i$G$9!#(B
$B!J(B@pxref{Indentation}$B!#!K(B
@menu
* Choosing Modes:: How major modes are specified or chosen.
@end menu
@node Choosing Modes,,Major Modes,Major Modes
@c @section How Major Modes are Chosen
@section $B%a%8%c!<%b!<%I$NA*BrJ}<0(B
@c @cindex choosing a major mode
@cindex $B%a%8%c!<%b!<%I$NA*Br(B
@c You can select a major mode explicitly for the current buffer, but
@c most of the time Emacs determines which mode to use based on the file
@c name or on special text in the file.
$B%+%l%s%H%P%C%U%!$KBP$7$FL@<(E*$K%a%8%c!<%b!<%I$rA*Br$9$k$3$H$b$G$-$^$9!#(B
$B$7$+$7!"$?$$$F$$$O!"%U%!%$%kL>$d%U%!%$%kFb$NFCJL$N%F%-%9%H$K4p$E$$$F(B
Emacs$B$O$I$N%b!<%I$r;H$&$+$r7hDj$7$^$9!#(B
@c Explicit selection of a new major mode is done with a @kbd{M-x} command.
@c From the name of a major mode, add @code{-mode} to get the name of a
@c command to select that mode. Thus, you can enter Lisp mode by executing
@c @kbd{M-x lisp-mode}.
$BL@<(E*$K?7$7$$%a%8%c!<%b!<%I$rA*Br$9$k$K$O!"(B@kbd{M-x}$B%3%^%s%I$G9T$$$^$9!#(B
$B%a%8%c!<%b!<%I$NL>A0$K(B@code{-mode}$B$rIU$12C$($k$H!"(B
$B$=$N%b!<%I$rA*$V%3%^%s%IL>$K$J$j$^$9!#(B
$B$7$?$,$C$F!"(BLisp$B%b!<%I$KF~$k$K$O(B@kbd{M-x lisp-mode}$B$r<B9T$7$^$9!#(B
@vindex auto-mode-alist
@c When you visit a file, Emacs usually chooses the right major mode based
@c on the file's name. For example, files whose names end in @samp{.c} are
@c edited in C mode. The correspondence between file names and major modes is
@c controlled by the variable @code{auto-mode-alist}. Its value is a list in
@c which each element has this form,
$B%U%!%$%k$rK,Ld$9$k$H!"(BEmacs$B$ODL>o%U%!%$%kL>$K4p$E$$$F(B
$B@5$7$$%a%8%c!<%b!<%I$rA*Br$7$^$9!#(B
$B$?$H$($P!"(B@samp{.c}$B$G=*$kL>A0$N%U%!%$%k$O!"(BC$B%b!<%I$GJT=8$5$l$^$9!#(B
$B%U%!%$%kL>$H%a%8%c!<%b!<%I$H$NBP1~$O!"(B
$BJQ?t(B@code{auto-mode-alist}$B$G@)8f$7$^$9!#(B
$B$=$NCM$O!"MWAG$,$D$.$N$h$&$J7A<0$N%j%9%H$G$9!#(B
@example
(@var{regexp} . @var{mode-function})
@end example
@noindent
@c or this form,
$B$^$?$O!"$D$.$N7A<0$G$9!#(B
@example
(@var{regexp} @var{mode-function} @var{flag})
@end example
@noindent
@c For example, one element normally found in the list has the form
@c @code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C
@c mode for files whose names end in @file{.c}. (Note that @samp{\\} is
@c needed in Lisp syntax to include a @samp{\} in the string, which is
@c needed to suppress the special meaning of @samp{.} in regexps.) If the
@c element has the form @code{(@var{regexp} @var{mode-function}
@c @var{flag})} and @var{flag} is non-@code{nil}, then after calling
@c @var{function}, the suffix that matched @var{regexp} is discarded and
@c the list is searched again for another match.
$B$?$H$($P!"$3$N%j%9%H$KDL>o$"$kMWAG$O!"(B
@code{(@t{"\\.c\\'"}. c-mode)}$B$G$9!#(B
$B$3$l$O!"(B@file{.c}$B$G=*$kL>A0$N%U%!%$%k$K$O(BC$B%b!<%I$rA*$S$^$9!#(B
$B!J(BLisp$B$N9=J8$G$O!"(B@samp{\}$B$r4^$a$k$K$O(B@samp{\\}$B$,I,MW!#(B
$B$^$?!"(B@samp{\}$B$O!"@55,I=8=$N(B@samp{.}$B$NFCJL$J0UL#$rM^@)$9$k$?$a$KI,MW!#!K(B
$B%j%9%H$NMWAG$,(B
@code{(@var{regexp} @var{mode-function} @var{flag})}$B$N7A<0$G(B
@var{flag}$B$,(B@code{nil}$B0J30$J$i$P!"(B
@var{function}$B$r8F$s$@$"$H$K(B@var{regexp}$B$K0lCW$9$k@\Hx<-$r<N$F$F!"(B
$B%j%9%H$GB>$K0lCW$9$k$b$N$r$U$?$?$SC5$7$^$9!#(B
@c You can specify which major mode should be used for editing a certain
@c file by a special sort of text in the first nonblank line of the file. The
@c mode name should appear in this line both preceded and followed by
@c @samp{-*-}. Other text may appear on the line as well. For example,
$B%U%!%$%k$N6u9T$G$J$$:G=i$N9T$NFCJL$J<oN`$N%F%-%9%H$K$h$C$F!"(B
$B$=$N%U%!%$%k$rJT=8$9$k$?$a$K$I$N%a%8%c!<%b!<%I$r;H$&$+$r;XDj$G$-$^$9!#(B
$B%b!<%IL>$O!"$=$N9T$K(B@samp{-*-}$B$G0O$^$l$F8=$l$^$9!#(B
$BB>$N%F%-%9%H$,$=$N9T$K$"$C$F$b$+$^$$$^$;$s!#(B
$B$?$H$($P!"(B
@example
;-*-Lisp-*-
@end example
@noindent
@c tells Emacs to use Lisp mode. Such an explicit specification overrides
@c any defaulting based on the file name. Note how the semicolon is used
@c to make Lisp treat this line as a comment.
$B$O!"(BEmacs$B$K(BLisp$B%b!<%I$r;H$&$h$&$K;X<($7$^$9!#(B
$B$3$N$h$&$JL@<(E*$J;XDj$O!"(B
$B%U%!%$%kL>$K4p$E$$$?%a%8%c!<%b!<%I$KM%@h$7$^$9!#(B
$B$3$N9T$,(BLisp$B$N%3%a%s%H$K$J$k$h$&$K(B
$B%;%_%3%m%s$r;H$C$F$$$k$3$H$KCm0U$7$F$/$@$5$$!#(B
@c Another format of mode specification is
$B%b!<%I$r;XDj$9$kJL$N=q<0$O!"$D$.$N$H$*$j$G$9!#(B
@example
-*- mode: @var{modename};-*-
@end example
@noindent
@c which allows you to specify local variables as well, like this:
$B$3$l$O!"F1MM$K%m!<%+%kJQ?t$b;XDj$G$-$F!"$D$.$N$h$&$K=q$-$^$9!#(B
@example
-*- mode: @var{modename}; @var{var}: @var{value}; @dots{} -*-
@end example
@noindent
@c @xref{File Variables}, for more information about this.
$B$h$j>\$7$/$O!"(B@xref{File Variables}$B!#(B
@vindex interpreter-mode-alist
@c When a file's contents begin with @samp{#!}, it can serve as an
@c executable shell command, which works by running an interpreter named on
@c the file's first line. The rest of the file is used as input to the
@c interpreter.
$B%U%!%$%k$NFbMF$,(B@samp{#!}$B$G;O$^$k$H$-$O!"(B
$B%U%!%$%k$N(B1$B9TL\$G;XDj$7$?%3%^%s%I%$%s%?!<%W%j%?$r<B9T$9$k$3$H$G!"(B
$B<B9T2DG=$J%7%'%k%3%^%s%I$H$7$FF/$-$^$9!#(B
$B%U%!%$%k$N;D$j$NItJ,$O!"%$%s%?!<%W%j%?$X$NF~NO$H$7$F;H$o$l$^$9!#(B
@c When you visit such a file in Emacs, if the file's name does not
@c specify a major mode, Emacs uses the interpreter name on the first line
@c to choose a mode. If the first line is the name of a recognized
@c interpreter program, such as @samp{perl} or @samp{tcl}, Emacs uses a
@c mode appropriate for programs for that interpreter. The variable
@c @code{interpreter-mode-alist} specifies the correspondence between
@c interpreter program names and major modes.
Emacs$B$G$=$N$h$&$J%U%!%$%k$rK,Ld$7$?$H$-!"(B
$B%U%!%$%k$NL>A0$,%a%8%c!<%b!<%I$r;XDj$7$J$$$H$-$K$O!"(B
Emacs$B$O%b!<%I$rA*Br$9$k$?$a$K(B1$B9TL\$N%$%s%?!<%W%j%?$NL>A0$r;H$$$^$9!#(B
1$B9TL\$,!"(B@samp{perl}$B$d(B@samp{tcl}$B$N$h$&$JG'<1$5$l$k(B
$B%$%s%?!<%W%j%?%W%m%0%i%`$NL>A0$J$i$P!"(B
Emacs$B$O%$%s%?!<%W%j%?$N%W%m%0%i%`$K$H$C$FE,@Z$J%b!<%I$r;HMQ$7$^$9!#(B
$BJQ?t(B@code{interpreter-mode-alist}$B$O!"(B
$B%$%s%?!<%W%j%?%W%m%0%i%`L>$H%a%8%c!<%b!<%I$H$NBP1~$r;XDj$7$^$9!#(B
@c When the first line starts with @samp{#!}, you cannot (on many
@c systems) use the @samp{-*-} feature on the first line, because the
@c system would get confused when running the interpreter. So Emacs looks
@c for @samp{-*-} on the second line in such files as well as on the
@c first line.
1$B9TL\$,(B@samp{#!}$B$G;O$^$k$H$-$K$O!"(B
$B%$%s%?!<%W%j%?$r<B9T$9$k$H$-$K%7%9%F%`$,:.Mp$9$k$?$a!"(B
1$B9TL\$G$O(B@samp{-*-}$B$N5!G=$r;H$($^$;$s!#(B
$B$=$N$?$a!"$=$N$h$&$J%U%!%$%k$G$O!"(BEmacs$B$O(B1$B9TL\$K2C$($F(B2$B9TL\$G$b(B
@samp{-*-}$B$rC5$7$^$9!#(B
@vindex default-major-mode
@c When you visit a file that does not specify a major mode to use, or
@c when you create a new buffer with @kbd{C-x b}, the variable
@c @code{default-major-mode} specifies which major mode to use. Normally
@c its value is the symbol @code{fundamental-mode}, which specifies
@c Fundamental mode. If @code{default-major-mode} is @code{nil}, the major
@c mode is taken from the previously selected buffer.
$B;HMQ$9$k%a%8%c!<%b!<%I$r;XDj$7$J$$%U%!%$%k$rK,Ld$7$?$H$-!"(B
$B$"$k$$$O!"(B@kbd{C-x b}$B$G?7$?$K%P%C%U%!$r:n$k$H$-$K$O!"(B
$BJQ?t(B@code{default-major-mode}$B$,!";HMQ$9$k%b!<%I$r;XDj$7$^$9!#(B
$BDL>o!"$=$NCM$O!"4pK\!J(Bfundamental$B!K%b!<%I$r;XDj$9$k(B
$B%7%s%\%k(B@code{fundamental-mode}$B$G$9!#(B
@code{default-major-mode}$B$,(B@code{nil}$B$J$i!"(B
$B%a%8%c!<%b!<%I$O$^$($KA*Br$7$F$$$?%P%C%U%!$N%b!<%I$HF1$8$b$N$H$J$j$^$9!#(B
@findex normal-mode
@c If you change the major mode of a buffer, you can go back to the major
@c mode Emacs would choose automatically: use the command @kbd{M-x
@c normal-mode} to do this. This is the same function that
@c @code{find-file} calls to choose the major mode. It also processes
@c the file's local variables list if any.
$B%P%C%U%!$N%a%8%c!<%b!<%I$rJQ99$7$F$b!"(B
Emacs$B$,<+F0E*$KA*Br$9$k%a%8%c!<%b!<%I$KLa$l$^$9!#(B
$B$=$l$K$O!"%3%^%s%I(B@kbd{M-x normal-mode}$B$r;H$$$^$9!#(B
$B$3$N%3%^%s%I$O!"%a%8%c!<%b!<%I$rA*Br$9$k$?$a$K(B
@code{find-file}$B$,8F$S=P$94X?t$HF1$84X?t$G$9!#(B
$B$3$N4X?t$O!"%U%!%$%kCf$K%m!<%+%kJQ?t%j%9%H$,$"$l$P$=$l$b=hM}$7$^$9!#(B
@vindex change-major-mode-with-file-name
@c The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to
@c a new major mode if the new file name implies a mode (@pxref{Saving}).
@c However, this does not happen if the buffer contents specify a major
@c mode, and certain ``special'' major modes do not allow the mode to
@c change. You can turn off this mode-changing feature by setting
@c @code{change-major-mode-with-file-name} to @code{nil}.
$B%3%^%s%I(B@kbd{C-x C-w}$B$H(B@code{set-visited-file-name}$B$O!"(B
$B?7$7$$%U%!%$%kL>$,%b!<%I$r<($9$b$N$G$"$k$J$i!"(B
$B?7$7$$%a%8%c!<%b!<%I$KJQ99$7$^$9!J(B@pxref{Saving}$B!K!#(B
$B$7$+$7!"%P%C%U%!$NFbMF$,%a%8%c!<%b!<%I$r;XDj$7$F$$$F!"$+$D!"(B
$B$"$k!XFCJL$J!Y%a%8%c!<%b!<%I$,$=$N%b!<%I$NJQ99$r5v$5$J$$$J$i!"(B
$B%a%8%c!<%b!<%I$OJQ99$5$l$^$;$s!#(B
@code{change-major-mode-with-file-name}$B$r(B@code{nil}$B$K@_Dj$9$k$H!"(B
$B$3$N%b!<%IJQ995!G=$r%*%U$K$G$-$^$9!#(B
|