home *** CD-ROM | disk | FTP | other *** search
- ;From ark1!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!liberte Thu Apr 19 12:34:17 EDT 1990
- ;Article 1772 of comp.emacs:
- ;Path: ark1!uakari.primate.wisc.edu!brutus.cs.uiuc.edu!liberte
- ;>From: liberte@cs.uiuc.edu (Daniel LaLiberte)
- ;Newsgroups: comp.emacs
- ;Subject: Re: text-mode-hook
- ;Message-ID: <LIBERTE.90Apr15174338@cassius.cs.uiuc.edu>
- ;Date: 15 Apr 90 22:41:10 GMT
- ;References: <sa7sr8K00hMN1MQG0R@cs.cmu.edu> <PD.90Apr10155710@rutland.ixi.uucp>
- ; <WEINER.90Apr11233748@novavax.UUCP>
- ;Sender: news@brutus.cs.uiuc.edu
- ;Organization: University of Illinois, Urbana-Champaign, Dept CS
- ;Lines: 50
- ;In-reply-to: weiner@novavax.UUCP's message of 12 Apr 90 03:37:48 GMT
- ;
- ;
- ;Here is another, more general way to solve the multiple hook problem.
- ;I may not have covered every case, but compared to Bob Weiner's,
- ;this one tests whether the hook-var already contains the hook-function;
- ;it also allows the hook-var to initially contain either a single function
- ;or a list of functions, as run-hooks supports.
- ;
- ;Now that I look at it again, I'm not even sure that it works correctly.
- ;But I thought I would toss it out for what it's worth.
-
- (defun add-hook (hook-var hook-function)
- "Prepend hook-function to hook-var's value, if it is not already an element.
- hook-var's value may be a single function or a list of functions."
- (if (boundp hook-var)
- (let ((value (symbol-value hook-var)))
- (if (and (listp value) (not (eq (car value) 'lambda)))
- (and (not (memq hook-function value))
- (set hook-var
- (cons hook-function value)))
- (and (not (eq hook-function value))
- (set hook-var
- (list hook-function value)))))
- (set hook-var hook-function)
- ))
-
- ;---------
- ;For comparison, here is the definition of run-hooks in subr.el:
- ;
- ;(defun run-hooks (&rest hooklist)
- ; "Takes hook names and runs each one in turn. Major mode functions use this.
- ;Each argument should be a symbol, a hook variable.
- ;These symbols are processed in the order specified.
- ;If a hook symbol has a non-nil value, that value may be a function
- ;or a list of functions to be called to run the hook.
- ;If the value is a function, it is called with no arguments.
- ;If it is a list, the elements are called, in order, with no arguments."
- ; (while hooklist
- ; (let ((sym (car hooklist)))
- ; (and (boundp sym)
- ; (symbol-value sym)
- ; (let ((value (symbol-value sym)))
- ; (if (and (listp value) (not (eq (car value) 'lambda)))
- ; (mapcar 'funcall value)
- ; (funcall value)))))
- ; (setq hooklist (cdr hooklist))))
- ;
- ;Dan LaLiberte
- ;uiucdcs!liberte
- ;liberte@cs.uiuc.edu
- ;liberte%a.cs.uiuc.edu@uiucvmd.bitnet
-