aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman2003-10-13 19:25:50 +0000
committerRichard M. Stallman2003-10-13 19:25:50 +0000
commitda3178e26d1bee1d1951e01987e9defd7a167fb9 (patch)
tree43f076bfd46a3fbef612b95c56dc7af94382d4e9
parent89f6de49f51624fb5aefe8fbc6594c3b4ff8add7 (diff)
downloademacs-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.texi57
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
2435calling @code{add-hook} (see below). The hook functions may be any of 2435calling @code{add-hook} (see below). The hook functions may be any of
2436the valid kinds of functions that @code{funcall} accepts (@pxref{What Is 2436the valid kinds of functions that @code{funcall} accepts (@pxref{What
2437a Function}). Most normal hook variables are initially void; 2437Is 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 2439globally or buffer-locally with @code{add-hook}.
2440With @code{add-hook}, you can also add hook functions to the
2441buffer-local value of a hook variable. If necessary, @code{add-hook}
2442first makes the hook variable buffer-local and adds @code{t} to the
2443buffer-local value. The element @code{t} in the buffer-local value of
2444a hook variable acts as a signal for the various functions that run
2445hooks to run the default value of the hook variable as well; @code{t}
2446is basically substituted with the elements of the default value of a
2447hook variable. Since @code{add-hook} normally adds hook functions to
2448the front of hook variables, this means that the hook functions in the
2449buffer-local value are called before the hook functions in the default
2450value 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
2481This function takes one or more normal hook variable names as 2470This function takes one or more normal hook variable names as
2482arguments, and runs each hook in turn. Each argument should be a 2471arguments, and runs each hook in turn. Each argument should be a
2483symbol that is a hook variable. These arguments are processed in the 2472symbol that is a normal hook variable. These arguments are processed
2484order specified. 2473in the order specified.
2485 2474
2486If a hook variable has a non-@code{nil} value, that value may be a 2475If a hook variable has a non-@code{nil} value, that value may be a
2487function or a list of functions. If the value is a function (either a 2476function or a list of functions. (The former option is considered
2488lambda expression or a symbol with a function definition), it is called. 2477obsolete.) If the value is a function (either a lambda expression or
2489If it is a list, the elements are called, in order. The hook functions 2478a symbol with a function definition), it is called. If it is a list
2490are called with no arguments. Nowadays, storing a single function in 2479that isn't a function, its elements are called, consecutively. All
2491the hook variable is semi-obsolete; you should always use a list of 2480the hook functions are called with no arguments.
2492functions.
2493 2481
2494For example, here's how @code{emacs-lisp-mode} runs its mode hook: 2482For 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
2514This function is the way to run an abnormal hook. It calls each of 2502This function is the way to run an abnormal hook and always call all
2515the hook functions, passing each of them the arguments @var{args}. 2503of the hook functions. It calls each of the hook functions one by
2504one, 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
2536This function is the handy way to add function @var{function} to hook 2525This function is the handy way to add function @var{function} to hook
2537variable @var{hook}. The argument @var{function} is not added if it 2526variable @var{hook}. You can use it for abnormal hooks as well as for
2538is already present on @var{hook} (comparisons are performed with 2527normal hooks. @var{function} can be any Lisp function that can accept
2539@code{equal}; @pxref{Equality Predicates}). @var{function} may be any 2528the proper number of arguments for @var{hook}. For example,
2540valid 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
2547adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}. 2535adds @code{my-text-hook-function} to the hook called @code{text-mode-hook}.
2548 2536
2549You can use @code{add-hook} for abnormal hooks as well as for normal 2537If @var{function} is already present in @var{hook} (comparing using
2550hooks. 2538@code{equal}), then @code{add-hook} does not add it a second time.
2551 2539
2552It is best to design your hook functions so that the order in which they 2540It is best to design your hook functions so that the order in which they
2553are executed does not matter. Any dependence on the order is ``asking 2541are 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
2568This function removes @var{function} from the hook variable 2556This 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}). 2558using @code{equal}, so it works for both symbols and lambda
2571This means that you can remove symbols with a function definition as 2559expressions.
2572well as lambda expressions.
2573 2560
2574If @var{local} is non-@code{nil}, that says to remove @var{function} 2561If @var{local} is non-@code{nil}, that says to remove @var{function}
2575from the buffer-local hook list instead of from the global hook list. 2562from the buffer-local hook list instead of from the global hook list.