comparison man/lispref/modes.texi @ 2135:e6d43c299b9c

[xemacs-hg @ 2004-06-17 03:01:10 by james] Synch with Emacs 21.3 derived.el, plus new stuff in subr.el to support it, as well as some documentation.
author james
date Thu, 17 Jun 2004 03:01:17 +0000
parents 1ccc32a20af4
children 9fae6227ede5
comparison
equal deleted inserted replaced
2134:ab08d33c34e5 2135:e6d43c299b9c
29 @section Major Modes 29 @section Major Modes
30 @cindex major mode 30 @cindex major mode
31 @cindex Fundamental mode 31 @cindex Fundamental mode
32 32
33 Major modes specialize XEmacs for editing particular kinds of text. 33 Major modes specialize XEmacs for editing particular kinds of text.
34 Each buffer has only one major mode at a time. 34 Each buffer has only one major mode at a time. For each major mode
35 there is a function to switch to that mode in the current buffer; its
36 name should end in @samp{-mode}. These functions work by setting
37 buffer-local variable bindings and other data associated with the
38 buffer, such as a local keymap. The effect lasts until you switch
39 to another major mode in the same buffer.
35 40
36 The least specialized major mode is called @dfn{Fundamental mode}. 41 The least specialized major mode is called @dfn{Fundamental mode}.
37 This mode has no mode-specific definitions or variable settings, so each 42 This mode has no mode-specific definitions or variable settings, so each
38 XEmacs command behaves in its default manner, and each option is in its 43 XEmacs command behaves in its default manner, and each option is in its
39 default state. All other major modes redefine various keys and options. 44 default state. All other major modes redefine various keys and options.
52 and alter the copy---or define a @dfn{derived mode} (@pxref{Derived 57 and alter the copy---or define a @dfn{derived mode} (@pxref{Derived
53 Modes}). For example, Rmail Edit mode, which is in 58 Modes}). For example, Rmail Edit mode, which is in
54 @file{emacs/lisp/rmailedit.el}, is a major mode that is very similar to 59 @file{emacs/lisp/rmailedit.el}, is a major mode that is very similar to
55 Text mode except that it provides three additional commands. Its 60 Text mode except that it provides three additional commands. Its
56 definition is distinct from that of Text mode, but was derived from it. 61 definition is distinct from that of Text mode, but was derived from it.
62
63 Even if the new mode is not an obvious derivative of any other mode,
64 it is convenient to use @code{define-derived-mode} with a @code{nil}
65 parent argument, since it automatically enforces the most important
66 coding conventions for you.
57 67
58 Rmail Edit mode is an example of a case where one piece of text is put 68 Rmail Edit mode is an example of a case where one piece of text is put
59 temporarily into a different major mode so it can be edited in a 69 temporarily into a different major mode so it can be edited in a
60 different way (with ordinary XEmacs commands rather than Rmail). In such 70 different way (with ordinary XEmacs commands rather than Rmail). In such
61 cases, the temporary major mode usually has a command to switch back to 71 cases, the temporary major mode usually has a command to switch back to
187 well as @code{indented-text-mode-hook}. It may run these other hooks 197 well as @code{indented-text-mode-hook}. It may run these other hooks
188 immediately before the mode's own hook (that is, after everything else), 198 immediately before the mode's own hook (that is, after everything else),
189 or it may run them earlier. 199 or it may run them earlier.
190 200
191 @item 201 @item
202 The major mode command may start by calling some other major mode
203 command (called the @dfn{parent mode}) and then alter some of its
204 settings. A mode that does this is called a @dfn{derived mode}. The
205 recommended way to define one is to use @code{define-derived-mode},
206 but this is not required. Such a mode should use
207 @code{delay-mode-hooks} around its entire body, including the call to
208 the parent mode command and the final call to @code{run-mode-hooks}.
209 (Using @code{define-derived-mode} does this automatically.)
210
211 @item
192 If something special should be done if the user switches a buffer from 212 If something special should be done if the user switches a buffer from
193 this mode to any other major mode, the mode can set a local value for 213 this mode to any other major mode, the mode can set a local value for
194 @code{change-major-mode-hook}. 214 @code{change-major-mode-hook}.
195 215
196 @item 216 @item
741 (setq case-fold-search nil)) 761 (setq case-fold-search nil))
742 762
743 (define-key hypertext-mode-map 763 (define-key hypertext-mode-map
744 [down-mouse-3] 'do-hyper-link) 764 [down-mouse-3] 'do-hyper-link)
745 @end example 765 @end example
766
767 Do not write an @code{interactive} spec in the definition;
768 @code{define-derived-mode} does that automatically.
746 @end defmac 769 @end defmac
747 770
748 @node Minor Modes 771 @node Minor Modes
749 @section Minor Modes 772 @section Minor Modes
750 @cindex minor mode 773 @cindex minor mode
1396 @example 1419 @example
1397 (run-hooks 'emacs-lisp-mode-hook) 1420 (run-hooks 'emacs-lisp-mode-hook)
1398 @end example 1421 @end example
1399 @end defun 1422 @end defun
1400 1423
1424 @defun run-mode-hooks &rest hookvars
1425 Like @code{run-hooks}, but is affected by the @code{delay-mode-hooks}
1426 macro.
1427 @end defun
1428
1429 @defmac delay-mode-hooks body...
1430 This macro executes the @var{body} forms but defers all calls to
1431 @code{run-mode-hooks} within them until the end of @var{body}.
1432 This macro enables a derived mode to arrange not to run
1433 its parent modes' mode hooks until the end.
1434 @end defmac
1435
1436 @defun run-hook-with-args hook &rest args
1437 This function is the way to run an abnormal hook and always call all
1438 of the hook functions. It calls each of the hook functions one by
1439 one, passing each of them the arguments @var{args}.
1440 @end defun
1441
1442 @defun run-hook-with-args-until-failure hook &rest args
1443 This function is the way to run an abnormal hook until one of the hook
1444 functions fails. It calls each of the hook functions, passing each of
1445 them the arguments @var{args}, until some hook function returns
1446 @code{nil}. It then stops and returns @code{nil}. If none of the
1447 hook functions return @code{nil}, it returns a non-@code{nil} value.
1448 @end defun
1449
1450 @defun run-hook-with-args-until-success hook &rest args
1451 This function is the way to run an abnormal hook until a hook function
1452 succeeds. It calls each of the hook functions, passing each of them
1453 the arguments @var{args}, until some hook function returns
1454 non-@code{nil}. Then it stops, and returns whatever was returned by
1455 the last hook function that was called. If all hook functions return
1456 @code{nil}, it returns @code{nil} as well.
1457 @end defun
1458
1401 @defun add-hook hook function &optional append local 1459 @defun add-hook hook function &optional append local
1402 This function is the handy way to add function @var{function} to hook 1460 This function is the handy way to add function @var{function} to hook
1403 variable @var{hook}. The argument @var{function} may be any valid Lisp 1461 variable @var{hook}. The argument @var{function} may be any valid Lisp
1404 function with the proper number of arguments. For example, 1462 function with the proper number of arguments. For example,
1405 1463