(Debugger Operation): Add description for
[bpt/emacs.git] / src / eval.c
CommitLineData
db9f0278 1/* Evaluator for GNU Emacs Lisp interpreter.
ed16fb98 2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001, 02, 2004
1182a7cb 3 Free Software Foundation, Inc.
db9f0278
JB
4
5This file is part of GNU Emacs.
6
7GNU Emacs is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
96277b2d 9the Free Software Foundation; either version 2, or (at your option)
db9f0278
JB
10any later version.
11
12GNU Emacs is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
19the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
db9f0278
JB
21
22
18160b98 23#include <config.h>
db9f0278 24#include "lisp.h"
9ac0d9e0 25#include "blockinput.h"
db9f0278 26#include "commands.h"
1f98fa48 27#include "keyboard.h"
3648c842 28#include "dispextern.h"
db9f0278
JB
29#include <setjmp.h>
30
31/* This definition is duplicated in alloc.c and keyboard.c */
32/* Putting it in lisp.h makes cc bomb out! */
33
34struct backtrace
4c576a83
GM
35{
36 struct backtrace *next;
37 Lisp_Object *function;
38 Lisp_Object *args; /* Points to vector of args. */
39 int nargs; /* Length of vector.
daa37602
JB
40 If nargs is UNEVALLED, args points to slot holding
41 list of unevalled args */
4c576a83
GM
42 char evalargs;
43 /* Nonzero means call value of debugger when done with this operation. */
44 char debug_on_exit;
45};
db9f0278
JB
46
47struct backtrace *backtrace_list;
48
82da7701
JB
49/* This structure helps implement the `catch' and `throw' control
50 structure. A struct catchtag contains all the information needed
51 to restore the state of the interpreter after a non-local jump.
52
53 Handlers for error conditions (represented by `struct handler'
54 structures) just point to a catch tag to do the cleanup required
55 for their jumps.
56
57 catchtag structures are chained together in the C calling stack;
58 the `next' member points to the next outer catchtag.
59
60 A call like (throw TAG VAL) searches for a catchtag whose `tag'
61 member is TAG, and then unbinds to it. The `val' member is used to
62 hold VAL while the stack is unwound; `val' is returned as the value
63 of the catch form.
64
65 All the other members are concerned with restoring the interpreter
66 state. */
4c576a83 67
db9f0278 68struct catchtag
4c576a83
GM
69{
70 Lisp_Object tag;
71 Lisp_Object val;
72 struct catchtag *next;
73 struct gcpro *gcpro;
74 jmp_buf jmp;
75 struct backtrace *backlist;
76 struct handler *handlerlist;
77 int lisp_eval_depth;
78 int pdlcount;
79 int poll_suppress_count;
2659a09f 80 int interrupt_input_blocked;
4c576a83
GM
81 struct byte_stack *byte_stack;
82};
db9f0278
JB
83
84struct catchtag *catchlist;
85
15934ffa
RS
86#ifdef DEBUG_GCPRO
87/* Count levels of GCPRO to detect failure to UNGCPRO. */
88int gcpro_level;
89#endif
90
6fd797f5 91Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
ad236261 92Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
db9f0278
JB
93Lisp_Object Qand_rest, Qand_optional;
94Lisp_Object Qdebug_on_error;
d6edd563 95Lisp_Object Qdeclare;
db9f0278 96
6e6e9f08
RS
97/* This holds either the symbol `run-hooks' or nil.
98 It is nil at an early stage of startup, and when Emacs
99 is shutting down. */
4c576a83 100
db9f0278
JB
101Lisp_Object Vrun_hooks;
102
103/* Non-nil means record all fset's and provide's, to be undone
104 if the file being autoloaded is not fully loaded.
105 They are recorded by being consed onto the front of Vautoload_queue:
106 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
107
108Lisp_Object Vautoload_queue;
109
110/* Current number of specbindings allocated in specpdl. */
4c576a83 111
db9f0278
JB
112int specpdl_size;
113
114/* Pointer to beginning of specpdl. */
4c576a83 115
db9f0278
JB
116struct specbinding *specpdl;
117
118/* Pointer to first unused element in specpdl. */
4c576a83 119
611a8f8c 120volatile struct specbinding *specpdl_ptr;
db9f0278
JB
121
122/* Maximum size allowed for specpdl allocation */
4c576a83 123
31ade731 124EMACS_INT max_specpdl_size;
db9f0278
JB
125
126/* Depth in Lisp evaluations and function calls. */
4c576a83 127
db9f0278
JB
128int lisp_eval_depth;
129
130/* Maximum allowed depth in Lisp evaluations and function calls. */
4c576a83 131
31ade731 132EMACS_INT max_lisp_eval_depth;
db9f0278
JB
133
134/* Nonzero means enter debugger before next function call */
4c576a83 135
db9f0278
JB
136int debug_on_next_call;
137
1b1acc13 138/* Non-zero means debugger may continue. This is zero when the
556d7314
GM
139 debugger is called during redisplay, where it might not be safe to
140 continue the interrupted redisplay. */
141
142int debugger_may_continue;
143
128c0f66 144/* List of conditions (non-nil atom means all) which cause a backtrace
4de86b16 145 if an error is handled by the command loop's error handler. */
4c576a83 146
128c0f66 147Lisp_Object Vstack_trace_on_error;
db9f0278 148
128c0f66 149/* List of conditions (non-nil atom means all) which enter the debugger
4de86b16 150 if an error is handled by the command loop's error handler. */
4c576a83 151
128c0f66 152Lisp_Object Vdebug_on_error;
db9f0278 153
fc950e09 154/* List of conditions and regexps specifying error messages which
1b1acc13 155 do not enter the debugger even if Vdebug_on_error says they should. */
4c576a83 156
fc950e09
KH
157Lisp_Object Vdebug_ignored_errors;
158
61ede770 159/* Non-nil means call the debugger even if the error will be handled. */
4c576a83 160
57a6e758 161Lisp_Object Vdebug_on_signal;
61ede770
RS
162
163/* Hook for edebug to use. */
4c576a83 164
61ede770
RS
165Lisp_Object Vsignal_hook_function;
166
db9f0278 167/* Nonzero means enter debugger if a quit signal
128c0f66 168 is handled by the command loop's error handler. */
4c576a83 169
db9f0278
JB
170int debug_on_quit;
171
be857679 172/* The value of num_nonmacro_input_events as of the last time we
82da7701 173 started to enter the debugger. If we decide to enter the debugger
be857679 174 again when this is still equal to num_nonmacro_input_events, then we
82da7701
JB
175 know that the debugger itself has an error, and we should just
176 signal the error instead of entering an infinite loop of debugger
177 invocations. */
4c576a83 178
82da7701 179int when_entered_debugger;
db9f0278
JB
180
181Lisp_Object Vdebugger;
182
a2ff3819
GM
183/* The function from which the last `signal' was called. Set in
184 Fsignal. */
185
186Lisp_Object Vsignaling_function;
187
4c576a83
GM
188/* Set to non-zero while processing X events. Checked in Feval to
189 make sure the Lisp interpreter isn't called from a signal handler,
190 which is unsafe because the interpreter isn't reentrant. */
191
192int handling_signal;
193
d6edd563
GM
194/* Function to process declarations in defmacro forms. */
195
196Lisp_Object Vmacro_declaration_function;
197
198
2901f1d1 199static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
db9f0278 200
dfcf069d 201void
db9f0278
JB
202init_eval_once ()
203{
204 specpdl_size = 50;
716acfce 205 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
270e8074 206 specpdl_ptr = specpdl;
a4547405 207 max_specpdl_size = 1000;
969f5145 208 max_lisp_eval_depth = 300;
34d470ba
RS
209
210 Vrun_hooks = Qnil;
db9f0278
JB
211}
212
dfcf069d 213void
db9f0278
JB
214init_eval ()
215{
216 specpdl_ptr = specpdl;
217 catchlist = 0;
218 handlerlist = 0;
219 backtrace_list = 0;
220 Vquit_flag = Qnil;
221 debug_on_next_call = 0;
222 lisp_eval_depth = 0;
87e21fbd 223#ifdef DEBUG_GCPRO
15934ffa 224 gcpro_level = 0;
87e21fbd 225#endif
be857679 226 /* This is less than the initial value of num_nonmacro_input_events. */
b5b911f9 227 when_entered_debugger = -1;
db9f0278
JB
228}
229
230Lisp_Object
231call_debugger (arg)
232 Lisp_Object arg;
233{
3648c842 234 int debug_while_redisplaying;
aed13378 235 int count = SPECPDL_INDEX ();
3648c842 236 Lisp_Object val;
177c0ea7 237
db9f0278
JB
238 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
239 max_lisp_eval_depth = lisp_eval_depth + 20;
177c0ea7 240
db9f0278
JB
241 if (specpdl_size + 40 > max_specpdl_size)
242 max_specpdl_size = specpdl_size + 40;
177c0ea7 243
237c23b0 244#ifdef HAVE_X_WINDOWS
df6c90d8
GM
245 if (display_hourglass_p)
246 cancel_hourglass ();
237c23b0
GM
247#endif
248
db9f0278 249 debug_on_next_call = 0;
be857679 250 when_entered_debugger = num_nonmacro_input_events;
3648c842
GM
251
252 /* Resetting redisplaying_p to 0 makes sure that debug output is
253 displayed if the debugger is invoked during redisplay. */
254 debug_while_redisplaying = redisplaying_p;
255 redisplaying_p = 0;
556d7314
GM
256 specbind (intern ("debugger-may-continue"),
257 debug_while_redisplaying ? Qnil : Qt);
8efb6cc7 258 specbind (Qinhibit_redisplay, Qnil);
9db6f6b4
GM
259
260#if 0 /* Binding this prevents execution of Lisp code during
261 redisplay, which necessarily leads to display problems. */
8efb6cc7 262 specbind (Qinhibit_eval_during_redisplay, Qt);
9db6f6b4 263#endif
177c0ea7 264
3648c842
GM
265 val = apply1 (Vdebugger, arg);
266
267 /* Interrupting redisplay and resuming it later is not safe under
268 all circumstances. So, when the debugger returns, abort the
1b1acc13 269 interrupted redisplay by going back to the top-level. */
3648c842
GM
270 if (debug_while_redisplaying)
271 Ftop_level ();
272
556d7314 273 return unbind_to (count, val);
db9f0278
JB
274}
275
dfcf069d 276void
db9f0278
JB
277do_debug_on_call (code)
278 Lisp_Object code;
279{
280 debug_on_next_call = 0;
281 backtrace_list->debug_on_exit = 1;
282 call_debugger (Fcons (code, Qnil));
283}
284\f
285/* NOTE!!! Every function that can call EVAL must protect its args
286 and temporaries from garbage collection while it needs them.
287 The definition of `For' shows what you have to do. */
288
289DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
9dbc9081
PJ
290 doc: /* Eval args until one of them yields non-nil, then return that value.
291The remaining args are not evalled at all.
292If all args return nil, return nil.
7a25dc6d 293usage: (or CONDITIONS ...) */)
9dbc9081 294 (args)
db9f0278
JB
295 Lisp_Object args;
296{
e509f168 297 register Lisp_Object val = Qnil;
db9f0278
JB
298 struct gcpro gcpro1;
299
e509f168 300 GCPRO1 (args);
db9f0278 301
e509f168 302 while (CONSP (args))
db9f0278 303 {
e509f168 304 val = Feval (XCAR (args));
265a9e55 305 if (!NILP (val))
db9f0278 306 break;
e509f168 307 args = XCDR (args);
db9f0278 308 }
db9f0278
JB
309
310 UNGCPRO;
311 return val;
312}
313
314DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
b8de5714 315 doc: /* Eval args until one of them yields nil, then return nil.
9dbc9081
PJ
316The remaining args are not evalled at all.
317If no arg yields nil, return the last arg's value.
7a25dc6d 318usage: (and CONDITIONS ...) */)
9dbc9081 319 (args)
db9f0278
JB
320 Lisp_Object args;
321{
e509f168 322 register Lisp_Object val = Qt;
db9f0278
JB
323 struct gcpro gcpro1;
324
e509f168 325 GCPRO1 (args);
db9f0278 326
e509f168 327 while (CONSP (args))
db9f0278 328 {
e509f168 329 val = Feval (XCAR (args));
265a9e55 330 if (NILP (val))
db9f0278 331 break;
e509f168 332 args = XCDR (args);
db9f0278 333 }
db9f0278
JB
334
335 UNGCPRO;
336 return val;
337}
338
339DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
b8de5714 340 doc: /* If COND yields non-nil, do THEN, else do ELSE...
9dbc9081
PJ
341Returns the value of THEN or the value of the last of the ELSE's.
342THEN must be one expression, but ELSE... can be zero or more expressions.
343If COND yields nil, and there are no ELSE's, the value is nil.
7a25dc6d 344usage: (if COND THEN ELSE...) */)
9dbc9081 345 (args)
db9f0278
JB
346 Lisp_Object args;
347{
348 register Lisp_Object cond;
349 struct gcpro gcpro1;
350
351 GCPRO1 (args);
352 cond = Feval (Fcar (args));
353 UNGCPRO;
354
265a9e55 355 if (!NILP (cond))
db9f0278
JB
356 return Feval (Fcar (Fcdr (args)));
357 return Fprogn (Fcdr (Fcdr (args)));
358}
359
360DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
9dbc9081
PJ
361 doc: /* Try each clause until one succeeds.
362Each clause looks like (CONDITION BODY...). CONDITION is evaluated
363and, if the value is non-nil, this clause succeeds:
364then the expressions in BODY are evaluated and the last one's
365value is the value of the cond-form.
366If no clause succeeds, cond returns nil.
367If a clause has one element, as in (CONDITION),
368CONDITION's value if non-nil is returned from the cond-form.
7a25dc6d 369usage: (cond CLAUSES...) */)
9dbc9081 370 (args)
db9f0278
JB
371 Lisp_Object args;
372{
373 register Lisp_Object clause, val;
374 struct gcpro gcpro1;
375
376 val = Qnil;
377 GCPRO1 (args);
265a9e55 378 while (!NILP (args))
db9f0278
JB
379 {
380 clause = Fcar (args);
381 val = Feval (Fcar (clause));
265a9e55 382 if (!NILP (val))
db9f0278 383 {
03699b14
KR
384 if (!EQ (XCDR (clause), Qnil))
385 val = Fprogn (XCDR (clause));
db9f0278
JB
386 break;
387 }
03699b14 388 args = XCDR (args);
db9f0278
JB
389 }
390 UNGCPRO;
391
392 return val;
393}
394
395DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
9dbc9081 396 doc: /* Eval BODY forms sequentially and return value of last one.
7a25dc6d 397usage: (progn BODY ...) */)
9dbc9081 398 (args)
db9f0278
JB
399 Lisp_Object args;
400{
e509f168 401 register Lisp_Object val = Qnil;
db9f0278
JB
402 struct gcpro gcpro1;
403
e509f168 404 GCPRO1 (args);
db9f0278 405
e509f168 406 while (CONSP (args))
db9f0278 407 {
e509f168
SM
408 val = Feval (XCAR (args));
409 args = XCDR (args);
db9f0278 410 }
db9f0278
JB
411
412 UNGCPRO;
413 return val;
414}
415
416DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
9dbc9081
PJ
417 doc: /* Eval FIRST and BODY sequentially; value from FIRST.
418The value of FIRST is saved during the evaluation of the remaining args,
419whose values are discarded.
7a25dc6d 420usage: (prog1 FIRST BODY...) */)
9dbc9081 421 (args)
db9f0278
JB
422 Lisp_Object args;
423{
424 Lisp_Object val;
425 register Lisp_Object args_left;
426 struct gcpro gcpro1, gcpro2;
427 register int argnum = 0;
428
265a9e55 429 if (NILP(args))
db9f0278
JB
430 return Qnil;
431
432 args_left = args;
433 val = Qnil;
434 GCPRO2 (args, val);
435
436 do
437 {
438 if (!(argnum++))
439 val = Feval (Fcar (args_left));
440 else
441 Feval (Fcar (args_left));
442 args_left = Fcdr (args_left);
443 }
265a9e55 444 while (!NILP(args_left));
db9f0278
JB
445
446 UNGCPRO;
447 return val;
448}
449
450DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
9dbc9081
PJ
451 doc: /* Eval X, Y and BODY sequentially; value from Y.
452The value of Y is saved during the evaluation of the remaining args,
453whose values are discarded.
7a25dc6d 454usage: (prog2 X Y BODY...) */)
9dbc9081 455 (args)
db9f0278
JB
456 Lisp_Object args;
457{
458 Lisp_Object val;
459 register Lisp_Object args_left;
460 struct gcpro gcpro1, gcpro2;
461 register int argnum = -1;
462
463 val = Qnil;
464
87d238ba 465 if (NILP (args))
db9f0278
JB
466 return Qnil;
467
468 args_left = args;
469 val = Qnil;
470 GCPRO2 (args, val);
471
472 do
473 {
474 if (!(argnum++))
475 val = Feval (Fcar (args_left));
476 else
477 Feval (Fcar (args_left));
478 args_left = Fcdr (args_left);
479 }
87d238ba 480 while (!NILP (args_left));
db9f0278
JB
481
482 UNGCPRO;
483 return val;
484}
485
486DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
9dbc9081
PJ
487 doc: /* Set each SYM to the value of its VAL.
488The symbols SYM are variables; they are literal (not evaluated).
489The values VAL are expressions; they are evaluated.
490Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
491The second VAL is not computed until after the first SYM is set, and so on;
492each VAL can use the new value of variables set earlier in the `setq'.
493The return value of the `setq' form is the value of the last VAL.
494usage: (setq SYM VAL SYM VAL ...) */)
495 (args)
db9f0278
JB
496 Lisp_Object args;
497{
498 register Lisp_Object args_left;
499 register Lisp_Object val, sym;
500 struct gcpro gcpro1;
501
265a9e55 502 if (NILP(args))
db9f0278
JB
503 return Qnil;
504
505 args_left = args;
506 GCPRO1 (args);
507
508 do
509 {
510 val = Feval (Fcar (Fcdr (args_left)));
511 sym = Fcar (args_left);
512 Fset (sym, val);
513 args_left = Fcdr (Fcdr (args_left));
514 }
265a9e55 515 while (!NILP(args_left));
db9f0278
JB
516
517 UNGCPRO;
518 return val;
519}
177c0ea7 520
db9f0278 521DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
9dbc9081
PJ
522 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
523usage: (quote ARG) */)
524 (args)
db9f0278
JB
525 Lisp_Object args;
526{
527 return Fcar (args);
528}
177c0ea7 529
db9f0278 530DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
9dbc9081
PJ
531 doc: /* Like `quote', but preferred for objects which are functions.
532In byte compilation, `function' causes its argument to be compiled.
533`quote' cannot do that.
534usage: (function ARG) */)
535 (args)
db9f0278
JB
536 Lisp_Object args;
537{
538 return Fcar (args);
539}
540
e0f331ab 541
db9f0278 542DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
c63df42b 543 doc: /* Return t if the function was run directly by user input.
9dbc9081
PJ
544This means that the function was called with call-interactively (which
545includes being called as the binding of a key)
c63df42b
RS
546and input is currently coming from the keyboard (not in keyboard macro),
547and Emacs is not running in batch mode (`noninteractive' is nil).
548
549The only known proper use of `interactive-p' is in deciding whether to
550display a helpful message, or how to display it. If you're thinking
551of using it for any other purpose, it is quite likely that you're
552making a mistake. Think: what do you want to do when the command is
553called from a keyboard macro?
554
555If you want to test whether your function was called with
556`call-interactively', the way to do that is by adding an extra
557optional argument, and making the `interactive' spec specify non-nil
558unconditionally for that argument. (`p' is a good way to do this.) */)
9dbc9081 559 ()
db9f0278 560{
c63df42b 561 return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
e0f331ab
GM
562}
563
564
4b664e76 565DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 0, 0,
c63df42b
RS
566 doc: /* Return t if the function using this was called with call-interactively.
567This is used for implementing advice and other function-modifying
568features of Emacs.
569
570The cleanest way to test whether your function was called with
571`call-interactively', the way to do that is by adding an extra
572optional argument, and making the `interactive' spec specify non-nil
573unconditionally for that argument. (`p' is a good way to do this.) */)
574 ()
575{
0b31741c 576 return interactive_p (1) ? Qt : Qnil;
c63df42b
RS
577}
578
579
580/* Return 1 if function in which this appears was called using
581 call-interactively.
e0f331ab
GM
582
583 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
584 called is a built-in. */
585
586int
587interactive_p (exclude_subrs_p)
588 int exclude_subrs_p;
589{
590 struct backtrace *btp;
591 Lisp_Object fun;
db9f0278 592
db9f0278 593 btp = backtrace_list;
daa37602
JB
594
595 /* If this isn't a byte-compiled function, there may be a frame at
e0f331ab 596 the top for Finteractive_p. If so, skip it. */
daa37602 597 fun = Findirect_function (*btp->function);
0b31741c
RS
598 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
599 || XSUBR (fun) == &Scalled_interactively_p))
db9f0278 600 btp = btp->next;
daa37602
JB
601
602 /* If we're running an Emacs 18-style byte-compiled function, there
4402a9ed
RS
603 may be a frame for Fbytecode at the top level. In any version of
604 Emacs there can be Fbytecode frames for subexpressions evaluated
605 inside catch and condition-case. Skip past them.
daa37602 606
4402a9ed 607 If this isn't a byte-compiled function, then we may now be
daa37602 608 looking at several frames for special forms. Skip past them. */
4402a9ed
RS
609 while (btp
610 && (EQ (*btp->function, Qbytecode)
611 || btp->nargs == UNEVALLED))
a6e3fa71
JB
612 btp = btp->next;
613
daa37602
JB
614 /* btp now points at the frame of the innermost function that isn't
615 a special form, ignoring frames for Finteractive_p and/or
616 Fbytecode at the top. If this frame is for a built-in function
617 (such as load or eval-region) return nil. */
ffd56f97 618 fun = Findirect_function (*btp->function);
e0f331ab
GM
619 if (exclude_subrs_p && SUBRP (fun))
620 return 0;
177c0ea7 621
db9f0278
JB
622 /* btp points to the frame of a Lisp function that called interactive-p.
623 Return t if that function was called interactively. */
624 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
e0f331ab
GM
625 return 1;
626 return 0;
db9f0278
JB
627}
628
e0f331ab 629
db9f0278 630DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
9dbc9081
PJ
631 doc: /* Define NAME as a function.
632The definition is (lambda ARGLIST [DOCSTRING] BODY...).
633See also the function `interactive'.
7a25dc6d 634usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
9dbc9081 635 (args)
db9f0278
JB
636 Lisp_Object args;
637{
638 register Lisp_Object fn_name;
639 register Lisp_Object defn;
640
641 fn_name = Fcar (args);
6992a868 642 CHECK_SYMBOL (fn_name);
db9f0278 643 defn = Fcons (Qlambda, Fcdr (args));
265a9e55 644 if (!NILP (Vpurify_flag))
db9f0278 645 defn = Fpurecopy (defn);
f58e9f8c
RS
646 if (CONSP (XSYMBOL (fn_name)->function)
647 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
648 LOADHIST_ATTACH (Fcons (Qt, fn_name));
db9f0278 649 Ffset (fn_name, defn);
6fd797f5 650 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
db9f0278
JB
651 return fn_name;
652}
653
654DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
9dbc9081 655 doc: /* Define NAME as a macro.
0654d6e3
RS
656The actual definition looks like
657 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
9dbc9081
PJ
658When the macro is called, as in (NAME ARGS...),
659the function (lambda ARGLIST BODY...) is applied to
660the list ARGS... as it appears in the expression,
661and the result should be a form to be evaluated instead of the original.
0654d6e3
RS
662
663DECL is a declaration, optional, which can specify how to indent
664calls to this macro and how Edebug should handle it. It looks like this:
665 (declare SPECS...)
666The elements can look like this:
667 (indent INDENT)
668 Set NAME's `lisp-indent-function' property to INDENT.
669
e509f168 670 (debug DEBUG)
0654d6e3 671 Set NAME's `edebug-form-spec' property to DEBUG. (This is
7d5c86e5 672 equivalent to writing a `def-edebug-spec' for the macro.)
0654d6e3 673usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
9dbc9081 674 (args)
db9f0278
JB
675 Lisp_Object args;
676{
677 register Lisp_Object fn_name;
678 register Lisp_Object defn;
d6edd563 679 Lisp_Object lambda_list, doc, tail;
db9f0278
JB
680
681 fn_name = Fcar (args);
8e975df9 682 CHECK_SYMBOL (fn_name);
d6edd563
GM
683 lambda_list = Fcar (Fcdr (args));
684 tail = Fcdr (Fcdr (args));
685
686 doc = Qnil;
687 if (STRINGP (Fcar (tail)))
688 {
e509f168
SM
689 doc = XCAR (tail);
690 tail = XCDR (tail);
d6edd563
GM
691 }
692
693 while (CONSP (Fcar (tail))
694 && EQ (Fcar (Fcar (tail)), Qdeclare))
695 {
696 if (!NILP (Vmacro_declaration_function))
697 {
698 struct gcpro gcpro1;
699 GCPRO1 (args);
700 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
701 UNGCPRO;
702 }
177c0ea7 703
d6edd563
GM
704 tail = Fcdr (tail);
705 }
706
707 if (NILP (doc))
708 tail = Fcons (lambda_list, tail);
709 else
710 tail = Fcons (lambda_list, Fcons (doc, tail));
711 defn = Fcons (Qmacro, Fcons (Qlambda, tail));
177c0ea7 712
265a9e55 713 if (!NILP (Vpurify_flag))
db9f0278 714 defn = Fpurecopy (defn);
f58e9f8c
RS
715 if (CONSP (XSYMBOL (fn_name)->function)
716 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
717 LOADHIST_ATTACH (Fcons (Qt, fn_name));
db9f0278 718 Ffset (fn_name, defn);
6fd797f5 719 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
db9f0278
JB
720 return fn_name;
721}
722
19cebf5a 723
1848d15d 724DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
9dbc9081
PJ
725 doc: /* Make SYMBOL a variable alias for symbol ALIASED.
726Setting the value of SYMBOL will subsequently set the value of ALIASED,
727and getting the value of SYMBOL will return the value ALIASED has.
6d59ebc3
LT
728Third arg DOCSTRING, if non-nil, is documentation for SYMBOL.
729The return value is ALIASED. */)
1848d15d
JB
730 (symbol, aliased, docstring)
731 Lisp_Object symbol, aliased, docstring;
19cebf5a
GM
732{
733 struct Lisp_Symbol *sym;
1848d15d 734
b7826503
PJ
735 CHECK_SYMBOL (symbol);
736 CHECK_SYMBOL (aliased);
19cebf5a
GM
737
738 if (SYMBOL_CONSTANT_P (symbol))
739 error ("Cannot make a constant an alias");
740
741 sym = XSYMBOL (symbol);
742 sym->indirect_variable = 1;
743 sym->value = aliased;
744 sym->constant = SYMBOL_CONSTANT_P (aliased);
6fd797f5 745 LOADHIST_ATTACH (symbol);
1848d15d
JB
746 if (!NILP (docstring))
747 Fput (symbol, Qvariable_documentation, docstring);
748
19cebf5a
GM
749 return aliased;
750}
751
752
db9f0278 753DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
9dbc9081
PJ
754 doc: /* Define SYMBOL as a variable.
755You are not required to define a variable in order to use it,
756but the definition can supply documentation and an initial value
757in a way that tags can recognize.
758
759INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
760If SYMBOL is buffer-local, its default value is what is set;
761 buffer-local values are not affected.
762INITVALUE and DOCSTRING are optional.
763If DOCSTRING starts with *, this variable is identified as a user option.
764 This means that M-x set-variable recognizes it.
765 See also `user-variable-p'.
766If INITVALUE is missing, SYMBOL's value is not set.
733f68b6
LT
767
768If SYMBOL has a local binding, then this form affects the local
769binding. This is usually not what you want. Thus, if you need to
770load a file defining variables, with this form or with `defconst' or
771`defcustom', you should always load that file _outside_ any bindings
772for these variables. \(`defconst' and `defcustom' behave similarly in
773this respect.)
2df5238c 774usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
9dbc9081 775 (args)
db9f0278
JB
776 Lisp_Object args;
777{
a42ba017 778 register Lisp_Object sym, tem, tail;
db9f0278
JB
779
780 sym = Fcar (args);
a42ba017
RS
781 tail = Fcdr (args);
782 if (!NILP (Fcdr (Fcdr (tail))))
783 error ("too many arguments");
784
33568849 785 tem = Fdefault_boundp (sym);
a42ba017 786 if (!NILP (tail))
db9f0278 787 {
265a9e55 788 if (NILP (tem))
33568849 789 Fset_default (sym, Feval (Fcar (tail)));
d0bce91e
SM
790 else
791 { /* Check if there is really a global binding rather than just a let
792 binding that shadows the global unboundness of the var. */
b28d0d9a 793 volatile struct specbinding *pdl = specpdl_ptr;
d0bce91e
SM
794 while (--pdl >= specpdl)
795 {
796 if (EQ (pdl->symbol, sym) && !pdl->func
797 && EQ (pdl->old_value, Qunbound))
798 {
799 message_with_string ("Warning: defvar ignored because %s is let-bound",
800 SYMBOL_NAME (sym), 1);
801 break;
802 }
803 }
804 }
33568849 805 tail = Fcdr (tail);
e509f168
SM
806 tem = Fcar (tail);
807 if (!NILP (tem))
33568849 808 {
33568849
SM
809 if (!NILP (Vpurify_flag))
810 tem = Fpurecopy (tem);
811 Fput (sym, Qvariable_documentation, tem);
812 }
6fd797f5 813 LOADHIST_ATTACH (sym);
db9f0278 814 }
33568849 815 else
d7c1d0fc
RS
816 /* Simple (defvar <var>) should not count as a definition at all.
817 It could get in the way of other definitions, and unloading this
818 package could try to make the variable unbound. */
addf35fd
AS
819 ;
820
db9f0278
JB
821 return sym;
822}
823
824DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
9dbc9081
PJ
825 doc: /* Define SYMBOL as a constant variable.
826The intent is that neither programs nor users should ever change this value.
827Always sets the value of SYMBOL to the result of evalling INITVALUE.
828If SYMBOL is buffer-local, its default value is what is set;
829 buffer-local values are not affected.
830DOCSTRING is optional.
733f68b6
LT
831
832If SYMBOL has a local binding, then this form sets the local binding's
833value. However, you should normally not make local bindings for
834variables defined with this form.
7a25dc6d 835usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
9dbc9081 836 (args)
db9f0278
JB
837 Lisp_Object args;
838{
839 register Lisp_Object sym, tem;
840
841 sym = Fcar (args);
a42ba017
RS
842 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
843 error ("too many arguments");
844
1182a7cb
DL
845 tem = Feval (Fcar (Fcdr (args)));
846 if (!NILP (Vpurify_flag))
847 tem = Fpurecopy (tem);
848 Fset_default (sym, tem);
db9f0278 849 tem = Fcar (Fcdr (Fcdr (args)));
265a9e55 850 if (!NILP (tem))
db9f0278 851 {
265a9e55 852 if (!NILP (Vpurify_flag))
db9f0278
JB
853 tem = Fpurecopy (tem);
854 Fput (sym, Qvariable_documentation, tem);
855 }
6fd797f5 856 LOADHIST_ATTACH (sym);
db9f0278
JB
857 return sym;
858}
859
860DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
9dbc9081
PJ
861 doc: /* Returns t if VARIABLE is intended to be set and modified by users.
862\(The alternative is a variable used internally in a Lisp program.)
863Determined by whether the first character of the documentation
864for the variable is `*' or if the variable is customizable (has a non-nil
225513e8 865value of `standard-value' or of `custom-autoload' on its property list). */)
9dbc9081 866 (variable)
db9f0278
JB
867 Lisp_Object variable;
868{
869 Lisp_Object documentation;
177c0ea7 870
5e78e475
RS
871 if (!SYMBOLP (variable))
872 return Qnil;
873
db9f0278 874 documentation = Fget (variable, Qvariable_documentation);
90165123 875 if (INTEGERP (documentation) && XINT (documentation) < 0)
db9f0278 876 return Qt;
65411977 877 if (STRINGP (documentation)
d5db4077 878 && ((unsigned char) SREF (documentation, 0) == '*'))
65411977
RS
879 return Qt;
880 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
881 if (CONSP (documentation)
03699b14
KR
882 && STRINGP (XCAR (documentation))
883 && INTEGERP (XCDR (documentation))
884 && XINT (XCDR (documentation)) < 0)
db9f0278 885 return Qt;
225513e8
MR
886 /* Customizable? See `custom-variable-p'. */
887 if ((!NILP (Fget (variable, intern ("standard-value"))))
888 || (!NILP (Fget (variable, intern ("custom-autoload")))))
caff32a7 889 return Qt;
db9f0278 890 return Qnil;
177c0ea7 891}
db9f0278
JB
892\f
893DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
9dbc9081
PJ
894 doc: /* Bind variables according to VARLIST then eval BODY.
895The value of the last form in BODY is returned.
896Each element of VARLIST is a symbol (which is bound to nil)
897or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
898Each VALUEFORM can refer to the symbols already bound by this VARLIST.
7a25dc6d 899usage: (let* VARLIST BODY...) */)
9dbc9081 900 (args)
db9f0278
JB
901 Lisp_Object args;
902{
903 Lisp_Object varlist, val, elt;
aed13378 904 int count = SPECPDL_INDEX ();
db9f0278
JB
905 struct gcpro gcpro1, gcpro2, gcpro3;
906
907 GCPRO3 (args, elt, varlist);
908
909 varlist = Fcar (args);
265a9e55 910 while (!NILP (varlist))
db9f0278
JB
911 {
912 QUIT;
913 elt = Fcar (varlist);
90165123 914 if (SYMBOLP (elt))
db9f0278 915 specbind (elt, Qnil);
08564963
JB
916 else if (! NILP (Fcdr (Fcdr (elt))))
917 Fsignal (Qerror,
918 Fcons (build_string ("`let' bindings can have only one value-form"),
919 elt));
db9f0278
JB
920 else
921 {
922 val = Feval (Fcar (Fcdr (elt)));
923 specbind (Fcar (elt), val);
924 }
925 varlist = Fcdr (varlist);
926 }
927 UNGCPRO;
928 val = Fprogn (Fcdr (args));
929 return unbind_to (count, val);
930}
931
932DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
9dbc9081
PJ
933 doc: /* Bind variables according to VARLIST then eval BODY.
934The value of the last form in BODY is returned.
935Each element of VARLIST is a symbol (which is bound to nil)
936or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
937All the VALUEFORMs are evalled before any symbols are bound.
7a25dc6d 938usage: (let VARLIST BODY...) */)
9dbc9081 939 (args)
db9f0278
JB
940 Lisp_Object args;
941{
942 Lisp_Object *temps, tem;
943 register Lisp_Object elt, varlist;
aed13378 944 int count = SPECPDL_INDEX ();
db9f0278
JB
945 register int argnum;
946 struct gcpro gcpro1, gcpro2;
947
948 varlist = Fcar (args);
949
950 /* Make space to hold the values to give the bound variables */
951 elt = Flength (varlist);
952 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
953
954 /* Compute the values and store them in `temps' */
955
956 GCPRO2 (args, *temps);
957 gcpro2.nvars = 0;
958
265a9e55 959 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
db9f0278
JB
960 {
961 QUIT;
962 elt = Fcar (varlist);
90165123 963 if (SYMBOLP (elt))
db9f0278 964 temps [argnum++] = Qnil;
08564963
JB
965 else if (! NILP (Fcdr (Fcdr (elt))))
966 Fsignal (Qerror,
967 Fcons (build_string ("`let' bindings can have only one value-form"),
968 elt));
db9f0278
JB
969 else
970 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
971 gcpro2.nvars = argnum;
972 }
973 UNGCPRO;
974
975 varlist = Fcar (args);
265a9e55 976 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
db9f0278
JB
977 {
978 elt = Fcar (varlist);
979 tem = temps[argnum++];
90165123 980 if (SYMBOLP (elt))
db9f0278
JB
981 specbind (elt, tem);
982 else
983 specbind (Fcar (elt), tem);
984 }
985
986 elt = Fprogn (Fcdr (args));
987 return unbind_to (count, elt);
988}
989
990DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
9dbc9081
PJ
991 doc: /* If TEST yields non-nil, eval BODY... and repeat.
992The order of execution is thus TEST, BODY, TEST, BODY and so on
993until TEST returns nil.
7a25dc6d 994usage: (while TEST BODY...) */)
9dbc9081 995 (args)
db9f0278
JB
996 Lisp_Object args;
997{
2b9bde76 998 Lisp_Object test, body;
db9f0278
JB
999 struct gcpro gcpro1, gcpro2;
1000
1001 GCPRO2 (test, body);
1002
1003 test = Fcar (args);
1004 body = Fcdr (args);
2b9bde76 1005 while (!NILP (Feval (test)))
db9f0278
JB
1006 {
1007 QUIT;
1008 Fprogn (body);
1009 }
1010
1011 UNGCPRO;
1012 return Qnil;
1013}
1014
1015DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
9dbc9081
PJ
1016 doc: /* Return result of expanding macros at top level of FORM.
1017If FORM is not a macro call, it is returned unchanged.
1018Otherwise, the macro is expanded and the expansion is considered
1019in place of FORM. When a non-macro-call results, it is returned.
1020
1021The second optional arg ENVIRONMENT specifies an environment of macro
1022definitions to shadow the loaded ones for use in file byte-compilation. */)
1023 (form, environment)
2e267a2e 1024 Lisp_Object form;
79e8bfbf 1025 Lisp_Object environment;
db9f0278 1026{
23d6b5a6 1027 /* With cleanups from Hallvard Furuseth. */
db9f0278
JB
1028 register Lisp_Object expander, sym, def, tem;
1029
1030 while (1)
1031 {
1032 /* Come back here each time we expand a macro call,
1033 in case it expands into another macro call. */
90165123 1034 if (!CONSP (form))
db9f0278 1035 break;
23d6b5a6 1036 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
03699b14 1037 def = sym = XCAR (form);
23d6b5a6 1038 tem = Qnil;
db9f0278
JB
1039 /* Trace symbols aliases to other symbols
1040 until we get a symbol that is not an alias. */
90165123 1041 while (SYMBOLP (def))
db9f0278
JB
1042 {
1043 QUIT;
23d6b5a6 1044 sym = def;
79e8bfbf 1045 tem = Fassq (sym, environment);
265a9e55 1046 if (NILP (tem))
db9f0278
JB
1047 {
1048 def = XSYMBOL (sym)->function;
23d6b5a6
JB
1049 if (!EQ (def, Qunbound))
1050 continue;
db9f0278 1051 }
23d6b5a6 1052 break;
db9f0278 1053 }
79e8bfbf 1054 /* Right now TEM is the result from SYM in ENVIRONMENT,
db9f0278 1055 and if TEM is nil then DEF is SYM's function definition. */
265a9e55 1056 if (NILP (tem))
db9f0278 1057 {
79e8bfbf 1058 /* SYM is not mentioned in ENVIRONMENT.
db9f0278 1059 Look at its function definition. */
90165123 1060 if (EQ (def, Qunbound) || !CONSP (def))
db9f0278
JB
1061 /* Not defined or definition not suitable */
1062 break;
03699b14 1063 if (EQ (XCAR (def), Qautoload))
db9f0278
JB
1064 {
1065 /* Autoloading function: will it be a macro when loaded? */
ee9ee63c 1066 tem = Fnth (make_number (4), def);
47ccd8b6 1067 if (EQ (tem, Qt) || EQ (tem, Qmacro))
ee9ee63c
JB
1068 /* Yes, load it and try again. */
1069 {
ca20916b
RS
1070 struct gcpro gcpro1;
1071 GCPRO1 (form);
ee9ee63c 1072 do_autoload (def, sym);
ca20916b 1073 UNGCPRO;
ee9ee63c
JB
1074 continue;
1075 }
1076 else
db9f0278 1077 break;
db9f0278 1078 }
03699b14 1079 else if (!EQ (XCAR (def), Qmacro))
db9f0278 1080 break;
03699b14 1081 else expander = XCDR (def);
db9f0278
JB
1082 }
1083 else
1084 {
03699b14 1085 expander = XCDR (tem);
265a9e55 1086 if (NILP (expander))
db9f0278
JB
1087 break;
1088 }
03699b14 1089 form = apply1 (expander, XCDR (form));
db9f0278
JB
1090 }
1091 return form;
1092}
1093\f
1094DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
9dbc9081
PJ
1095 doc: /* Eval BODY allowing nonlocal exits using `throw'.
1096TAG is evalled to get the tag to use; it must not be nil.
1097
1098Then the BODY is executed.
1099Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1100If no throw happens, `catch' returns the value of the last BODY form.
1101If a throw happens, it specifies the value to return from `catch'.
7a25dc6d 1102usage: (catch TAG BODY...) */)
9dbc9081 1103 (args)
db9f0278
JB
1104 Lisp_Object args;
1105{
1106 register Lisp_Object tag;
1107 struct gcpro gcpro1;
1108
1109 GCPRO1 (args);
1110 tag = Feval (Fcar (args));
1111 UNGCPRO;
1112 return internal_catch (tag, Fprogn, Fcdr (args));
1113}
1114
1115/* Set up a catch, then call C function FUNC on argument ARG.
1116 FUNC should return a Lisp_Object.
1117 This is how catches are done from within C code. */
1118
1119Lisp_Object
1120internal_catch (tag, func, arg)
1121 Lisp_Object tag;
1122 Lisp_Object (*func) ();
1123 Lisp_Object arg;
1124{
1125 /* This structure is made part of the chain `catchlist'. */
1126 struct catchtag c;
1127
1128 /* Fill in the components of c, and put it on the list. */
1129 c.next = catchlist;
1130 c.tag = tag;
1131 c.val = Qnil;
1132 c.backlist = backtrace_list;
1133 c.handlerlist = handlerlist;
1134 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1135 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1136 c.poll_suppress_count = poll_suppress_count;
2659a09f 1137 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1138 c.gcpro = gcprolist;
bcf28080 1139 c.byte_stack = byte_stack_list;
db9f0278
JB
1140 catchlist = &c;
1141
1142 /* Call FUNC. */
1143 if (! _setjmp (c.jmp))
1144 c.val = (*func) (arg);
1145
1146 /* Throw works by a longjmp that comes right here. */
1147 catchlist = c.next;
1148 return c.val;
1149}
1150
ba410f40
JB
1151/* Unwind the specbind, catch, and handler stacks back to CATCH, and
1152 jump to that CATCH, returning VALUE as the value of that catch.
db9f0278 1153
ba410f40
JB
1154 This is the guts Fthrow and Fsignal; they differ only in the way
1155 they choose the catch tag to throw to. A catch tag for a
1156 condition-case form has a TAG of Qnil.
db9f0278 1157
ba410f40
JB
1158 Before each catch is discarded, unbind all special bindings and
1159 execute all unwind-protect clauses made above that catch. Unwind
1160 the handler stack as we go, so that the proper handlers are in
1161 effect for each unwind-protect clause we run. At the end, restore
1162 some static info saved in CATCH, and longjmp to the location
1163 specified in the
1164
1165 This is used for correct unwinding in Fthrow and Fsignal. */
db9f0278
JB
1166
1167static void
ba410f40 1168unwind_to_catch (catch, value)
db9f0278 1169 struct catchtag *catch;
ba410f40 1170 Lisp_Object value;
db9f0278
JB
1171{
1172 register int last_time;
1173
ba410f40
JB
1174 /* Save the value in the tag. */
1175 catch->val = value;
1176
0b31741c 1177 /* Restore certain special C variables. */
1cdc3155 1178 set_poll_suppress_count (catch->poll_suppress_count);
c1788fbc 1179 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
0b31741c 1180 handling_signal = 0;
69bbd6bd 1181 immediate_quit = 0;
82da7701 1182
db9f0278
JB
1183 do
1184 {
1185 last_time = catchlist == catch;
82da7701
JB
1186
1187 /* Unwind the specpdl stack, and then restore the proper set of
1188 handlers. */
db9f0278
JB
1189 unbind_to (catchlist->pdlcount, Qnil);
1190 handlerlist = catchlist->handlerlist;
1191 catchlist = catchlist->next;
1192 }
1193 while (! last_time);
1194
bcf28080 1195 byte_stack_list = catch->byte_stack;
db9f0278 1196 gcprolist = catch->gcpro;
15934ffa
RS
1197#ifdef DEBUG_GCPRO
1198 if (gcprolist != 0)
1199 gcpro_level = gcprolist->level + 1;
1200 else
1201 gcpro_level = 0;
1202#endif
db9f0278
JB
1203 backtrace_list = catch->backlist;
1204 lisp_eval_depth = catch->lisp_eval_depth;
177c0ea7 1205
ba410f40 1206 _longjmp (catch->jmp, 1);
db9f0278
JB
1207}
1208
1209DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
9dbc9081
PJ
1210 doc: /* Throw to the catch for TAG and return VALUE from it.
1211Both TAG and VALUE are evalled. */)
1212 (tag, value)
79e8bfbf 1213 register Lisp_Object tag, value;
db9f0278
JB
1214{
1215 register struct catchtag *c;
1216
1217 while (1)
1218 {
265a9e55 1219 if (!NILP (tag))
db9f0278
JB
1220 for (c = catchlist; c; c = c->next)
1221 {
1222 if (EQ (c->tag, tag))
79e8bfbf 1223 unwind_to_catch (c, value);
db9f0278 1224 }
79e8bfbf 1225 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
db9f0278
JB
1226 }
1227}
1228
1229
1230DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
9dbc9081
PJ
1231 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1232If BODYFORM completes normally, its value is returned
1233after executing the UNWINDFORMS.
1234If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
7a25dc6d 1235usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
9dbc9081 1236 (args)
db9f0278
JB
1237 Lisp_Object args;
1238{
1239 Lisp_Object val;
aed13378 1240 int count = SPECPDL_INDEX ();
db9f0278 1241
04b28167 1242 record_unwind_protect (Fprogn, Fcdr (args));
db9f0278 1243 val = Feval (Fcar (args));
177c0ea7 1244 return unbind_to (count, val);
db9f0278
JB
1245}
1246\f
1247/* Chain of condition handlers currently in effect.
1248 The elements of this chain are contained in the stack frames
1249 of Fcondition_case and internal_condition_case.
1250 When an error is signaled (by calling Fsignal, below),
1251 this chain is searched for an element that applies. */
1252
1253struct handler *handlerlist;
1254
1255DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
9dbc9081 1256 doc: /* Regain control when an error is signaled.
1b1acc13 1257Executes BODYFORM and returns its value if no error happens.
9dbc9081
PJ
1258Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1259where the BODY is made of Lisp expressions.
1260
1261A handler is applicable to an error
1262if CONDITION-NAME is one of the error's condition names.
1263If an error happens, the first applicable handler is run.
1264
1265The car of a handler may be a list of condition names
1266instead of a single condition name.
1267
1268When a handler handles an error,
1269control returns to the condition-case and the handler BODY... is executed
1270with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1271VAR may be nil; then you do not get access to the signal information.
1272
1273The value of the last BODY form is returned from the condition-case.
1274See also the function `signal' for more info.
2b47b74d 1275usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
9dbc9081 1276 (args)
db9f0278
JB
1277 Lisp_Object args;
1278{
1279 Lisp_Object val;
1280 struct catchtag c;
1281 struct handler h;
17401c97
GM
1282 register Lisp_Object bodyform, handlers;
1283 volatile Lisp_Object var;
db9f0278 1284
82da7701
JB
1285 var = Fcar (args);
1286 bodyform = Fcar (Fcdr (args));
1287 handlers = Fcdr (Fcdr (args));
b7826503 1288 CHECK_SYMBOL (var);
82da7701 1289
2b47b74d 1290 for (val = handlers; CONSP (val); val = XCDR (val))
82da7701
JB
1291 {
1292 Lisp_Object tem;
2b47b74d 1293 tem = XCAR (val);
5f96776a
RS
1294 if (! (NILP (tem)
1295 || (CONSP (tem)
03699b14
KR
1296 && (SYMBOLP (XCAR (tem))
1297 || CONSP (XCAR (tem))))))
82da7701
JB
1298 error ("Invalid condition handler", tem);
1299 }
db9f0278
JB
1300
1301 c.tag = Qnil;
1302 c.val = Qnil;
1303 c.backlist = backtrace_list;
1304 c.handlerlist = handlerlist;
1305 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1306 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1307 c.poll_suppress_count = poll_suppress_count;
2659a09f 1308 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1309 c.gcpro = gcprolist;
bcf28080 1310 c.byte_stack = byte_stack_list;
db9f0278
JB
1311 if (_setjmp (c.jmp))
1312 {
265a9e55 1313 if (!NILP (h.var))
9d58218c
RS
1314 specbind (h.var, c.val);
1315 val = Fprogn (Fcdr (h.chosen_clause));
82da7701
JB
1316
1317 /* Note that this just undoes the binding of h.var; whoever
1318 longjumped to us unwound the stack to c.pdlcount before
1319 throwing. */
db9f0278
JB
1320 unbind_to (c.pdlcount, Qnil);
1321 return val;
1322 }
1323 c.next = catchlist;
1324 catchlist = &c;
177c0ea7 1325
82da7701
JB
1326 h.var = var;
1327 h.handler = handlers;
db9f0278 1328 h.next = handlerlist;
db9f0278
JB
1329 h.tag = &c;
1330 handlerlist = &h;
1331
82da7701 1332 val = Feval (bodyform);
db9f0278
JB
1333 catchlist = c.next;
1334 handlerlist = h.next;
1335 return val;
1336}
1337
f029ca5f
RS
1338/* Call the function BFUN with no arguments, catching errors within it
1339 according to HANDLERS. If there is an error, call HFUN with
1340 one argument which is the data that describes the error:
1341 (SIGNALNAME . DATA)
1342
1343 HANDLERS can be a list of conditions to catch.
1344 If HANDLERS is Qt, catch all errors.
1345 If HANDLERS is Qerror, catch all errors
1346 but allow the debugger to run if that is enabled. */
1347
db9f0278
JB
1348Lisp_Object
1349internal_condition_case (bfun, handlers, hfun)
1350 Lisp_Object (*bfun) ();
1351 Lisp_Object handlers;
1352 Lisp_Object (*hfun) ();
1353{
1354 Lisp_Object val;
1355 struct catchtag c;
1356 struct handler h;
1357
2659a09f
RS
1358#if 0 /* We now handle interrupt_input_blocked properly.
1359 What we still do not handle is exiting a signal handler. */
01591d17 1360 abort ();
dccfb979 1361#endif
01591d17 1362
db9f0278
JB
1363 c.tag = Qnil;
1364 c.val = Qnil;
1365 c.backlist = backtrace_list;
1366 c.handlerlist = handlerlist;
1367 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1368 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1369 c.poll_suppress_count = poll_suppress_count;
2659a09f 1370 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1371 c.gcpro = gcprolist;
bcf28080 1372 c.byte_stack = byte_stack_list;
db9f0278
JB
1373 if (_setjmp (c.jmp))
1374 {
9d58218c 1375 return (*hfun) (c.val);
db9f0278
JB
1376 }
1377 c.next = catchlist;
1378 catchlist = &c;
1379 h.handler = handlers;
1380 h.var = Qnil;
db9f0278
JB
1381 h.next = handlerlist;
1382 h.tag = &c;
1383 handlerlist = &h;
1384
1385 val = (*bfun) ();
1386 catchlist = c.next;
1387 handlerlist = h.next;
1388 return val;
1389}
1390
2659a09f 1391/* Like internal_condition_case but call BFUN with ARG as its argument. */
f029ca5f 1392
d227775c
RS
1393Lisp_Object
1394internal_condition_case_1 (bfun, arg, handlers, hfun)
1395 Lisp_Object (*bfun) ();
1396 Lisp_Object arg;
1397 Lisp_Object handlers;
1398 Lisp_Object (*hfun) ();
1399{
1400 Lisp_Object val;
1401 struct catchtag c;
1402 struct handler h;
1403
1404 c.tag = Qnil;
1405 c.val = Qnil;
1406 c.backlist = backtrace_list;
1407 c.handlerlist = handlerlist;
1408 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1409 c.pdlcount = SPECPDL_INDEX ();
d227775c 1410 c.poll_suppress_count = poll_suppress_count;
2659a09f 1411 c.interrupt_input_blocked = interrupt_input_blocked;
d227775c 1412 c.gcpro = gcprolist;
bcf28080 1413 c.byte_stack = byte_stack_list;
d227775c
RS
1414 if (_setjmp (c.jmp))
1415 {
9d58218c 1416 return (*hfun) (c.val);
d227775c
RS
1417 }
1418 c.next = catchlist;
1419 catchlist = &c;
1420 h.handler = handlers;
1421 h.var = Qnil;
1422 h.next = handlerlist;
1423 h.tag = &c;
1424 handlerlist = &h;
1425
1426 val = (*bfun) (arg);
1427 catchlist = c.next;
1428 handlerlist = h.next;
1429 return val;
1430}
10b29d41
GM
1431
1432
2659a09f 1433/* Like internal_condition_case but call BFUN with NARGS as first,
10b29d41
GM
1434 and ARGS as second argument. */
1435
1436Lisp_Object
1437internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1438 Lisp_Object (*bfun) ();
1439 int nargs;
1440 Lisp_Object *args;
1441 Lisp_Object handlers;
1442 Lisp_Object (*hfun) ();
1443{
1444 Lisp_Object val;
1445 struct catchtag c;
1446 struct handler h;
1447
1448 c.tag = Qnil;
1449 c.val = Qnil;
1450 c.backlist = backtrace_list;
1451 c.handlerlist = handlerlist;
1452 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1453 c.pdlcount = SPECPDL_INDEX ();
10b29d41 1454 c.poll_suppress_count = poll_suppress_count;
2659a09f 1455 c.interrupt_input_blocked = interrupt_input_blocked;
10b29d41
GM
1456 c.gcpro = gcprolist;
1457 c.byte_stack = byte_stack_list;
1458 if (_setjmp (c.jmp))
1459 {
1460 return (*hfun) (c.val);
1461 }
1462 c.next = catchlist;
1463 catchlist = &c;
1464 h.handler = handlers;
1465 h.var = Qnil;
1466 h.next = handlerlist;
1467 h.tag = &c;
1468 handlerlist = &h;
1469
1470 val = (*bfun) (nargs, args);
1471 catchlist = c.next;
1472 handlerlist = h.next;
1473 return val;
1474}
1475
d227775c 1476\f
2901f1d1
SM
1477static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
1478 Lisp_Object, Lisp_Object,
1479 Lisp_Object *));
db9f0278
JB
1480
1481DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
9dbc9081
PJ
1482 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1483This function does not return.
1484
1485An error symbol is a symbol with an `error-conditions' property
1486that is a list of condition names.
1487A handler for any of those names will get to handle this signal.
1488The symbol `error' should normally be one of them.
1489
1490DATA should be a list. Its elements are printed as part of the error message.
3297ec22
LT
1491See Info anchor `(elisp)Definition of signal' for some details on how this
1492error message is constructed.
9dbc9081
PJ
1493If the signal is handled, DATA is made available to the handler.
1494See also the function `condition-case'. */)
1495 (error_symbol, data)
4200e719 1496 Lisp_Object error_symbol, data;
db9f0278 1497{
bfa8ca43 1498 /* When memory is full, ERROR-SYMBOL is nil,
26631f2b
RS
1499 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1500 That is a special case--don't do this in other situations. */
db9f0278
JB
1501 register struct handler *allhandlers = handlerlist;
1502 Lisp_Object conditions;
1503 extern int gc_in_progress;
1504 extern int waiting_for_input;
1505 Lisp_Object debugger_value;
c11d3d17 1506 Lisp_Object string;
1ea9dec4 1507 Lisp_Object real_error_symbol;
a2ff3819 1508 struct backtrace *bp;
db9f0278 1509
346598f1 1510 immediate_quit = handling_signal = 0;
d063129f 1511 abort_on_gc = 0;
db9f0278
JB
1512 if (gc_in_progress || waiting_for_input)
1513 abort ();
1514
1ea9dec4
RS
1515 if (NILP (error_symbol))
1516 real_error_symbol = Fcar (data);
1517 else
1518 real_error_symbol = error_symbol;
1519
26631f2b
RS
1520#if 0 /* rms: I don't know why this was here,
1521 but it is surely wrong for an error that is handled. */
48f8dfa3 1522#ifdef HAVE_X_WINDOWS
df6c90d8
GM
1523 if (display_hourglass_p)
1524 cancel_hourglass ();
48f8dfa3 1525#endif
177c0ea7 1526#endif
48f8dfa3 1527
61ede770 1528 /* This hook is used by edebug. */
26631f2b
RS
1529 if (! NILP (Vsignal_hook_function)
1530 && ! NILP (error_symbol))
f01a9c5b 1531 call2 (Vsignal_hook_function, error_symbol, data);
61ede770 1532
1ea9dec4 1533 conditions = Fget (real_error_symbol, Qerror_conditions);
db9f0278 1534
a2ff3819
GM
1535 /* Remember from where signal was called. Skip over the frame for
1536 `signal' itself. If a frame for `error' follows, skip that,
26631f2b
RS
1537 too. Don't do this when ERROR_SYMBOL is nil, because that
1538 is a memory-full error. */
090a072f 1539 Vsignaling_function = Qnil;
26631f2b 1540 if (backtrace_list && !NILP (error_symbol))
090a072f
GM
1541 {
1542 bp = backtrace_list->next;
1543 if (bp && bp->function && EQ (*bp->function, Qerror))
1544 bp = bp->next;
1545 if (bp && bp->function)
1546 Vsignaling_function = *bp->function;
1547 }
a2ff3819 1548
db9f0278
JB
1549 for (; handlerlist; handlerlist = handlerlist->next)
1550 {
1551 register Lisp_Object clause;
177c0ea7 1552
8515044c
GM
1553 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1554 max_lisp_eval_depth = lisp_eval_depth + 20;
177c0ea7 1555
8515044c
GM
1556 if (specpdl_size + 40 > max_specpdl_size)
1557 max_specpdl_size = specpdl_size + 40;
177c0ea7 1558
db9f0278 1559 clause = find_handler_clause (handlerlist->handler, conditions,
4200e719 1560 error_symbol, data, &debugger_value);
db9f0278 1561
db9f0278 1562 if (EQ (clause, Qlambda))
82da7701 1563 {
690337b7
KH
1564 /* We can't return values to code which signaled an error, but we
1565 can continue code which has signaled a quit. */
1ea9dec4 1566 if (EQ (real_error_symbol, Qquit))
82da7701
JB
1567 return Qnil;
1568 else
d3e6f8be 1569 error ("Cannot return from the debugger in an error");
82da7701 1570 }
db9f0278 1571
265a9e55 1572 if (!NILP (clause))
db9f0278 1573 {
9d58218c 1574 Lisp_Object unwind_data;
db9f0278 1575 struct handler *h = handlerlist;
9d58218c 1576
db9f0278 1577 handlerlist = allhandlers;
1ea9dec4
RS
1578
1579 if (NILP (error_symbol))
1580 unwind_data = data;
9d58218c
RS
1581 else
1582 unwind_data = Fcons (error_symbol, data);
1583 h->chosen_clause = clause;
1584 unwind_to_catch (h->tag, unwind_data);
db9f0278
JB
1585 }
1586 }
1587
1588 handlerlist = allhandlers;
1589 /* If no handler is present now, try to run the debugger,
1590 and if that fails, throw to top level. */
4200e719 1591 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
c11d3d17
RS
1592 if (catchlist != 0)
1593 Fthrow (Qtop_level, Qt);
1594
1ea9dec4 1595 if (! NILP (error_symbol))
c11d3d17
RS
1596 data = Fcons (error_symbol, data);
1597
1598 string = Ferror_message_string (data);
d5db4077 1599 fatal ("%s", SDATA (string), 0);
db9f0278
JB
1600}
1601
128c0f66
RM
1602/* Return nonzero iff LIST is a non-nil atom or
1603 a list containing one of CONDITIONS. */
1604
1605static int
1606wants_debugger (list, conditions)
1607 Lisp_Object list, conditions;
1608{
4de86b16 1609 if (NILP (list))
128c0f66
RM
1610 return 0;
1611 if (! CONSP (list))
1612 return 1;
1613
ab67260b 1614 while (CONSP (conditions))
128c0f66 1615 {
ab67260b 1616 Lisp_Object this, tail;
03699b14
KR
1617 this = XCAR (conditions);
1618 for (tail = list; CONSP (tail); tail = XCDR (tail))
1619 if (EQ (XCAR (tail), this))
128c0f66 1620 return 1;
03699b14 1621 conditions = XCDR (conditions);
128c0f66 1622 }
ab67260b 1623 return 0;
128c0f66
RM
1624}
1625
fc950e09
KH
1626/* Return 1 if an error with condition-symbols CONDITIONS,
1627 and described by SIGNAL-DATA, should skip the debugger
1b1acc13 1628 according to debugger-ignored-errors. */
fc950e09
KH
1629
1630static int
1631skip_debugger (conditions, data)
1632 Lisp_Object conditions, data;
1633{
1634 Lisp_Object tail;
1635 int first_string = 1;
1636 Lisp_Object error_message;
1637
17401c97
GM
1638 error_message = Qnil;
1639 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
fc950e09 1640 {
03699b14 1641 if (STRINGP (XCAR (tail)))
fc950e09
KH
1642 {
1643 if (first_string)
1644 {
1645 error_message = Ferror_message_string (data);
1646 first_string = 0;
1647 }
177c0ea7 1648
03699b14 1649 if (fast_string_match (XCAR (tail), error_message) >= 0)
fc950e09
KH
1650 return 1;
1651 }
1652 else
1653 {
1654 Lisp_Object contail;
1655
17401c97 1656 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
03699b14 1657 if (EQ (XCAR (tail), XCAR (contail)))
fc950e09
KH
1658 return 1;
1659 }
1660 }
1661
1662 return 0;
1663}
1664
128c0f66 1665/* Value of Qlambda means we have called debugger and user has continued.
1ea9dec4 1666 There are two ways to pass SIG and DATA:
9b942ebd 1667 = SIG is the error symbol, and DATA is the rest of the data.
1ea9dec4 1668 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
9b942ebd 1669 This is for memory-full errors only.
1ea9dec4 1670
128c0f66 1671 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
db9f0278
JB
1672
1673static Lisp_Object
1674find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
1675 Lisp_Object handlers, conditions, sig, data;
1676 Lisp_Object *debugger_value_ptr;
1677{
1678 register Lisp_Object h;
1679 register Lisp_Object tem;
db9f0278
JB
1680
1681 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
1682 return Qt;
61ede770
RS
1683 /* error is used similarly, but means print an error message
1684 and run the debugger if that is enabled. */
1685 if (EQ (handlers, Qerror)
57a6e758
RS
1686 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
1687 there is a handler. */
db9f0278 1688 {
aed13378 1689 int count = SPECPDL_INDEX ();
61ede770 1690 int debugger_called = 0;
1ea9dec4 1691 Lisp_Object sig_symbol, combined_data;
9b942ebd
RS
1692 /* This is set to 1 if we are handling a memory-full error,
1693 because these must not run the debugger.
1694 (There is no room in memory to do that!) */
1695 int no_debugger = 0;
1ea9dec4
RS
1696
1697 if (NILP (sig))
1698 {
1699 combined_data = data;
1700 sig_symbol = Fcar (data);
9b942ebd 1701 no_debugger = 1;
1ea9dec4
RS
1702 }
1703 else
1704 {
1705 combined_data = Fcons (sig, data);
1706 sig_symbol = sig;
1707 }
61ede770 1708
128c0f66 1709 if (wants_debugger (Vstack_trace_on_error, conditions))
88817f3b 1710 {
b369fa65 1711#ifdef PROTOTYPES
88817f3b
RS
1712 internal_with_output_to_temp_buffer ("*Backtrace*",
1713 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
1714 Qnil);
1715#else
1716 internal_with_output_to_temp_buffer ("*Backtrace*",
1717 Fbacktrace, Qnil);
1718#endif
1719 }
9b942ebd
RS
1720 if (! no_debugger
1721 && (EQ (sig_symbol, Qquit)
1722 ? debug_on_quit
1723 : wants_debugger (Vdebug_on_error, conditions))
1ea9dec4 1724 && ! skip_debugger (conditions, combined_data)
be857679 1725 && when_entered_debugger < num_nonmacro_input_events)
db9f0278 1726 {
db9f0278 1727 specbind (Qdebug_on_error, Qnil);
fc950e09
KH
1728 *debugger_value_ptr
1729 = call_debugger (Fcons (Qerror,
1ea9dec4 1730 Fcons (combined_data, Qnil)));
61ede770
RS
1731 debugger_called = 1;
1732 }
1733 /* If there is no handler, return saying whether we ran the debugger. */
1734 if (EQ (handlers, Qerror))
1735 {
1736 if (debugger_called)
1737 return unbind_to (count, Qlambda);
1738 return Qt;
db9f0278 1739 }
db9f0278
JB
1740 }
1741 for (h = handlers; CONSP (h); h = Fcdr (h))
1742 {
5f96776a
RS
1743 Lisp_Object handler, condit;
1744
1745 handler = Fcar (h);
1746 if (!CONSP (handler))
db9f0278 1747 continue;
5f96776a
RS
1748 condit = Fcar (handler);
1749 /* Handle a single condition name in handler HANDLER. */
1750 if (SYMBOLP (condit))
1751 {
1752 tem = Fmemq (Fcar (handler), conditions);
1753 if (!NILP (tem))
1754 return handler;
1755 }
1756 /* Handle a list of condition names in handler HANDLER. */
1757 else if (CONSP (condit))
1758 {
1759 while (CONSP (condit))
1760 {
1761 tem = Fmemq (Fcar (condit), conditions);
1762 if (!NILP (tem))
1763 return handler;
03699b14 1764 condit = XCDR (condit);
5f96776a
RS
1765 }
1766 }
db9f0278
JB
1767 }
1768 return Qnil;
1769}
1770
1771/* dump an error message; called like printf */
1772
1773/* VARARGS 1 */
1774void
1775error (m, a1, a2, a3)
1776 char *m;
9125da08 1777 char *a1, *a2, *a3;
db9f0278
JB
1778{
1779 char buf[200];
9125da08
RS
1780 int size = 200;
1781 int mlen;
1782 char *buffer = buf;
1783 char *args[3];
1784 int allocated = 0;
1785 Lisp_Object string;
1786
1787 args[0] = a1;
1788 args[1] = a2;
1789 args[2] = a3;
1790
1791 mlen = strlen (m);
db9f0278
JB
1792
1793 while (1)
9125da08 1794 {
955f3ff9 1795 int used = doprnt (buffer, size, m, m + mlen, 3, args);
9125da08
RS
1796 if (used < size)
1797 break;
1798 size *= 2;
1799 if (allocated)
1800 buffer = (char *) xrealloc (buffer, size);
5ece1728
RS
1801 else
1802 {
1803 buffer = (char *) xmalloc (size);
1804 allocated = 1;
1805 }
9125da08
RS
1806 }
1807
955f3ff9 1808 string = build_string (buffer);
9125da08 1809 if (allocated)
9ae6734f 1810 xfree (buffer);
9125da08
RS
1811
1812 Fsignal (Qerror, Fcons (string, Qnil));
9402dba5 1813 abort ();
db9f0278
JB
1814}
1815\f
e72706be 1816DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
9dbc9081
PJ
1817 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
1818This means it contains a description for how to read arguments to give it.
1819The value is nil for an invalid function or a symbol with no function
1820definition.
1821
1822Interactively callable functions include strings and vectors (treated
1823as keyboard macros), lambda-expressions that contain a top-level call
1824to `interactive', autoload definitions made by `autoload' with non-nil
1825fourth argument, and some of the built-in functions of Lisp.
1826
e72706be
RS
1827Also, a symbol satisfies `commandp' if its function definition does so.
1828
1829If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
769b4fb2 1830then strings and vectors are not accepted. */)
e72706be
RS
1831 (function, for_call_interactively)
1832 Lisp_Object function, for_call_interactively;
db9f0278
JB
1833{
1834 register Lisp_Object fun;
1835 register Lisp_Object funcar;
db9f0278
JB
1836
1837 fun = function;
1838
ffd56f97
JB
1839 fun = indirect_function (fun);
1840 if (EQ (fun, Qunbound))
1841 return Qnil;
db9f0278
JB
1842
1843 /* Emacs primitives are interactive if their DEFUN specifies an
1844 interactive spec. */
90165123 1845 if (SUBRP (fun))
db9f0278
JB
1846 {
1847 if (XSUBR (fun)->prompt)
1848 return Qt;
1849 else
1850 return Qnil;
1851 }
1852
1853 /* Bytecode objects are interactive if they are long enough to
1854 have an element whose index is COMPILED_INTERACTIVE, which is
1855 where the interactive spec is stored. */
90165123 1856 else if (COMPILEDP (fun))
845975f5 1857 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
db9f0278
JB
1858 ? Qt : Qnil);
1859
1860 /* Strings and vectors are keyboard macros. */
e72706be 1861 if (NILP (for_call_interactively) && (STRINGP (fun) || VECTORP (fun)))
db9f0278
JB
1862 return Qt;
1863
1864 /* Lists may represent commands. */
1865 if (!CONSP (fun))
1866 return Qnil;
ed16fb98 1867 funcar = XCAR (fun);
db9f0278 1868 if (EQ (funcar, Qlambda))
ed16fb98 1869 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
db9f0278 1870 if (EQ (funcar, Qautoload))
ed16fb98 1871 return Fcar (Fcdr (Fcdr (XCDR (fun))));
db9f0278
JB
1872 else
1873 return Qnil;
1874}
1875
1876/* ARGSUSED */
1877DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
9dbc9081
PJ
1878 doc: /* Define FUNCTION to autoload from FILE.
1879FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1880Third arg DOCSTRING is documentation for the function.
1881Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1882Fifth arg TYPE indicates the type of the object:
1883 nil or omitted says FUNCTION is a function,
1884 `keymap' says FUNCTION is really a keymap, and
1885 `macro' or t says FUNCTION is really a macro.
1886Third through fifth args give info about the real definition.
1887They default to nil.
1888If FUNCTION is already defined other than as an autoload,
1889this does nothing and returns nil. */)
1890 (function, file, docstring, interactive, type)
ee9ee63c 1891 Lisp_Object function, file, docstring, interactive, type;
db9f0278
JB
1892{
1893#ifdef NO_ARG_ARRAY
1894 Lisp_Object args[4];
1895#endif
1896
b7826503
PJ
1897 CHECK_SYMBOL (function);
1898 CHECK_STRING (file);
db9f0278
JB
1899
1900 /* If function is defined and not as an autoload, don't override */
1901 if (!EQ (XSYMBOL (function)->function, Qunbound)
90165123 1902 && !(CONSP (XSYMBOL (function)->function)
03699b14 1903 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
db9f0278
JB
1904 return Qnil;
1905
7973e637
SM
1906 if (NILP (Vpurify_flag))
1907 /* Only add entries after dumping, because the ones before are
1908 not useful and else we get loads of them from the loaddefs.el. */
1909 LOADHIST_ATTACH (Fcons (Qautoload, function));
1910
db9f0278
JB
1911#ifdef NO_ARG_ARRAY
1912 args[0] = file;
1913 args[1] = docstring;
1914 args[2] = interactive;
ee9ee63c 1915 args[3] = type;
db9f0278
JB
1916
1917 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
1918#else /* NO_ARG_ARRAY */
1919 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
1920#endif /* not NO_ARG_ARRAY */
1921}
1922
1923Lisp_Object
1924un_autoload (oldqueue)
1925 Lisp_Object oldqueue;
1926{
1927 register Lisp_Object queue, first, second;
1928
1929 /* Queue to unwind is current value of Vautoload_queue.
1930 oldqueue is the shadowed value to leave in Vautoload_queue. */
1931 queue = Vautoload_queue;
1932 Vautoload_queue = oldqueue;
1933 while (CONSP (queue))
1934 {
e509f168 1935 first = XCAR (queue);
db9f0278
JB
1936 second = Fcdr (first);
1937 first = Fcar (first);
1938 if (EQ (second, Qnil))
1939 Vfeatures = first;
1940 else
1941 Ffset (first, second);
e509f168 1942 queue = XCDR (queue);
db9f0278
JB
1943 }
1944 return Qnil;
1945}
1946
ca20916b
RS
1947/* Load an autoloaded function.
1948 FUNNAME is the symbol which is the function's name.
1949 FUNDEF is the autoload definition (a list). */
1950
045ba794 1951void
db9f0278
JB
1952do_autoload (fundef, funname)
1953 Lisp_Object fundef, funname;
1954{
aed13378 1955 int count = SPECPDL_INDEX ();
cb81ac97 1956 Lisp_Object fun, queue, first, second;
ca20916b 1957 struct gcpro gcpro1, gcpro2, gcpro3;
db9f0278 1958
aea6173f
RS
1959 /* This is to make sure that loadup.el gives a clear picture
1960 of what files are preloaded and when. */
ab4db096
RS
1961 if (! NILP (Vpurify_flag))
1962 error ("Attempt to autoload %s while preparing to dump",
d5db4077 1963 SDATA (SYMBOL_NAME (funname)));
ab4db096 1964
db9f0278 1965 fun = funname;
b7826503 1966 CHECK_SYMBOL (funname);
ca20916b 1967 GCPRO3 (fun, funname, fundef);
db9f0278 1968
f87740dc
RS
1969 /* Preserve the match data. */
1970 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil));
177c0ea7 1971
f87740dc 1972 /* Value saved here is to be restored into Vautoload_queue. */
db9f0278
JB
1973 record_unwind_protect (un_autoload, Vautoload_queue);
1974 Vautoload_queue = Qt;
4aac2302 1975 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt);
2a49b6e5 1976
f87740dc 1977 /* Save the old autoloads, in case we ever do an unload. */
2a49b6e5
RS
1978 queue = Vautoload_queue;
1979 while (CONSP (queue))
1980 {
e509f168 1981 first = XCAR (queue);
2a49b6e5
RS
1982 second = Fcdr (first);
1983 first = Fcar (first);
5739ce6b
ER
1984
1985 /* Note: This test is subtle. The cdr of an autoload-queue entry
1986 may be an atom if the autoload entry was generated by a defalias
f87740dc 1987 or fset. */
5739ce6b 1988 if (CONSP (second))
e509f168 1989 Fput (first, Qautoload, (XCDR (second)));
5739ce6b 1990
e509f168 1991 queue = XCDR (queue);
2a49b6e5
RS
1992 }
1993
db9f0278
JB
1994 /* Once loading finishes, don't undo it. */
1995 Vautoload_queue = Qt;
1996 unbind_to (count, Qnil);
1997
ffd56f97
JB
1998 fun = Findirect_function (fun);
1999
76c2b0cc 2000 if (!NILP (Fequal (fun, fundef)))
db9f0278 2001 error ("Autoloading failed to define function %s",
d5db4077 2002 SDATA (SYMBOL_NAME (funname)));
ca20916b 2003 UNGCPRO;
db9f0278 2004}
4c576a83 2005
db9f0278
JB
2006\f
2007DEFUN ("eval", Feval, Seval, 1, 1, 0,
9dbc9081
PJ
2008 doc: /* Evaluate FORM and return its value. */)
2009 (form)
db9f0278
JB
2010 Lisp_Object form;
2011{
2012 Lisp_Object fun, val, original_fun, original_args;
2013 Lisp_Object funcar;
2014 struct backtrace backtrace;
2015 struct gcpro gcpro1, gcpro2, gcpro3;
2016
df470e3b 2017 if (handling_signal)
48f8dfa3 2018 abort ();
177c0ea7 2019
90165123 2020 if (SYMBOLP (form))
2b9bde76 2021 return Fsymbol_value (form);
db9f0278
JB
2022 if (!CONSP (form))
2023 return form;
2024
2025 QUIT;
2026 if (consing_since_gc > gc_cons_threshold)
2027 {
2028 GCPRO1 (form);
2029 Fgarbage_collect ();
2030 UNGCPRO;
2031 }
2032
2033 if (++lisp_eval_depth > max_lisp_eval_depth)
2034 {
2035 if (max_lisp_eval_depth < 100)
2036 max_lisp_eval_depth = 100;
2037 if (lisp_eval_depth > max_lisp_eval_depth)
2038 error ("Lisp nesting exceeds max-lisp-eval-depth");
2039 }
2040
2041 original_fun = Fcar (form);
2042 original_args = Fcdr (form);
2043
2044 backtrace.next = backtrace_list;
2045 backtrace_list = &backtrace;
2046 backtrace.function = &original_fun; /* This also protects them from gc */
2047 backtrace.args = &original_args;
2048 backtrace.nargs = UNEVALLED;
2049 backtrace.evalargs = 1;
2050 backtrace.debug_on_exit = 0;
2051
2052 if (debug_on_next_call)
2053 do_debug_on_call (Qt);
2054
2055 /* At this point, only original_fun and original_args
2056 have values that will be used below */
2057 retry:
ffd56f97 2058 fun = Findirect_function (original_fun);
db9f0278 2059
90165123 2060 if (SUBRP (fun))
db9f0278
JB
2061 {
2062 Lisp_Object numargs;
166c822d 2063 Lisp_Object argvals[8];
db9f0278
JB
2064 Lisp_Object args_left;
2065 register int i, maxargs;
2066
2067 args_left = original_args;
2068 numargs = Flength (args_left);
2069
c1788fbc
RS
2070 CHECK_CONS_LIST ();
2071
db9f0278
JB
2072 if (XINT (numargs) < XSUBR (fun)->min_args ||
2073 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
2074 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
2075
2076 if (XSUBR (fun)->max_args == UNEVALLED)
2077 {
2078 backtrace.evalargs = 0;
2079 val = (*XSUBR (fun)->function) (args_left);
2080 goto done;
2081 }
2082
2083 if (XSUBR (fun)->max_args == MANY)
2084 {
2085 /* Pass a vector of evaluated arguments */
2086 Lisp_Object *vals;
2087 register int argnum = 0;
2088
2089 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2090
2091 GCPRO3 (args_left, fun, fun);
2092 gcpro3.var = vals;
2093 gcpro3.nvars = 0;
2094
265a9e55 2095 while (!NILP (args_left))
db9f0278
JB
2096 {
2097 vals[argnum++] = Feval (Fcar (args_left));
2098 args_left = Fcdr (args_left);
2099 gcpro3.nvars = argnum;
2100 }
db9f0278
JB
2101
2102 backtrace.args = vals;
2103 backtrace.nargs = XINT (numargs);
2104
2105 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
a6e3fa71 2106 UNGCPRO;
db9f0278
JB
2107 goto done;
2108 }
2109
2110 GCPRO3 (args_left, fun, fun);
2111 gcpro3.var = argvals;
2112 gcpro3.nvars = 0;
2113
2114 maxargs = XSUBR (fun)->max_args;
2115 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2116 {
2117 argvals[i] = Feval (Fcar (args_left));
2118 gcpro3.nvars = ++i;
2119 }
2120
2121 UNGCPRO;
2122
2123 backtrace.args = argvals;
2124 backtrace.nargs = XINT (numargs);
2125
2126 switch (i)
2127 {
2128 case 0:
2129 val = (*XSUBR (fun)->function) ();
2130 goto done;
2131 case 1:
2132 val = (*XSUBR (fun)->function) (argvals[0]);
2133 goto done;
2134 case 2:
2135 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
2136 goto done;
2137 case 3:
2138 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2139 argvals[2]);
2140 goto done;
2141 case 4:
2142 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2143 argvals[2], argvals[3]);
2144 goto done;
2145 case 5:
2146 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2147 argvals[3], argvals[4]);
2148 goto done;
2149 case 6:
2150 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2151 argvals[3], argvals[4], argvals[5]);
2152 goto done;
15c65264
RS
2153 case 7:
2154 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2155 argvals[3], argvals[4], argvals[5],
2156 argvals[6]);
2157 goto done;
db9f0278 2158
166c822d
KH
2159 case 8:
2160 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2161 argvals[3], argvals[4], argvals[5],
2162 argvals[6], argvals[7]);
2163 goto done;
2164
db9f0278 2165 default:
08564963
JB
2166 /* Someone has created a subr that takes more arguments than
2167 is supported by this code. We need to either rewrite the
2168 subr to use a different argument protocol, or add more
2169 cases to this switch. */
2170 abort ();
db9f0278
JB
2171 }
2172 }
90165123 2173 if (COMPILEDP (fun))
db9f0278
JB
2174 val = apply_lambda (fun, original_args, 1);
2175 else
2176 {
2177 if (!CONSP (fun))
2178 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2179 funcar = Fcar (fun);
90165123 2180 if (!SYMBOLP (funcar))
db9f0278
JB
2181 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2182 if (EQ (funcar, Qautoload))
2183 {
2184 do_autoload (fun, original_fun);
2185 goto retry;
2186 }
2187 if (EQ (funcar, Qmacro))
2188 val = Feval (apply1 (Fcdr (fun), original_args));
2189 else if (EQ (funcar, Qlambda))
2190 val = apply_lambda (fun, original_args, 1);
db9f0278
JB
2191 else
2192 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2193 }
2194 done:
c1788fbc
RS
2195 CHECK_CONS_LIST ();
2196
db9f0278
JB
2197 lisp_eval_depth--;
2198 if (backtrace.debug_on_exit)
2199 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2200 backtrace_list = backtrace.next;
824eb35e 2201
db9f0278
JB
2202 return val;
2203}
2204\f
2205DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
9dbc9081
PJ
2206 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2207Then return the value FUNCTION returns.
2208Thus, (apply '+ 1 2 '(3 4)) returns 10.
2209usage: (apply FUNCTION &rest ARGUMENTS) */)
2210 (nargs, args)
db9f0278
JB
2211 int nargs;
2212 Lisp_Object *args;
2213{
2214 register int i, numargs;
2215 register Lisp_Object spread_arg;
2216 register Lisp_Object *funcall_args;
db9f0278 2217 Lisp_Object fun;
96d44c64 2218 struct gcpro gcpro1;
db9f0278
JB
2219
2220 fun = args [0];
2221 funcall_args = 0;
2222 spread_arg = args [nargs - 1];
b7826503 2223 CHECK_LIST (spread_arg);
177c0ea7 2224
db9f0278
JB
2225 numargs = XINT (Flength (spread_arg));
2226
2227 if (numargs == 0)
2228 return Ffuncall (nargs - 1, args);
2229 else if (numargs == 1)
2230 {
03699b14 2231 args [nargs - 1] = XCAR (spread_arg);
db9f0278
JB
2232 return Ffuncall (nargs, args);
2233 }
2234
a6e3fa71 2235 numargs += nargs - 2;
db9f0278 2236
ffd56f97
JB
2237 fun = indirect_function (fun);
2238 if (EQ (fun, Qunbound))
db9f0278 2239 {
ffd56f97
JB
2240 /* Let funcall get the error */
2241 fun = args[0];
2242 goto funcall;
db9f0278
JB
2243 }
2244
90165123 2245 if (SUBRP (fun))
db9f0278
JB
2246 {
2247 if (numargs < XSUBR (fun)->min_args
2248 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2249 goto funcall; /* Let funcall get the error */
2250 else if (XSUBR (fun)->max_args > numargs)
2251 {
2252 /* Avoid making funcall cons up a yet another new vector of arguments
2253 by explicitly supplying nil's for optional values */
2254 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
2255 * sizeof (Lisp_Object));
2256 for (i = numargs; i < XSUBR (fun)->max_args;)
2257 funcall_args[++i] = Qnil;
96d44c64
SM
2258 GCPRO1 (*funcall_args);
2259 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
db9f0278
JB
2260 }
2261 }
2262 funcall:
2263 /* We add 1 to numargs because funcall_args includes the
2264 function itself as well as its arguments. */
2265 if (!funcall_args)
a6e3fa71
JB
2266 {
2267 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
2268 * sizeof (Lisp_Object));
96d44c64
SM
2269 GCPRO1 (*funcall_args);
2270 gcpro1.nvars = 1 + numargs;
a6e3fa71
JB
2271 }
2272
db9f0278
JB
2273 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
2274 /* Spread the last arg we got. Its first element goes in
2275 the slot that it used to occupy, hence this value of I. */
2276 i = nargs - 1;
265a9e55 2277 while (!NILP (spread_arg))
db9f0278 2278 {
03699b14
KR
2279 funcall_args [i++] = XCAR (spread_arg);
2280 spread_arg = XCDR (spread_arg);
db9f0278 2281 }
a6e3fa71 2282
96d44c64
SM
2283 /* By convention, the caller needs to gcpro Ffuncall's args. */
2284 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
db9f0278
JB
2285}
2286\f
ff936e53
SM
2287/* Run hook variables in various ways. */
2288
2289enum run_hooks_condition {to_completion, until_success, until_failure};
2901f1d1
SM
2290static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
2291 enum run_hooks_condition));
ff936e53 2292
8b5176cd 2293DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
9dbc9081
PJ
2294 doc: /* Run each hook in HOOKS. Major mode functions use this.
2295Each argument should be a symbol, a hook variable.
2296These symbols are processed in the order specified.
2297If a hook symbol has a non-nil value, that value may be a function
2298or a list of functions to be called to run the hook.
2299If the value is a function, it is called with no arguments.
2300If it is a list, the elements are called, in order, with no arguments.
2301
72e85d5d
RS
2302Do not use `make-local-variable' to make a hook variable buffer-local.
2303Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081
PJ
2304usage: (run-hooks &rest HOOKS) */)
2305 (nargs, args)
ff936e53
SM
2306 int nargs;
2307 Lisp_Object *args;
2308{
2309 Lisp_Object hook[1];
2310 register int i;
2311
2312 for (i = 0; i < nargs; i++)
2313 {
2314 hook[0] = args[i];
2315 run_hook_with_args (1, hook, to_completion);
2316 }
2317
2318 return Qnil;
2319}
177c0ea7 2320
a0d76c27 2321DEFUN ("run-hook-with-args", Frun_hook_with_args,
9dbc9081
PJ
2322 Srun_hook_with_args, 1, MANY, 0,
2323 doc: /* Run HOOK with the specified arguments ARGS.
2324HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2325value, that value may be a function or a list of functions to be
2326called to run the hook. If the value is a function, it is called with
2327the given arguments and its return value is returned. If it is a list
2328of functions, those functions are called, in order,
2329with the given arguments ARGS.
d5e2c90c 2330It is best not to depend on the value returned by `run-hook-with-args',
9dbc9081
PJ
2331as that may change.
2332
72e85d5d
RS
2333Do not use `make-local-variable' to make a hook variable buffer-local.
2334Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081
PJ
2335usage: (run-hook-with-args HOOK &rest ARGS) */)
2336 (nargs, args)
ff936e53
SM
2337 int nargs;
2338 Lisp_Object *args;
2339{
2340 return run_hook_with_args (nargs, args, to_completion);
2341}
2342
a0d76c27 2343DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
9dbc9081
PJ
2344 Srun_hook_with_args_until_success, 1, MANY, 0,
2345 doc: /* Run HOOK with the specified arguments ARGS.
d5e2c90c
RS
2346HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2347value, that value may be a function or a list of functions to be
2348called to run the hook. If the value is a function, it is called with
2349the given arguments and its return value is returned.
2350If it is a list of functions, those functions are called, in order,
2351with the given arguments ARGS, until one of them
9dbc9081 2352returns a non-nil value. Then we return that value.
d5e2c90c 2353However, if they all return nil, we return nil.
9dbc9081 2354
72e85d5d
RS
2355Do not use `make-local-variable' to make a hook variable buffer-local.
2356Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081
PJ
2357usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2358 (nargs, args)
b0b667cb
KH
2359 int nargs;
2360 Lisp_Object *args;
2361{
ff936e53
SM
2362 return run_hook_with_args (nargs, args, until_success);
2363}
2364
a0d76c27 2365DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
9dbc9081
PJ
2366 Srun_hook_with_args_until_failure, 1, MANY, 0,
2367 doc: /* Run HOOK with the specified arguments ARGS.
d5e2c90c
RS
2368HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2369value, that value may be a function or a list of functions to be
2370called to run the hook. If the value is a function, it is called with
2371the given arguments and its return value is returned.
2372If it is a list of functions, those functions are called, in order,
2373with the given arguments ARGS, until one of them returns nil.
2374Then we return nil. However, if they all return non-nil, we return non-nil.
9dbc9081 2375
72e85d5d
RS
2376Do not use `make-local-variable' to make a hook variable buffer-local.
2377Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081
PJ
2378usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2379 (nargs, args)
ff936e53
SM
2380 int nargs;
2381 Lisp_Object *args;
2382{
2383 return run_hook_with_args (nargs, args, until_failure);
2384}
2385
c933ea05
RS
2386/* ARGS[0] should be a hook symbol.
2387 Call each of the functions in the hook value, passing each of them
2388 as arguments all the rest of ARGS (all NARGS - 1 elements).
2389 COND specifies a condition to test after each call
2390 to decide whether to stop.
2391 The caller (or its caller, etc) must gcpro all of ARGS,
2392 except that it isn't necessary to gcpro ARGS[0]. */
2393
2901f1d1 2394static Lisp_Object
ff936e53
SM
2395run_hook_with_args (nargs, args, cond)
2396 int nargs;
2397 Lisp_Object *args;
2398 enum run_hooks_condition cond;
2399{
2400 Lisp_Object sym, val, ret;
fada05d6
KH
2401 Lisp_Object globals;
2402 struct gcpro gcpro1, gcpro2, gcpro3;
b0b667cb 2403
f029ca5f
RS
2404 /* If we are dying or still initializing,
2405 don't do anything--it would probably crash if we tried. */
2406 if (NILP (Vrun_hooks))
caff32a7 2407 return Qnil;
f029ca5f 2408
b0b667cb 2409 sym = args[0];
aa681b51 2410 val = find_symbol_value (sym);
ff936e53
SM
2411 ret = (cond == until_failure ? Qt : Qnil);
2412
b0b667cb 2413 if (EQ (val, Qunbound) || NILP (val))
ff936e53 2414 return ret;
03699b14 2415 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
b0b667cb
KH
2416 {
2417 args[0] = val;
2418 return Ffuncall (nargs, args);
2419 }
2420 else
2421 {
fada05d6
KH
2422 globals = Qnil;
2423 GCPRO3 (sym, val, globals);
cb9d21f8 2424
ff936e53
SM
2425 for (;
2426 CONSP (val) && ((cond == to_completion)
2427 || (cond == until_success ? NILP (ret)
2428 : !NILP (ret)));
03699b14 2429 val = XCDR (val))
b0b667cb 2430 {
03699b14 2431 if (EQ (XCAR (val), Qt))
b0b667cb
KH
2432 {
2433 /* t indicates this hook has a local binding;
2434 it means to run the global binding too. */
b0b667cb 2435
ff936e53
SM
2436 for (globals = Fdefault_value (sym);
2437 CONSP (globals) && ((cond == to_completion)
2438 || (cond == until_success ? NILP (ret)
2439 : !NILP (ret)));
03699b14 2440 globals = XCDR (globals))
b0b667cb 2441 {
03699b14 2442 args[0] = XCAR (globals);
77d92e05
RS
2443 /* In a global value, t should not occur. If it does, we
2444 must ignore it to avoid an endless loop. */
2445 if (!EQ (args[0], Qt))
2446 ret = Ffuncall (nargs, args);
b0b667cb
KH
2447 }
2448 }
2449 else
2450 {
03699b14 2451 args[0] = XCAR (val);
ff936e53 2452 ret = Ffuncall (nargs, args);
b0b667cb
KH
2453 }
2454 }
cb9d21f8
RS
2455
2456 UNGCPRO;
ff936e53 2457 return ret;
b0b667cb
KH
2458 }
2459}
c933ea05
RS
2460
2461/* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2462 present value of that symbol.
2463 Call each element of FUNLIST,
2464 passing each of them the rest of ARGS.
2465 The caller (or its caller, etc) must gcpro all of ARGS,
2466 except that it isn't necessary to gcpro ARGS[0]. */
2467
2468Lisp_Object
2469run_hook_list_with_args (funlist, nargs, args)
2470 Lisp_Object funlist;
2471 int nargs;
2472 Lisp_Object *args;
2473{
2474 Lisp_Object sym;
2475 Lisp_Object val;
fada05d6
KH
2476 Lisp_Object globals;
2477 struct gcpro gcpro1, gcpro2, gcpro3;
c933ea05
RS
2478
2479 sym = args[0];
fada05d6
KH
2480 globals = Qnil;
2481 GCPRO3 (sym, val, globals);
c933ea05 2482
03699b14 2483 for (val = funlist; CONSP (val); val = XCDR (val))
c933ea05 2484 {
03699b14 2485 if (EQ (XCAR (val), Qt))
c933ea05
RS
2486 {
2487 /* t indicates this hook has a local binding;
2488 it means to run the global binding too. */
c933ea05
RS
2489
2490 for (globals = Fdefault_value (sym);
2491 CONSP (globals);
03699b14 2492 globals = XCDR (globals))
c933ea05 2493 {
03699b14 2494 args[0] = XCAR (globals);
77d92e05
RS
2495 /* In a global value, t should not occur. If it does, we
2496 must ignore it to avoid an endless loop. */
2497 if (!EQ (args[0], Qt))
2498 Ffuncall (nargs, args);
c933ea05
RS
2499 }
2500 }
2501 else
2502 {
03699b14 2503 args[0] = XCAR (val);
c933ea05
RS
2504 Ffuncall (nargs, args);
2505 }
2506 }
2507 UNGCPRO;
2508 return Qnil;
2509}
7d48558f
RS
2510
2511/* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2512
2513void
2514run_hook_with_args_2 (hook, arg1, arg2)
2515 Lisp_Object hook, arg1, arg2;
2516{
2517 Lisp_Object temp[3];
2518 temp[0] = hook;
2519 temp[1] = arg1;
2520 temp[2] = arg2;
2521
2522 Frun_hook_with_args (3, temp);
2523}
ff936e53 2524\f
db9f0278
JB
2525/* Apply fn to arg */
2526Lisp_Object
2527apply1 (fn, arg)
2528 Lisp_Object fn, arg;
2529{
a6e3fa71
JB
2530 struct gcpro gcpro1;
2531
2532 GCPRO1 (fn);
265a9e55 2533 if (NILP (arg))
a6e3fa71
JB
2534 RETURN_UNGCPRO (Ffuncall (1, &fn));
2535 gcpro1.nvars = 2;
db9f0278
JB
2536#ifdef NO_ARG_ARRAY
2537 {
2538 Lisp_Object args[2];
2539 args[0] = fn;
2540 args[1] = arg;
a6e3fa71
JB
2541 gcpro1.var = args;
2542 RETURN_UNGCPRO (Fapply (2, args));
db9f0278
JB
2543 }
2544#else /* not NO_ARG_ARRAY */
a6e3fa71 2545 RETURN_UNGCPRO (Fapply (2, &fn));
db9f0278
JB
2546#endif /* not NO_ARG_ARRAY */
2547}
2548
2549/* Call function fn on no arguments */
2550Lisp_Object
2551call0 (fn)
2552 Lisp_Object fn;
2553{
a6e3fa71
JB
2554 struct gcpro gcpro1;
2555
2556 GCPRO1 (fn);
2557 RETURN_UNGCPRO (Ffuncall (1, &fn));
db9f0278
JB
2558}
2559
15285f9f 2560/* Call function fn with 1 argument arg1 */
db9f0278
JB
2561/* ARGSUSED */
2562Lisp_Object
15285f9f
RS
2563call1 (fn, arg1)
2564 Lisp_Object fn, arg1;
db9f0278 2565{
a6e3fa71 2566 struct gcpro gcpro1;
db9f0278 2567#ifdef NO_ARG_ARRAY
177c0ea7 2568 Lisp_Object args[2];
a6e3fa71 2569
db9f0278 2570 args[0] = fn;
15285f9f 2571 args[1] = arg1;
a6e3fa71
JB
2572 GCPRO1 (args[0]);
2573 gcpro1.nvars = 2;
2574 RETURN_UNGCPRO (Ffuncall (2, args));
db9f0278 2575#else /* not NO_ARG_ARRAY */
a6e3fa71
JB
2576 GCPRO1 (fn);
2577 gcpro1.nvars = 2;
2578 RETURN_UNGCPRO (Ffuncall (2, &fn));
db9f0278
JB
2579#endif /* not NO_ARG_ARRAY */
2580}
2581
15285f9f 2582/* Call function fn with 2 arguments arg1, arg2 */
db9f0278
JB
2583/* ARGSUSED */
2584Lisp_Object
15285f9f
RS
2585call2 (fn, arg1, arg2)
2586 Lisp_Object fn, arg1, arg2;
db9f0278 2587{
a6e3fa71 2588 struct gcpro gcpro1;
db9f0278
JB
2589#ifdef NO_ARG_ARRAY
2590 Lisp_Object args[3];
2591 args[0] = fn;
15285f9f
RS
2592 args[1] = arg1;
2593 args[2] = arg2;
a6e3fa71
JB
2594 GCPRO1 (args[0]);
2595 gcpro1.nvars = 3;
2596 RETURN_UNGCPRO (Ffuncall (3, args));
db9f0278 2597#else /* not NO_ARG_ARRAY */
a6e3fa71
JB
2598 GCPRO1 (fn);
2599 gcpro1.nvars = 3;
2600 RETURN_UNGCPRO (Ffuncall (3, &fn));
db9f0278
JB
2601#endif /* not NO_ARG_ARRAY */
2602}
2603
15285f9f 2604/* Call function fn with 3 arguments arg1, arg2, arg3 */
db9f0278
JB
2605/* ARGSUSED */
2606Lisp_Object
15285f9f
RS
2607call3 (fn, arg1, arg2, arg3)
2608 Lisp_Object fn, arg1, arg2, arg3;
db9f0278 2609{
a6e3fa71 2610 struct gcpro gcpro1;
db9f0278
JB
2611#ifdef NO_ARG_ARRAY
2612 Lisp_Object args[4];
2613 args[0] = fn;
15285f9f
RS
2614 args[1] = arg1;
2615 args[2] = arg2;
2616 args[3] = arg3;
a6e3fa71
JB
2617 GCPRO1 (args[0]);
2618 gcpro1.nvars = 4;
2619 RETURN_UNGCPRO (Ffuncall (4, args));
db9f0278 2620#else /* not NO_ARG_ARRAY */
a6e3fa71
JB
2621 GCPRO1 (fn);
2622 gcpro1.nvars = 4;
2623 RETURN_UNGCPRO (Ffuncall (4, &fn));
db9f0278
JB
2624#endif /* not NO_ARG_ARRAY */
2625}
2626
15285f9f 2627/* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
a5a44b91
JB
2628/* ARGSUSED */
2629Lisp_Object
15285f9f
RS
2630call4 (fn, arg1, arg2, arg3, arg4)
2631 Lisp_Object fn, arg1, arg2, arg3, arg4;
a5a44b91
JB
2632{
2633 struct gcpro gcpro1;
2634#ifdef NO_ARG_ARRAY
2635 Lisp_Object args[5];
2636 args[0] = fn;
15285f9f
RS
2637 args[1] = arg1;
2638 args[2] = arg2;
2639 args[3] = arg3;
2640 args[4] = arg4;
a5a44b91
JB
2641 GCPRO1 (args[0]);
2642 gcpro1.nvars = 5;
2643 RETURN_UNGCPRO (Ffuncall (5, args));
2644#else /* not NO_ARG_ARRAY */
2645 GCPRO1 (fn);
2646 gcpro1.nvars = 5;
2647 RETURN_UNGCPRO (Ffuncall (5, &fn));
2648#endif /* not NO_ARG_ARRAY */
2649}
2650
15285f9f
RS
2651/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2652/* ARGSUSED */
2653Lisp_Object
2654call5 (fn, arg1, arg2, arg3, arg4, arg5)
2655 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2656{
2657 struct gcpro gcpro1;
2658#ifdef NO_ARG_ARRAY
2659 Lisp_Object args[6];
2660 args[0] = fn;
2661 args[1] = arg1;
2662 args[2] = arg2;
2663 args[3] = arg3;
2664 args[4] = arg4;
2665 args[5] = arg5;
2666 GCPRO1 (args[0]);
2667 gcpro1.nvars = 6;
2668 RETURN_UNGCPRO (Ffuncall (6, args));
2669#else /* not NO_ARG_ARRAY */
2670 GCPRO1 (fn);
2671 gcpro1.nvars = 6;
2672 RETURN_UNGCPRO (Ffuncall (6, &fn));
2673#endif /* not NO_ARG_ARRAY */
2674}
2675
2676/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2677/* ARGSUSED */
2678Lisp_Object
2679call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2680 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2681{
2682 struct gcpro gcpro1;
2683#ifdef NO_ARG_ARRAY
2684 Lisp_Object args[7];
2685 args[0] = fn;
2686 args[1] = arg1;
2687 args[2] = arg2;
2688 args[3] = arg3;
2689 args[4] = arg4;
2690 args[5] = arg5;
2691 args[6] = arg6;
2692 GCPRO1 (args[0]);
2693 gcpro1.nvars = 7;
2694 RETURN_UNGCPRO (Ffuncall (7, args));
2695#else /* not NO_ARG_ARRAY */
2696 GCPRO1 (fn);
2697 gcpro1.nvars = 7;
2698 RETURN_UNGCPRO (Ffuncall (7, &fn));
2699#endif /* not NO_ARG_ARRAY */
2700}
2701
6c2ef893
RS
2702/* The caller should GCPRO all the elements of ARGS. */
2703
db9f0278 2704DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
9dbc9081
PJ
2705 doc: /* Call first argument as a function, passing remaining arguments to it.
2706Return the value that function returns.
2707Thus, (funcall 'cons 'x 'y) returns (x . y).
2708usage: (funcall FUNCTION &rest ARGUMENTS) */)
2709 (nargs, args)
db9f0278
JB
2710 int nargs;
2711 Lisp_Object *args;
2712{
2713 Lisp_Object fun;
2714 Lisp_Object funcar;
2715 int numargs = nargs - 1;
2716 Lisp_Object lisp_numargs;
2717 Lisp_Object val;
2718 struct backtrace backtrace;
2719 register Lisp_Object *internal_args;
2720 register int i;
2721
2722 QUIT;
2723 if (consing_since_gc > gc_cons_threshold)
a6e3fa71 2724 Fgarbage_collect ();
db9f0278
JB
2725
2726 if (++lisp_eval_depth > max_lisp_eval_depth)
2727 {
2728 if (max_lisp_eval_depth < 100)
2729 max_lisp_eval_depth = 100;
2730 if (lisp_eval_depth > max_lisp_eval_depth)
2731 error ("Lisp nesting exceeds max-lisp-eval-depth");
2732 }
2733
2734 backtrace.next = backtrace_list;
2735 backtrace_list = &backtrace;
2736 backtrace.function = &args[0];
2737 backtrace.args = &args[1];
2738 backtrace.nargs = nargs - 1;
2739 backtrace.evalargs = 0;
2740 backtrace.debug_on_exit = 0;
2741
2742 if (debug_on_next_call)
2743 do_debug_on_call (Qlambda);
2744
fff3ff9c
KS
2745 CHECK_CONS_LIST ();
2746
db9f0278
JB
2747 retry:
2748
2749 fun = args[0];
ffd56f97
JB
2750
2751 fun = Findirect_function (fun);
db9f0278 2752
90165123 2753 if (SUBRP (fun))
db9f0278 2754 {
fff3ff9c 2755 if (numargs < XSUBR (fun)->min_args
db9f0278
JB
2756 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2757 {
a631e24c 2758 XSETFASTINT (lisp_numargs, numargs);
db9f0278
JB
2759 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
2760 }
2761
2762 if (XSUBR (fun)->max_args == UNEVALLED)
2763 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2764
2765 if (XSUBR (fun)->max_args == MANY)
2766 {
2767 val = (*XSUBR (fun)->function) (numargs, args + 1);
2768 goto done;
2769 }
2770
2771 if (XSUBR (fun)->max_args > numargs)
2772 {
2773 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2774 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2775 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2776 internal_args[i] = Qnil;
2777 }
2778 else
2779 internal_args = args + 1;
2780 switch (XSUBR (fun)->max_args)
2781 {
2782 case 0:
2783 val = (*XSUBR (fun)->function) ();
2784 goto done;
2785 case 1:
2786 val = (*XSUBR (fun)->function) (internal_args[0]);
2787 goto done;
2788 case 2:
2789 val = (*XSUBR (fun)->function) (internal_args[0],
2790 internal_args[1]);
2791 goto done;
2792 case 3:
2793 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2794 internal_args[2]);
2795 goto done;
2796 case 4:
2797 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2798 internal_args[2],
2799 internal_args[3]);
2800 goto done;
2801 case 5:
2802 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2803 internal_args[2], internal_args[3],
2804 internal_args[4]);
2805 goto done;
2806 case 6:
2807 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2808 internal_args[2], internal_args[3],
2809 internal_args[4], internal_args[5]);
2810 goto done;
15c65264
RS
2811 case 7:
2812 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2813 internal_args[2], internal_args[3],
2814 internal_args[4], internal_args[5],
2815 internal_args[6]);
2816 goto done;
db9f0278 2817
166c822d
KH
2818 case 8:
2819 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
2820 internal_args[2], internal_args[3],
2821 internal_args[4], internal_args[5],
2822 internal_args[6], internal_args[7]);
2823 goto done;
2824
db9f0278 2825 default:
70ee42f7 2826
166c822d 2827 /* If a subr takes more than 8 arguments without using MANY
177c0ea7 2828 or UNEVALLED, we need to extend this function to support it.
70ee42f7
JB
2829 Until this is done, there is no way to call the function. */
2830 abort ();
db9f0278
JB
2831 }
2832 }
90165123 2833 if (COMPILEDP (fun))
db9f0278
JB
2834 val = funcall_lambda (fun, numargs, args + 1);
2835 else
2836 {
2837 if (!CONSP (fun))
2838 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2839 funcar = Fcar (fun);
90165123 2840 if (!SYMBOLP (funcar))
db9f0278
JB
2841 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2842 if (EQ (funcar, Qlambda))
2843 val = funcall_lambda (fun, numargs, args + 1);
db9f0278
JB
2844 else if (EQ (funcar, Qautoload))
2845 {
2846 do_autoload (fun, args[0]);
fff3ff9c 2847 CHECK_CONS_LIST ();
db9f0278
JB
2848 goto retry;
2849 }
2850 else
2851 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2852 }
2853 done:
c1788fbc 2854 CHECK_CONS_LIST ();
db9f0278
JB
2855 lisp_eval_depth--;
2856 if (backtrace.debug_on_exit)
2857 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2858 backtrace_list = backtrace.next;
2859 return val;
2860}
2861\f
2862Lisp_Object
2863apply_lambda (fun, args, eval_flag)
2864 Lisp_Object fun, args;
2865 int eval_flag;
2866{
2867 Lisp_Object args_left;
2868 Lisp_Object numargs;
2869 register Lisp_Object *arg_vector;
2870 struct gcpro gcpro1, gcpro2, gcpro3;
2871 register int i;
2872 register Lisp_Object tem;
2873
2874 numargs = Flength (args);
2875 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2876 args_left = args;
2877
2878 GCPRO3 (*arg_vector, args_left, fun);
2879 gcpro1.nvars = 0;
2880
2881 for (i = 0; i < XINT (numargs);)
2882 {
2883 tem = Fcar (args_left), args_left = Fcdr (args_left);
2884 if (eval_flag) tem = Feval (tem);
2885 arg_vector[i++] = tem;
2886 gcpro1.nvars = i;
2887 }
2888
2889 UNGCPRO;
2890
2891 if (eval_flag)
2892 {
2893 backtrace_list->args = arg_vector;
2894 backtrace_list->nargs = i;
2895 }
2896 backtrace_list->evalargs = 0;
2897 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
2898
2899 /* Do the debug-on-exit now, while arg_vector still exists. */
2900 if (backtrace_list->debug_on_exit)
2901 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
2902 /* Don't do it again when we return to eval. */
2903 backtrace_list->debug_on_exit = 0;
2904 return tem;
2905}
2906
2907/* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2908 and return the result of evaluation.
2909 FUN must be either a lambda-expression or a compiled-code object. */
2910
2901f1d1 2911static Lisp_Object
db9f0278
JB
2912funcall_lambda (fun, nargs, arg_vector)
2913 Lisp_Object fun;
2914 int nargs;
2915 register Lisp_Object *arg_vector;
2916{
9ab90667 2917 Lisp_Object val, syms_left, next;
aed13378 2918 int count = SPECPDL_INDEX ();
9ab90667 2919 int i, optional, rest;
db9f0278 2920
90165123 2921 if (CONSP (fun))
9ab90667
GM
2922 {
2923 syms_left = XCDR (fun);
2924 if (CONSP (syms_left))
2925 syms_left = XCAR (syms_left);
2926 else
2927 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2928 }
90165123 2929 else if (COMPILEDP (fun))
845975f5 2930 syms_left = AREF (fun, COMPILED_ARGLIST);
9ab90667
GM
2931 else
2932 abort ();
db9f0278 2933
9ab90667
GM
2934 i = optional = rest = 0;
2935 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
db9f0278
JB
2936 {
2937 QUIT;
177c0ea7 2938
9ab90667 2939 next = XCAR (syms_left);
90165123 2940 while (!SYMBOLP (next))
9ffa21d4 2941 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
177c0ea7 2942
db9f0278
JB
2943 if (EQ (next, Qand_rest))
2944 rest = 1;
2945 else if (EQ (next, Qand_optional))
2946 optional = 1;
2947 else if (rest)
2948 {
9ffa21d4 2949 specbind (next, Flist (nargs - i, &arg_vector[i]));
db9f0278
JB
2950 i = nargs;
2951 }
2952 else if (i < nargs)
9ab90667 2953 specbind (next, arg_vector[i++]);
db9f0278 2954 else if (!optional)
9ab90667
GM
2955 return Fsignal (Qwrong_number_of_arguments,
2956 Fcons (fun, Fcons (make_number (nargs), Qnil)));
db9f0278
JB
2957 else
2958 specbind (next, Qnil);
2959 }
2960
9ab90667
GM
2961 if (!NILP (syms_left))
2962 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
2963 else if (i < nargs)
2964 return Fsignal (Qwrong_number_of_arguments,
2965 Fcons (fun, Fcons (make_number (nargs), Qnil)));
db9f0278 2966
90165123 2967 if (CONSP (fun))
9ab90667 2968 val = Fprogn (XCDR (XCDR (fun)));
db9f0278 2969 else
ca248607
RS
2970 {
2971 /* If we have not actually read the bytecode string
2972 and constants vector yet, fetch them from the file. */
845975f5 2973 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
661c7d6e 2974 Ffetch_bytecode (fun);
845975f5
SM
2975 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
2976 AREF (fun, COMPILED_CONSTANTS),
2977 AREF (fun, COMPILED_STACK_DEPTH));
ca248607 2978 }
177c0ea7 2979
db9f0278
JB
2980 return unbind_to (count, val);
2981}
661c7d6e
KH
2982
2983DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
9dbc9081
PJ
2984 1, 1, 0,
2985 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2986 (object)
661c7d6e
KH
2987 Lisp_Object object;
2988{
2989 Lisp_Object tem;
2990
845975f5 2991 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
661c7d6e 2992 {
845975f5 2993 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
5bbdb090 2994 if (!CONSP (tem))
845975f5
SM
2995 {
2996 tem = AREF (object, COMPILED_BYTECODE);
2997 if (CONSP (tem) && STRINGP (XCAR (tem)))
d5db4077 2998 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
845975f5
SM
2999 else
3000 error ("Invalid byte code");
3001 }
3002 AREF (object, COMPILED_BYTECODE) = XCAR (tem);
3003 AREF (object, COMPILED_CONSTANTS) = XCDR (tem);
661c7d6e
KH
3004 }
3005 return object;
3006}
db9f0278
JB
3007\f
3008void
3009grow_specpdl ()
3010{
aed13378 3011 register int count = SPECPDL_INDEX ();
db9f0278
JB
3012 if (specpdl_size >= max_specpdl_size)
3013 {
3014 if (max_specpdl_size < 400)
3015 max_specpdl_size = 400;
3016 if (specpdl_size >= max_specpdl_size)
3017 {
debee8fe
RS
3018 if (!NILP (Vdebug_on_error))
3019 /* Leave room for some specpdl in the debugger. */
3020 max_specpdl_size = specpdl_size + 100;
db9f0278
JB
3021 Fsignal (Qerror,
3022 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
db9f0278
JB
3023 }
3024 }
3025 specpdl_size *= 2;
3026 if (specpdl_size > max_specpdl_size)
3027 specpdl_size = max_specpdl_size;
3028 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
3029 specpdl_ptr = specpdl + count;
3030}
3031
3032void
3033specbind (symbol, value)
3034 Lisp_Object symbol, value;
3035{
db9f0278 3036 Lisp_Object ovalue;
19cebf5a 3037 Lisp_Object valcontents;
db9f0278 3038
b7826503 3039 CHECK_SYMBOL (symbol);
db9f0278
JB
3040 if (specpdl_ptr == specpdl + specpdl_size)
3041 grow_specpdl ();
719177b3 3042
19cebf5a
GM
3043 /* The most common case is that of a non-constant symbol with a
3044 trivial value. Make that as fast as we can. */
3045 valcontents = SYMBOL_VALUE (symbol);
3046 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
719177b3 3047 {
9ab90667 3048 specpdl_ptr->symbol = symbol;
19cebf5a 3049 specpdl_ptr->old_value = valcontents;
9ab90667
GM
3050 specpdl_ptr->func = NULL;
3051 ++specpdl_ptr;
19cebf5a 3052 SET_SYMBOL_VALUE (symbol, value);
719177b3
RS
3053 }
3054 else
9ab90667 3055 {
eb700b82 3056 Lisp_Object valcontents;
177c0ea7 3057
9ab90667
GM
3058 ovalue = find_symbol_value (symbol);
3059 specpdl_ptr->func = 0;
3060 specpdl_ptr->old_value = ovalue;
719177b3 3061
eb700b82
GM
3062 valcontents = XSYMBOL (symbol)->value;
3063
3064 if (BUFFER_LOCAL_VALUEP (valcontents)
3065 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
3066 || BUFFER_OBJFWDP (valcontents))
9ab90667 3067 {
0967b4b0
GM
3068 Lisp_Object where, current_buffer;
3069
3070 current_buffer = Fcurrent_buffer ();
177c0ea7 3071
9ab90667 3072 /* For a local variable, record both the symbol and which
eb700b82
GM
3073 buffer's or frame's value we are saving. */
3074 if (!NILP (Flocal_variable_p (symbol, Qnil)))
0967b4b0 3075 where = current_buffer;
eb700b82
GM
3076 else if (!BUFFER_OBJFWDP (valcontents)
3077 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
3078 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
3079 else
3080 where = Qnil;
3081
3082 /* We're not using the `unused' slot in the specbinding
3083 structure because this would mean we have to do more
3084 work for simple variables. */
0967b4b0 3085 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, current_buffer));
06bccf8e
GM
3086
3087 /* If SYMBOL is a per-buffer variable which doesn't have a
3088 buffer-local value here, make the `let' change the global
3089 value by changing the value of SYMBOL in all buffers not
3090 having their own value. This is consistent with what
3091 happens with other buffer-local variables. */
eb700b82
GM
3092 if (NILP (where)
3093 && BUFFER_OBJFWDP (valcontents))
06bccf8e
GM
3094 {
3095 ++specpdl_ptr;
3096 Fset_default (symbol, value);
3097 return;
3098 }
9ab90667
GM
3099 }
3100 else
3101 specpdl_ptr->symbol = symbol;
3102
3103 specpdl_ptr++;
3104 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
eae0e123 3105 store_symval_forwarding (symbol, ovalue, value, NULL);
9ab90667
GM
3106 else
3107 set_internal (symbol, value, 0, 1);
3108 }
db9f0278
JB
3109}
3110
3111void
3112record_unwind_protect (function, arg)
1d159538 3113 Lisp_Object (*function) P_ ((Lisp_Object));
db9f0278
JB
3114 Lisp_Object arg;
3115{
3116 if (specpdl_ptr == specpdl + specpdl_size)
3117 grow_specpdl ();
3118 specpdl_ptr->func = function;
3119 specpdl_ptr->symbol = Qnil;
3120 specpdl_ptr->old_value = arg;
3121 specpdl_ptr++;
3122}
3123
3124Lisp_Object
3125unbind_to (count, value)
3126 int count;
3127 Lisp_Object value;
3128{
265a9e55 3129 int quitf = !NILP (Vquit_flag);
db9f0278
JB
3130 struct gcpro gcpro1;
3131
3132 GCPRO1 (value);
db9f0278
JB
3133 Vquit_flag = Qnil;
3134
3135 while (specpdl_ptr != specpdl + count)
3136 {
611a8f8c
RS
3137 /* Copy the binding, and decrement specpdl_ptr, before we do
3138 the work to unbind it. We decrement first
3139 so that an error in unbinding won't try to unbind
3140 the same entry again, and we copy the binding first
3141 in case more bindings are made during some of the code we run. */
eb700b82 3142
45f266dc
DL
3143 struct specbinding this_binding;
3144 this_binding = *--specpdl_ptr;
611a8f8c
RS
3145
3146 if (this_binding.func != 0)
3147 (*this_binding.func) (this_binding.old_value);
0967b4b0
GM
3148 /* If the symbol is a list, it is really (SYMBOL WHERE
3149 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3150 frame. If WHERE is a buffer or frame, this indicates we
1b1acc13
PJ
3151 bound a variable that had a buffer-local or frame-local
3152 binding. WHERE nil means that the variable had the default
0967b4b0
GM
3153 value when it was bound. CURRENT-BUFFER is the buffer that
3154 was current when the variable was bound. */
611a8f8c 3155 else if (CONSP (this_binding.symbol))
719177b3 3156 {
eb700b82 3157 Lisp_Object symbol, where;
719177b3 3158
611a8f8c
RS
3159 symbol = XCAR (this_binding.symbol);
3160 where = XCAR (XCDR (this_binding.symbol));
719177b3 3161
eb700b82 3162 if (NILP (where))
611a8f8c 3163 Fset_default (symbol, this_binding.old_value);
eb700b82 3164 else if (BUFFERP (where))
611a8f8c 3165 set_internal (symbol, this_binding.old_value, XBUFFER (where), 1);
177c0ea7 3166 else
611a8f8c 3167 set_internal (symbol, this_binding.old_value, NULL, 1);
719177b3 3168 }
db9f0278 3169 else
9ab90667
GM
3170 {
3171 /* If variable has a trivial value (no forwarding), we can
3172 just set it. No need to check for constant symbols here,
3173 since that was already done by specbind. */
611a8f8c
RS
3174 if (!MISCP (SYMBOL_VALUE (this_binding.symbol)))
3175 SET_SYMBOL_VALUE (this_binding.symbol, this_binding.old_value);
9ab90667 3176 else
611a8f8c 3177 set_internal (this_binding.symbol, this_binding.old_value, 0, 1);
9ab90667 3178 }
db9f0278 3179 }
177c0ea7 3180
9ab90667
GM
3181 if (NILP (Vquit_flag) && quitf)
3182 Vquit_flag = Qt;
db9f0278
JB
3183
3184 UNGCPRO;
db9f0278
JB
3185 return value;
3186}
3187\f
db9f0278 3188DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
9dbc9081
PJ
3189 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3190The debugger is entered when that frame exits, if the flag is non-nil. */)
3191 (level, flag)
db9f0278
JB
3192 Lisp_Object level, flag;
3193{
3194 register struct backtrace *backlist = backtrace_list;
3195 register int i;
3196
b7826503 3197 CHECK_NUMBER (level);
db9f0278
JB
3198
3199 for (i = 0; backlist && i < XINT (level); i++)
3200 {
3201 backlist = backlist->next;
3202 }
3203
3204 if (backlist)
265a9e55 3205 backlist->debug_on_exit = !NILP (flag);
db9f0278
JB
3206
3207 return flag;
3208}
3209
3210DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
9dbc9081
PJ
3211 doc: /* Print a trace of Lisp function calls currently active.
3212Output stream used is value of `standard-output'. */)
3213 ()
db9f0278
JB
3214{
3215 register struct backtrace *backlist = backtrace_list;
3216 register int i;
3217 Lisp_Object tail;
3218 Lisp_Object tem;
3219 extern Lisp_Object Vprint_level;
3220 struct gcpro gcpro1;
3221
a631e24c 3222 XSETFASTINT (Vprint_level, 3);
db9f0278
JB
3223
3224 tail = Qnil;
3225 GCPRO1 (tail);
3226
3227 while (backlist)
3228 {
3229 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3230 if (backlist->nargs == UNEVALLED)
3231 {
3232 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
b6703b02 3233 write_string ("\n", -1);
db9f0278
JB
3234 }
3235 else
3236 {
3237 tem = *backlist->function;
3238 Fprin1 (tem, Qnil); /* This can QUIT */
3239 write_string ("(", -1);
3240 if (backlist->nargs == MANY)
3241 {
3242 for (tail = *backlist->args, i = 0;
265a9e55 3243 !NILP (tail);
db9f0278
JB
3244 tail = Fcdr (tail), i++)
3245 {
3246 if (i) write_string (" ", -1);
3247 Fprin1 (Fcar (tail), Qnil);
3248 }
3249 }
3250 else
3251 {
3252 for (i = 0; i < backlist->nargs; i++)
3253 {
3254 if (i) write_string (" ", -1);
3255 Fprin1 (backlist->args[i], Qnil);
3256 }
3257 }
b6703b02 3258 write_string (")\n", -1);
db9f0278 3259 }
db9f0278
JB
3260 backlist = backlist->next;
3261 }
3262
3263 Vprint_level = Qnil;
3264 UNGCPRO;
3265 return Qnil;
3266}
3267
17401c97 3268DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
9dbc9081
PJ
3269 doc: /* Return the function and arguments NFRAMES up from current execution point.
3270If that frame has not evaluated the arguments yet (or is a special form),
3271the value is (nil FUNCTION ARG-FORMS...).
3272If that frame has evaluated its arguments and called its function already,
3273the value is (t FUNCTION ARG-VALUES...).
3274A &rest arg is represented as the tail of the list ARG-VALUES.
3275FUNCTION is whatever was supplied as car of evaluated list,
3276or a lambda expression for macro calls.
3277If NFRAMES is more than the number of frames, the value is nil. */)
3278 (nframes)
db9f0278
JB
3279 Lisp_Object nframes;
3280{
3281 register struct backtrace *backlist = backtrace_list;
3282 register int i;
3283 Lisp_Object tem;
3284
b7826503 3285 CHECK_NATNUM (nframes);
db9f0278
JB
3286
3287 /* Find the frame requested. */
b6703b02 3288 for (i = 0; backlist && i < XFASTINT (nframes); i++)
db9f0278
JB
3289 backlist = backlist->next;
3290
3291 if (!backlist)
3292 return Qnil;
3293 if (backlist->nargs == UNEVALLED)
3294 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3295 else
3296 {
3297 if (backlist->nargs == MANY)
3298 tem = *backlist->args;
3299 else
3300 tem = Flist (backlist->nargs, backlist->args);
3301
3302 return Fcons (Qt, Fcons (*backlist->function, tem));
3303 }
3304}
a2ff3819 3305
db9f0278 3306\f
4ce0541e
SM
3307void
3308mark_backtrace ()
3309{
3310 register struct backtrace *backlist;
3311 register int i;
3312
3313 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3314 {
3315 mark_object (*backlist->function);
3316
3317 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
3318 i = 0;
3319 else
3320 i = backlist->nargs - 1;
3321 for (; i >= 0; i--)
3322 mark_object (backlist->args[i]);
3323 }
3324}
3325
dfcf069d 3326void
db9f0278
JB
3327syms_of_eval ()
3328{
3329 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
9dbc9081
PJ
3330 doc: /* *Limit on number of Lisp variable bindings & unwind-protects.
3331If Lisp code tries to make more than this many at once,
2520dc0c
RS
3332an error is signaled.
3333You can safely use a value considerably larger than the default value,
3334if that proves inconveniently small. However, if you increase it too far,
3335Emacs could run out of memory trying to make the stack bigger. */);
db9f0278
JB
3336
3337 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
9dbc9081 3338 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
2520dc0c
RS
3339
3340This limit serves to catch infinite recursions for you before they cause
9dbc9081
PJ
3341actual stack overflow in C, which would be fatal for Emacs.
3342You can safely make it considerably larger than its default value,
2520dc0c
RS
3343if that proves inconveniently small. However, if you increase it too far,
3344Emacs could overflow the real C stack, and crash. */);
db9f0278
JB
3345
3346 DEFVAR_LISP ("quit-flag", &Vquit_flag,
9dbc9081 3347 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
42ed718e
RS
3348If the value is t, that means do an ordinary quit.
3349If the value equals `throw-on-input', that means quit by throwing
3350to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3351Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3352but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
db9f0278
JB
3353 Vquit_flag = Qnil;
3354
3355 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
9dbc9081
PJ
3356 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3357Note that `quit-flag' will still be set by typing C-g,
3358so a quit will be signaled as soon as `inhibit-quit' is nil.
3359To prevent this happening, set `quit-flag' to nil
3360before making `inhibit-quit' nil. */);
db9f0278
JB
3361 Vinhibit_quit = Qnil;
3362
ad236261
JB
3363 Qinhibit_quit = intern ("inhibit-quit");
3364 staticpro (&Qinhibit_quit);
3365
db9f0278
JB
3366 Qautoload = intern ("autoload");
3367 staticpro (&Qautoload);
3368
3369 Qdebug_on_error = intern ("debug-on-error");
3370 staticpro (&Qdebug_on_error);
3371
3372 Qmacro = intern ("macro");
3373 staticpro (&Qmacro);
3374
d6edd563
GM
3375 Qdeclare = intern ("declare");
3376 staticpro (&Qdeclare);
177c0ea7 3377
db9f0278
JB
3378 /* Note that the process handling also uses Qexit, but we don't want
3379 to staticpro it twice, so we just do it here. */
3380 Qexit = intern ("exit");
3381 staticpro (&Qexit);
3382
3383 Qinteractive = intern ("interactive");
3384 staticpro (&Qinteractive);
3385
3386 Qcommandp = intern ("commandp");
3387 staticpro (&Qcommandp);
3388
3389 Qdefun = intern ("defun");
3390 staticpro (&Qdefun);
3391
3392 Qand_rest = intern ("&rest");
3393 staticpro (&Qand_rest);
3394
3395 Qand_optional = intern ("&optional");
3396 staticpro (&Qand_optional);
3397
128c0f66 3398 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
704788b3
RS
3399 doc: /* *Non-nil means errors display a backtrace buffer.
3400More precisely, this happens for any error that is handled
3401by the editor command loop.
9dbc9081
PJ
3402If the value is a list, an error only means to display a backtrace
3403if one of its condition symbols appears in the list. */);
128c0f66 3404 Vstack_trace_on_error = Qnil;
db9f0278 3405
128c0f66 3406 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
9dbc9081
PJ
3407 doc: /* *Non-nil means enter debugger if an error is signaled.
3408Does not apply to errors handled by `condition-case' or those
3409matched by `debug-ignored-errors'.
3410If the value is a list, an error only means to enter the debugger
3411if one of its condition symbols appears in the list.
3412When you evaluate an expression interactively, this variable
3413is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3414See also variable `debug-on-quit'. */);
128c0f66 3415 Vdebug_on_error = Qnil;
db9f0278 3416
fc950e09 3417 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
9dbc9081
PJ
3418 doc: /* *List of errors for which the debugger should not be called.
3419Each element may be a condition-name or a regexp that matches error messages.
3420If any element applies to a given error, that error skips the debugger
3421and just returns to top level.
3422This overrides the variable `debug-on-error'.
3423It does not apply to errors handled by `condition-case'. */);
fc950e09
KH
3424 Vdebug_ignored_errors = Qnil;
3425
db9f0278 3426 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
9dbc9081
PJ
3427 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3428Does not apply if quit is handled by a `condition-case'.
3429When you evaluate an expression interactively, this variable
3430is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
db9f0278
JB
3431 debug_on_quit = 0;
3432
3433 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
9dbc9081 3434 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
db9f0278 3435
556d7314 3436 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
9dbc9081
PJ
3437 doc: /* Non-nil means debugger may continue execution.
3438This is nil when the debugger is called under circumstances where it
3439might not be safe to continue. */);
dac204bc 3440 debugger_may_continue = 1;
556d7314 3441
db9f0278 3442 DEFVAR_LISP ("debugger", &Vdebugger,
9dbc9081
PJ
3443 doc: /* Function to call to invoke debugger.
3444If due to frame exit, args are `exit' and the value being returned;
3445 this function's value will be returned instead of that.
3446If due to error, args are `error' and a list of the args to `signal'.
3447If due to `apply' or `funcall' entry, one arg, `lambda'.
3448If due to `eval' entry, one arg, t. */);
db9f0278
JB
3449 Vdebugger = Qnil;
3450
61ede770 3451 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
9dbc9081
PJ
3452 doc: /* If non-nil, this is a function for `signal' to call.
3453It receives the same arguments that `signal' was given.
3454The Edebug package uses this to regain control. */);
61ede770
RS
3455 Vsignal_hook_function = Qnil;
3456
57a6e758 3457 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
9dbc9081
PJ
3458 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3459Note that `debug-on-error', `debug-on-quit' and friends
3460still determine whether to handle the particular condition. */);
57a6e758 3461 Vdebug_on_signal = Qnil;
61ede770 3462
d6edd563
GM
3463 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function,
3464 doc: /* Function to process declarations in a macro definition.
3465The function will be called with two args MACRO and DECL.
3466MACRO is the name of the macro being defined.
3467DECL is a list `(declare ...)' containing the declarations.
3468The value the function returns is not used. */);
3469 Vmacro_declaration_function = Qnil;
3470
6e6e9f08
RS
3471 Vrun_hooks = intern ("run-hooks");
3472 staticpro (&Vrun_hooks);
db9f0278
JB
3473
3474 staticpro (&Vautoload_queue);
3475 Vautoload_queue = Qnil;
a2ff3819
GM
3476 staticpro (&Vsignaling_function);
3477 Vsignaling_function = Qnil;
db9f0278
JB
3478
3479 defsubr (&Sor);
3480 defsubr (&Sand);
3481 defsubr (&Sif);
3482 defsubr (&Scond);
3483 defsubr (&Sprogn);
3484 defsubr (&Sprog1);
3485 defsubr (&Sprog2);
3486 defsubr (&Ssetq);
3487 defsubr (&Squote);
3488 defsubr (&Sfunction);
3489 defsubr (&Sdefun);
3490 defsubr (&Sdefmacro);
3491 defsubr (&Sdefvar);
19cebf5a 3492 defsubr (&Sdefvaralias);
db9f0278
JB
3493 defsubr (&Sdefconst);
3494 defsubr (&Suser_variable_p);
3495 defsubr (&Slet);
3496 defsubr (&SletX);
3497 defsubr (&Swhile);
3498 defsubr (&Smacroexpand);
3499 defsubr (&Scatch);
3500 defsubr (&Sthrow);
3501 defsubr (&Sunwind_protect);
3502 defsubr (&Scondition_case);
3503 defsubr (&Ssignal);
3504 defsubr (&Sinteractive_p);
4b664e76 3505 defsubr (&Scalled_interactively_p);
db9f0278
JB
3506 defsubr (&Scommandp);
3507 defsubr (&Sautoload);
3508 defsubr (&Seval);
3509 defsubr (&Sapply);
3510 defsubr (&Sfuncall);
ff936e53
SM
3511 defsubr (&Srun_hooks);
3512 defsubr (&Srun_hook_with_args);
3513 defsubr (&Srun_hook_with_args_until_success);
3514 defsubr (&Srun_hook_with_args_until_failure);
661c7d6e 3515 defsubr (&Sfetch_bytecode);
db9f0278
JB
3516 defsubr (&Sbacktrace_debug);
3517 defsubr (&Sbacktrace);
3518 defsubr (&Sbacktrace_frame);
3519}
ab5796a9
MB
3520
3521/* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3522 (do not change this comment) */