home *** CD-ROM | disk | FTP | other *** search
- ;; hook-add.el - Utility to add a function to a hook list.
- ;;
- ;; $Header: hook-add.el,v 1.1 89/08/04 17:11:46 howard Exp $
- ;;
- ;; Copyright 1989 Howard Lee Gayle
- ;; This file is written in the ISO 8859/1 character set.
- ;;
- ;; $Header: hook-add.el,v 1.1 89/08/04 17:11:46 howard Exp $
- ;;
- ;; This program is free software; you can redistribute it and/or modify
- ;; it under the terms of the GNU General Public License version 1,
- ;; as published by the Free Software Foundation.
- ;;
- ;; This program is distributed in the hope that it will be useful,
- ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
- ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ;; GNU General Public License for more details.
- ;;
- ;; You should have received a copy of the GNU General Public License
- ;; along with this program; if not, write to the Free Software
- ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- (defun hook-add (s f)
- "Append to the value of HOOK-SYMBOL a new FUNCTION.
- If HOOK-SYMBOL is unbound or nil, just set it to FUNCTION.
- If HOOK-SYMBOL is bound to an atom, make a list.
- If HOOK-SYMBOL is already a list, append FUNCTION to the end.
- If FUNCTION is already on the list, do nothing.
- Typically, both arguments are quoted."
- (if (boundp s)
- (let
- ((sv (eval s))) ; Value of s.
- (cond
- ((null sv) (set s f))
- ((eq sv f) sv)
- ((not (listp sv)) (set s (cons sv (list f))))
- ((memq f sv) sv)
- (t (set s (nconc sv (list f))))
- )
- )
- (set s f)
- )
- )
-
- (provide 'hook-add)
-