summaryrefslogtreecommitdiff
path: root/src/eval.c
diff options
context:
space:
mode:
authorRichard M. Stallman <rms@gnu.org>1995-08-05 22:53:03 +0000
committerRichard M. Stallman <rms@gnu.org>1995-08-05 22:53:03 +0000
commitf460f26ff82fb9509977a4eba8896bd6f4f0e30f (patch)
tree85a6d9b221286e70172202524fe09af2d66e3c06 /src/eval.c
parent84b1a4d68fe2e21b3f1f2afaac152cf3ece22c2a (diff)
downloademacs-f460f26ff82fb9509977a4eba8896bd6f4f0e30f.tar.gz
(run_hook_with_args): Add gcpros.
(run_hook_list_with_args): New function.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/eval.c b/src/eval.c
index bc09eb2871e..07fbf871b68 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1906,6 +1906,14 @@ not `make-local-variable'.")
return run_hook_with_args (nargs, args, until_failure);
}
+/* ARGS[0] should be a hook symbol.
+ Call each of the functions in the hook value, passing each of them
+ as arguments all the rest of ARGS (all NARGS - 1 elements).
+ COND specifies a condition to test after each call
+ to decide whether to stop.
+ The caller (or its caller, etc) must gcpro all of ARGS,
+ except that it isn't necessary to gcpro ARGS[0]. */
+
Lisp_Object
run_hook_with_args (nargs, args, cond)
int nargs;
@@ -1913,11 +1921,14 @@ run_hook_with_args (nargs, args, cond)
enum run_hooks_condition cond;
{
Lisp_Object sym, val, ret;
+ struct gcpro gcpro1, gcpro2;
sym = args[0];
val = find_symbol_value (sym);
ret = (cond == until_failure ? Qt : Qnil);
+ GCPRO2 (sym, val);
+
if (EQ (val, Qunbound) || NILP (val))
return ret;
else if (!CONSP (val) || EQ (XCONS (val)->car, Qlambda))
@@ -1958,6 +1969,52 @@ run_hook_with_args (nargs, args, cond)
return ret;
}
}
+
+/* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
+ present value of that symbol.
+ Call each element of FUNLIST,
+ passing each of them the rest of ARGS.
+ The caller (or its caller, etc) must gcpro all of ARGS,
+ except that it isn't necessary to gcpro ARGS[0]. */
+
+Lisp_Object
+run_hook_list_with_args (funlist, nargs, args)
+ Lisp_Object funlist;
+ int nargs;
+ Lisp_Object *args;
+{
+ Lisp_Object sym;
+ Lisp_Object val;
+ struct gcpro gcpro1, gcpro2;
+
+ sym = args[0];
+ GCPRO2 (sym, val);
+
+ for (val = funlist; CONSP (val); val = XCONS (val)->cdr)
+ {
+ if (EQ (XCONS (val)->car, Qt))
+ {
+ /* t indicates this hook has a local binding;
+ it means to run the global binding too. */
+ Lisp_Object globals;
+
+ for (globals = Fdefault_value (sym);
+ CONSP (globals);
+ globals = XCONS (globals)->cdr)
+ {
+ args[0] = XCONS (globals)->car;
+ Ffuncall (nargs, args);
+ }
+ }
+ else
+ {
+ args[0] = XCONS (val)->car;
+ Ffuncall (nargs, args);
+ }
+ }
+ UNGCPRO;
+ return Qnil;
+}
/* Apply fn to arg */
Lisp_Object