X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/d94888e3f85e5f049358afde6c92c24c48e897ca..d8aa9ea9093472abd0a95c495e46bfd6638e58c6:/man/major.texi diff --git a/man/major.texi b/man/major.texi index 35b95d06ba..74613a2432 100644 --- a/man/major.texi +++ b/man/major.texi @@ -1,5 +1,6 @@ @c This is part of the Emacs manual. -@c Copyright (C) 1985, 86, 87, 93, 94, 95, 97, 2000 Free Software Foundation, Inc. +@c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001, +@c 2002, 2003, 2004, 2005 Free Software Foundation, Inc. @c See file emacs.texi for copying conditions. @node Major Modes, Indentation, International, Top @chapter Major Modes @@ -18,9 +19,10 @@ parentheses (@pxref{Mode Line}). The least specialized major mode is called @dfn{Fundamental mode}. This mode has no mode-specific redefinitions or variable settings, so that each Emacs command behaves in its most general manner, and each -option is in its default state. For editing text of a specific type -that Emacs knows about, such as Lisp code or English text, you should -switch to the appropriate major mode, such as Lisp mode or Text mode. +user option variable is in its default state. For editing text of a +specific type that Emacs knows about, such as Lisp code or English +text, you should switch to the appropriate major mode, such as Lisp +mode or Text mode. Selecting a major mode changes the meanings of a few keys to become more specifically adapted to the language being edited. The ones that @@ -31,14 +33,16 @@ how comments are to be delimited. Many major modes redefine the syntactical properties of characters appearing in the buffer. @xref{Syntax}. - The major modes fall into three major groups. Lisp mode (which has -several variants), C mode, Fortran mode and others are for specific -programming languages. Text mode, Nroff mode, SGML mode, @TeX{} mode -and Outline mode are for normal text, plain or marked up. The remaining -major modes are not intended for use on users' files; they are used in -buffers created for specific purposes by Emacs, such as Dired mode for -buffers made by Dired (@pxref{Dired}), Mail mode for buffers made by -@kbd{C-x m} (@pxref{Sending Mail}), and Shell mode for buffers used for + The major modes fall into three major groups. The first group +contains modes for normal text, either plain or with mark-up. It +includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline +mode. The second group contains modes for specific programming +languages. These include Lisp mode (which has several variants), C +mode, Fortran mode, and others. The remaining major modes are not +intended for use on users' files; they are used in buffers created for +specific purposes by Emacs, such as Dired mode for buffers made by +Dired (@pxref{Dired}), Mail mode for buffers made by @kbd{C-x m} +(@pxref{Sending Mail}), and Shell mode for buffers used for communicating with an inferior shell process (@pxref{Interactive Shell}). @@ -88,15 +92,30 @@ or this form, For example, one element normally found in the list has the form @code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C mode for files whose names end in @file{.c}. (Note that @samp{\\} is -needed in Lisp syntax to include a @samp{\} in the string, which is -needed to suppress the special meaning of @samp{.} in regexps.) If the -element has the form @code{(@var{regexp} @var{mode-function} +needed in Lisp syntax to include a @samp{\} in the string, which must +be used to suppress the special meaning of @samp{.} in regexps.) If +the element has the form @code{(@var{regexp} @var{mode-function} @var{flag})} and @var{flag} is non-@code{nil}, then after calling -@var{function}, the suffix that matched @var{regexp} is discarded and -the list is searched again for another match. +@var{mode-function}, Emacs discards the suffix that matched +@var{regexp} and searches the list again for another match. - You can specify which major mode should be used for editing a certain -file by a special sort of text in the first nonblank line of the file. The +@vindex magic-mode-alist + Sometimes the major mode is determined from the way the file's text +begins. The variable @code{magic-mode-alist} controls this. Its value +is a list of elements of this form: + +@example +(@var{regexp} . @var{mode-function}) +@end example + +@noindent +This looks like an element of @code{auto-mode-alist}, but it doesn't work +the same: this @var{regexp} is matched against the text at the start +of the buffer, not against the file name. @code{magic-mode-alist} +takes priority over @code{auto-mode-alist}. + + You can specify the major mode to use for editing a certain file by +special text in the first nonblank line of the file. The mode name should appear in this line both preceded and followed by @samp{-*-}. Other text may appear on the line as well. For example, @@ -106,7 +125,7 @@ mode name should appear in this line both preceded and followed by @noindent tells Emacs to use Lisp mode. Such an explicit specification overrides -any defaulting based on the file name. Note how the semicolon is used +any defaults based on the file name. Note how the semicolon is used to make Lisp treat this line as a comment. Another format of mode specification is @@ -151,19 +170,25 @@ when you create a new buffer with @kbd{C-x b}, the variable @code{default-major-mode} specifies which major mode to use. Normally its value is the symbol @code{fundamental-mode}, which specifies Fundamental mode. If @code{default-major-mode} is @code{nil}, the major -mode is taken from the previously selected buffer. +mode is taken from the previously current buffer. @findex normal-mode If you change the major mode of a buffer, you can go back to the major mode Emacs would choose automatically: use the command @kbd{M-x normal-mode} to do this. This is the same function that @code{find-file} calls to choose the major mode. It also processes -the file's local variables list if any. +the file's @samp{-*-} line or local variables list (if any). +@xref{File Variables}. @vindex change-major-mode-with-file-name The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to a new major mode if the new file name implies a mode (@pxref{Saving}). +(@kbd{C-x C-s} does this too, if the buffer wasn't visiting a file.) However, this does not happen if the buffer contents specify a major mode, and certain ``special'' major modes do not allow the mode to change. You can turn off this mode-changing feature by setting @code{change-major-mode-with-file-name} to @code{nil}. + +@ignore + arch-tag: f2558800-cf32-4839-8acb-7d3b4df2a155 +@end ignore