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 | |
| parent | 4f8aaa7480ecc26189f1a338bd7f45f6d54446bf (diff) | |
| download | emacs-dd73b091cbdfa4a9268fb0de925faab04e5bab44.tar.gz emacs-dd73b091cbdfa4a9268fb0de925faab04e5bab44.zip | |
Explain better about abnormal hooks.
| -rw-r--r-- | lispref/hooks.texi | 25 | ||||
| -rw-r--r-- | lispref/modes.texi | 43 |
2 files changed, 39 insertions, 29 deletions
diff --git a/lispref/hooks.texi b/lispref/hooks.texi index 18f8bcfcad5..046ac7cc5d5 100644 --- a/lispref/hooks.texi +++ b/lispref/hooks.texi | |||
| @@ -11,19 +11,22 @@ functions to be called from within Emacs on suitable occasions. | |||
| 11 | 11 | ||
| 12 | Most of these variables have names ending with @samp{-hook}. They are | 12 | Most of these variables have names ending with @samp{-hook}. They are |
| 13 | @dfn{normal hooks}, run by means of @code{run-hooks}. The value of such | 13 | @dfn{normal hooks}, run by means of @code{run-hooks}. The value of such |
| 14 | a hook is a list of functions. The recommended way to put a new | 14 | a hook is a list of functions; the functions are called with no |
| 15 | function on such a hook is to call @code{add-hook}. @xref{Hooks}, for | 15 | arguments and their values are completely ignored. The recommended way |
| 16 | more information about using hooks. | 16 | to put a new function on such a hook is to call @code{add-hook}. |
| 17 | @xref{Hooks}, for more information about using hooks. | ||
| 17 | 18 | ||
| 18 | The variables whose names end in @samp{-function} have single functions | 19 | The variables whose names end in @samp{-hooks} or @samp{-functions} are |
| 19 | as their values. Usually there is a specific reason why the variable is | 20 | usually @dfn{abnormal hooks}; their values are lists of functions, but |
| 20 | not a normal hook, such as the need to pass arguments to the function. | 21 | these functions are called in a special way (they are passed arguments, |
| 21 | (In older Emacs versions, some of these variables had names ending in | 22 | or their values are used). A few of these variables are actually normal |
| 22 | @samp{-hook} even though they were not normal hooks.) | 23 | hooks which were named before we established the convention that normal |
| 24 | hooks' names should end in @samp{-hook}. | ||
| 23 | 25 | ||
| 24 | The variables whose names end in @samp{-hooks} or @samp{-functions} have | 26 | The variables whose names end in @samp{-function} have single functions |
| 25 | lists of functions as their values, but these functions are called in a | 27 | as their values. (In older Emacs versions, some of these variables had |
| 26 | special way (they are passed arguments, or else their values are used). | 28 | names ending in @samp{-hook} even though they were not normal hooks; |
| 29 | however, we have renamed all of those.) | ||
| 27 | 30 | ||
| 28 | @c !!! need xref to where each hook is documented or else document it | 31 | @c !!! need xref to where each hook is documented or else document it |
| 29 | @c by specifying what is expected, and when it is called relative to | 32 | @c by specifying what is expected, and when it is called relative to |
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: |