aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2005-05-29 08:28:51 +0000
committerRichard M. Stallman2005-05-29 08:28:51 +0000
commit801f0dc37d6c930ff63ef9573bcea63a117facd9 (patch)
tree9fd85ee4f1f0f95c5d290b50cca1f1d95d13b7a1
parenta1a886a1d5aec8087a0f9c688a3502506c831d14 (diff)
downloademacs-801f0dc37d6c930ff63ef9573bcea63a117facd9.tar.gz
emacs-801f0dc37d6c930ff63ef9573bcea63a117facd9.zip
(Mode Hooks): Explain that after-change-major-mode-hook is
new, and what that implies. Clarify.
-rw-r--r--lispref/modes.texi56
1 files changed, 32 insertions, 24 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi
index 61bc878b581..488265b0b68 100644
--- a/lispref/modes.texi
+++ b/lispref/modes.texi
@@ -1117,7 +1117,7 @@ it runs the mode hook variable @code{@var{mode}-hook}.
1117@node Mode Hooks 1117@node Mode Hooks
1118@subsection Mode Hooks 1118@subsection Mode Hooks
1119 1119
1120The two last things a major mode function does is to run its mode 1120 The two last things a major mode function should do is run its mode
1121hook and finally the mode independent normal hook 1121hook and finally the mode independent normal hook
1122@code{after-change-major-mode-hook}. If the major mode is a derived 1122@code{after-change-major-mode-hook}. If the major mode is a derived
1123mode, that is if it calls another major mode (the parent mode) in its 1123mode, that is if it calls another major mode (the parent mode) in its
@@ -1125,45 +1125,53 @@ body, then the parent's mode hook is run just before the derived
1125mode's hook. Neither the parent's mode hook nor 1125mode's hook. Neither the parent's mode hook nor
1126@code{after-change-major-mode-hook} are run at the end of the actual 1126@code{after-change-major-mode-hook} are run at the end of the actual
1127call to the parent mode. This applies recursively if the parent mode 1127call to the parent mode. This applies recursively if the parent mode
1128has itself a parent. That is, the mode hooks of all major modes called 1128has itself a parent. That is, the mode hooks of all major modes
1129directly or indirectly by the major mode function are all run in 1129called directly or indirectly by the major mode function are all run
1130sequence at the end, just before @code{after-change-major-mode-hook}. 1130in sequence at the end, just before
1131 1131@code{after-change-major-mode-hook}.
1132If you are customizing a major mode, rather than defining one, the 1132
1133above is all you need to know about the hooks run at the end of a 1133 These conventions are new in Emacs 22, and some major modes
1134major mode. This also applies if you use @code{define-derived-mode} 1134implemented by users do not follow them yet. So if you put a function
1135to define a major mode, because that macro will automatically 1135onto @code{after-change-major-mode-hook}, keep in mind that some modes
1136implement the above for you. 1136will fail to run it. If user complains about that, you can respond,
1137 1137``That major mode fails to follow Emacs conventions, and that's why it
1138Programmers wishing to define a major mode without using 1138fails to work. Please fix the major mode.'' In most cases, that is
1139@code{define-derived-mode}, should make sure that their major mode 1139good enough, so go ahead and use @code{after-change-major-mode-hook}.
1140follows the above conventions. @xref{Major Mode Conventions}, for how 1140However, if a certain feature needs to be completely reliable,
1141this should be accomplished. Below, we give some implementation 1141it should not use @code{after-change-major-mode-hook} as of yet.
1142details. 1142
1143 When you defined a major mode using @code{define-derived-mode}, it
1144automatically makes sure these conventions are followed. If you
1145define a major mode ``from scratch'', not using
1146@code{define-derived-mode}, make sure the major mode command follows
1147these and other conventions. @xref{Major Mode Conventions}. You use
1148these functions to do it properly.
1143 1149
1144@defun run-mode-hooks &rest hookvars 1150@defun run-mode-hooks &rest hookvars
1145Major modes should run their mode hook using this function. It is 1151Major modes should run their mode hook using this function. It is
1146similar to @code{run-hooks} (@pxref{Hooks}), but if run inside a 1152similar to @code{run-hooks} (@pxref{Hooks}), but it also runs
1147@code{delay-mode-hooks} form, this function does not run any hooks.
1148Instead, it arranges for @var{hookvars} to be run at a later call to
1149the function. Otherwise, @code{run-mode-hooks} runs any delayed hooks
1150in order, then @var{hookvars} and finally
1151@code{after-change-major-mode-hook}. 1153@code{after-change-major-mode-hook}.
1154
1155When the call to this function is dynamically inside a
1156@code{delay-mode-hooks} form, this function does not run any hooks.
1157Instead, it arranges for the next call to @code{run-mode-hooks} to run
1158@var{hookvars}.
1152@end defun 1159@end defun
1153 1160
1154@defmac delay-mode-hooks body... 1161@defmac delay-mode-hooks body...
1155This macro executes @var{body} like @code{progn}, but all calls to 1162This macro executes @var{body} like @code{progn}, but all calls to
1156@code{run-mode-hooks} inside @var{body} delay running their hooks. 1163@code{run-mode-hooks} inside @var{body} delay running their hooks.
1157They will be run by the first call to @code{run-mode-hooks} after exit 1164They will be run by the first call to @code{run-mode-hooks} after exit
1158from @code{delay-mode-hooks}. 1165from @code{delay-mode-hooks}. This is the proper way for a major mode
1166command to invoke its parent mode.
1159@end defmac 1167@end defmac
1160 1168
1161@defvar after-change-major-mode-hook 1169@defvar after-change-major-mode-hook
1162Every major mode function should run this normal hook at its very end. 1170Every major mode function should run this normal hook at its very end.
1163It normally does not need to do so explicitly. Indeed, a major mode 1171It normally does not need to do so explicitly. Indeed, a major mode
1164function should normally run its mode hook with @code{run-mode-hooks} 1172function should normally run its mode hook with @code{run-mode-hooks}
1165as the very last thing it does and @code{run-mode-hooks} runs 1173as the very last thing it does, and the last thing
1166@code{after-change-major-mode-hook} at its very end. 1174@code{run-mode-hooks} does is run @code{after-change-major-mode-hook}.
1167@end defvar 1175@end defvar
1168 1176
1169@node Minor Modes 1177@node Minor Modes