diff options
| author | Richard M. Stallman | 1994-04-26 07:43:54 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1994-04-26 07:43:54 +0000 |
| commit | e8976c8a2c6bc87470e1e8442227755b0db1ed15 (patch) | |
| tree | da12fffcc1fb973672248c7528002d7fa1587649 | |
| parent | a27a38d8a7b704402065457fd324540ce9d1f4b8 (diff) | |
| download | emacs-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.el | 23 |
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. | ||
| 503 | HOOK should be a symbol, a hook variable. If HOOK has a non-nil | ||
| 504 | value, that value may be a function or a list of functions to be | ||
| 505 | called to run the hook. If the value is a function, it is called with | ||
| 506 | the given arguments and its return value is returned. If it is a list | ||
| 507 | of functions, those functions are called, in order, | ||
| 508 | with the given arguments ARGS. | ||
| 509 | It is best not to depend on the value return by `run-hook-with-args', | ||
| 510 | as 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'. |