diff options
| author | Richard M. Stallman | 1996-09-01 22:44:57 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1996-09-01 22:44:57 +0000 |
| commit | dd73b091cbdfa4a9268fb0de925faab04e5bab44 (patch) | |
| tree | 00b6ec415506b4160f49e5cf28a411855b69e407 /lispref/modes.texi | |
| parent | 4f8aaa7480ecc26189f1a338bd7f45f6d54446bf (diff) | |
| download | emacs-dd73b091cbdfa4a9268fb0de925faab04e5bab44.tar.gz emacs-dd73b091cbdfa4a9268fb0de925faab04e5bab44.zip | |
Explain better about abnormal hooks.
Diffstat (limited to 'lispref/modes.texi')
| -rw-r--r-- | lispref/modes.texi | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi index e7b164f3b2c..10c71d00993 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -1262,10 +1262,17 @@ up in the @file{.emacs} file, but Lisp programs can set them also. | |||
| 1262 | @xref{Standard Hooks}, for a list of standard hook variables. | 1262 | @xref{Standard Hooks}, for a list of standard hook variables. |
| 1263 | 1263 | ||
| 1264 | Most of the hooks in Emacs are @dfn{normal hooks}. These variables | 1264 | Most of the hooks in Emacs are @dfn{normal hooks}. These variables |
| 1265 | contain lists of functions to be called with no arguments. The reason | 1265 | contain lists of functions to be called with no arguments. When the |
| 1266 | most hooks are normal hooks is so that you can use them in a uniform | 1266 | hook name ends in @samp{-hook}, that tells you it is normal. We try to |
| 1267 | way. You can always tell when a hook is a normal hook, because its | 1267 | make all hooks normal, as much as possible, so that you can use them in |
| 1268 | name ends in @samp{-hook}. | 1268 | a uniform way. |
| 1269 | |||
| 1270 | Every major mode function is supposed to run a normal hook called the | ||
| 1271 | @dfn{mode hook} as the last step of initialization. This makes it easy | ||
| 1272 | for a user to customize the behavior of the mode, by overriding the | ||
| 1273 | local variable assignments already made by the mode. But hooks are used | ||
| 1274 | in other contexts too. For example, the hook @code{suspend-hook} runs | ||
| 1275 | just before Emacs suspends itself (@pxref{Suspending Emacs}). | ||
| 1269 | 1276 | ||
| 1270 | The recommended way to add a hook function to a normal hook is by | 1277 | The recommended way to add a hook function to a normal hook is by |
| 1271 | calling @code{add-hook} (see below). The hook functions may be any of | 1278 | calling @code{add-hook} (see below). The hook functions may be any of |
| @@ -1273,20 +1280,20 @@ the valid kinds of functions that @code{funcall} accepts (@pxref{What Is | |||
| 1273 | a Function}). Most normal hook variables are initially void; | 1280 | a Function}). Most normal hook variables are initially void; |
| 1274 | @code{add-hook} knows how to deal with this. | 1281 | @code{add-hook} knows how to deal with this. |
| 1275 | 1282 | ||
| 1276 | As for abnormal hooks, those whose names end in @samp{-function} have | 1283 | If the hook variable's name does not end with @samp{-hook}, that |
| 1277 | a value that is a single function. Those whose names end in | 1284 | indicates it is probably an abnormal hook; you should look at its |
| 1278 | @samp{-hooks} have a value that is a list of functions. Any hook that | 1285 | documentation to see how to use the hook properly. |
| 1279 | is abnormal is abnormal because a normal hook won't do the job; either | 1286 | |
| 1280 | the functions are called with arguments, or their values are meaningful. | 1287 | If the variable's name ends in @samp{-functions} or @samp{-hooks}, |
| 1281 | The name shows you that the hook is abnormal and that you should look at | 1288 | then the value is a list of functions, but it is abnormal in that either |
| 1282 | its documentation string to see how to use it properly. | 1289 | these functions are called with arguments or their values are used in |
| 1283 | 1290 | some way. You can use @code{add-hook} to add a function to the list, | |
| 1284 | Major mode functions are supposed to run a hook called the @dfn{mode | 1291 | but you must take care in writing the function. (A few of these |
| 1285 | hook} as the last step of initialization. This makes it easy for a user | 1292 | variables are actually normal hooks which were named before we |
| 1286 | to customize the behavior of the mode, by overriding the local variable | 1293 | established the convention of using @samp{-hook} for them.) |
| 1287 | assignments already made by the mode. But hooks are used in other | 1294 | |
| 1288 | contexts too. For example, the hook @code{suspend-hook} runs just | 1295 | If the variable's name ends in @samp{-function}, then its value |
| 1289 | before Emacs suspends itself (@pxref{Suspending Emacs}). | 1296 | is just a single function, not a list of functions. |
| 1290 | 1297 | ||
| 1291 | Here's an expression that uses a mode hook to turn on Auto Fill mode | 1298 | Here's an expression that uses a mode hook to turn on Auto Fill mode |
| 1292 | when in Lisp Interaction mode: | 1299 | when in Lisp Interaction mode: |