elisp: Setting Hooks

 
 22.1.2 Setting Hooks
 --------------------
 
 Here’s an example that uses a mode hook to turn on Auto Fill mode when
 in Lisp Interaction mode:
 
      (add-hook 'lisp-interaction-mode-hook 'auto-fill-mode)
 
  -- Function: add-hook hook function &optional append local
      This function is the handy way to add function FUNCTION to hook
      variable HOOK.  You can use it for abnormal hooks as well as for
      normal hooks.  FUNCTION can be any Lisp function that can accept
      the proper number of arguments for HOOK.  For example,
 
           (add-hook 'text-mode-hook 'my-text-hook-function)
 
      adds ‘my-text-hook-function’ to the hook called ‘text-mode-hook’.
 
      If FUNCTION is already present in HOOK (comparing using ‘equal’),
      then ‘add-hook’ does not add it a second time.
 
      If FUNCTION has a non-‘nil’ property ‘permanent-local-hook’, then
      ‘kill-all-local-variables’ (or changing major modes) won’t delete
      it from the hook variable’s local value.
 
      For a normal hook, hook functions should be designed so that the
      order in which they are executed does not matter.  Any dependence
      on the order is asking for trouble.  However, the order is
      predictable: normally, FUNCTION goes at the front of the hook list,
      so it is executed first (barring another ‘add-hook’ call).  If the
      optional argument APPEND is non-‘nil’, the new hook function goes
      at the end of the hook list and is executed last.
 
      ‘add-hook’ can handle the cases where HOOK is void or its value is
      a single function; it sets or changes the value to a list of
      functions.
 
      If LOCAL is non-‘nil’, that says to add FUNCTION to the
      buffer-local hook list instead of to the global hook list.  This
      makes the hook buffer-local and adds ‘t’ to the buffer-local value.
      The latter acts as a flag to run the hook functions in the default
      value as well as in the local value.
 
  -- Function: remove-hook hook function &optional local
      This function removes FUNCTION from the hook variable HOOK.  It
      compares FUNCTION with elements of HOOK using ‘equal’, so it works
      for both symbols and lambda expressions.
 
      If LOCAL is non-‘nil’, that says to remove FUNCTION from the
      buffer-local hook list instead of from the global hook list.