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