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