diff options
| author | Richard M. Stallman | 2003-10-13 19:25:50 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 2003-10-13 19:25:50 +0000 |
| commit | da3178e26d1bee1d1951e01987e9defd7a167fb9 (patch) | |
| tree | 43f076bfd46a3fbef612b95c56dc7af94382d4e9 | |
| parent | 89f6de49f51624fb5aefe8fbc6594c3b4ff8add7 (diff) | |
| download | emacs-da3178e26d1bee1d1951e01987e9defd7a167fb9.tar.gz emacs-da3178e26d1bee1d1951e01987e9defd7a167fb9.zip | |
(Hooks): Don't explain local hook details here.
Clarify run-hooks and run-hook-with-args a little.
Clean up add-hook and remove-hook.
| -rw-r--r-- | lispref/modes.texi | 57 |
1 files changed, 22 insertions, 35 deletions
diff --git a/lispref/modes.texi b/lispref/modes.texi index 6a1eddca0c4..e29dd25587a 100644 --- a/lispref/modes.texi +++ b/lispref/modes.texi | |||
| @@ -2433,21 +2433,10 @@ are used in other contexts too. For example, the hook | |||
| 2433 | 2433 | ||
| 2434 | The recommended way to add a hook function to a normal hook is by | 2434 | The recommended way to add a hook function to a normal hook is by |
| 2435 | calling @code{add-hook} (see below). The hook functions may be any of | 2435 | calling @code{add-hook} (see below). The hook functions may be any of |
| 2436 | the valid kinds of functions that @code{funcall} accepts (@pxref{What Is | 2436 | the valid kinds of functions that @code{funcall} accepts (@pxref{What |
| 2437 | a Function}). Most normal hook variables are initially void; | 2437 | Is a Function}). Most normal hook variables are initially void; |
| 2438 | @code{add-hook} knows how to deal with this. | 2438 | @code{add-hook} knows how to deal with this. You can add hooks either |
| 2439 | 2439 | globally or buffer-locally with @code{add-hook}. | |
| 2440 | With @code{add-hook}, you can also add hook functions to the | ||
| 2441 | buffer-local value of a hook variable. If necessary, @code{add-hook} | ||
| 2442 | first makes the hook variable buffer-local and adds @code{t} to the | ||
| 2443 | buffer-local value. The element @code{t} in the buffer-local value of | ||
| 2444 | a hook variable acts as a signal for the various functions that run | ||
| 2445 | hooks to run the default value of the hook variable as well; @code{t} | ||
| 2446 | is basically substituted with the elements of the default value of a | ||
| 2447 | hook variable. Since @code{add-hook} normally adds hook functions to | ||
| 2448 | the front of hook variables, this means that the hook functions in the | ||
| 2449 | buffer-local value are called before the hook functions in the default | ||
| 2450 | value of hook variables. | ||
| 2451 | 2440 | ||
| 2452 | @cindex abnormal hook | 2441 | @cindex abnormal hook |
| 2453 | If the hook variable's name does not end with @samp{-hook}, that | 2442 | If the hook variable's name does not end with @samp{-hook}, that |
| @@ -2480,16 +2469,15 @@ been added with @code{add-hook}. | |||
| 2480 | @defun run-hooks &rest hookvars | 2469 | @defun run-hooks &rest hookvars |
| 2481 | This function takes one or more normal hook variable names as | 2470 | This function takes one or more normal hook variable names as |
| 2482 | arguments, and runs each hook in turn. Each argument should be a | 2471 | arguments, and runs each hook in turn. Each argument should be a |
| 2483 | symbol that is a hook variable. These arguments are processed in the | 2472 | symbol that is a normal hook variable. These arguments are processed |
| 2484 | order specified. | 2473 | in the order specified. |
| 2485 | 2474 | ||
| 2486 | If a hook variable has a non-@code{nil} value, that value may be a | 2475 | If a hook variable has a non-@code{nil} value, that value may be a |
| 2487 | function or a list of functions. If the value is a function (either a | 2476 | function or a list of functions. (The former option is considered |
| 2488 | lambda expression or a symbol with a function definition), it is called. | 2477 | obsolete.) If the value is a function (either a lambda expression or |
| 2489 | If it is a list, the elements are called, in order. The hook functions | 2478 | a symbol with a function definition), it is called. If it is a list |
| 2490 | are called with no arguments. Nowadays, storing a single function in | 2479 | that isn't a function, its elements are called, consecutively. All |
| 2491 | the hook variable is semi-obsolete; you should always use a list of | 2480 | the hook functions are called with no arguments. |
| 2492 | functions. | ||
| 2493 | 2481 | ||
| 2494 | For example, here's how @code{emacs-lisp-mode} runs its mode hook: | 2482 | For example, here's how @code{emacs-lisp-mode} runs its mode hook: |
| 2495 | 2483 | ||
| @@ -2511,8 +2499,9 @@ its parent modes' mode hooks until the end. | |||
| 2511 | @end defmac | 2499 | @end defmac |
| 2512 | 2500 | ||
| 2513 | @defun run-hook-with-args hook &rest args | 2501 | @defun run-hook-with-args hook &rest args |
| 2514 | This function is the way to run an abnormal hook. It calls each of | 2502 | This function is the way to run an abnormal hook and always call all |
| 2515 | the hook functions, passing each of them the arguments @var{args}. | 2503 | of the hook functions. It calls each of the hook functions one by |
| 2504 | one, passing each of them the arguments @var{args}. | ||
| 2516 | @end defun | 2505 | @end defun |
| 2517 | 2506 | ||
| 2518 | @defun run-hook-with-args-until-failure hook &rest args | 2507 | @defun run-hook-with-args-until-failure hook &rest args |
| @@ -2534,10 +2523,9 @@ the last hook function that was called. If all hook functions return | |||
| 2534 | 2523 | ||
| 2535 | @defun add-hook hook function &optional append local | 2524 | @defun add-hook hook function &optional append local |
| 2536 | This function is the handy way to add function @var{function} to hook | 2525 | This function is the handy way to add function @var{function} to hook |
| 2537 | variable @var{hook}. The argument @var{function} is not added if it | 2526 | variable @var{hook}. You can use it for abnormal hooks as well as for |
| 2538 | is already present on @var{hook} (comparisons are performed with | 2527 | normal hooks. @var{function} can be any Lisp function that can accept |
| 2539 | @code{equal}; @pxref{Equality Predicates}). @var{function} may be any | 2528 | the proper number of arguments for @var{hook}. For example, |
| 2540 | valid Lisp function with the proper number of arguments. For example, | ||
| 2541 | 2529 | ||
| 2542 | @example | 2530 | @example |
| 2543 | (add-hook 'text-mode-hook 'my-text-hook-function) | 2531 | (add-hook 'text-mode-hook 'my-text-hook-function) |
| @@ -2546,8 +2534,8 @@ valid Lisp function with the proper number of arguments. For example, | |||
| 2546 | @noindent | 2534 | @noindent |
| 2547 | adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}. | 2535 | adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}. |
| 2548 | 2536 | ||
| 2549 | You can use @code{add-hook} for abnormal hooks as well as for normal | 2537 | If @var{function} is already present in @var{hook} (comparing using |
| 2550 | hooks. | 2538 | @code{equal}), then @code{add-hook} does not add it a second time. |
| 2551 | 2539 | ||
| 2552 | It is best to design your hook functions so that the order in which they | 2540 | It is best to design your hook functions so that the order in which they |
| 2553 | are executed does not matter. Any dependence on the order is ``asking | 2541 | are executed does not matter. Any dependence on the order is ``asking |
| @@ -2566,10 +2554,9 @@ functions in the default value as well as in the local value. | |||
| 2566 | 2554 | ||
| 2567 | @defun remove-hook hook function &optional local | 2555 | @defun remove-hook hook function &optional local |
| 2568 | This function removes @var{function} from the hook variable | 2556 | This function removes @var{function} from the hook variable |
| 2569 | @var{hook}. The argument @var{function} is compared with elements of | 2557 | @var{hook}. It compares @var{function} with elements of @var{hook} |
| 2570 | @var{hook} by means of @code{equal} (@pxref{Equality Predicates}). | 2558 | using @code{equal}, so it works for both symbols and lambda |
| 2571 | This means that you can remove symbols with a function definition as | 2559 | expressions. |
| 2572 | well as lambda expressions. | ||
| 2573 | 2560 | ||
| 2574 | If @var{local} is non-@code{nil}, that says to remove @var{function} | 2561 | If @var{local} is non-@code{nil}, that says to remove @var{function} |
| 2575 | from the buffer-local hook list instead of from the global hook list. | 2562 | from the buffer-local hook list instead of from the global hook list. |