summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c23
-rw-r--r--stdlib/doc-syms.tl2
-rw-r--r--tests/019/load-hook.tl10
-rw-r--r--txr.138
4 files changed, 73 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 006861b1..487df9d7 100644
--- a/eval.c
+++ b/eval.c
@@ -4579,6 +4579,25 @@ static val me_load_for(val form, val menv)
return cons(rt_load_for_s, out);
}
+static val me_push_after_load(val form, val menv)
+{
+ (void) menv;
+ return list(set_s,
+ load_hooks_s,
+ list(cons_s,
+ cons(lambda_s, cons(nil, cdr(form))),
+ load_hooks_s,
+ nao), nao);
+}
+
+static val me_pop_after_load(val form, val menv)
+{
+ (void) menv;
+ if (cdr(form))
+ expand_error(form, lit("~s: no arguments required"), car(form), nao);
+ return list(set_s, load_hooks_s, list(cdr_s, load_hooks_s, nao), nao);
+}
+
void run_load_hooks(val load_dyn_env)
{
val hooks_binding = lookup_var(load_dyn_env, load_hooks_s);
@@ -6808,6 +6827,10 @@ void eval_init(void)
reg_mac(intern(lit("mlet"), user_package), func_n2(me_mlet));
reg_mac(load_time_s, func_n2(me_load_time));
reg_mac(intern(lit("load-for"), user_package), func_n2(me_load_for));
+ reg_mac(intern(lit("push-after-load"), user_package),
+ func_n2(me_push_after_load));
+ reg_mac(intern(lit("pop-after-load"), user_package),
+ func_n2(me_pop_after_load));
reg_mac(intern(lit("assert"), user_package), func_n2(me_assert));
reg_fun(cons_s, func_n2(cons));
diff --git a/stdlib/doc-syms.tl b/stdlib/doc-syms.tl
index a14a83d6..6243ffaa 100644
--- a/stdlib/doc-syms.tl
+++ b/stdlib/doc-syms.tl
@@ -1430,6 +1430,7 @@
("poll" "N-0386D39D")
("poly" "N-026201AD")
("pop" "N-017F39D2")
+ ("pop-after-load" "N-01F489FE")
("portable-abs-path-p" "N-00477B23")
("pos" "N-02C2BBDB")
("pos-if" "N-02C2BBDB")
@@ -1472,6 +1473,7 @@
("pure-rel-path-p" "N-019DEA44")
("purge-deferred-warning" "N-0077C4FE")
("push" "N-01C211C1")
+ ("push-after-load" "N-01F489FE")
("pushhash" "N-022660B2")
("pushnew" "N-02C37AB0")
("put-buf" "D-007E")
diff --git a/tests/019/load-hook.tl b/tests/019/load-hook.tl
index 0f33d081..e62e689b 100644
--- a/tests/019/load-hook.tl
+++ b/tests/019/load-hook.tl
@@ -16,3 +16,13 @@
(set counter nil)
(load "../load-hook.tlo")
(test counter 1)
+
+(mtest
+ (macroexpand-1 '(push-after-load))
+ (set *load-hooks* (cons (lambda ()) *load-hooks*))
+
+ (macroexpand-1 '(push-after-load x))
+ (set *load-hooks* (cons (lambda () x) *load-hooks*))
+
+ (macroexpand-1 '(pop-after-load))
+ (set *load-hooks* (cdr *load-hooks*)))
diff --git a/txr.1 b/txr.1
index e2bb0fdc..2b657a4c 100644
--- a/txr.1
+++ b/txr.1
@@ -74640,6 +74640,44 @@ is not processed after the listener reads the
file. Hooks installed by the profile file will activate when the process
exits.
+.coNP Macros @ push-after-load and @ pop-after-load
+.synb
+.mets (push-after-load << form *)
+.mets (pop-after-load)
+.syne
+.desc
+The
+.code push-after-load
+and
+.code pop-after-load
+macros work with the
+.code *load-hooks*
+list.
+
+The
+.code push-after-load
+macro's arguments are zero or more
+.metn form s.
+These forms are converted into the body of an anonymous function,
+which is pushed onto the
+.code *load-hooks*
+list. The return value is the new value of
+.codn *load-hooks* .
+
+The
+.code pop-after-macro
+removes the first item from
+.codn *load-hooks* .
+The return value is the new value of
+.codn *load-hooks* .
+
+The following equivalences hold:
+
+.verb
+ (push-after-load ...) <--> (push (lambda () ...) *load-hooks*)
+ (pop-after-load) <--> (set *load-hooks* (cdr *load-hooks*))
+.brev
+
.coNP Macro @ load-for
.synb
.mets (load-for >> {( kind < sym << target )}*)