aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Teirlinck2004-09-25 02:21:51 +0000
committerLuc Teirlinck2004-09-25 02:21:51 +0000
commita3ee0299ed17ade533b0b668fd274fff48811c5d (patch)
tree4faa209e393d0fea89f124b0db74dcd2c34d6bd7
parent45c9a0f754636bccb041c1414136546101e839a0 (diff)
downloademacs-a3ee0299ed17ade533b0b668fd274fff48811c5d.tar.gz
emacs-a3ee0299ed17ade533b0b668fd274fff48811c5d.zip
Various minor changes in addition to:
(Major Mode Conventions): Final call to `run-mode-hooks' should not be inside the `delay-mode-hooks' form. (Mode Hooks): New node. (Hooks): Delete obsolete example. Move definitions of `run-mode-hooks' and `delay-mode-hooks' to new node "Mode Hooks".
-rw-r--r--lispref/ChangeLog10
-rw-r--r--lispref/modes.texi89
2 files changed, 73 insertions, 26 deletions
diff --git a/lispref/ChangeLog b/lispref/ChangeLog
index 2dd35cd1844..a7681ddfbf0 100644
--- a/lispref/ChangeLog
+++ b/lispref/ChangeLog
@@ -1,3 +1,13 @@
12004-09-24 Luc Teirlinck <teirllm@auburn.edu>
2
3 * modes.texi: Various minor changes in addition to:
4 (Major Mode Conventions): Final call to `run-mode-hooks' should
5 not be inside the `delay-mode-hooks' form.
6 (Mode Hooks): New node.
7 (Hooks): Delete obsolete example.
8 Move definitions of `run-mode-hooks' and `delay-mode-hooks' to new
9 node "Mode Hooks".
10
12004-09-22 Luc Teirlinck <teirllm@auburn.edu> 112004-09-22 Luc Teirlinck <teirllm@auburn.edu>
2 12
3 * display.texi: Correct various typos. 13 * display.texi: Correct various typos.
diff --git a/lispref/modes.texi b/lispref/modes.texi
index 78b8fc440d7..f74f7c89da7 100644
--- a/lispref/modes.texi
+++ b/lispref/modes.texi
@@ -1,6 +1,6 @@
1@c -*-texinfo-*- 1@c -*-texinfo-*-
2@c This is part of the GNU Emacs Lisp Reference Manual. 2@c This is part of the GNU Emacs Lisp Reference Manual.
3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003 3@c Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2003, 2004
4@c Free Software Foundation, Inc. 4@c Free Software Foundation, Inc.
5@c See the file elisp.texi for copying conditions. 5@c See the file elisp.texi for copying conditions.
6@setfilename ../info/modes 6@setfilename ../info/modes
@@ -103,6 +103,7 @@ Fundamental mode. Rmail mode is a complicated and specialized mode.
103* Mode Help:: Finding out how to use a mode. 103* Mode Help:: Finding out how to use a mode.
104* Derived Modes:: Defining a new major mode based on another major 104* Derived Modes:: Defining a new major mode based on another major
105 mode. 105 mode.
106* Mode Hooks:: Hooks run at the end of major mode functions.
106@end menu 107@end menu
107 108
108@node Major Mode Conventions 109@node Major Mode Conventions
@@ -276,7 +277,7 @@ other packages would interfere with them.
276Each major mode should have a @dfn{mode hook} named 277Each major mode should have a @dfn{mode hook} named
277@code{@var{modename}-mode-hook}. The major mode command should run that 278@code{@var{modename}-mode-hook}. The major mode command should run that
278hook, with @code{run-mode-hooks}, as the very last thing it 279hook, with @code{run-mode-hooks}, as the very last thing it
279does. @xref{Hooks}. 280does. @xref{Mode Hooks}.
280 281
281@item 282@item
282The major mode command may start by calling some other major mode 283The major mode command may start by calling some other major mode
@@ -284,9 +285,11 @@ command (called the @dfn{parent mode}) and then alter some of its
284settings. A mode that does this is called a @dfn{derived mode}. The 285settings. A mode that does this is called a @dfn{derived mode}. The
285recommended way to define one is to use @code{define-derived-mode}, 286recommended way to define one is to use @code{define-derived-mode},
286but this is not required. Such a mode should use 287but this is not required. Such a mode should use
287@code{delay-mode-hooks} around its entire body, including the call to 288@code{delay-mode-hooks} around its entire body (including the call to
288the parent mode command and the final call to @code{run-mode-hooks}. 289the parent mode command) @emph{except} for the final call to
289(Using @code{define-derived-mode} does this automatically.) 290@code{run-mode-hooks}, which runs the derived mode's hook. (Using
291@code{define-derived-mode} does this automatically.) @xref{Derived
292Modes}, and @ref{Mode Hooks}.
290 293
291@item 294@item
292If something special should be done if the user switches a buffer from 295If something special should be done if the user switches a buffer from
@@ -575,7 +578,7 @@ visited. It also processes local variables specified in the file text.
575in particular. Other major modes are defined in effect by comparison 578in particular. Other major modes are defined in effect by comparison
576with this one---their definitions say what to change, starting from 579with this one---their definitions say what to change, starting from
577Fundamental mode. The @code{fundamental-mode} function does @emph{not} 580Fundamental mode. The @code{fundamental-mode} function does @emph{not}
578run any hooks; you're not supposed to customize it. (If you want Emacs 581run any mode hooks; you're not supposed to customize it. (If you want Emacs
579to behave differently in Fundamental mode, change the @emph{global} 582to behave differently in Fundamental mode, change the @emph{global}
580state of Emacs.) 583state of Emacs.)
581@end deffn 584@end deffn
@@ -808,6 +811,58 @@ Do not write an @code{interactive} spec in the definition;
808@code{define-derived-mode} does that automatically. 811@code{define-derived-mode} does that automatically.
809@end defmac 812@end defmac
810 813
814@node Mode Hooks
815@subsection Mode Hooks
816
817The two last things a major mode function does is to run its mode
818hook and finally the mode independent normal hook
819@code{after-change-major-mode-hook}. If the major mode is a derived
820mode, that is if it calls another major mode (the parent mode) in its
821body, then the parent's mode hook is run just before the derived
822mode's hook. Neither the parent's mode hook nor
823@code{after-change-major-mode-hook} are run at the end of the actual
824call to the parent mode. This applies recursively if the parent mode
825has itself a parent. That is, the mode hooks of all major modes called
826directly or indirectly by the major mode function are all run in
827sequence at the end, just before @code{after-change-major-mode-hook}.
828
829If you are customizing a major mode, rather than defining one, the
830above is all you need to know about the hooks run at the end of a
831major mode. This also applies if you use @code{define-derived-mode}
832to define a major mode, because that macro will automatically
833implement the above for you.
834
835Programmers wishing to define a major mode without using
836@code{define-derived-mode}, should make sure that their major mode
837follows the above conventions. @xref{Major Mode Conventions}, for how
838this should be accomplished. Below, we give some implementation
839details.
840
841@defun run-mode-hooks &rest hookvars
842Major modes should run their mode hook using this function. It is
843similar to @code{run-hooks} (@pxref{Hooks}), but if run inside a
844@code{delay-mode-hooks} form, this function does not run any hooks.
845Instead, it arranges for @var{hookvars} to be run at a later call to
846the function. Otherwise, @code{run-mode-hooks} runs any delayed hooks
847in order, then @var{hookvars} and finally
848@code{after-change-major-mode-hook}.
849@end defun
850
851@defmac delay-mode-hooks body...
852This macro executes @var{body} like @code{progn}, but all calls to
853@code{run-mode-hooks} inside @var{body} delay running their hooks.
854They will be run by the first call to @code{run-mode-hooks} after exit
855from @code{delay-mode-hooks}.
856@end defmac
857
858@defvar after-change-major-mode-hook
859Every major mode function should run this normal hook at its very end.
860It normally does not need to do so explicitly. Indeed, a major mode
861function should normally run its mode hook with @code{run-mode-hooks}
862as the very last thing it does and @code{run-mode-hooks} runs
863@code{after-change-major-mode-hook} at its very end.
864@end defvar
865
811@node Minor Modes 866@node Minor Modes
812@section Minor Modes 867@section Minor Modes
813@cindex minor mode 868@cindex minor mode
@@ -2087,7 +2142,7 @@ if there is no subexpression numbered @var{subexp} in @var{matcher}.
2087Obviously, fontification of the subexpression numbered @var{subexp} will 2142Obviously, fontification of the subexpression numbered @var{subexp} will
2088not occur. However, fontification of other subexpressions (and other 2143not occur. However, fontification of other subexpressions (and other
2089regexps) will continue. If @var{laxmatch} is @code{nil}, and the 2144regexps) will continue. If @var{laxmatch} is @code{nil}, and the
2090specified subexpression is missing, then an error is signalled which 2145specified subexpression is missing, then an error is signaled which
2091terminates search-based fontification. 2146terminates search-based fontification.
2092 2147
2093Here are some examples of elements of this kind, and what they do: 2148Here are some examples of elements of this kind, and what they do:
@@ -2450,7 +2505,7 @@ a file, don't have to do anything to use this feature.
2450 2505
2451For buffers not visiting a file to have their state saved, the major 2506For buffers not visiting a file to have their state saved, the major
2452mode must bind the buffer local variable @code{desktop-save-buffer} to 2507mode must bind the buffer local variable @code{desktop-save-buffer} to
2453a non-nil value. 2508a non-@code{nil} value.
2454 2509
2455@defvar desktop-save-buffer 2510@defvar desktop-save-buffer
2456If this buffer-local variable is non-@code{nil}, the buffer will have 2511If this buffer-local variable is non-@code{nil}, the buffer will have
@@ -2563,26 +2618,8 @@ obsolete.) If the value is a function (either a lambda expression or
2563a symbol with a function definition), it is called. If it is a list 2618a symbol with a function definition), it is called. If it is a list
2564that isn't a function, its elements are called, consecutively. All 2619that isn't a function, its elements are called, consecutively. All
2565the hook functions are called with no arguments. 2620the hook functions are called with no arguments.
2566
2567For example, here's how @code{emacs-lisp-mode} runs its mode hook:
2568
2569@example
2570(run-hooks 'emacs-lisp-mode-hook)
2571@end example
2572@end defun 2621@end defun
2573 2622
2574@defun run-mode-hooks &rest hookvars
2575Like @code{run-hooks}, but is affected by the @code{delay-mode-hooks}
2576macro.
2577@end defun
2578
2579@defmac delay-mode-hooks body...
2580This macro executes the @var{body} forms but defers all calls to
2581@code{run-mode-hooks} within them until the end of @var{body}.
2582This macro enables a derived mode to arrange not to run
2583its parent modes' mode hooks until the end.
2584@end defmac
2585
2586@defun run-hook-with-args hook &rest args 2623@defun run-hook-with-args hook &rest args
2587This function is the way to run an abnormal hook and always call all 2624This function is the way to run an abnormal hook and always call all
2588of the hook functions. It calls each of the hook functions one by 2625of the hook functions. It calls each of the hook functions one by