annotate man/lispref/modes.texi @ 5044:e84a30b0e4a2

remove duplicative code in change_frame_size() -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2010-02-15 Ben Wing <ben@xemacs.org> * frame.c (change_frame_size_1): Simplify the logic in this function. (1) Don't allow 0 as the value of height or width. The old code that tried to allow this was totally broken, anyway, so obviously this never happens any more. (2) Don't duplicate the code in frame_conversion_internal() that converts displayable pixel size to total pixel size -- just call that function.
author Ben Wing <ben@xemacs.org>
date Mon, 15 Feb 2010 22:58:10 -0600
parents e6d43c299b9c
children 9fae6227ede5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 @c -*-texinfo-*-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 @c This is part of the XEmacs Lisp Reference Manual.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3 @c Copyright (C) 1990, 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 @c See the file lispref.texi for copying conditions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 @setfilename ../../info/modes.info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 @node Modes, Documentation, Drag and Drop, Top
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 @chapter Major and Minor Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 @cindex mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 A @dfn{mode} is a set of definitions that customize XEmacs and can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 turned on and off while you edit. There are two varieties of modes:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 @dfn{major modes}, which are mutually exclusive and used for editing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 particular kinds of text, and @dfn{minor modes}, which provide features
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 that users can enable individually.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 This chapter describes how to write both major and minor modes, how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 indicate them in the modeline, and how they run hooks supplied by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 user. For related topics such as keymaps and syntax tables, see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 @ref{Keymaps}, and @ref{Syntax Tables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 * Major Modes:: Defining major modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 * Minor Modes:: Defining minor modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 * Modeline Format:: Customizing the text that appears in the modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25 * Hooks:: How to use hooks; how to write code that provides hooks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 @node Major Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 @section Major Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 @cindex major mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 @cindex Fundamental mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
33 Major modes specialize XEmacs for editing particular kinds of text.
2135
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
34 Each buffer has only one major mode at a time. For each major mode
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
35 there is a function to switch to that mode in the current buffer; its
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
36 name should end in @samp{-mode}. These functions work by setting
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
37 buffer-local variable bindings and other data associated with the
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
38 buffer, such as a local keymap. The effect lasts until you switch
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
39 to another major mode in the same buffer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 The least specialized major mode is called @dfn{Fundamental mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 This mode has no mode-specific definitions or variable settings, so each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 XEmacs command behaves in its default manner, and each option is in its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 default state. All other major modes redefine various keys and options.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 For example, Lisp Interaction mode provides special key bindings for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 @key{LFD} (@code{eval-print-last-sexp}), @key{TAB}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 (@code{lisp-indent-line}), and other keys.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 When you need to write several editing commands to help you perform a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 specialized editing task, creating a new major mode is usually a good
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 idea. In practice, writing a major mode is easy (in contrast to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 writing a minor mode, which is often difficult).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 If the new mode is similar to an old one, it is often unwise to modify
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 the old one to serve two purposes, since it may become harder to use and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 maintain. Instead, copy and rename an existing major mode definition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 and alter the copy---or define a @dfn{derived mode} (@pxref{Derived
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Modes}). For example, Rmail Edit mode, which is in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 @file{emacs/lisp/rmailedit.el}, is a major mode that is very similar to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Text mode except that it provides three additional commands. Its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 definition is distinct from that of Text mode, but was derived from it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62
2135
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
63 Even if the new mode is not an obvious derivative of any other mode,
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
64 it is convenient to use @code{define-derived-mode} with a @code{nil}
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
65 parent argument, since it automatically enforces the most important
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
66 coding conventions for you.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
67
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 Rmail Edit mode is an example of a case where one piece of text is put
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 temporarily into a different major mode so it can be edited in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 different way (with ordinary XEmacs commands rather than Rmail). In such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 cases, the temporary major mode usually has a command to switch back to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 the buffer's usual mode (Rmail mode, in this case). You might be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 tempted to present the temporary redefinitions inside a recursive edit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 and restore the usual ones when the user exits; but this is a bad idea
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 because it constrains the user's options when it is done in more than
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 one buffer: recursive edits must be exited most-recently-entered first.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 Using alternative major modes avoids this limitation. @xref{Recursive
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 Editing}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 The standard XEmacs Lisp library directory contains the code for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 several major modes, in files including @file{text-mode.el},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 @file{texinfo.el}, @file{lisp-mode.el}, @file{c-mode.el}, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 @file{rmail.el}. You can look at these libraries to see how modes are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 written. Text mode is perhaps the simplest major mode aside from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 Fundamental mode. Rmail mode is a complicated and specialized mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 * Major Mode Conventions:: Coding conventions for keymaps, etc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 * Example Major Modes:: Text mode and Lisp modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 * Auto Major Mode:: How XEmacs chooses the major mode automatically.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 * Mode Help:: Finding out how to use a mode.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
92 * Derived Modes:: Defining a new major mode based on another major
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 @node Major Mode Conventions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 @subsection Major Mode Conventions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 The code for existing major modes follows various coding conventions,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 including conventions for local keymap and syntax table initialization,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 global names, and hooks. Please follow these conventions when you
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 define a new major mode:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 Define a command whose name ends in @samp{-mode}, with no arguments,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 that switches to the new mode in the current buffer. This command
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 should set up the keymap, syntax table, and local variables in an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 existing buffer without changing the buffer's text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 Write a documentation string for this command that describes the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 special commands available in this mode. @kbd{C-h m}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 (@code{describe-mode}) in your mode will display this string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 The documentation string may include the special documentation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 substrings, @samp{\[@var{command}]}, @samp{\@{@var{keymap}@}}, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 @samp{\<@var{keymap}>}, that enable the documentation to adapt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 automatically to the user's own key bindings. @xref{Keys in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 Documentation}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 The major mode command should start by calling
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 @code{kill-all-local-variables}. This is what gets rid of the local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 variables of the major mode previously in effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 The major mode command should set the variable @code{major-mode} to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 major mode command symbol. This is how @code{describe-mode} discovers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 which documentation to print.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 The major mode command should set the variable @code{mode-name} to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 ``pretty'' name of the mode, as a string. This appears in the mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 @cindex functions in modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 Since all global names are in the same name space, all the global
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 variables, constants, and functions that are part of the mode should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 have names that start with the major mode name (or with an abbreviation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 of it if the name is long). @xref{Style Tips}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 @cindex keymaps in modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 The major mode should usually have its own keymap, which is used as the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 local keymap in all buffers in that mode. The major mode function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 should call @code{use-local-map} to install this local map.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 @xref{Active Keymaps}, for more information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 This keymap should be kept in a global variable named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 @code{@var{modename}-mode-map}. Normally the library that defines the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 mode sets this variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 @cindex syntax tables in modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 The mode may have its own syntax table or may share one with other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 related modes. If it has its own syntax table, it should store this in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 a variable named @code{@var{modename}-mode-syntax-table}. @xref{Syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 Tables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 @cindex abbrev tables in modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 The mode may have its own abbrev table or may share one with other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 related modes. If it has its own abbrev table, it should store this in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 a variable named @code{@var{modename}-mode-abbrev-table}. @xref{Abbrev
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 Tables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 Use @code{defvar} to set mode-related variables, so that they are not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 reinitialized if they already have a value. (Such reinitialization
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 could discard customizations made by the user.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 @cindex buffer-local variables in modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 To make a buffer-local binding for an Emacs customization variable, use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 @code{make-local-variable} in the major mode command, not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 @code{make-variable-buffer-local}. The latter function would make the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 variable local to every buffer in which it is subsequently set, which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 would affect buffers that do not use this mode. It is undesirable for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 mode to have such global effects. @xref{Buffer-Local Variables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 It's ok to use @code{make-variable-buffer-local}, if you wish, for a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 variable used only within a single Lisp package.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 @cindex mode hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 @cindex major mode hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 Each major mode should have a @dfn{mode hook} named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 @code{@var{modename}-mode-hook}. The major mode command should run that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 hook, with @code{run-hooks}, as the very last thing it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 does. @xref{Hooks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 The major mode command may also run the hooks of some more basic modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 For example, @code{indented-text-mode} runs @code{text-mode-hook} as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 well as @code{indented-text-mode-hook}. It may run these other hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 immediately before the mode's own hook (that is, after everything else),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 or it may run them earlier.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 @item
2135
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
202 The major mode command may start by calling some other major mode
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
203 command (called the @dfn{parent mode}) and then alter some of its
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
204 settings. A mode that does this is called a @dfn{derived mode}. The
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
205 recommended way to define one is to use @code{define-derived-mode},
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
206 but this is not required. Such a mode should use
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
207 @code{delay-mode-hooks} around its entire body, including the call to
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
208 the parent mode command and the final call to @code{run-mode-hooks}.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
209 (Using @code{define-derived-mode} does this automatically.)
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
210
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
211 @item
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 If something special should be done if the user switches a buffer from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 this mode to any other major mode, the mode can set a local value for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 @code{change-major-mode-hook}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 If this mode is appropriate only for specially-prepared text, then the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 major mode command symbol should have a property named @code{mode-class}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 with value @code{special}, put on as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 @cindex @code{mode-class} property
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 @cindex @code{special}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (put 'funny-mode 'mode-class 'special)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 This tells XEmacs that new buffers created while the current buffer has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 Funny mode should not inherit Funny mode. Modes such as Dired, Rmail,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 and Buffer List use this feature.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 If you want to make the new mode the default for files with certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 recognizable names, add an element to @code{auto-mode-alist} to select
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 the mode for those file names. If you define the mode command to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 autoload, you should add this element in the same file that calls
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 @code{autoload}. Otherwise, it is sufficient to add the element in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 file that contains the mode definition. @xref{Auto Major Mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 @cindex @file{.emacs} customization
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 In the documentation, you should provide a sample @code{autoload} form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 and an example of how to add to @code{auto-mode-alist}, that users can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 include in their @file{.emacs} files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 @cindex mode loading
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 The top-level forms in the file defining the mode should be written so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 that they may be evaluated more than once without adverse consequences.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 Even if you never load the file more than once, someone else will.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 @defvar change-major-mode-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 This normal hook is run by @code{kill-all-local-variables} before it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 does anything else. This gives major modes a way to arrange for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 something special to be done if the user switches to a different major
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 mode. For best results, make this variable buffer-local, so that it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 will disappear after doing its job and will not interfere with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 subsequent major mode. @xref{Hooks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 @node Example Major Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 @subsection Major Mode Examples
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 Text mode is perhaps the simplest mode besides Fundamental mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 Here are excerpts from @file{text-mode.el} that illustrate many of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 the conventions listed above:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 ;; @r{Create mode-specific tables.}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
272 (defvar text-mode-syntax-table nil
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 "Syntax table used while in text mode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 (if text-mode-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 () ; @r{Do not change the table if it is already set up.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279 (setq text-mode-syntax-table (make-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 (modify-syntax-entry ?\" ". " text-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 (modify-syntax-entry ?\\ ". " text-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 (modify-syntax-entry ?' "w " text-mode-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (defvar text-mode-abbrev-table nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 "Abbrev table used while in text mode.")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 (define-abbrev-table 'text-mode-abbrev-table ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 (defvar text-mode-map nil) ; @r{Create a mode-specific keymap.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 (if text-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 () ; @r{Do not change the keymap if it is already set up.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 (setq text-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 (define-key text-mode-map "\t" 'tab-to-tab-stop)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 (define-key text-mode-map "\es" 'center-line)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (define-key text-mode-map "\eS" 'center-paragraph))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 Here is the complete major mode function definition for Text mode:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (defun text-mode ()
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
308 "Major mode for editing text intended for humans to read.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 Special commands: \\@{text-mode-map@}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 Turning on text-mode runs the hook `text-mode-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 (use-local-map text-mode-map) ; @r{This provides the local keymap.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 (setq mode-name "Text") ; @r{This name goes into the modeline.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 (setq major-mode 'text-mode) ; @r{This is how @code{describe-mode}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 ; @r{finds the doc string to print.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 (setq local-abbrev-table text-mode-abbrev-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 (set-syntax-table text-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (run-hooks 'text-mode-hook)) ; @r{Finally, this permits the user to}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 ; @r{customize the mode with a hook.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 @cindex @file{lisp-mode.el}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 The three Lisp modes (Lisp mode, Emacs Lisp mode, and Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 Interaction mode) have more features than Text mode and the code is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 correspondingly more complicated. Here are excerpts from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 @file{lisp-mode.el} that illustrate how these modes are written.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 @cindex syntax table example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 ;; @r{Create mode-specific table variables.}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
338 (defvar lisp-mode-syntax-table nil "")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 (defvar emacs-lisp-mode-syntax-table nil "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 (defvar lisp-mode-abbrev-table nil "")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 (if (not emacs-lisp-mode-syntax-table) ; @r{Do not change the table}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 ; @r{if it is already set.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 (let ((i 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 (setq emacs-lisp-mode-syntax-table (make-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 ;; @r{Set syntax of chars up to 0 to class of chars that are}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 ;; @r{part of symbol names but not words.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 ;; @r{(The number 0 is @code{48} in the @sc{ascii} character set.)}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
354 (while (< i ?0)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 (modify-syntax-entry i "_ " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 (setq i (1+ i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 @dots{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 ;; @r{Set the syntax for other characters.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 (modify-syntax-entry ? " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 (modify-syntax-entry ?\t " " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 @dots{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 (modify-syntax-entry ?\( "() " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 (modify-syntax-entry ?\) ")( " emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 @dots{}))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 ;; @r{Create an abbrev table for lisp-mode.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 (define-abbrev-table 'lisp-mode-abbrev-table ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 Much code is shared among the three Lisp modes. The following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 function sets various variables; it is called by each of the major Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 mode functions:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 (defun lisp-mode-variables (lisp-syntax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 ;; @r{The @code{lisp-syntax} argument is @code{nil} in Emacs Lisp mode,}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 ;; @r{and @code{t} in the other two Lisp modes.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 (cond (lisp-syntax
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 (if (not lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 ;; @r{The Emacs Lisp mode syntax table always exists, but}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 ;; @r{the Lisp Mode syntax table is created the first time a}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 ;; @r{mode that needs it is called. This is to save space.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 (progn (setq lisp-mode-syntax-table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 (copy-syntax-table emacs-lisp-mode-syntax-table))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 ;; @r{Change some entries for Lisp mode.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 (modify-syntax-entry ?\| "\" "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 (modify-syntax-entry ?\[ "_ "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 (modify-syntax-entry ?\] "_ "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 lisp-mode-syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 (set-syntax-table lisp-mode-syntax-table)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 (setq local-abbrev-table lisp-mode-abbrev-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 @dots{})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 Functions such as @code{forward-paragraph} use the value of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 @code{paragraph-start} variable. Since Lisp code is different from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 ordinary text, the @code{paragraph-start} variable needs to be set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 specially to handle Lisp. Also, comments are indented in a special
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 fashion in Lisp and the Lisp modes need their own mode-specific
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 @code{comment-indent-function}. The code to set these variables is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 rest of @code{lisp-mode-variables}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 (make-local-variable 'paragraph-start)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 ;; @r{Having @samp{^} is not clean, but @code{page-delimiter}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ;; @r{has them too, and removing those is a pain.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 (setq paragraph-start (concat "^$\\|" page-delimiter))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 @dots{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 (make-local-variable 'comment-indent-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 (setq comment-indent-function 'lisp-comment-indent))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 Each of the different Lisp modes has a slightly different keymap. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 example, Lisp mode binds @kbd{C-c C-l} to @code{run-lisp}, but the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 Lisp modes do not. However, all Lisp modes have some commands in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 common. The following function adds these common commands to a given
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 (defun lisp-mode-commands (map)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 (define-key map "\e\C-q" 'indent-sexp)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 (define-key map "\177" 'backward-delete-char-untabify)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 (define-key map "\t" 'lisp-indent-line))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 Here is an example of using @code{lisp-mode-commands} to initialize a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 keymap, as part of the code for Emacs Lisp mode. First we declare a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 variable with @code{defvar} to hold the mode-specific keymap. When this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 @code{defvar} executes, it sets the variable to @code{nil} if it was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 void. Then we set up the keymap if the variable is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 This code avoids changing the keymap or the variable if it is already
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 set up. This lets the user customize the keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
455 (defvar emacs-lisp-mode-map () "")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 (if emacs-lisp-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 (setq emacs-lisp-mode-map (make-sparse-keymap))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 (define-key emacs-lisp-mode-map "\e\C-x" 'eval-defun)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 (lisp-mode-commands emacs-lisp-mode-map))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 Finally, here is the complete major mode function definition for
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
465 Emacs Lisp mode.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 (defun emacs-lisp-mode ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 "Major mode for editing Lisp code to run in XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 Commands:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 Delete converts tabs to spaces as it moves back.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 Blank lines separate paragraphs. Semicolons start comments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 \\@{emacs-lisp-mode-map@}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 Entry to this mode runs the hook `emacs-lisp-mode-hook'."
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 (interactive)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 (kill-all-local-variables)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (use-local-map emacs-lisp-mode-map) ; @r{This provides the local keymap.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 (set-syntax-table emacs-lisp-mode-syntax-table)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 (setq major-mode 'emacs-lisp-mode) ; @r{This is how @code{describe-mode}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 ; @r{finds out what to describe.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 (setq mode-name "Emacs-Lisp") ; @r{This goes into the modeline.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 (lisp-mode-variables nil) ; @r{This defines various variables.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (run-hooks 'emacs-lisp-mode-hook)) ; @r{This permits the user to use a}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 ; @r{hook to customize the mode.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 @node Auto Major Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 @subsection How XEmacs Chooses a Major Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 Based on information in the file name or in the file itself, XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 automatically selects a major mode for the new buffer when a file is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 visited.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 @deffn Command fundamental-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 Fundamental mode is a major mode that is not specialized for anything
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 in particular. Other major modes are defined in effect by comparison
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 with this one---their definitions say what to change, starting from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 Fundamental mode. The @code{fundamental-mode} function does @emph{not}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 run any hooks; you're not supposed to customize it. (If you want Emacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 to behave differently in Fundamental mode, change the @emph{global}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 state of Emacs.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 @deffn Command normal-mode &optional find-file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 This function establishes the proper major mode and local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 bindings for the current buffer. First it calls @code{set-auto-mode},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 then it runs @code{hack-local-variables} to parse, and bind or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 evaluate as appropriate, any local variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 If the @var{find-file} argument to @code{normal-mode} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 non-@code{nil}, @code{normal-mode} assumes that the @code{find-file}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 function is calling it. In this case, it may process a local variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 list at the end of the file and in the @samp{-*-} line. The variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 @code{enable-local-variables} controls whether to do so.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 If you run @code{normal-mode} interactively, the argument
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 @var{find-file} is normally @code{nil}. In this case,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 @code{normal-mode} unconditionally processes any local variables list.
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
525 @xref{File variables, , Local Variables in Files, xemacs, The XEmacs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 Reference Manual}, for the syntax of the local variables section of a file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 @cindex file mode specification error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 @code{normal-mode} uses @code{condition-case} around the call to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 major mode function, so errors are caught and reported as a @samp{File
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 mode specification error}, followed by the original error message.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 @defopt enable-local-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 This variable controls processing of local variables lists in files
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 being visited. A value of @code{t} means process the local variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 lists unconditionally; @code{nil} means ignore them; anything else means
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 ask the user what to do for each file. The default value is @code{t}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 @defvar ignored-local-variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 This variable holds a list of variables that should not be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 set by a local variables list. Any value specified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 for one of these variables is ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 In addition to this list, any variable whose name has a non-@code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 @code{risky-local-variable} property is also ignored.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 @defopt enable-local-eval
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 This variable controls processing of @samp{Eval:} in local variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 lists in files being visited. A value of @code{t} means process them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 unconditionally; @code{nil} means ignore them; anything else means ask
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 the user what to do for each file. The default value is @code{maybe}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 @defun set-auto-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 @cindex visited file mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 This function selects the major mode that is appropriate for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 current buffer. It may base its decision on the value of the @w{@samp{-*-}}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 line, on the visited file name (using @code{auto-mode-alist}), or on the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 value of a local variable. However, this function does not look for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 the @samp{mode:} local variable near the end of a file; the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 @code{hack-local-variables} function does that. @xref{Choosing Modes, ,
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
565 How Major Modes are Chosen, xemacs, The XEmacs Lisp Reference Manual}.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
568 @defopt default-major-mode
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 This variable holds the default major mode for new buffers. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 standard value is @code{fundamental-mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 If the value of @code{default-major-mode} is @code{nil}, XEmacs uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 the (previously) current buffer's major mode for the major mode of a new
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 buffer. However, if the major mode symbol has a @code{mode-class}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 property with value @code{special}, then it is not used for new buffers;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 Fundamental mode is used instead. The modes that have this property are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 those such as Dired and Rmail that are useful only with text that has
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 been specially prepared.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 @end defopt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 @defun set-buffer-major-mode buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582 This function sets the major mode of @var{buffer} to the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 @code{default-major-mode}. If that variable is @code{nil}, it uses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 the current buffer's major mode (if that is suitable).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 The low-level primitives for creating buffers do not use this function,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 but medium-level commands such as @code{switch-to-buffer} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 @code{find-file-noselect} use it whenever they create buffers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 @defvar initial-major-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 @cindex @samp{*scratch*}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 The value of this variable determines the major mode of the initial
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 @samp{*scratch*} buffer. The value should be a symbol that is a major
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 mode command name. The default value is @code{lisp-interaction-mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 @defvar auto-mode-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 This variable contains an association list of file name patterns
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (regular expressions; @pxref{Regular Expressions}) and corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 major mode functions. Usually, the file name patterns test for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 suffixes, such as @samp{.el} and @samp{.c}, but this need not be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 case. An ordinary element of the alist looks like @code{(@var{regexp} .
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 @var{mode-function})}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606 For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 (("^/tmp/fol/" . text-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 ("\\.texinfo\\'" . texinfo-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 ("\\.texi\\'" . texinfo-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 ("\\.el\\'" . emacs-lisp-mode)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
616 ("\\.c\\'" . c-mode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 ("\\.h\\'" . c-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 @dots{})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 When you visit a file whose expanded file name (@pxref{File Name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 Expansion}) matches a @var{regexp}, @code{set-auto-mode} calls the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 corresponding @var{mode-function}. This feature enables XEmacs to select
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 the proper major mode for most files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 If an element of @code{auto-mode-alist} has the form @code{(@var{regexp}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 @var{function} t)}, then after calling @var{function}, XEmacs searches
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 @code{auto-mode-alist} again for a match against the portion of the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 name that did not match before.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 This match-again feature is useful for uncompression packages: an entry
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 of the form @code{("\\.gz\\'" . @var{function})} can uncompress the file
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 and then put the uncompressed file in the proper mode according to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 name sans @samp{.gz}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 Here is an example of how to prepend several pattern pairs to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 @code{auto-mode-alist}. (You might use this sort of expression in your
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 @file{.emacs} file.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 (setq auto-mode-alist
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
644 (append
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 ;; @r{File name starts with a dot.}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
646 '(("/\\.[^/]*\\'" . fundamental-mode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 ;; @r{File name has no dot.}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
648 ("[^\\./]*\\'" . fundamental-mode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 ;; @r{File name ends in @samp{.C}.}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 ("\\.C\\'" . c++-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
651 auto-mode-alist))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 @defvar interpreter-mode-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 This variable specifies major modes to use for scripts that specify a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 command interpreter in an @samp{#!} line. Its value is a list of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 elements of the form @code{(@var{interpreter} . @var{mode})}; for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 example, @code{("perl" . perl-mode)} is one element present by default.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 The element says to use mode @var{mode} if the file specifies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 @var{interpreter}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 This variable is applicable only when the @code{auto-mode-alist} does
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 not indicate which major mode to use.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 @defun hack-local-variables &optional force
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 This function parses, and binds or evaluates as appropriate, any local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 variables for the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 The handling of @code{enable-local-variables} documented for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 @code{normal-mode} actually takes place here. The argument @var{force}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 usually comes from the argument @var{find-file} given to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 @code{normal-mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 @node Mode Help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 @subsection Getting Help about a Major Mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 @cindex mode help
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 @cindex help for major mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 @cindex documentation for major mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 The @code{describe-mode} function is used to provide information
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 about major modes. It is normally called with @kbd{C-h m}. The
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 @code{describe-mode} function uses the value of @code{major-mode},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 which is why every major mode function needs to set the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 @code{major-mode} variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 @deffn Command describe-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 This function displays the documentation of the current major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 The @code{describe-mode} function calls the @code{documentation}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 function using the value of @code{major-mode} as an argument. Thus, it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 displays the documentation string of the major mode function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 (@xref{Accessing Documentation}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 @end deffn
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 @defvar major-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 This variable holds the symbol for the current buffer's major mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 This symbol should have a function definition that is the command to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 switch to that major mode. The @code{describe-mode} function uses the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 documentation string of the function as the documentation of the major
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 @node Derived Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 @subsection Defining Derived Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 It's often useful to define a new major mode in terms of an existing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 one. An easy way to do this is to use @code{define-derived-mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 @defmac define-derived-mode variant parent name docstring body@dots{}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 This construct defines @var{variant} as a major mode command, using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 @var{name} as the string form of the mode name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 The new command @var{variant} is defined to call the function
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 @var{parent}, then override certain aspects of that parent mode:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
720 @itemize @bullet
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 The new mode has its own keymap, named @code{@var{variant}-map}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 @code{define-derived-mode} initializes this map to inherit from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 @code{@var{parent}-map}, if it is not already set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 The new mode has its own syntax table, kept in the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 @code{@var{variant}-syntax-table}.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
729 @code{define-derived-mode} initializes this variable by copying
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 @code{@var{parent}-syntax-table}, if it is not already set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 The new mode has its own abbrev table, kept in the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 @code{@var{variant}-abbrev-table}.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
735 @code{define-derived-mode} initializes this variable by copying
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 @code{@var{parent}-abbrev-table}, if it is not already set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 The new mode has its own mode hook, @code{@var{variant}-hook},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 which it runs in standard fashion as the very last thing that it does.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
741 (The new mode also runs the mode hook of @var{parent} as part
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 of calling @var{parent}.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 In addition, you can specify how to override other aspects of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 @var{parent} with @var{body}. The command @var{variant}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
747 evaluates the forms in @var{body} after setting up all its usual
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 overrides, just before running @code{@var{variant}-hook}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 The argument @var{docstring} specifies the documentation string for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 new mode. If you omit @var{docstring}, @code{define-derived-mode}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 generates a documentation string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 Here is a hypothetical example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 (define-derived-mode hypertext-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 text-mode "Hypertext"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 "Major mode for hypertext.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 \\@{hypertext-mode-map@}"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 (setq case-fold-search nil))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (define-key hypertext-mode-map
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 [down-mouse-3] 'do-hyper-link)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 @end example
2135
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
766
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
767 Do not write an @code{interactive} spec in the definition;
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
768 @code{define-derived-mode} does that automatically.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 @end defmac
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 @node Minor Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 @section Minor Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 @cindex minor mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 A @dfn{minor mode} provides features that users may enable or disable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 independently of the choice of major mode. Minor modes can be enabled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 individually or in combination. Minor modes would be better named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 ``Generally available, optional feature modes'' except that such a name is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 unwieldy.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 A minor mode is not usually a modification of single major mode. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 example, Auto Fill mode may be used in any major mode that permits text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 insertion. To be general, a minor mode must be effectively independent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 of the things major modes do.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 A minor mode is often much more difficult to implement than a major
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 mode. One reason is that you should be able to activate and deactivate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 minor modes in any order. A minor mode should be able to have its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 desired effect regardless of the major mode and regardless of the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 minor modes in effect.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 Often the biggest problem in implementing a minor mode is finding a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 way to insert the necessary hook into the rest of XEmacs. Minor mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 keymaps make this easier than it used to be.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 * Minor Mode Conventions:: Tips for writing a minor mode.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 * Keymaps and Minor Modes:: How a minor mode can have its own keymap.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 @node Minor Mode Conventions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 @subsection Conventions for Writing Minor Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 @cindex minor mode conventions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 @cindex conventions for writing minor modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 There are conventions for writing minor modes just as there are for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 major modes. Several of the major mode conventions apply to minor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 modes as well: those regarding the name of the mode initialization
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 function, the names of global symbols, and the use of keymaps and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 other tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 In addition, there are several conventions that are specific to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 minor modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 @itemize @bullet
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 @cindex mode variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 Make a variable whose name ends in @samp{-mode} to represent the minor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 mode. Its value should enable or disable the mode (@code{nil} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 disable; anything else to enable.) We call this the @dfn{mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 variable}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 This variable is used in conjunction with the @code{minor-mode-alist} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 display the minor mode name in the modeline. It can also enable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 or disable a minor mode keymap. Individual commands or hooks can also
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 check the variable's value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 If you want the minor mode to be enabled separately in each buffer,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 make the variable buffer-local.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 Define a command whose name is the same as the mode variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 Its job is to enable and disable the mode by setting the variable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 The command should accept one optional argument. If the argument is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 @code{nil}, it should toggle the mode (turn it on if it is off, and off
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837 if it is on). Otherwise, it should turn the mode on if the argument is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 a positive integer, a symbol other than @code{nil} or @code{-}, or a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 list whose @sc{car} is such an integer or symbol; it should turn the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 mode off otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 Here is an example taken from the definition of @code{transient-mark-mode}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 It shows the use of @code{transient-mark-mode} as a variable that enables or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 disables the mode's behavior, and also shows the proper way to toggle,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 enable or disable the minor mode based on the raw prefix argument value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 (setq transient-mark-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 (if (null arg) (not transient-mark-mode)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 (> (prefix-numeric-value arg) 0)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 @item
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 Add an element to @code{minor-mode-alist} for each minor mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 (@pxref{Modeline Variables}). This element should be a list of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 following form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 (@var{mode-variable} @var{string})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 Here @var{mode-variable} is the variable that controls enabling of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 minor mode, and @var{string} is a short string, starting with a space,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 to represent the mode in the modeline. These strings must be short so
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 that there is room for several of them at once.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 When you add an element to @code{minor-mode-alist}, use @code{assq} to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 check for an existing element, to avoid duplication. For example:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 @smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 (or (assq 'leif-mode minor-mode-alist)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 (setq minor-mode-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 (cons '(leif-mode " Leif") minor-mode-alist)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 @end smallexample
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 @end itemize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 @node Keymaps and Minor Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 @subsection Keymaps and Minor Modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 Each minor mode can have its own keymap, which is active when the mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 is enabled. To set up a keymap for a minor mode, add an element to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 alist @code{minor-mode-map-alist}. @xref{Active Keymaps}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 @cindex @code{self-insert-command}, minor modes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 One use of minor mode keymaps is to modify the behavior of certain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 self-inserting characters so that they do something else as well as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 self-insert. In general, this is the only way to do that, since the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 facilities for customizing @code{self-insert-command} are limited to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 special cases (designed for abbrevs and Auto Fill mode). (Do not try
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 substituting your own definition of @code{self-insert-command} for the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 standard one. The editor command loop handles this function specially.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 @node Modeline Format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 @section Modeline Format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 @cindex modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 Each Emacs window (aside from minibuffer windows) includes a modeline,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 which displays status information about the buffer displayed in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 window. The modeline contains information about the buffer, such as its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 name, associated file, depth of recursive editing, and the major and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 minor modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 This section describes how the contents of the modeline are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 controlled. It is in the chapter on modes because much of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 information displayed in the modeline relates to the enabled major and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 minor modes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 @code{modeline-format} is a buffer-local variable that holds a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 template used to display the modeline of the current buffer. All
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 windows for the same buffer use the same @code{modeline-format} and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 their modelines appear the same (except for scrolling percentages and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 line numbers).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 The modeline of a window is normally updated whenever a different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 buffer is shown in the window, or when the buffer's modified-status
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920 changes from @code{nil} to @code{t} or vice-versa. If you modify any of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921 the variables referenced by @code{modeline-format} (@pxref{Modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 Variables}), you may want to force an update of the modeline so as to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923 display the new information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925 @c Emacs 19 feature
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 @defun redraw-modeline &optional all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 Force redisplay of the current buffer's modeline. If @var{all} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 non-@code{nil}, then force redisplay of all modelines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 The modeline is usually displayed in inverse video. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 is controlled using the @code{modeline} face. @xref{Faces}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 @menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 * Modeline Data:: The data structure that controls the modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 * Modeline Variables:: Variables used in that data structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 * %-Constructs:: Putting information into a modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 @end menu
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
940 @node Modeline Data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 @subsection The Data Structure of the Modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
942 @cindex modeline construct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 The modeline contents are controlled by a data structure of lists,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 strings, symbols, and numbers kept in the buffer-local variable
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
946 @code{modeline-format}. The data structure is called a @dfn{modeline
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 construct}, and it is built in recursive fashion out of simpler modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948 constructs. The same data structure is used for constructing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 frame titles (@pxref{Frame Titles}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 @defvar modeline-format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 The value of this variable is a modeline construct with overall
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953 responsibility for the modeline format. The value of this variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 controls which other variables are used to form the modeline text, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 where they appear.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 A modeline construct may be as simple as a fixed string of text, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 it usually specifies how to use other variables to construct the text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 Many of these variables are themselves defined to have modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 constructs as their values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 The default value of @code{modeline-format} incorporates the values
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 of variables such as @code{mode-name} and @code{minor-mode-alist}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 Because of this, very few modes need to alter @code{modeline-format}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 For most purposes, it is sufficient to alter the variables referenced by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 @code{modeline-format}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
969 A modeline construct may be a string, symbol, glyph, generic
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
970 specifier, list or cons cell.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 @cindex percent symbol in modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 @item @var{string}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 A string as a modeline construct is displayed verbatim in the mode line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 except for @dfn{@code{%}-constructs}. Decimal digits after the @samp{%}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 specify the field width for space filling on the right (i.e., the data
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 is left justified). @xref{%-Constructs}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 @item @var{symbol}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 A symbol as a modeline construct stands for its value. The value of
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
982 @var{symbol} is processed as a modeline construct, in place of
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
983 @var{symbol}. However, the symbols @code{t} and @code{nil} are ignored;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
984 so is any symbol whose value is void.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 There is one exception: if the value of @var{symbol} is a string, it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 displayed verbatim: the @code{%}-constructs are not recognized.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
989 @item @var{glyph}
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
990 A glyph is displayed as is.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
991
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
992 @item @var{generic-specifier}
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
993 A @var{generic-specifier} (i.e. a specifier of type @code{generic})
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
994 stands for its instance. The instance of @var{generic-specifier} is
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
995 computed in the current window using the equivalent of
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
996 @code{specifier-instance} and the value is processed.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
997
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 @item (@var{string} @var{rest}@dots{}) @r{or} (@var{list} @var{rest}@dots{})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999 A list whose first element is a string or list means to process all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 elements recursively and concatenate the results. This is the most
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 common form of mode line construct.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003 @item (@var{symbol} @var{then} @var{else})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 A list whose first element is a symbol is a conditional. Its meaning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 depends on the value of @var{symbol}. If the value is non-@code{nil},
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 the second element, @var{then}, is processed recursively as a modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 element. But if the value of @var{symbol} is @code{nil}, the third
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 element, @var{else}, is processed recursively. You may omit @var{else};
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 then the mode line element displays nothing if the value of @var{symbol}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 @item (@var{width} @var{rest}@dots{})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 A list whose first element is an integer specifies truncation or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 padding of the results of @var{rest}. The remaining elements
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 @var{rest} are processed recursively as modeline constructs and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 concatenated together. Then the result is space filled (if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 @var{width} is positive) or truncated (to @minus{}@var{width} columns,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 if @var{width} is negative) on the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 For example, the usual way to show what percentage of a buffer is above
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 the top of the window is to use a list like this: @code{(-3 "%p")}.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1022
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1023 @item (@var{extent} @var{rest}@dots{})
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1024
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1025 A list whose car is an extent means the cdr of the list is processed
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1026 normally but the results are displayed using the face of the extent, and
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1027 mouse clicks over this section are processed using the keymap of the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1028 extent. (In addition, if the extent has a help-echo property, that
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1029 string will be echoed when the mouse moves over this section.) If
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1030 extents are nested, all keymaps are properly consulted when processing
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1031 mouse clicks, but multiple faces are not correctly merged (only the
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1032 first face is used), and lists of faces are not correctly handled.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1033 @c #### Document generate-modeline-string.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1034 @c See `generated-modeline-string' for more information.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 If you do alter @code{modeline-format} itself, the new value should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 use the same variables that appear in the default value (@pxref{Modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 Variables}), rather than duplicating their contents or displaying
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 the information in another fashion. This way, customizations made by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 the user or by Lisp programs (such as @code{display-time} and major
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 modes) via changes to those variables remain effective.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 @cindex Shell mode @code{modeline-format}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 Here is an example of a @code{modeline-format} that might be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 useful for @code{shell-mode}, since it contains the hostname and default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 directory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1051 (setq modeline-format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 (list ""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053 'modeline-modified
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1054 "%b--"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1055 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 (getenv "HOST") ; @r{One element is not constant.}
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1057 ":"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1058 'default-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1059 " "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 'global-mode-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 " %[("
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1062 'mode-name
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1063 'modeline-process
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1064 'minor-mode-alist
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1065 "%n"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 ")%]----"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1068 '(line-number-mode "L%l--")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 '(-3 . "%p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 "-%-"))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1072 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1073
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1074 @node Modeline Variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1075 @subsection Variables Used in the Modeline
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1077 This section describes variables incorporated by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1078 standard value of @code{modeline-format} into the text of the mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1079 line. There is nothing inherently special about these variables; any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1080 other variables could have the same effects on the modeline if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1081 @code{modeline-format} were changed to use them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1083 @defvar modeline-modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1084 This variable holds the value of the modeline construct that displays
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1085 whether the current buffer is modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1087 The default value of @code{modeline-modified} is @code{("--%1*%1+-")}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1088 This means that the modeline displays @samp{--**-} if the buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1089 modified, @samp{-----} if the buffer is not modified, @samp{--%%-} if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1090 the buffer is read only, and @samp{--%*--} if the buffer is read only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1091 and modified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1092
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1093 Changing this variable does not force an update of the modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1094 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1096 @defvar modeline-buffer-identification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1097 This variable identifies the buffer being displayed in the window. Its
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 default value is @code{("%F: %17b")}, which means that it usually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1099 displays @samp{Emacs:} followed by seventeen characters of the buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1100 name. (In a terminal frame, it displays the frame name instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1101 @samp{Emacs}; this has the effect of showing the frame number.) You may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1102 want to change this in modes such as Rmail that do not behave like a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1103 ``normal'' XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1104 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1106 @defvar global-mode-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1107 This variable holds a modeline spec that appears in the mode line by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1108 default, just after the buffer name. The command @code{display-time}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1109 sets @code{global-mode-string} to refer to the variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1110 @code{display-time-string}, which holds a string containing the time and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 load information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113 The @samp{%M} construct substitutes the value of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 @code{global-mode-string}, but this is obsolete, since the variable is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 included directly in the modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 @defvar mode-name
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 This buffer-local variable holds the ``pretty'' name of the current
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 buffer's major mode. Each major mode should set this variable so that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 mode name will appear in the modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124 @defvar minor-mode-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 This variable holds an association list whose elements specify how the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 modeline should indicate that a minor mode is active. Each element of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 the @code{minor-mode-alist} should be a two-element list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 (@var{minor-mode-variable} @var{modeline-string})
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 More generally, @var{modeline-string} can be any mode line spec. It
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 appears in the mode line when the value of @var{minor-mode-variable} is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135 non-@code{nil}, and not otherwise. These strings should begin with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 spaces so that they don't run together. Conventionally, the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 @var{minor-mode-variable} for a specific mode is set to a non-@code{nil}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 value when that minor mode is activated.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 The default value of @code{minor-mode-alist} is:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 minor-mode-alist
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 @result{} ((vc-mode vc-mode)
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1146 (abbrev-mode " Abbrev")
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1147 (overwrite-mode overwrite-mode)
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1148 (auto-fill-function " Fill")
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1149 (defining-kbd-macro " Def")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1150 (isearch-mode isearch-mode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1151 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1154 @code{minor-mode-alist} is not buffer-local. The variables mentioned
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1155 in the alist should be buffer-local if the minor mode can be enabled
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 separately in each buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 @defvar modeline-process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 This buffer-local variable contains the modeline information on process
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 status in modes used for communicating with subprocesses. It is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 displayed immediately following the major mode name, with no intervening
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 space. For example, its value in the @samp{*shell*} buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164 @code{(":@: %s")}, which allows the shell to display its status along
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 with the major mode as: @samp{(Shell:@: run)}. Normally this variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 is @code{nil}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 @defvar default-modeline-format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 This variable holds the default @code{modeline-format} for buffers
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 that do not override it. This is the same as @code{(default-value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 'modeline-format)}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 The default value of @code{default-modeline-format} is:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 (""
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 modeline-modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 modeline-buffer-identification
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 " "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 global-mode-string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 " %[("
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1184 mode-name
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 modeline-process
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1188 minor-mode-alist
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1189 "%n"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 ")%]----"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 (line-number-mode "L%l--")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192 (-3 . "%p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193 "-%-")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 @defvar vc-mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 The variable @code{vc-mode}, local in each buffer, records whether the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 buffer's visited file is maintained with version control, and, if so,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 which kind. Its value is @code{nil} for no version control, or a string
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1202 that appears in the mode line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 @end defvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 @node %-Constructs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 @subsection @code{%}-Constructs in the ModeLine
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208 The following table lists the recognized @code{%}-constructs and what
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 they mean. In any construct except @samp{%%}, you can add a decimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 integer after the @samp{%} to specify how many characters to display.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 @item %b
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 The current buffer name, obtained with the @code{buffer-name} function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 @xref{Buffer Names}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217 @item %f
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 The visited file name, obtained with the @code{buffer-file-name}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 function. @xref{Buffer File Name}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 @item %F
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 The name of the selected frame.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1224 @item %c
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 The current column number of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 @item %l
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 The current line number of point.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 @item %*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 @samp{%} if the buffer is read only (see @code{buffer-read-only}); @*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 @samp{*} if the buffer is modified (see @code{buffer-modified-p}); @*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 @samp{-} otherwise. @xref{Buffer Modification}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 @item %+
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236 @samp{*} if the buffer is modified (see @code{buffer-modified-p}); @*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 @samp{%} if the buffer is read only (see @code{buffer-read-only}); @*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 @samp{-} otherwise. This differs from @samp{%*} only for a modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 read-only buffer. @xref{Buffer Modification}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241 @item %&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 @samp{*} if the buffer is modified, and @samp{-} otherwise.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 @item %s
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 The status of the subprocess belonging to the current buffer, obtained with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 @code{process-status}. @xref{Process Information}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 @c The following two may only apply in XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 @item %l
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1250 The current line number.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 @item %S
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1253 The name of the selected frame; this is only meaningful under the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 X Window System. @xref{Frame Name}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 @item %t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 Whether the visited file is a text file or a binary file. (This is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 meaningful distinction only on certain operating systems.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 @item %p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 The percentage of the buffer text above the @strong{top} of window, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 @samp{Top}, @samp{Bottom} or @samp{All}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 @item %P
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 The percentage of the buffer text that is above the @strong{bottom} of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 the window (which includes the text visible in the window, as well as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 the text above the top), plus @samp{Top} if the top of the buffer is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 visible on screen; or @samp{Bottom} or @samp{All}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 @item %n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 @samp{Narrow} when narrowing is in effect; nothing otherwise (see
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 @code{narrow-to-region} in @ref{Narrowing}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1274 @item %C
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1275 Under XEmacs/mule, the mnemonic for @code{buffer-file-coding-system}.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 428
diff changeset
1276
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 @item %[
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 An indication of the depth of recursive editing levels (not counting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 minibuffer levels): one @samp{[} for each editing level.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 @xref{Recursive Editing}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 @item %]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 One @samp{]} for each recursive editing level (not counting minibuffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 levels).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 @item %%
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 The character @samp{%}---this is how to include a literal @samp{%} in a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 string in which @code{%}-constructs are allowed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 @item %-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 Dashes sufficient to fill the remainder of the modeline.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 The following two @code{%}-constructs are still supported, but they are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 obsolete, since you can get the same results with the variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 @code{mode-name} and @code{global-mode-string}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 @table @code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 @item %m
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 The value of @code{mode-name}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 @item %M
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 The value of @code{global-mode-string}. Currently, only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 @code{display-time} modifies the value of @code{global-mode-string}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 @end table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 @node Hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 @section Hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 @cindex hooks
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 A @dfn{hook} is a variable where you can store a function or functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 to be called on a particular occasion by an existing program. XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1313 provides hooks for the sake of customization. Most often, hooks are set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 up in the @file{.emacs} file, but Lisp programs can set them also.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 @xref{Standard Hooks}, for a list of standard hook variables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317 Most of the hooks in XEmacs are @dfn{normal hooks}. These variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 contain lists of functions to be called with no arguments. The reason
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 most hooks are normal hooks is so that you can use them in a uniform
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1320 way. You can usually tell when a hook is a normal hook, because its
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 name ends in @samp{-hook}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 The recommended way to add a hook function to a normal hook is by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 calling @code{add-hook} (see below). The hook functions may be any of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 the valid kinds of functions that @code{funcall} accepts (@pxref{What Is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 a Function}). Most normal hook variables are initially void;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 @code{add-hook} knows how to deal with this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329 As for abnormal hooks, those whose names end in @samp{-function} have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 a value that is a single function. Those whose names end in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1331 @samp{-hooks} have a value that is a list of functions. Any hook that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332 is abnormal is abnormal because a normal hook won't do the job; either
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 the functions are called with arguments, or their values are meaningful.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 The name shows you that the hook is abnormal and that you should look at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 its documentation string to see how to use it properly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 Major mode functions are supposed to run a hook called the @dfn{mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 hook} as the last step of initialization. This makes it easy for a user
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 to customize the behavior of the mode, by overriding the local variable
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 assignments already made by the mode. But hooks are used in other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 contexts too. For example, the hook @code{suspend-hook} runs just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 before XEmacs suspends itself (@pxref{Suspending XEmacs}).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 Here's an expression that uses a mode hook to turn on Auto Fill mode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 when in Lisp Interaction mode:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 (add-hook 'lisp-interaction-mode-hook 'turn-on-auto-fill)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 The next example shows how to use a hook to customize the way XEmacs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 formats C code. (People often have strong personal preferences for one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 format or another.) Here the hook function is an anonymous lambda
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 expression.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 @cindex lambda expression in hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 @group
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1359 (add-hook 'c-mode-hook
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 (function (lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 (setq c-indent-level 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 c-argdecl-indent 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 c-label-offset -4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 c-continued-statement-indent 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 c-brace-offset 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368 comment-column 40))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 (setq c++-mode-hook c-mode-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 The final example shows how the appearance of the modeline can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 modified for a particular class of buffers only.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 (add-hook 'text-mode-hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 (function (lambda ()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 (setq modeline-format
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 '(modeline-modified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 "Emacs: %14b"
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1384 " "
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 @group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 default-directory
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 " "
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 global-mode-string
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1390 "%[("
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1391 mode-name
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1392 minor-mode-alist
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1393 "%n"
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1394 modeline-process
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 ") %]---"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 (-3 . "%p")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 "-%-")))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 @end group
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 At the appropriate time, XEmacs uses the @code{run-hooks} function to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 run particular hooks. This function calls the hook functions you have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 added with @code{add-hooks}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 @defun run-hooks &rest hookvar
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 This function takes one or more hook variable names as arguments, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 runs each hook in turn. Each @var{hookvar} argument should be a symbol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 that is a hook variable. These arguments are processed in the order
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 specified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 If a hook variable has a non-@code{nil} value, that value may be a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 function or a list of functions. If the value is a function (either a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 lambda expression or a symbol with a function definition), it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 called. If it is a list, the elements are called, in order.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 The hook functions are called with no arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 For example, here's how @code{emacs-lisp-mode} runs its mode hook:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 (run-hooks 'emacs-lisp-mode-hook)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423
2135
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1424 @defun run-mode-hooks &rest hookvars
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1425 Like @code{run-hooks}, but is affected by the @code{delay-mode-hooks}
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1426 macro.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1427 @end defun
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1428
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1429 @defmac delay-mode-hooks body...
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1430 This macro executes the @var{body} forms but defers all calls to
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1431 @code{run-mode-hooks} within them until the end of @var{body}.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1432 This macro enables a derived mode to arrange not to run
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1433 its parent modes' mode hooks until the end.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1434 @end defmac
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1435
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1436 @defun run-hook-with-args hook &rest args
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1437 This function is the way to run an abnormal hook and always call all
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1438 of the hook functions. It calls each of the hook functions one by
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1439 one, passing each of them the arguments @var{args}.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1440 @end defun
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1441
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1442 @defun run-hook-with-args-until-failure hook &rest args
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1443 This function is the way to run an abnormal hook until one of the hook
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1444 functions fails. It calls each of the hook functions, passing each of
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1445 them the arguments @var{args}, until some hook function returns
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1446 @code{nil}. It then stops and returns @code{nil}. If none of the
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1447 hook functions return @code{nil}, it returns a non-@code{nil} value.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1448 @end defun
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1449
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1450 @defun run-hook-with-args-until-success hook &rest args
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1451 This function is the way to run an abnormal hook until a hook function
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1452 succeeds. It calls each of the hook functions, passing each of them
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1453 the arguments @var{args}, until some hook function returns
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1454 non-@code{nil}. Then it stops, and returns whatever was returned by
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1455 the last hook function that was called. If all hook functions return
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1456 @code{nil}, it returns @code{nil} as well.
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1457 @end defun
e6d43c299b9c [xemacs-hg @ 2004-06-17 03:01:10 by james]
james
parents: 446
diff changeset
1458
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1459 @defun add-hook hook function &optional append local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 This function is the handy way to add function @var{function} to hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461 variable @var{hook}. The argument @var{function} may be any valid Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 function with the proper number of arguments. For example,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 @example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 (add-hook 'text-mode-hook 'my-text-hook-function)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 @end example
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 @noindent
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1469 adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 You can use @code{add-hook} for abnormal hooks as well as for normal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472 hooks.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 It is best to design your hook functions so that the order in which they
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 are executed does not matter. Any dependence on the order is ``asking
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1476 for trouble.'' However, the order is predictable: normally,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 @var{function} goes at the front of the hook list, so it will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 executed first (barring another @code{add-hook} call).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 If the optional argument @var{append} is non-@code{nil}, the new hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 function goes at the end of the hook list and will be executed last.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 If @var{local} is non-@code{nil}, that says to make the new hook
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 function local to the current buffer. Before you can do this, you must
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485 make the hook itself buffer-local by calling @code{make-local-hook}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1486 (@strong{not} @code{make-local-variable}). If the hook itself is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 buffer-local, then the value of @var{local} makes no difference---the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 hook function is always global.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 @defun remove-hook hook function &optional local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 This function removes @var{function} from the hook variable @var{hook}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 If @var{local} is non-@code{nil}, that says to remove @var{function}
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 from the local hook list instead of from the global hook list. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 hook itself is not buffer-local, then the value of @var{local} makes no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 difference.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 @end defun
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 @defun make-local-hook hook
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1501 This function makes the hook variable @var{hook} local to the current
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 buffer. When a hook variable is local, it can have local and global
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 hook functions, and @code{run-hooks} runs all of them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 This function works by making @code{t} an element of the buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 value. That serves as a flag to use the hook functions in the default
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 value of the hook variable as well as those in the local value. Since
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 @code{run-hooks} understands this flag, @code{make-local-hook} works
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 with all normal hooks. It works for only some non-normal hooks---those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 whose callers have been updated to understand this meaning of @code{t}.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 Do not use @code{make-local-variable} directly for hook variables; it is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 not sufficient.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 @end defun