home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume8 / cz / part08 / hook-add.el < prev    next >
Encoding:
Text File  |  1989-10-01  |  1.6 KB  |  46 lines

  1. ;; hook-add.el - Utility to add a function to a hook list.
  2. ;;
  3. ;; $Header: hook-add.el,v 1.1 89/08/04 17:11:46 howard Exp $
  4. ;;
  5. ;; Copyright   1989 Howard Lee Gayle
  6. ;; This file is written in the ISO 8859/1 character set.
  7. ;;
  8. ;; $Header: hook-add.el,v 1.1 89/08/04 17:11:46 howard Exp $
  9. ;;
  10. ;; This program is free software; you can redistribute it and/or modify
  11. ;; it under the terms of the GNU General Public License version 1,
  12. ;; as published by the Free Software Foundation.
  13. ;;
  14. ;; This program is distributed in the hope that it will be useful,
  15. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;; GNU General Public License for more details.
  18. ;;
  19. ;; You should have received a copy of the GNU General Public License
  20. ;; along with this program; if not, write to the Free Software
  21. ;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. (defun hook-add (s f)
  24.    "Append to the value of HOOK-SYMBOL a new FUNCTION.
  25. If HOOK-SYMBOL is unbound or nil, just set it to FUNCTION.
  26. If HOOK-SYMBOL is bound to an atom, make a list.
  27. If HOOK-SYMBOL is already a list, append FUNCTION to the end.
  28. If FUNCTION is already on the list, do nothing.
  29. Typically, both arguments are quoted."
  30.    (if (boundp s)
  31.       (let
  32.             ((sv (eval s))) ; Value of s.
  33.          (cond
  34.             ((null sv) (set s f))
  35.             ((eq sv f) sv)
  36.             ((not (listp sv)) (set s (cons sv (list f))))
  37.             ((memq f sv) sv)
  38.             (t (set s (nconc sv (list f))))
  39.          )
  40.       )
  41.       (set s f)
  42.    )
  43. )
  44.  
  45. (provide 'hook-add)
  46.