aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1994-04-26 07:43:54 +0000
committerRichard M. Stallman1994-04-26 07:43:54 +0000
commite8976c8a2c6bc87470e1e8442227755b0db1ed15 (patch)
treeda12fffcc1fb973672248c7528002d7fa1587649
parenta27a38d8a7b704402065457fd324540ce9d1f4b8 (diff)
downloademacs-e8976c8a2c6bc87470e1e8442227755b0db1ed15.tar.gz
emacs-e8976c8a2c6bc87470e1e8442227755b0db1ed15.zip
(run-hooks): Don't use mapcar--save consing.
(run-hook-with-args): New function.
-rw-r--r--lisp/subr.el23
1 files changed, 22 insertions, 1 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 6da51773429..760d1edc22d 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -491,10 +491,31 @@ If it is a list, the elements are called, in order, with no arguments."
491 (symbol-value sym) 491 (symbol-value sym)
492 (let ((value (symbol-value sym))) 492 (let ((value (symbol-value sym)))
493 (if (and (listp value) (not (eq (car value) 'lambda))) 493 (if (and (listp value) (not (eq (car value) 'lambda)))
494 (mapcar 'funcall value) 494 (let ((functions value))
495 (while value
496 (funcall (car value))
497 (setq value (cdr value))))
495 (funcall value))))) 498 (funcall value)))))
496 (setq hooklist (cdr hooklist)))) 499 (setq hooklist (cdr hooklist))))
497 500
501(defun run-hook-with-args (hook &rest args)
502 "Run HOOK with the specified arguments ARGS.
503HOOK should be a symbol, a hook variable. If HOOK has a non-nil
504value, that value may be a function or a list of functions to be
505called to run the hook. If the value is a function, it is called with
506the given arguments and its return value is returned. If it is a list
507of functions, those functions are called, in order,
508with the given arguments ARGS.
509It is best not to depend on the value return by `run-hook-with-args',
510as that may change."
511 (and (boundp hook)
512 (symbol-value hook)
513 (let ((value (symbol-value hook)))
514 (if (and (listp value) (not (eq (car value) 'lambda)))
515 (mapcar '(lambda (foo) (apply foo args))
516 value)
517 (apply value args)))))
518
498;; Tell C code how to call this function. 519;; Tell C code how to call this function.
499(defconst run-hooks 'run-hooks 520(defconst run-hooks 'run-hooks
500 "Variable by which C primitives find the function `run-hooks'. 521 "Variable by which C primitives find the function `run-hooks'.