tm 7.67.
[elisp/tm.git] / tl-18.el
1 ;;;
2 ;;; $Id: tl-18.el,v 0.6 1994/08/01 05:07:03 morioka Exp $
3 ;;;
4
5 (provide 'tl-18)
6
7 (defun add-hook (hook function &optional append)
8   "Add to the value of HOOK the function FUNCTION.
9 FUNCTION is not added if already present.
10 FUNCTION is added (if necessary) at the beginning of the hook list
11 unless the optional argument APPEND is non-nil, in which case
12 FUNCTION is added at the end.
13  
14 HOOK should be a symbol, and FUNCTION may be any valid function.  If
15 HOOK is void, it is first set to nil.  If HOOK's value is a single
16 function, it is changed to a list of functions."
17   (or (boundp hook)
18       (set hook nil)
19       )
20   ;; If the hook value is a single function, turn it into a list.
21   (let ((old (symbol-value hook)))
22     (if (or (not (listp old))
23             (eq (car old) 'lambda))
24         (set hook (list old))
25       ))
26   (or (if (consp function)
27           ;; Clever way to tell whether a given lambda-expression
28           ;; is equal to anything in the hook.
29           (let ((tail (assoc (cdr function) (symbol-value hook))))
30             (equal function tail)
31             )
32         (memq function (symbol-value hook))
33         )
34       (set hook 
35            (if append
36                (nconc (symbol-value hook) (list function))
37              (cons function (symbol-value hook))
38              ))
39       ))
40
41 (defun member (elt list)
42   "Return non-nil if ELT is an element of LIST.  Comparison done with EQUAL.
43 The value is actually the tail of LIST whose car is ELT."
44   (while (and list (not (equal elt (car list))))
45     (setq list (cdr list)))
46   list)