Go to the first, previous, next, last section, table of contents.


Normal Hooks

This is the standard type of hook, it is a variable whose value is a list of functions. When the hook is evaluated each of the named functions will be called in turn until one of them returns a value which is not nil. This value becomes the value of the hook and no more of the functions are called. If all of the functions in the hook return nil the value of the hook is nil.

The names of hooks of this type will normally end in -hook.

Function: add-hook hook function &optional at-end
This function adds a new function function to the list of functions installed in the (list) hook hook (a symbol).

If at-end is non-nil the new function is added at the end of the hook's list of functions (and therefore will be called last when the hook is evaluated), otherwise the new function is added to the front of the list.

text-mode-hook
    => (fill-mode-on)
(add-hook 'text-mode-hook 'my-function)
    => (my-function fill-mode-on)

Function: remove-hook hook function
This function removes the function function from the list of functions stored in the (list) hook hook (a symbol).

All instances of function are deleted from the hook.

text-mode-hook
    => (my-function fill-mode-on)
(remove-hook 'text-mode-hook 'my-function)
    => (fill-mode-on)

Function: eval-hook hook &rest args
Evaluates the (list) hook hook (a symbol) with argument values args.

Each function stored in the hook is applied to the args in turn until one returns non-nil. This non-nil value becomes the result of the hook. If all functions return nil then the result of the hook is nil.

Note that most functions which are installed in hooks should always return nil to ensure that all the functions in the hook are evaluated.


Go to the first, previous, next, last section, table of contents.