]> code.delx.au - gnu-emacs/commitdiff
(run-hooks): Don't use mapcar--save consing.
authorRichard M. Stallman <rms@gnu.org>
Tue, 26 Apr 1994 07:43:54 +0000 (07:43 +0000)
committerRichard M. Stallman <rms@gnu.org>
Tue, 26 Apr 1994 07:43:54 +0000 (07:43 +0000)
(run-hook-with-args): New function.

lisp/subr.el

index 6da5177342913bb1239efca987484eedf5f9f6ed..760d1edc22df21a8da2dfe3916d7d6fdfc5cc9e0 100644 (file)
@@ -491,10 +491,31 @@ If it is a list, the elements are called, in order, with no arguments."
           (symbol-value sym)
           (let ((value (symbol-value sym)))
             (if (and (listp value) (not (eq (car value) 'lambda)))
-                (mapcar 'funcall value)
+                (let ((functions value))
+                  (while value
+                    (funcall (car value))
+                    (setq value (cdr value))))
               (funcall value)))))
     (setq hooklist (cdr hooklist))))
 
+(defun run-hook-with-args (hook &rest args)
+  "Run HOOK with the specified arguments ARGS.
+HOOK should be a symbol, a hook variable.  If HOOK 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
+the given arguments and its return value is returned.  If it is a list
+of functions, those functions are called, in order,
+with the given arguments ARGS.
+It is best not to depend on the value return by `run-hook-with-args',
+as that may change."
+  (and (boundp hook)
+       (symbol-value hook)
+       (let ((value (symbol-value hook)))
+        (if (and (listp value) (not (eq (car value) 'lambda)))
+            (mapcar '(lambda (foo) (apply foo args))
+                    value)
+          (apply value args)))))
+
 ;; Tell C code how to call this function.
 (defconst run-hooks 'run-hooks
   "Variable by which C primitives find the function `run-hooks'.