annotate doc/emacs/major.texi @ 100666:dab9cf44bf3f

In comments, write delete_frame instead of Fdelete_frame.
author Martin Rudalics <rudalics@gmx.at>
date Tue, 23 Dec 2008 07:28:06 +0000
parents 42ce934093e6
children cb5d2387102c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84253
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
1 @c This is part of the Emacs manual.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
2 @c Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1997, 2000, 2001,
87903
5d58981e6690 Merge from emacs--rel--22
Miles Bader <miles@gnu.org>
parents: 86148
diff changeset
3 @c 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
84253
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
4 @c See file emacs.texi for copying conditions.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
5 @node Major Modes, Indentation, International, Top
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 @chapter Major Modes
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
7 @cindex major modes
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
8 @cindex mode, major
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
9 @kindex TAB @r{(and major modes)}
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
10 @kindex DEL @r{(and major modes)}
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
11 @kindex C-j @r{(and major modes)}
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
12
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
13 Emacs provides many alternative @dfn{major modes}, each of which
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
14 customizes Emacs for editing text of a particular sort. The major modes
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
15 are mutually exclusive, and each buffer has one major mode at any time.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
16 The mode line normally shows the name of the current major mode, in
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
17 parentheses (@pxref{Mode Line}).
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
18
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
19 The least specialized major mode is called @dfn{Fundamental mode}.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
20 This mode has no mode-specific redefinitions or variable settings, so
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21 that each Emacs command behaves in its most general manner, and each
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 user option variable is in its default state. For editing text of a
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 specific type that Emacs knows about, such as Lisp code or English
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24 text, you should switch to the appropriate major mode, such as Lisp
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 mode or Text mode.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 Selecting a major mode changes the meanings of a few keys to become
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28 more specifically adapted to the language being edited. The ones that
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 are changed frequently are @key{TAB}, @key{DEL}, and @kbd{C-j}. The
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 prefix key @kbd{C-c} normally contains mode-specific commands. In
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 addition, the commands which handle comments use the mode to determine
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32 how comments are to be delimited. Many major modes redefine the
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 syntactical properties of characters appearing in the buffer.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 @xref{Syntax}.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36 The major modes fall into three major groups. The first group
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 contains modes for normal text, either plain or with mark-up. It
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
38 includes Text mode, HTML mode, SGML mode, @TeX{} mode and Outline
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 mode. The second group contains modes for specific programming
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 languages. These include Lisp mode (which has several variants), C
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 mode, Fortran mode, and others. The remaining major modes are not
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
42 intended for use on users' files; they are used in buffers created for
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 specific purposes by Emacs, such as Dired mode for buffers made by
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 Dired (@pxref{Dired}), Mail mode for buffers made by @kbd{C-x m}
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45 (@pxref{Sending Mail}), and Shell mode for buffers used for
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 communicating with an inferior shell process (@pxref{Interactive
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 Shell}).
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 Most programming-language major modes specify that only blank lines
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
50 separate paragraphs. This is to make the paragraph commands useful.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
51 (@xref{Paragraphs}.) They also cause Auto Fill mode to use the
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 definition of @key{TAB} to indent the new lines it creates. This is
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 because most lines in a program are usually indented
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54 (@pxref{Indentation}).
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 @menu
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 * Choosing Modes:: How major modes are specified or chosen.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 @end menu
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 @node Choosing Modes,,Major Modes,Major Modes
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 @section How Major Modes are Chosen
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 @cindex choosing a major mode
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 You can select a major mode explicitly for the current buffer, but
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 most of the time Emacs determines which mode to use based on the file
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 name or on special text in the file.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
67
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
68 To explicitly select a new major, you use an @kbd{M-x} command.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 Take the name of a major mode and add @code{-mode} to get the name of
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
70 the command to select that mode. Thus, you can enter Lisp mode by
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
71 executing @kbd{M-x lisp-mode}.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 @vindex auto-mode-alist
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
74 When you visit a file, Emacs usually chooses the right major mode
99006
42ce934093e6 Minor language tweaks (suggested by rms).
Chong Yidong <cyd@stupidchicken.com>
parents: 98954
diff changeset
75 automatically. Normally, it makes the choice based on the file
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
76 name---for example, files whose names end in @samp{.c} are normally
99006
42ce934093e6 Minor language tweaks (suggested by rms).
Chong Yidong <cyd@stupidchicken.com>
parents: 98954
diff changeset
77 edited in C mode---but sometimes it chooses the major mode based on
42ce934093e6 Minor language tweaks (suggested by rms).
Chong Yidong <cyd@stupidchicken.com>
parents: 98954
diff changeset
78 the contents of the file. Here is the exact procedure:
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
79
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
80 First, Emacs checks whether the file contains a file-local variable
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
81 that specifies the major mode. If so, it uses that major mode,
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
82 ignoring all other criteria. @xref{File Variables}. There are
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
83 several methods to specify a major mode using a file-local variable;
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
84 the simplest is to put the mode name in the first nonblank line,
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
85 preceded and followed by @samp{-*-}. Other text may appear on the
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
86 line as well. For example,
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
87
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
88 @example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
89 ; -*-Lisp-*-
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
90 @end example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
91
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
92 @noindent
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
93 tells Emacs to use Lisp mode. Note how the semicolon is used to make
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
94 Lisp treat this line as a comment. Alternatively, you could write
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
95
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
96 @example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
97 ; -*- mode: Lisp;-*-
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
98 @end example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
99
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
100 @noindent
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
101 The latter format allows you to specify local variables as well, like
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
102 this:
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
103
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
104 @example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
105 ; -*- mode: Lisp; tab-width: 4; -*-
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
106 @end example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
107
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
108 @vindex interpreter-mode-alist
99006
42ce934093e6 Minor language tweaks (suggested by rms).
Chong Yidong <cyd@stupidchicken.com>
parents: 98954
diff changeset
109 Second, Emacs checks whether the file's contents begin with
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
110 @samp{#!}. If so, that indicates that the file can serve as an
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
111 executable shell command, which works by running an interpreter named
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
112 on the file's first line (the rest of the file is used as input to the
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
113 interpreter). Therefore, Emacs tries to use the interpreter name to
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
114 choose a mode. For instance, a file that begins with
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
115 @samp{#!/usr/bin/perl} is opened in Perl mode. The variable
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
116 @code{interpreter-mode-alist} specifies the correspondence between
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
117 interpreter program names and major modes.
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
118
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
119 When the first line starts with @samp{#!}, you usually cannot use
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
120 the @samp{-*-} feature on the first line, because the system would get
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
121 confused when running the interpreter. So Emacs looks for @samp{-*-}
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
122 on the second line in such files as well as on the first line. The
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
123 same is true for man pages which start with the magic string
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
124 @samp{'\"} to specify a list of troff preprocessors.
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
125
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
126 @vindex magic-mode-alist
99006
42ce934093e6 Minor language tweaks (suggested by rms).
Chong Yidong <cyd@stupidchicken.com>
parents: 98954
diff changeset
127 Third, Emacs tries to determine the major mode by looking at the
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
128 text at the start of the buffer, based on the variable
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
129 @code{magic-mode-alist}. By default, this variable is @code{nil} (an
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
130 empty list), so Emacs skips this step; however, you can customize it
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
131 in your init file (@pxref{Init File}). The value should be a list of
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
132 elements of the form
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
133
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
134 @example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
135 (@var{regexp} . @var{mode-function})
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
136 @end example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
137
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
138 @noindent
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
139 where @var{regexp} is a regular expression (@pxref{Regexps}), and
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
140 @var{mode-function} is a Lisp function that toggles a major mode. If
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
141 the text at the beginning of the file matches @var{regexp}, Emacs
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
142 chooses the major mode specified by @var{mode-function}.
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
143
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
144 Alternatively, an element of @code{magic-mode-alist} may have the form
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
145
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
146 @example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
147 (@var{match-function} . @var{mode-function})
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
148 @end example
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
149
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
150 @noindent
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
151 where @var{match-function} is a Lisp function that is called at the
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
152 beginning of the buffer; if the function returns non-@code{nil}, Emacs
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
153 set the major mode wit @var{mode-function}.
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
154
99006
42ce934093e6 Minor language tweaks (suggested by rms).
Chong Yidong <cyd@stupidchicken.com>
parents: 98954
diff changeset
155 Fourth---if Emacs still hasn't found a suitable major mode---it
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
156 looks at the file's name. The correspondence between file names and
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
157 major modes is controlled by the variable @code{auto-mode-alist}. Its
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
158 value is a list in which each element has this form,
84253
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
159
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
160 @example
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
161 (@var{regexp} . @var{mode-function})
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
162 @end example
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
163
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
164 @noindent
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
165 or this form,
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
166
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
167 @example
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
168 (@var{regexp} @var{mode-function} @var{flag})
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
169 @end example
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
170
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
171 @noindent
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
172 For example, one element normally found in the list has the form
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
173 @code{(@t{"\\.c\\'"} . c-mode)}, and it is responsible for selecting C
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
174 mode for files whose names end in @file{.c}. (Note that @samp{\\} is
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
175 needed in Lisp syntax to include a @samp{\} in the string, which must
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
176 be used to suppress the special meaning of @samp{.} in regexps.) If
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
177 the element has the form @code{(@var{regexp} @var{mode-function}
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
178 @var{flag})} and @var{flag} is non-@code{nil}, then after calling
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
179 @var{mode-function}, Emacs discards the suffix that matched
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
180 @var{regexp} and searches the list again for another match.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
181
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
182 @vindex auto-mode-case-fold
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
183 On systems with case-insensitive file names, such as Microsoft
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
184 Windows, Emacs performs a single case-insensitive search through
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
185 @code{auto-mode-alist}. On other systems, Emacs normally performs a
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
186 single case-sensitive search through the alist. However, if you
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
187 change the variable @code{auto-mode-case-fold} to @code{t}, Emacs
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
188 performs a second case-insensitive search if the first search fails.
84253
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
189
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
190 @vindex magic-fallback-mode-alist
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
191 Finally, if Emacs @emph{still} hasn't found a major mode to use, it
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
192 compares the text at the start of the buffer to the variable
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
193 @code{magic-fallback-mode-alist}. This variable works like
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
194 @code{magic-mode-alist}, described above, except that is consulted
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
195 only after @code{auto-mode-alist}. By default,
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
196 @code{magic-fallback-mode-alist} contains forms that check for image
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
197 files, HTML/XML/SGML files, and Postscript files.
84253
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
198
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
199 @vindex default-major-mode
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
200 When you visit a file that does not specify a major mode to use, or
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
201 when you create a new buffer with @kbd{C-x b}, the variable
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
202 @code{default-major-mode} specifies which major mode to use. Normally
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
203 its value is the symbol @code{fundamental-mode}, which specifies
98954
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
204 Fundamental mode. If @code{default-major-mode} is @code{nil}, the
576242ffca27 (Choosing Modes): Make mode selection sequence more obvious by
Chong Yidong <cyd@stupidchicken.com>
parents: 87903
diff changeset
205 major mode is taken from the previously current buffer.
84253
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
206
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
207 @findex normal-mode
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
208 If you change the major mode of a buffer, you can go back to the major
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
209 mode Emacs would choose automatically: use the command @kbd{M-x
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
210 normal-mode} to do this. This is the same function that
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
211 @code{find-file} calls to choose the major mode. It also processes
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
212 the file's @samp{-*-} line or local variables list (if any).
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
213 @xref{File Variables}.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
214
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
215 @vindex change-major-mode-with-file-name
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
216 The commands @kbd{C-x C-w} and @code{set-visited-file-name} change to
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
217 a new major mode if the new file name implies a mode (@pxref{Saving}).
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
218 (@kbd{C-x C-s} does this too, if the buffer wasn't visiting a file.)
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
219 However, this does not happen if the buffer contents specify a major
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
220 mode, and certain ``special'' major modes do not allow the mode to
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
221 change. You can turn off this mode-changing feature by setting
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
222 @code{change-major-mode-with-file-name} to @code{nil}.
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
223
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
224 @ignore
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
225 arch-tag: f2558800-cf32-4839-8acb-7d3b4df2a155
33cbe0daee0d Move here from ../../man
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
226 @end ignore