Skip to content

Commit f475e2a

Browse files
committed
Allow run-hook to take arguments.
1 parent cf8e2e3 commit f475e2a

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

hooks.lisp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,26 @@
2424
,@body))
2525

2626
(defun run-hooks (&rest hooks)
27-
"Run all the hooks in HOOKS.
27+
"Run all the hooks in HOOKS, without arguments.
2828
The variable `*hook*' is bound to the name of each hook as it is being
2929
run."
3030
(dolist (*hook* hooks)
3131
(run-hook *hook*)))
3232

33-
(defgeneric run-hook (hook)
34-
(:documentation "Run the functions in HOOK.")
35-
(:method ((*hook* symbol))
36-
(dolist (fn (symbol-value *hook*))
37-
(with-hook-restart
38-
(funcall fn)))))
39-
40-
(defgeneric run-hook-with-args (hook &rest args)
33+
(defgeneric run-hook (hook &rest args)
4134
(:documentation "Apply each function in HOOK to ARGS.")
4235
(:method ((*hook* symbol) &rest args)
4336
(dolist (fn (symbol-value *hook*))
4437
(with-hook-restart
4538
(apply fn args)))))
4639

47-
(defgeneric run-hook-with-args-until-failure (hook &rest args)
40+
(defgeneric run-hook-until-failure (hook &rest args)
4841
(:documentation "Like `run-hook-with-args', but quit once a function returns nil.")
4942
(:method ((*hook* symbol) &rest args)
5043
(loop for fn in (symbol-value *hook*)
5144
always (apply fn args))))
5245

53-
(defgeneric run-hook-with-args-until-success (hook &rest args)
46+
(defgeneric run-hook-until-success (hook &rest args)
5447
(:documentation "Like `run-hook-with-args', but quit once a function returns
5548
non-nil.")
5649
(:method ((*hook* symbol) &rest args)

package.lisp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@
286286
#:remove-hook
287287
#:run-hooks
288288
#:run-hook
289-
#:run-hook-with-args
290-
#:run-hook-with-args-until-failure
291-
#:run-hook-with-args-until-success
289+
#:run-hook
290+
#:run-hook-until-failure
291+
#:run-hook-until-success
292292
;; Fbind.
293293
#:fbind
294294
#:fbind*

tests/hooks.lisp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@
3434
(let ((list '()))
3535
(flet ((add (n) (push n list)))
3636
(add-hook hook #'add)
37-
(run-hook-with-args hook '2)
38-
(run-hook-with-args hook '1)
37+
(run-hook hook '2)
38+
(run-hook hook '1)
3939
(is (equal list '(1 2)))))))
4040

41-
(test run-hook-with-args-until-failure
41+
(test run-hook-until-failure
4242
(with-temp-hook (hook)
4343
(add-hook hook (constantly nil))
4444
(add-hook hook
4545
(lambda () (fail "This function should not run"))
4646
:append t)
47-
(run-hook-with-args-until-failure hook)))
47+
(run-hook-until-failure hook)))
4848

49-
(test run-hook-with-args-until-success
49+
(test run-hook-until-success
5050
(with-temp-hook (hook)
5151
(add-hook hook (constantly t))
5252
(add-hook hook
5353
(lambda () (fail "This function should not run"))
5454
:append t)
55-
(run-hook-with-args-until-success hook)))
55+
(run-hook-until-success hook)))

0 commit comments

Comments
 (0)