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