Previous: , Up: Hooks   [Contents][Index]

5.25.2 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 functions will be called in turn.

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

These functions are exported by the rep.system module.

Function: add-hook hook function #!optional at-end

This function adds a function function to the list of functions installed in the (list) hook hook (a symbol).

If at-end is true 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.

A new element of function is always added, i.e. even if it’s already present in hook, unlike Emacs lisp.

    ⇒ (#<closure fill-mode-on>)
(add-hook 'text-mode-hook my-function)
    ⇒ (#<closure my-function> #<closure 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.

Function: remove-hook-by-name hook name

This function removes all functions whose name is name from the hook (a symbol).

Function: in-hook-p hook function

Returns t is the function function is stored in the hook hook (a symbol).

There are actually three calling conventions for this type of hook, differing in how many of the functions in the list actually get called. In this simplest form, all functions are called. In an and type hook, functions are only invoked while all others have returned true. As soon as the first function in the hook returns false, no others will be called. Finally, an or type hook aborts when a function returns a true result.

Function: call-hook hook arg-list #!optional type

Call the hook named by the symbol hook, passing all functions the arguments in the list arg-list. Note that hook may also be the actual list of functions to call.

type defines how the return values of each function in the hook are treated. If type is false they are ignored, if type is the symbol and the hook aborts after a function returns false, if type is or the hook aborts when a function returns true.

In all cases the value returned by the last-evaluated function is returned.

Previous: , Up: Hooks   [Contents][Index]