diff options
| author | Richard M. Stallman | 2005-05-29 08:28:51 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2005-05-29 08:28:51 +0000 |
| commit | 801f0dc37d6c930ff63ef9573bcea63a117facd9 (patch) | |
| tree | 9fd85ee4f1f0f95c5d290b50cca1f1d95d13b7a1 | |
| parent | a1a886a1d5aec8087a0f9c688a3502506c831d14 (diff) | |
| download | emacs-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.texi | 56 |
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 | ||
| 1120 | The 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 |
| 1121 | hook and finally the mode independent normal hook | 1121 | hook 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 |
| 1123 | mode, that is if it calls another major mode (the parent mode) in its | 1123 | mode, 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 | |||
| 1125 | mode's hook. Neither the parent's mode hook nor | 1125 | mode'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 |
| 1127 | call to the parent mode. This applies recursively if the parent mode | 1127 | call to the parent mode. This applies recursively if the parent mode |
| 1128 | has itself a parent. That is, the mode hooks of all major modes called | 1128 | has itself a parent. That is, the mode hooks of all major modes |
| 1129 | directly or indirectly by the major mode function are all run in | 1129 | called directly or indirectly by the major mode function are all run |
| 1130 | sequence at the end, just before @code{after-change-major-mode-hook}. | 1130 | in sequence at the end, just before |
| 1131 | 1131 | @code{after-change-major-mode-hook}. | |
| 1132 | If you are customizing a major mode, rather than defining one, the | 1132 | |
| 1133 | above 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 |
| 1134 | major mode. This also applies if you use @code{define-derived-mode} | 1134 | implemented by users do not follow them yet. So if you put a function |
| 1135 | to define a major mode, because that macro will automatically | 1135 | onto @code{after-change-major-mode-hook}, keep in mind that some modes |
| 1136 | implement the above for you. | 1136 | will 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 | |
| 1138 | Programmers wishing to define a major mode without using | 1138 | fails to work. Please fix the major mode.'' In most cases, that is |
| 1139 | @code{define-derived-mode}, should make sure that their major mode | 1139 | good enough, so go ahead and use @code{after-change-major-mode-hook}. |
| 1140 | follows the above conventions. @xref{Major Mode Conventions}, for how | 1140 | However, if a certain feature needs to be completely reliable, |
| 1141 | this should be accomplished. Below, we give some implementation | 1141 | it should not use @code{after-change-major-mode-hook} as of yet. |
| 1142 | details. | 1142 | |
| 1143 | When you defined a major mode using @code{define-derived-mode}, it | ||
| 1144 | automatically makes sure these conventions are followed. If you | ||
| 1145 | define a major mode ``from scratch'', not using | ||
| 1146 | @code{define-derived-mode}, make sure the major mode command follows | ||
| 1147 | these and other conventions. @xref{Major Mode Conventions}. You use | ||
| 1148 | these functions to do it properly. | ||
| 1143 | 1149 | ||
| 1144 | @defun run-mode-hooks &rest hookvars | 1150 | @defun run-mode-hooks &rest hookvars |
| 1145 | Major modes should run their mode hook using this function. It is | 1151 | Major modes should run their mode hook using this function. It is |
| 1146 | similar to @code{run-hooks} (@pxref{Hooks}), but if run inside a | 1152 | similar to @code{run-hooks} (@pxref{Hooks}), but it also runs |
| 1147 | @code{delay-mode-hooks} form, this function does not run any hooks. | ||
| 1148 | Instead, it arranges for @var{hookvars} to be run at a later call to | ||
| 1149 | the function. Otherwise, @code{run-mode-hooks} runs any delayed hooks | ||
| 1150 | in order, then @var{hookvars} and finally | ||
| 1151 | @code{after-change-major-mode-hook}. | 1153 | @code{after-change-major-mode-hook}. |
| 1154 | |||
| 1155 | When the call to this function is dynamically inside a | ||
| 1156 | @code{delay-mode-hooks} form, this function does not run any hooks. | ||
| 1157 | Instead, 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... |
| 1155 | This macro executes @var{body} like @code{progn}, but all calls to | 1162 | This 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. |
| 1157 | They will be run by the first call to @code{run-mode-hooks} after exit | 1164 | They will be run by the first call to @code{run-mode-hooks} after exit |
| 1158 | from @code{delay-mode-hooks}. | 1165 | from @code{delay-mode-hooks}. This is the proper way for a major mode |
| 1166 | command 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 |
| 1162 | Every major mode function should run this normal hook at its very end. | 1170 | Every major mode function should run this normal hook at its very end. |
| 1163 | It normally does not need to do so explicitly. Indeed, a major mode | 1171 | It normally does not need to do so explicitly. Indeed, a major mode |
| 1164 | function should normally run its mode hook with @code{run-mode-hooks} | 1172 | function should normally run its mode hook with @code{run-mode-hooks} |
| 1165 | as the very last thing it does and @code{run-mode-hooks} runs | 1173 | as 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 |