Initial code for buffer locking.
[emacs.git] / src / eval.c
blobe0ab399caa3b711151011949ab247e7d95e60345
1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 #include <config.h>
23 #include <setjmp.h>
24 #include "lisp.h"
25 #include "blockinput.h"
26 #include "commands.h"
27 #include "keyboard.h"
28 #include "dispextern.h"
30 #if HAVE_X_WINDOWS
31 #include "xterm.h"
32 #endif
34 /* This definition is duplicated in alloc.c and keyboard.c */
35 /* Putting it in lisp.h makes cc bomb out! */
37 struct backtrace
39 struct backtrace *next;
40 Lisp_Object *function;
41 Lisp_Object *args; /* Points to vector of args. */
42 int nargs; /* Length of vector.
43 If nargs is UNEVALLED, args points to slot holding
44 list of unevalled args */
45 char evalargs;
46 /* Nonzero means call value of debugger when done with this operation. */
47 char debug_on_exit;
50 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
51 Lisp_Object Qinhibit_quit, impl_Vinhibit_quit, impl_Vquit_flag;
52 Lisp_Object Qand_rest, Qand_optional;
53 Lisp_Object Qdebug_on_error;
54 Lisp_Object Qdeclare;
55 Lisp_Object Qdebug;
56 extern Lisp_Object Qinteractive_form;
58 /* This holds either the symbol `run-hooks' or nil.
59 It is nil at an early stage of startup, and when Emacs
60 is shutting down. */
62 Lisp_Object Vrun_hooks;
64 /* Non-nil means record all fset's and provide's, to be undone
65 if the file being autoloaded is not fully loaded.
66 They are recorded by being consed onto the front of Vautoload_queue:
67 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
69 Lisp_Object Vautoload_queue;
71 /* Maximum size allowed for specpdl allocation */
73 EMACS_INT max_specpdl_size;
75 /* Maximum allowed depth in Lisp evaluations and function calls. */
77 EMACS_INT max_lisp_eval_depth;
79 /* Nonzero means enter debugger before next function call */
81 int debug_on_next_call;
83 /* Non-zero means debugger may continue. This is zero when the
84 debugger is called during redisplay, where it might not be safe to
85 continue the interrupted redisplay. */
87 int debugger_may_continue;
89 /* List of conditions (non-nil atom means all) which cause a backtrace
90 if an error is handled by the command loop's error handler. */
92 Lisp_Object impl_Vstack_trace_on_error;
94 /* List of conditions (non-nil atom means all) which enter the debugger
95 if an error is handled by the command loop's error handler. */
97 Lisp_Object impl_Vdebug_on_error;
99 /* List of conditions and regexps specifying error messages which
100 do not enter the debugger even if Vdebug_on_error says they should. */
102 Lisp_Object impl_Vdebug_ignored_errors;
104 /* Non-nil means call the debugger even if the error will be handled. */
106 Lisp_Object impl_Vdebug_on_signal;
108 /* Hook for edebug to use. */
110 Lisp_Object impl_Vsignal_hook_function;
112 /* Nonzero means enter debugger if a quit signal
113 is handled by the command loop's error handler. */
115 int debug_on_quit;
117 /* The value of num_nonmacro_input_events as of the last time we
118 started to enter the debugger. If we decide to enter the debugger
119 again when this is still equal to num_nonmacro_input_events, then we
120 know that the debugger itself has an error, and we should just
121 signal the error instead of entering an infinite loop of debugger
122 invocations. */
124 int when_entered_debugger;
126 Lisp_Object impl_Vdebugger;
128 /* The function from which the last `signal' was called. Set in
129 Fsignal. */
131 Lisp_Object Vsignaling_function;
133 /* Set to non-zero while processing X events. Checked in Feval to
134 make sure the Lisp interpreter isn't called from a signal handler,
135 which is unsafe because the interpreter isn't reentrant. */
137 int handling_signal;
139 /* Function to process declarations in defmacro forms. */
141 Lisp_Object impl_Vmacro_declaration_function;
143 extern Lisp_Object Qrisky_local_variable;
145 extern Lisp_Object Qfunction;
147 static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
148 static void unwind_to_catch P_ ((struct catchtag *, Lisp_Object)) NO_RETURN;
150 #if __GNUC__
151 /* "gcc -O3" enables automatic function inlining, which optimizes out
152 the arguments for the invocations of these functions, whereas they
153 expect these values on the stack. */
154 Lisp_Object apply1 () __attribute__((noinline));
155 Lisp_Object call2 () __attribute__((noinline));
156 #endif
158 void
159 init_eval_once ()
161 specpdl_size = 50;
162 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
163 specpdl_ptr = specpdl;
164 /* Don't forget to update docs (lispref node "Local Variables"). */
165 max_specpdl_size = 1000;
166 max_lisp_eval_depth = 500;
168 Vrun_hooks = Qnil;
171 void
172 init_eval ()
174 specpdl_ptr = specpdl;
175 catchlist = 0;
176 handlerlist = 0;
177 backtrace_list = 0;
178 Vquit_flag = Qnil;
179 debug_on_next_call = 0;
180 lisp_eval_depth = 0;
181 #ifdef DEBUG_GCPRO
182 gcpro_level = 0;
183 #endif
184 /* This is less than the initial value of num_nonmacro_input_events. */
185 when_entered_debugger = -1;
188 void
189 mark_catchlist (struct catchtag *catch)
191 for (; catch; catch = catch->next)
193 mark_object (catch->tag);
194 mark_object (catch->val);
198 /* unwind-protect function used by call_debugger. */
200 static Lisp_Object
201 restore_stack_limits (data)
202 Lisp_Object data;
204 max_specpdl_size = XINT (XCAR (data));
205 max_lisp_eval_depth = XINT (XCDR (data));
206 return Qnil;
209 /* Call the Lisp debugger, giving it argument ARG. */
211 Lisp_Object
212 call_debugger (arg)
213 Lisp_Object arg;
215 int debug_while_redisplaying;
216 int count = SPECPDL_INDEX ();
217 Lisp_Object val;
218 int old_max = max_specpdl_size;
220 /* Temporarily bump up the stack limits,
221 so the debugger won't run out of stack. */
223 max_specpdl_size += 1;
224 record_unwind_protect (restore_stack_limits,
225 Fcons (make_number (old_max),
226 make_number (max_lisp_eval_depth)));
227 max_specpdl_size = old_max;
229 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
230 max_lisp_eval_depth = lisp_eval_depth + 40;
232 if (SPECPDL_INDEX () + 100 > max_specpdl_size)
233 max_specpdl_size = SPECPDL_INDEX () + 100;
235 #ifdef HAVE_WINDOW_SYSTEM
236 if (display_hourglass_p)
237 cancel_hourglass ();
238 #endif
240 debug_on_next_call = 0;
241 when_entered_debugger = num_nonmacro_input_events;
243 /* Resetting redisplaying_p to 0 makes sure that debug output is
244 displayed if the debugger is invoked during redisplay. */
245 debug_while_redisplaying = redisplaying_p;
246 redisplaying_p = 0;
247 specbind (intern ("debugger-may-continue"),
248 debug_while_redisplaying ? Qnil : Qt);
249 specbind (Qinhibit_redisplay, Qnil);
250 specbind (Qdebug_on_error, Qnil);
252 #if 0 /* Binding this prevents execution of Lisp code during
253 redisplay, which necessarily leads to display problems. */
254 specbind (Qinhibit_eval_during_redisplay, Qt);
255 #endif
257 val = apply1 (Vdebugger, arg);
259 /* Interrupting redisplay and resuming it later is not safe under
260 all circumstances. So, when the debugger returns, abort the
261 interrupted redisplay by going back to the top-level. */
262 if (debug_while_redisplaying)
263 Ftop_level ();
265 return unbind_to (count, val);
268 void
269 do_debug_on_call (code)
270 Lisp_Object code;
272 debug_on_next_call = 0;
273 backtrace_list->debug_on_exit = 1;
274 call_debugger (Fcons (code, Qnil));
277 /* NOTE!!! Every function that can call EVAL must protect its args
278 and temporaries from garbage collection while it needs them.
279 The definition of `For' shows what you have to do. */
281 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
282 doc: /* Eval args until one of them yields non-nil, then return that value.
283 The remaining args are not evalled at all.
284 If all args return nil, return nil.
285 usage: (or CONDITIONS...) */)
286 (args)
287 Lisp_Object args;
289 register Lisp_Object val = Qnil;
290 struct gcpro gcpro1;
292 GCPRO1 (args);
294 while (CONSP (args))
296 val = Feval (XCAR (args));
297 if (!NILP (val))
298 break;
299 args = XCDR (args);
302 UNGCPRO;
303 return val;
306 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
307 doc: /* Eval args until one of them yields nil, then return nil.
308 The remaining args are not evalled at all.
309 If no arg yields nil, return the last arg's value.
310 usage: (and CONDITIONS...) */)
311 (args)
312 Lisp_Object args;
314 register Lisp_Object val = Qt;
315 struct gcpro gcpro1;
317 GCPRO1 (args);
319 while (CONSP (args))
321 val = Feval (XCAR (args));
322 if (NILP (val))
323 break;
324 args = XCDR (args);
327 UNGCPRO;
328 return val;
331 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
332 doc: /* If COND yields non-nil, do THEN, else do ELSE...
333 Returns the value of THEN or the value of the last of the ELSE's.
334 THEN must be one expression, but ELSE... can be zero or more expressions.
335 If COND yields nil, and there are no ELSE's, the value is nil.
336 usage: (if COND THEN ELSE...) */)
337 (args)
338 Lisp_Object args;
340 register Lisp_Object cond;
341 struct gcpro gcpro1;
343 GCPRO1 (args);
344 cond = Feval (Fcar (args));
345 UNGCPRO;
347 if (!NILP (cond))
348 return Feval (Fcar (Fcdr (args)));
349 return Fprogn (Fcdr (Fcdr (args)));
352 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
353 doc: /* Try each clause until one succeeds.
354 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
355 and, if the value is non-nil, this clause succeeds:
356 then the expressions in BODY are evaluated and the last one's
357 value is the value of the cond-form.
358 If no clause succeeds, cond returns nil.
359 If a clause has one element, as in (CONDITION),
360 CONDITION's value if non-nil is returned from the cond-form.
361 usage: (cond CLAUSES...) */)
362 (args)
363 Lisp_Object args;
365 register Lisp_Object clause, val;
366 struct gcpro gcpro1;
368 val = Qnil;
369 GCPRO1 (args);
370 while (!NILP (args))
372 clause = Fcar (args);
373 val = Feval (Fcar (clause));
374 if (!NILP (val))
376 if (!EQ (XCDR (clause), Qnil))
377 val = Fprogn (XCDR (clause));
378 break;
380 args = XCDR (args);
382 UNGCPRO;
384 return val;
387 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
388 doc: /* Eval BODY forms sequentially and return value of last one.
389 usage: (progn BODY...) */)
390 (args)
391 Lisp_Object args;
393 register Lisp_Object val = Qnil;
394 struct gcpro gcpro1;
396 GCPRO1 (args);
398 while (CONSP (args))
400 val = Feval (XCAR (args));
401 args = XCDR (args);
404 UNGCPRO;
405 return val;
408 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
409 doc: /* Eval FIRST and BODY sequentially; return value from FIRST.
410 The value of FIRST is saved during the evaluation of the remaining args,
411 whose values are discarded.
412 usage: (prog1 FIRST BODY...) */)
413 (args)
414 Lisp_Object args;
416 Lisp_Object val;
417 register Lisp_Object args_left;
418 struct gcpro gcpro1, gcpro2;
419 register int argnum = 0;
421 if (NILP (args))
422 return Qnil;
424 args_left = args;
425 val = Qnil;
426 GCPRO2 (args, val);
430 if (!(argnum++))
431 val = Feval (Fcar (args_left));
432 else
433 Feval (Fcar (args_left));
434 args_left = Fcdr (args_left);
436 while (!NILP(args_left));
438 UNGCPRO;
439 return val;
442 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
443 doc: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
444 The value of FORM2 is saved during the evaluation of the
445 remaining args, whose values are discarded.
446 usage: (prog2 FORM1 FORM2 BODY...) */)
447 (args)
448 Lisp_Object args;
450 Lisp_Object val;
451 register Lisp_Object args_left;
452 struct gcpro gcpro1, gcpro2;
453 register int argnum = -1;
455 val = Qnil;
457 if (NILP (args))
458 return Qnil;
460 args_left = args;
461 val = Qnil;
462 GCPRO2 (args, val);
466 if (!(argnum++))
467 val = Feval (Fcar (args_left));
468 else
469 Feval (Fcar (args_left));
470 args_left = Fcdr (args_left);
472 while (!NILP (args_left));
474 UNGCPRO;
475 return val;
478 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
479 doc: /* Set each SYM to the value of its VAL.
480 The symbols SYM are variables; they are literal (not evaluated).
481 The values VAL are expressions; they are evaluated.
482 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
483 The second VAL is not computed until after the first SYM is set, and so on;
484 each VAL can use the new value of variables set earlier in the `setq'.
485 The return value of the `setq' form is the value of the last VAL.
486 usage: (setq [SYM VAL]...) */)
487 (args)
488 Lisp_Object args;
490 register Lisp_Object args_left;
491 register Lisp_Object val, sym;
492 struct gcpro gcpro1;
494 if (NILP (args))
495 return Qnil;
497 args_left = args;
498 GCPRO1 (args);
502 val = Feval (Fcar (Fcdr (args_left)));
503 sym = Fcar (args_left);
504 Fset (sym, val);
505 args_left = Fcdr (Fcdr (args_left));
507 while (!NILP(args_left));
509 UNGCPRO;
510 return val;
513 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
514 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
515 usage: (quote ARG) */)
516 (args)
517 Lisp_Object args;
519 if (!NILP (Fcdr (args)))
520 xsignal2 (Qwrong_number_of_arguments, Qquote, Flength (args));
521 return Fcar (args);
524 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
525 doc: /* Like `quote', but preferred for objects which are functions.
526 In byte compilation, `function' causes its argument to be compiled.
527 `quote' cannot do that.
528 usage: (function ARG) */)
529 (args)
530 Lisp_Object args;
532 if (!NILP (Fcdr (args)))
533 xsignal2 (Qwrong_number_of_arguments, Qfunction, Flength (args));
534 return Fcar (args);
538 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
539 doc: /* Return t if the containing function was run directly by user input.
540 This means that the function was called with `call-interactively'
541 \(which includes being called as the binding of a key)
542 and input is currently coming from the keyboard (not a keyboard macro),
543 and Emacs is not running in batch mode (`noninteractive' is nil).
545 The only known proper use of `interactive-p' is in deciding whether to
546 display a helpful message, or how to display it. If you're thinking
547 of using it for any other purpose, it is quite likely that you're
548 making a mistake. Think: what do you want to do when the command is
549 called from a keyboard macro?
551 To test whether your function was called with `call-interactively',
552 either (i) add an extra optional argument and give it an `interactive'
553 spec that specifies non-nil unconditionally (such as \"p\"); or (ii)
554 use `called-interactively-p'. */)
557 return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
561 DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 1, 0,
562 doc: /* Return t if the containing function was called by `call-interactively'.
563 If KIND is `interactive', then only return t if the call was made
564 interactively by the user, i.e. not in `noninteractive' mode nor
565 when `executing-kbd-macro'.
566 If KIND is `any', on the other hand, it will return t for any kind of
567 interactive call, including being called as the binding of a key, or
568 from a keyboard macro, or in `noninteractive' mode.
570 The only known proper use of `interactive' for KIND is in deciding
571 whether to display a helpful message, or how to display it. If you're
572 thinking of using it for any other purpose, it is quite likely that
573 you're making a mistake. Think: what do you want to do when the
574 command is called from a keyboard macro?
576 This function is meant for implementing advice and other
577 function-modifying features. Instead of using this, it is sometimes
578 cleaner to give your function an extra optional argument whose
579 `interactive' spec specifies non-nil unconditionally (\"p\" is a good
580 way to do this), or via (not (or executing-kbd-macro noninteractive)). */)
581 (kind)
582 Lisp_Object kind;
584 return ((INTERACTIVE || !EQ (kind, intern ("interactive")))
585 && interactive_p (1)) ? Qt : Qnil;
589 /* Return 1 if function in which this appears was called using
590 call-interactively.
592 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
593 called is a built-in. */
596 interactive_p (exclude_subrs_p)
597 int exclude_subrs_p;
599 struct backtrace *btp;
600 Lisp_Object fun;
602 btp = backtrace_list;
604 /* If this isn't a byte-compiled function, there may be a frame at
605 the top for Finteractive_p. If so, skip it. */
606 fun = Findirect_function (*btp->function, Qnil);
607 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
608 || XSUBR (fun) == &Scalled_interactively_p))
609 btp = btp->next;
611 /* If we're running an Emacs 18-style byte-compiled function, there
612 may be a frame for Fbytecode at the top level. In any version of
613 Emacs there can be Fbytecode frames for subexpressions evaluated
614 inside catch and condition-case. Skip past them.
616 If this isn't a byte-compiled function, then we may now be
617 looking at several frames for special forms. Skip past them. */
618 while (btp
619 && (EQ (*btp->function, Qbytecode)
620 || btp->nargs == UNEVALLED))
621 btp = btp->next;
623 /* btp now points at the frame of the innermost function that isn't
624 a special form, ignoring frames for Finteractive_p and/or
625 Fbytecode at the top. If this frame is for a built-in function
626 (such as load or eval-region) return nil. */
627 fun = Findirect_function (*btp->function, Qnil);
628 if (exclude_subrs_p && SUBRP (fun))
629 return 0;
631 /* btp points to the frame of a Lisp function that called interactive-p.
632 Return t if that function was called interactively. */
633 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
634 return 1;
635 return 0;
639 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
640 doc: /* Define NAME as a function.
641 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
642 See also the function `interactive'.
643 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
644 (args)
645 Lisp_Object args;
647 register Lisp_Object fn_name;
648 register Lisp_Object defn;
650 fn_name = Fcar (args);
651 CHECK_SYMBOL (fn_name);
652 defn = Fcons (Qlambda, Fcdr (args));
653 if (!NILP (Vpurify_flag))
654 defn = Fpurecopy (defn);
655 if (CONSP (XSYMBOL (fn_name)->function)
656 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
657 LOADHIST_ATTACH (Fcons (Qt, fn_name));
658 Ffset (fn_name, defn);
659 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
660 return fn_name;
663 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
664 doc: /* Define NAME as a macro.
665 The actual definition looks like
666 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
667 When the macro is called, as in (NAME ARGS...),
668 the function (lambda ARGLIST BODY...) is applied to
669 the list ARGS... as it appears in the expression,
670 and the result should be a form to be evaluated instead of the original.
672 DECL is a declaration, optional, which can specify how to indent
673 calls to this macro, how Edebug should handle it, and which argument
674 should be treated as documentation. It looks like this:
675 (declare SPECS...)
676 The elements can look like this:
677 (indent INDENT)
678 Set NAME's `lisp-indent-function' property to INDENT.
680 (debug DEBUG)
681 Set NAME's `edebug-form-spec' property to DEBUG. (This is
682 equivalent to writing a `def-edebug-spec' for the macro.)
684 (doc-string ELT)
685 Set NAME's `doc-string-elt' property to ELT.
687 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
688 (args)
689 Lisp_Object args;
691 register Lisp_Object fn_name;
692 register Lisp_Object defn;
693 Lisp_Object lambda_list, doc, tail;
695 fn_name = Fcar (args);
696 CHECK_SYMBOL (fn_name);
697 lambda_list = Fcar (Fcdr (args));
698 tail = Fcdr (Fcdr (args));
700 doc = Qnil;
701 if (STRINGP (Fcar (tail)))
703 doc = XCAR (tail);
704 tail = XCDR (tail);
707 while (CONSP (Fcar (tail))
708 && EQ (Fcar (Fcar (tail)), Qdeclare))
710 if (!NILP (Vmacro_declaration_function))
712 struct gcpro gcpro1;
713 GCPRO1 (args);
714 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
715 UNGCPRO;
718 tail = Fcdr (tail);
721 if (NILP (doc))
722 tail = Fcons (lambda_list, tail);
723 else
724 tail = Fcons (lambda_list, Fcons (doc, tail));
725 defn = Fcons (Qmacro, Fcons (Qlambda, tail));
727 if (!NILP (Vpurify_flag))
728 defn = Fpurecopy (defn);
729 if (CONSP (XSYMBOL (fn_name)->function)
730 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
731 LOADHIST_ATTACH (Fcons (Qt, fn_name));
732 Ffset (fn_name, defn);
733 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
734 return fn_name;
738 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
739 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
740 Aliased variables always have the same value; setting one sets the other.
741 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
742 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
743 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
744 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
745 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
746 The return value is BASE-VARIABLE. */)
747 (new_alias, base_variable, docstring)
748 Lisp_Object new_alias, base_variable, docstring;
750 struct Lisp_Symbol *sym;
752 CHECK_SYMBOL (new_alias);
753 CHECK_SYMBOL (base_variable);
755 if (SYMBOL_CONSTANT_P (new_alias))
756 error ("Cannot make a constant an alias");
758 sym = XSYMBOL (new_alias);
759 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
760 If n_a is bound, but b_v is not, set the value of b_v to n_a.
761 This is for the sake of define-obsolete-variable-alias and user
762 customizations. */
763 if (NILP (Fboundp (base_variable)) && !NILP (Fboundp (new_alias)))
764 XSYMBOL(base_variable)->value = sym->value;
765 sym->indirect_variable = 1;
766 sym->value = base_variable;
767 sym->constant = SYMBOL_CONSTANT_P (base_variable);
768 LOADHIST_ATTACH (new_alias);
769 if (!NILP (docstring))
770 Fput (new_alias, Qvariable_documentation, docstring);
771 else
772 Fput (new_alias, Qvariable_documentation, Qnil);
774 return base_variable;
778 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
779 doc: /* Define SYMBOL as a variable, and return SYMBOL.
780 You are not required to define a variable in order to use it,
781 but the definition can supply documentation and an initial value
782 in a way that tags can recognize.
784 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
785 If SYMBOL is buffer-local, its default value is what is set;
786 buffer-local values are not affected.
787 INITVALUE and DOCSTRING are optional.
788 If DOCSTRING starts with *, this variable is identified as a user option.
789 This means that M-x set-variable recognizes it.
790 See also `user-variable-p'.
791 If INITVALUE is missing, SYMBOL's value is not set.
793 If SYMBOL has a local binding, then this form affects the local
794 binding. This is usually not what you want. Thus, if you need to
795 load a file defining variables, with this form or with `defconst' or
796 `defcustom', you should always load that file _outside_ any bindings
797 for these variables. \(`defconst' and `defcustom' behave similarly in
798 this respect.)
799 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
800 (args)
801 Lisp_Object args;
803 register Lisp_Object sym, tem, tail;
805 sym = Fcar (args);
806 tail = Fcdr (args);
807 if (!NILP (Fcdr (Fcdr (tail))))
808 error ("Too many arguments");
810 tem = Fdefault_boundp (sym);
811 if (!NILP (tail))
813 if (SYMBOL_CONSTANT_P (sym))
815 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
816 Lisp_Object tem = Fcar (tail);
817 if (! (CONSP (tem)
818 && EQ (XCAR (tem), Qquote)
819 && CONSP (XCDR (tem))
820 && EQ (XCAR (XCDR (tem)), sym)))
821 error ("Constant symbol `%s' specified in defvar",
822 SDATA (SYMBOL_NAME (sym)));
825 if (NILP (tem))
826 Fset_default (sym, Feval (Fcar (tail)));
827 else
828 { /* Check if there is really a global binding rather than just a let
829 binding that shadows the global unboundness of the var. */
830 volatile struct specbinding *pdl = specpdl_ptr;
831 while (--pdl >= specpdl)
833 if (EQ (pdl->symbol, sym) && !pdl->func
834 && EQ (pdl->old_value, Qunbound))
836 message_with_string ("Warning: defvar ignored because %s is let-bound",
837 SYMBOL_NAME (sym), 1);
838 break;
842 tail = Fcdr (tail);
843 tem = Fcar (tail);
844 if (!NILP (tem))
846 if (!NILP (Vpurify_flag))
847 tem = Fpurecopy (tem);
848 Fput (sym, Qvariable_documentation, tem);
850 LOADHIST_ATTACH (sym);
852 else
853 /* Simple (defvar <var>) should not count as a definition at all.
854 It could get in the way of other definitions, and unloading this
855 package could try to make the variable unbound. */
858 return sym;
861 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
862 doc: /* Define SYMBOL as a constant variable.
863 The intent is that neither programs nor users should ever change this value.
864 Always sets the value of SYMBOL to the result of evalling INITVALUE.
865 If SYMBOL is buffer-local, its default value is what is set;
866 buffer-local values are not affected.
867 DOCSTRING is optional.
869 If SYMBOL has a local binding, then this form sets the local binding's
870 value. However, you should normally not make local bindings for
871 variables defined with this form.
872 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
873 (args)
874 Lisp_Object args;
876 register Lisp_Object sym, tem;
878 sym = Fcar (args);
879 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
880 error ("Too many arguments");
882 tem = Feval (Fcar (Fcdr (args)));
883 if (!NILP (Vpurify_flag))
884 tem = Fpurecopy (tem);
885 Fset_default (sym, tem);
886 tem = Fcar (Fcdr (Fcdr (args)));
887 if (!NILP (tem))
889 if (!NILP (Vpurify_flag))
890 tem = Fpurecopy (tem);
891 Fput (sym, Qvariable_documentation, tem);
893 Fput (sym, Qrisky_local_variable, Qt);
894 LOADHIST_ATTACH (sym);
895 return sym;
898 /* Error handler used in Fuser_variable_p. */
899 static Lisp_Object
900 user_variable_p_eh (ignore)
901 Lisp_Object ignore;
903 return Qnil;
906 static Lisp_Object
907 lisp_indirect_variable (Lisp_Object sym)
909 XSETSYMBOL (sym, indirect_variable (XSYMBOL (sym)));
910 return sym;
913 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
914 doc: /* Return t if VARIABLE is intended to be set and modified by users.
915 \(The alternative is a variable used internally in a Lisp program.)
916 A variable is a user variable if
917 \(1) the first character of its documentation is `*', or
918 \(2) it is customizable (its property list contains a non-nil value
919 of `standard-value' or `custom-autoload'), or
920 \(3) it is an alias for another user variable.
921 Return nil if VARIABLE is an alias and there is a loop in the
922 chain of symbols. */)
923 (variable)
924 Lisp_Object variable;
926 Lisp_Object documentation;
928 if (!SYMBOLP (variable))
929 return Qnil;
931 /* If indirect and there's an alias loop, don't check anything else. */
932 if (XSYMBOL (variable)->indirect_variable
933 && NILP (internal_condition_case_1 (lisp_indirect_variable, variable,
934 Qt, user_variable_p_eh)))
935 return Qnil;
937 while (1)
939 documentation = Fget (variable, Qvariable_documentation);
940 if (INTEGERP (documentation) && XINT (documentation) < 0)
941 return Qt;
942 if (STRINGP (documentation)
943 && ((unsigned char) SREF (documentation, 0) == '*'))
944 return Qt;
945 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
946 if (CONSP (documentation)
947 && STRINGP (XCAR (documentation))
948 && INTEGERP (XCDR (documentation))
949 && XINT (XCDR (documentation)) < 0)
950 return Qt;
951 /* Customizable? See `custom-variable-p'. */
952 if ((!NILP (Fget (variable, intern ("standard-value"))))
953 || (!NILP (Fget (variable, intern ("custom-autoload")))))
954 return Qt;
956 if (!XSYMBOL (variable)->indirect_variable)
957 return Qnil;
959 /* An indirect variable? Let's follow the chain. */
960 variable = XSYMBOL (variable)->value;
964 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
965 doc: /* Bind variables according to VARLIST then eval BODY.
966 The value of the last form in BODY is returned.
967 Each element of VARLIST is a symbol (which is bound to nil)
968 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
969 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
970 usage: (let* VARLIST BODY...) */)
971 (args)
972 Lisp_Object args;
974 Lisp_Object varlist, val, elt;
975 int count = SPECPDL_INDEX ();
976 struct gcpro gcpro1, gcpro2, gcpro3;
978 GCPRO3 (args, elt, varlist);
980 varlist = Fcar (args);
981 while (!NILP (varlist))
983 QUIT;
984 elt = Fcar (varlist);
985 if (SYMBOLP (elt))
986 specbind (elt, Qnil);
987 else if (! NILP (Fcdr (Fcdr (elt))))
988 signal_error ("`let' bindings can have only one value-form", elt);
989 else
991 val = Feval (Fcar (Fcdr (elt)));
992 specbind (Fcar (elt), val);
994 varlist = Fcdr (varlist);
996 UNGCPRO;
997 val = Fprogn (Fcdr (args));
998 return unbind_to (count, val);
1001 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
1002 doc: /* Bind variables according to VARLIST then eval BODY.
1003 The value of the last form in BODY is returned.
1004 Each element of VARLIST is a symbol (which is bound to nil)
1005 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1006 All the VALUEFORMs are evalled before any symbols are bound.
1007 usage: (let VARLIST BODY...) */)
1008 (args)
1009 Lisp_Object args;
1011 Lisp_Object *temps, tem;
1012 register Lisp_Object elt, varlist;
1013 int count = SPECPDL_INDEX ();
1014 register int argnum;
1015 struct gcpro gcpro1, gcpro2;
1017 varlist = Fcar (args);
1019 /* Make space to hold the values to give the bound variables */
1020 elt = Flength (varlist);
1021 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
1023 /* Compute the values and store them in `temps' */
1025 GCPRO2 (args, *temps);
1026 gcpro2.nvars = 0;
1028 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
1030 QUIT;
1031 elt = XCAR (varlist);
1032 if (SYMBOLP (elt))
1033 temps [argnum++] = Qnil;
1034 else if (! NILP (Fcdr (Fcdr (elt))))
1035 signal_error ("`let' bindings can have only one value-form", elt);
1036 else
1037 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
1038 gcpro2.nvars = argnum;
1040 UNGCPRO;
1042 varlist = Fcar (args);
1043 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
1045 elt = XCAR (varlist);
1046 tem = temps[argnum++];
1047 if (SYMBOLP (elt))
1048 specbind (elt, tem);
1049 else
1050 specbind (Fcar (elt), tem);
1053 elt = Fprogn (Fcdr (args));
1054 return unbind_to (count, elt);
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;
1065 Lisp_Object test, body;
1066 struct gcpro gcpro1, gcpro2;
1068 GCPRO2 (test, body);
1070 test = Fcar (args);
1071 body = Fcdr (args);
1072 while (!NILP (Feval (test)))
1074 QUIT;
1075 Fprogn (body);
1078 UNGCPRO;
1079 return Qnil;
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.
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;
1094 /* With cleanups from Hallvard Furuseth. */
1095 register Lisp_Object expander, sym, def, tem;
1097 while (1)
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))
1110 QUIT;
1111 sym = def;
1112 tem = Fassq (sym, environment);
1113 if (NILP (tem))
1115 def = XSYMBOL (sym)->function;
1116 if (!EQ (def, Qunbound))
1117 continue;
1119 break;
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))
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))
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. */
1137 struct gcpro gcpro1;
1138 GCPRO1 (form);
1139 do_autoload (def, sym);
1140 UNGCPRO;
1141 continue;
1143 else
1144 break;
1146 else if (!EQ (XCAR (def), Qmacro))
1147 break;
1148 else expander = XCDR (def);
1150 else
1152 expander = XCDR (tem);
1153 if (NILP (expander))
1154 break;
1156 form = apply1 (expander, XCDR (form));
1158 return form;
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.
1165 Then the BODY is executed.
1166 Within BODY, a call to `throw' with the same TAG exits BODY and 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;
1173 register Lisp_Object tag;
1174 struct gcpro gcpro1;
1176 GCPRO1 (args);
1177 tag = Feval (Fcar (args));
1178 UNGCPRO;
1179 return internal_catch (tag, Fprogn, Fcdr (args));
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. */
1186 Lisp_Object
1187 internal_catch (tag, func, arg)
1188 Lisp_Object tag;
1189 Lisp_Object (*func) ();
1190 Lisp_Object arg;
1192 /* This structure is made part of the chain `catchlist'. */
1193 struct catchtag c;
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.m_handlerlist = handlerlist;
1201 c.m_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;
1209 /* Call FUNC. */
1210 if (! _setjmp (c.jmp))
1211 c.val = (*func) (arg);
1213 /* Throw works by a longjmp that comes right here. */
1214 catchlist = c.next;
1215 return c.val;
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.
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.
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
1232 This is used for correct unwinding in Fthrow and Fsignal. */
1234 static void
1235 unwind_to_catch (catch, value)
1236 struct catchtag *catch;
1237 Lisp_Object value;
1239 register int last_time;
1241 /* Save the value in the tag. */
1242 catch->val = value;
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;
1252 last_time = catchlist == catch;
1254 /* Unwind the specpdl stack, and then restore the proper set of
1255 handlers. */
1256 unbind_to (catchlist->pdlcount, Qnil);
1257 handlerlist = catchlist->m_handlerlist;
1258 catchlist = catchlist->next;
1260 while (! last_time);
1262 #if HAVE_X_WINDOWS
1263 /* If x_catch_errors was done, turn it off now.
1264 (First we give unbind_to a chance to do that.) */
1265 #if 0 /* This would disable x_catch_errors after x_connection_closed.
1266 * The catch must remain in effect during that delicate
1267 * state. --lorentey */
1268 x_fully_uncatch_errors ();
1269 #endif
1270 #endif
1272 byte_stack_list = catch->byte_stack;
1273 gcprolist = catch->gcpro;
1274 #ifdef DEBUG_GCPRO
1275 if (gcprolist != 0)
1276 gcpro_level = gcprolist->level + 1;
1277 else
1278 gcpro_level = 0;
1279 #endif
1280 backtrace_list = catch->backlist;
1281 lisp_eval_depth = catch->m_lisp_eval_depth;
1283 _longjmp (catch->jmp, 1);
1286 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
1287 doc: /* Throw to the catch for TAG and return VALUE from it.
1288 Both TAG and VALUE are evalled. */)
1289 (tag, value)
1290 register Lisp_Object tag, value;
1292 register struct catchtag *c;
1294 if (!NILP (tag))
1295 for (c = catchlist; c; c = c->next)
1297 if (EQ (c->tag, tag))
1298 unwind_to_catch (c, value);
1300 xsignal2 (Qno_catch, tag, value);
1304 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
1305 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1306 If BODYFORM completes normally, its value is returned
1307 after executing the UNWINDFORMS.
1308 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1309 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1310 (args)
1311 Lisp_Object args;
1313 Lisp_Object val;
1314 int count = SPECPDL_INDEX ();
1316 record_unwind_protect (Fprogn, Fcdr (args));
1317 val = Feval (Fcar (args));
1318 return unbind_to (count, val);
1321 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
1322 doc: /* Regain control when an error is signaled.
1323 Executes BODYFORM and returns its value if no error happens.
1324 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1325 where the BODY is made of Lisp expressions.
1327 A handler is applicable to an error
1328 if CONDITION-NAME is one of the error's condition names.
1329 If an error happens, the first applicable handler is run.
1331 The car of a handler may be a list of condition names
1332 instead of a single condition name. Then it handles all of them.
1334 When a handler handles an error, control returns to the `condition-case'
1335 and it executes the handler's BODY...
1336 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1337 (If VAR is nil, the handler can't access that information.)
1338 Then the value of the last BODY form is returned from the `condition-case'
1339 expression.
1341 See also the function `signal' for more info.
1342 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1343 (args)
1344 Lisp_Object args;
1346 register Lisp_Object bodyform, handlers;
1347 volatile Lisp_Object var;
1349 var = Fcar (args);
1350 bodyform = Fcar (Fcdr (args));
1351 handlers = Fcdr (Fcdr (args));
1353 return internal_lisp_condition_case (var, bodyform, handlers);
1356 /* Like Fcondition_case, but the args are separate
1357 rather than passed in a list. Used by Fbyte_code. */
1359 Lisp_Object
1360 internal_lisp_condition_case (var, bodyform, handlers)
1361 volatile Lisp_Object var;
1362 Lisp_Object bodyform, handlers;
1364 Lisp_Object val;
1365 struct catchtag c;
1366 struct handler h;
1368 CHECK_SYMBOL (var);
1370 for (val = handlers; CONSP (val); val = XCDR (val))
1372 Lisp_Object tem;
1373 tem = XCAR (val);
1374 if (! (NILP (tem)
1375 || (CONSP (tem)
1376 && (SYMBOLP (XCAR (tem))
1377 || CONSP (XCAR (tem))))))
1378 error ("Invalid condition handler", tem);
1381 c.tag = Qnil;
1382 c.val = Qnil;
1383 c.backlist = backtrace_list;
1384 c.m_handlerlist = handlerlist;
1385 c.m_lisp_eval_depth = lisp_eval_depth;
1386 c.pdlcount = SPECPDL_INDEX ();
1387 c.poll_suppress_count = poll_suppress_count;
1388 c.interrupt_input_blocked = interrupt_input_blocked;
1389 c.gcpro = gcprolist;
1390 c.byte_stack = byte_stack_list;
1391 if (_setjmp (c.jmp))
1393 if (!NILP (h.var))
1394 specbind (h.var, c.val);
1395 val = Fprogn (Fcdr (h.chosen_clause));
1397 /* Note that this just undoes the binding of h.var; whoever
1398 longjumped to us unwound the stack to c.pdlcount before
1399 throwing. */
1400 unbind_to (c.pdlcount, Qnil);
1401 return val;
1403 c.next = catchlist;
1404 catchlist = &c;
1406 h.var = var;
1407 h.handler = handlers;
1408 h.next = handlerlist;
1409 h.tag = &c;
1410 handlerlist = &h;
1412 val = Feval (bodyform);
1413 catchlist = c.next;
1414 handlerlist = h.next;
1415 return val;
1418 /* Call the function BFUN with no arguments, catching errors within it
1419 according to HANDLERS. If there is an error, call HFUN with
1420 one argument which is the data that describes the error:
1421 (SIGNALNAME . DATA)
1423 HANDLERS can be a list of conditions to catch.
1424 If HANDLERS is Qt, catch all errors.
1425 If HANDLERS is Qerror, catch all errors
1426 but allow the debugger to run if that is enabled. */
1428 Lisp_Object
1429 internal_condition_case (bfun, handlers, hfun)
1430 Lisp_Object (*bfun) ();
1431 Lisp_Object handlers;
1432 Lisp_Object (*hfun) ();
1434 Lisp_Object val;
1435 struct catchtag c;
1436 struct handler h;
1438 /* Since Fsignal will close off all calls to x_catch_errors,
1439 we will get the wrong results if some are not closed now. */
1440 #if HAVE_X_WINDOWS
1441 if (x_catching_errors ())
1442 abort ();
1443 #endif
1445 c.tag = Qnil;
1446 c.val = Qnil;
1447 c.backlist = backtrace_list;
1448 c.m_handlerlist = handlerlist;
1449 c.m_lisp_eval_depth = lisp_eval_depth;
1450 c.pdlcount = SPECPDL_INDEX ();
1451 c.poll_suppress_count = poll_suppress_count;
1452 c.interrupt_input_blocked = interrupt_input_blocked;
1453 c.gcpro = gcprolist;
1454 c.byte_stack = byte_stack_list;
1455 if (_setjmp (c.jmp))
1457 return (*hfun) (c.val);
1459 c.next = catchlist;
1460 catchlist = &c;
1461 h.handler = handlers;
1462 h.var = Qnil;
1463 h.next = handlerlist;
1464 h.tag = &c;
1465 handlerlist = &h;
1467 val = (*bfun) ();
1468 catchlist = c.next;
1469 handlerlist = h.next;
1470 return val;
1473 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1475 Lisp_Object
1476 internal_condition_case_1 (bfun, arg, handlers, hfun)
1477 Lisp_Object (*bfun) ();
1478 Lisp_Object arg;
1479 Lisp_Object handlers;
1480 Lisp_Object (*hfun) ();
1482 Lisp_Object val;
1483 struct catchtag c;
1484 struct handler h;
1486 /* Since Fsignal will close off all calls to x_catch_errors,
1487 we will get the wrong results if some are not closed now. */
1488 #if HAVE_X_WINDOWS
1489 if (x_catching_errors ())
1490 abort ();
1491 #endif
1493 c.tag = Qnil;
1494 c.val = Qnil;
1495 c.backlist = backtrace_list;
1496 c.m_handlerlist = handlerlist;
1497 c.m_lisp_eval_depth = lisp_eval_depth;
1498 c.pdlcount = SPECPDL_INDEX ();
1499 c.poll_suppress_count = poll_suppress_count;
1500 c.interrupt_input_blocked = interrupt_input_blocked;
1501 c.gcpro = gcprolist;
1502 c.byte_stack = byte_stack_list;
1503 if (_setjmp (c.jmp))
1505 return (*hfun) (c.val);
1507 c.next = catchlist;
1508 catchlist = &c;
1509 h.handler = handlers;
1510 h.var = Qnil;
1511 h.next = handlerlist;
1512 h.tag = &c;
1513 handlerlist = &h;
1515 val = (*bfun) (arg);
1516 catchlist = c.next;
1517 handlerlist = h.next;
1518 return val;
1522 /* Like internal_condition_case but call BFUN with NARGS as first,
1523 and ARGS as second argument. */
1525 Lisp_Object
1526 internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
1527 Lisp_Object (*bfun) ();
1528 int nargs;
1529 Lisp_Object *args;
1530 Lisp_Object handlers;
1531 Lisp_Object (*hfun) ();
1533 Lisp_Object val;
1534 struct catchtag c;
1535 struct handler h;
1537 /* Since Fsignal will close off all calls to x_catch_errors,
1538 we will get the wrong results if some are not closed now. */
1539 #if HAVE_X_WINDOWS
1540 if (x_catching_errors ())
1541 abort ();
1542 #endif
1544 c.tag = Qnil;
1545 c.val = Qnil;
1546 c.backlist = backtrace_list;
1547 c.m_handlerlist = handlerlist;
1548 c.m_lisp_eval_depth = lisp_eval_depth;
1549 c.pdlcount = SPECPDL_INDEX ();
1550 c.poll_suppress_count = poll_suppress_count;
1551 c.interrupt_input_blocked = interrupt_input_blocked;
1552 c.gcpro = gcprolist;
1553 c.byte_stack = byte_stack_list;
1554 if (_setjmp (c.jmp))
1556 return (*hfun) (c.val);
1558 c.next = catchlist;
1559 catchlist = &c;
1560 h.handler = handlers;
1561 h.var = Qnil;
1562 h.next = handlerlist;
1563 h.tag = &c;
1564 handlerlist = &h;
1566 val = (*bfun) (nargs, args);
1567 catchlist = c.next;
1568 handlerlist = h.next;
1569 return val;
1573 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
1574 Lisp_Object, Lisp_Object));
1576 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
1577 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1578 This function does not return.
1580 An error symbol is a symbol with an `error-conditions' property
1581 that is a list of condition names.
1582 A handler for any of those names will get to handle this signal.
1583 The symbol `error' should normally be one of them.
1585 DATA should be a list. Its elements are printed as part of the error message.
1586 See Info anchor `(elisp)Definition of signal' for some details on how this
1587 error message is constructed.
1588 If the signal is handled, DATA is made available to the handler.
1589 See also the function `condition-case'. */)
1590 (error_symbol, data)
1591 Lisp_Object error_symbol, data;
1593 /* When memory is full, ERROR-SYMBOL is nil,
1594 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1595 That is a special case--don't do this in other situations. */
1596 register struct handler *allhandlers = handlerlist;
1597 Lisp_Object conditions;
1598 extern int gc_in_progress;
1599 extern int waiting_for_input;
1600 Lisp_Object string;
1601 Lisp_Object real_error_symbol;
1602 struct backtrace *bp;
1604 immediate_quit = handling_signal = 0;
1605 abort_on_gc = 0;
1606 if (gc_in_progress || waiting_for_input)
1607 abort ();
1609 if (NILP (error_symbol))
1610 real_error_symbol = Fcar (data);
1611 else
1612 real_error_symbol = error_symbol;
1614 #if 0 /* rms: I don't know why this was here,
1615 but it is surely wrong for an error that is handled. */
1616 #ifdef HAVE_WINDOW_SYSTEM
1617 if (display_hourglass_p)
1618 cancel_hourglass ();
1619 #endif
1620 #endif
1622 /* This hook is used by edebug. */
1623 if (! NILP (Vsignal_hook_function)
1624 && ! NILP (error_symbol))
1626 /* Edebug takes care of restoring these variables when it exits. */
1627 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1628 max_lisp_eval_depth = lisp_eval_depth + 20;
1630 if (SPECPDL_INDEX () + 40 > max_specpdl_size)
1631 max_specpdl_size = SPECPDL_INDEX () + 40;
1633 call2 (Vsignal_hook_function, error_symbol, data);
1636 conditions = Fget (real_error_symbol, Qerror_conditions);
1638 /* Remember from where signal was called. Skip over the frame for
1639 `signal' itself. If a frame for `error' follows, skip that,
1640 too. Don't do this when ERROR_SYMBOL is nil, because that
1641 is a memory-full error. */
1642 Vsignaling_function = Qnil;
1643 if (backtrace_list && !NILP (error_symbol))
1645 bp = backtrace_list->next;
1646 if (bp && bp->function && EQ (*bp->function, Qerror))
1647 bp = bp->next;
1648 if (bp && bp->function)
1649 Vsignaling_function = *bp->function;
1652 for (; handlerlist; handlerlist = handlerlist->next)
1654 register Lisp_Object clause;
1656 clause = find_handler_clause (handlerlist->handler, conditions,
1657 error_symbol, data);
1659 if (EQ (clause, Qlambda))
1661 /* We can't return values to code which signaled an error, but we
1662 can continue code which has signaled a quit. */
1663 if (EQ (real_error_symbol, Qquit))
1664 return Qnil;
1665 else
1666 error ("Cannot return from the debugger in an error");
1669 if (!NILP (clause))
1671 Lisp_Object unwind_data;
1672 struct handler *h = handlerlist;
1674 handlerlist = allhandlers;
1676 if (NILP (error_symbol))
1677 unwind_data = data;
1678 else
1679 unwind_data = Fcons (error_symbol, data);
1680 h->chosen_clause = clause;
1681 unwind_to_catch (h->tag, unwind_data);
1685 handlerlist = allhandlers;
1686 /* If no handler is present now, try to run the debugger,
1687 and if that fails, throw to top level. */
1688 find_handler_clause (Qerror, conditions, error_symbol, data);
1689 if (catchlist != 0)
1690 Fthrow (Qtop_level, Qt);
1692 if (! NILP (error_symbol))
1693 data = Fcons (error_symbol, data);
1695 string = Ferror_message_string (data);
1696 fatal ("%s", SDATA (string), 0);
1699 /* Internal version of Fsignal that never returns.
1700 Used for anything but Qquit (which can return from Fsignal). */
1702 void
1703 xsignal (error_symbol, data)
1704 Lisp_Object error_symbol, data;
1706 Fsignal (error_symbol, data);
1707 abort ();
1710 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1712 void
1713 xsignal0 (error_symbol)
1714 Lisp_Object error_symbol;
1716 xsignal (error_symbol, Qnil);
1719 void
1720 xsignal1 (error_symbol, arg)
1721 Lisp_Object error_symbol, arg;
1723 xsignal (error_symbol, list1 (arg));
1726 void
1727 xsignal2 (error_symbol, arg1, arg2)
1728 Lisp_Object error_symbol, arg1, arg2;
1730 xsignal (error_symbol, list2 (arg1, arg2));
1733 void
1734 xsignal3 (error_symbol, arg1, arg2, arg3)
1735 Lisp_Object error_symbol, arg1, arg2, arg3;
1737 xsignal (error_symbol, list3 (arg1, arg2, arg3));
1740 /* Signal `error' with message S, and additional arg ARG.
1741 If ARG is not a genuine list, make it a one-element list. */
1743 void
1744 signal_error (s, arg)
1745 char *s;
1746 Lisp_Object arg;
1748 Lisp_Object tortoise, hare;
1750 hare = tortoise = arg;
1751 while (CONSP (hare))
1753 hare = XCDR (hare);
1754 if (!CONSP (hare))
1755 break;
1757 hare = XCDR (hare);
1758 tortoise = XCDR (tortoise);
1760 if (EQ (hare, tortoise))
1761 break;
1764 if (!NILP (hare))
1765 arg = Fcons (arg, Qnil); /* Make it a list. */
1767 xsignal (Qerror, Fcons (build_string (s), arg));
1771 /* Return nonzero if LIST is a non-nil atom or
1772 a list containing one of CONDITIONS. */
1774 static int
1775 wants_debugger (list, conditions)
1776 Lisp_Object list, conditions;
1778 if (NILP (list))
1779 return 0;
1780 if (! CONSP (list))
1781 return 1;
1783 while (CONSP (conditions))
1785 Lisp_Object this, tail;
1786 this = XCAR (conditions);
1787 for (tail = list; CONSP (tail); tail = XCDR (tail))
1788 if (EQ (XCAR (tail), this))
1789 return 1;
1790 conditions = XCDR (conditions);
1792 return 0;
1795 /* Return 1 if an error with condition-symbols CONDITIONS,
1796 and described by SIGNAL-DATA, should skip the debugger
1797 according to debugger-ignored-errors. */
1799 static int
1800 skip_debugger (conditions, data)
1801 Lisp_Object conditions, data;
1803 Lisp_Object tail;
1804 int first_string = 1;
1805 Lisp_Object error_message;
1807 error_message = Qnil;
1808 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
1810 if (STRINGP (XCAR (tail)))
1812 if (first_string)
1814 error_message = Ferror_message_string (data);
1815 first_string = 0;
1818 if (fast_string_match (XCAR (tail), error_message) >= 0)
1819 return 1;
1821 else
1823 Lisp_Object contail;
1825 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
1826 if (EQ (XCAR (tail), XCAR (contail)))
1827 return 1;
1831 return 0;
1834 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1835 SIG and DATA describe the signal, as in find_handler_clause. */
1837 static int
1838 maybe_call_debugger (conditions, sig, data)
1839 Lisp_Object conditions, sig, data;
1841 Lisp_Object combined_data;
1843 combined_data = Fcons (sig, data);
1845 if (
1846 /* Don't try to run the debugger with interrupts blocked.
1847 The editing loop would return anyway. */
1848 ! INPUT_BLOCKED_P
1849 /* Does user want to enter debugger for this kind of error? */
1850 && (EQ (sig, Qquit)
1851 ? debug_on_quit
1852 : wants_debugger (Vdebug_on_error, conditions))
1853 && ! skip_debugger (conditions, combined_data)
1854 /* rms: what's this for? */
1855 && when_entered_debugger < num_nonmacro_input_events)
1857 call_debugger (Fcons (Qerror, Fcons (combined_data, Qnil)));
1858 return 1;
1861 return 0;
1864 /* Value of Qlambda means we have called debugger and user has continued.
1865 There are two ways to pass SIG and DATA:
1866 = SIG is the error symbol, and DATA is the rest of the data.
1867 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1868 This is for memory-full errors only.
1870 We need to increase max_specpdl_size temporarily around
1871 anything we do that can push on the specpdl, so as not to get
1872 a second error here in case we're handling specpdl overflow. */
1874 static Lisp_Object
1875 find_handler_clause (handlers, conditions, sig, data)
1876 Lisp_Object handlers, conditions, sig, data;
1878 register Lisp_Object h;
1879 register Lisp_Object tem;
1880 int debugger_called = 0;
1881 int debugger_considered = 0;
1883 /* t is used by handlers for all conditions, set up by C code. */
1884 if (EQ (handlers, Qt))
1885 return Qt;
1887 /* Don't run the debugger for a memory-full error.
1888 (There is no room in memory to do that!) */
1889 if (NILP (sig))
1890 debugger_considered = 1;
1892 /* error is used similarly, but means print an error message
1893 and run the debugger if that is enabled. */
1894 if (EQ (handlers, Qerror)
1895 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
1896 there is a handler. */
1898 if (!NILP (sig) && wants_debugger (Vstack_trace_on_error, conditions))
1900 max_lisp_eval_depth += 15;
1901 max_specpdl_size++;
1902 if (noninteractive)
1903 Fbacktrace ();
1904 else
1905 internal_with_output_to_temp_buffer
1906 ("*Backtrace*",
1907 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
1908 Qnil);
1909 max_specpdl_size--;
1910 max_lisp_eval_depth -= 15;
1913 if (!debugger_considered)
1915 debugger_considered = 1;
1916 debugger_called = maybe_call_debugger (conditions, sig, data);
1919 /* If there is no handler, return saying whether we ran the debugger. */
1920 if (EQ (handlers, Qerror))
1922 if (debugger_called)
1923 return Qlambda;
1924 return Qt;
1928 for (h = handlers; CONSP (h); h = Fcdr (h))
1930 Lisp_Object handler, condit;
1932 handler = Fcar (h);
1933 if (!CONSP (handler))
1934 continue;
1935 condit = Fcar (handler);
1936 /* Handle a single condition name in handler HANDLER. */
1937 if (SYMBOLP (condit))
1939 tem = Fmemq (Fcar (handler), conditions);
1940 if (!NILP (tem))
1941 return handler;
1943 /* Handle a list of condition names in handler HANDLER. */
1944 else if (CONSP (condit))
1946 Lisp_Object tail;
1947 for (tail = condit; CONSP (tail); tail = XCDR (tail))
1949 tem = Fmemq (Fcar (tail), conditions);
1950 if (!NILP (tem))
1952 /* This handler is going to apply.
1953 Does it allow the debugger to run first? */
1954 if (! debugger_considered && !NILP (Fmemq (Qdebug, condit)))
1955 maybe_call_debugger (conditions, sig, data);
1956 return handler;
1962 return Qnil;
1965 /* dump an error message; called like printf */
1967 /* VARARGS 1 */
1968 void
1969 error (m, a1, a2, a3)
1970 char *m;
1971 char *a1, *a2, *a3;
1973 char buf[200];
1974 int size = 200;
1975 int mlen;
1976 char *buffer = buf;
1977 char *args[3];
1978 int allocated = 0;
1979 Lisp_Object string;
1981 args[0] = a1;
1982 args[1] = a2;
1983 args[2] = a3;
1985 mlen = strlen (m);
1987 while (1)
1989 int used = doprnt (buffer, size, m, m + mlen, 3, args);
1990 if (used < size)
1991 break;
1992 size *= 2;
1993 if (allocated)
1994 buffer = (char *) xrealloc (buffer, size);
1995 else
1997 buffer = (char *) xmalloc (size);
1998 allocated = 1;
2002 string = build_string (buffer);
2003 if (allocated)
2004 xfree (buffer);
2006 xsignal1 (Qerror, string);
2009 DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
2010 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
2011 This means it contains a description for how to read arguments to give it.
2012 The value is nil for an invalid function or a symbol with no function
2013 definition.
2015 Interactively callable functions include strings and vectors (treated
2016 as keyboard macros), lambda-expressions that contain a top-level call
2017 to `interactive', autoload definitions made by `autoload' with non-nil
2018 fourth argument, and some of the built-in functions of Lisp.
2020 Also, a symbol satisfies `commandp' if its function definition does so.
2022 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
2023 then strings and vectors are not accepted. */)
2024 (function, for_call_interactively)
2025 Lisp_Object function, for_call_interactively;
2027 register Lisp_Object fun;
2028 register Lisp_Object funcar;
2029 Lisp_Object if_prop = Qnil;
2031 fun = function;
2033 fun = indirect_function (fun); /* Check cycles. */
2034 if (NILP (fun) || EQ (fun, Qunbound))
2035 return Qnil;
2037 /* Check an `interactive-form' property if present, analogous to the
2038 function-documentation property. */
2039 fun = function;
2040 while (SYMBOLP (fun))
2042 Lisp_Object tmp = Fget (fun, Qinteractive_form);
2043 if (!NILP (tmp))
2044 if_prop = Qt;
2045 fun = Fsymbol_function (fun);
2048 /* Emacs primitives are interactive if their DEFUN specifies an
2049 interactive spec. */
2050 if (SUBRP (fun))
2051 return XSUBR (fun)->intspec ? Qt : if_prop;
2053 /* Bytecode objects are interactive if they are long enough to
2054 have an element whose index is COMPILED_INTERACTIVE, which is
2055 where the interactive spec is stored. */
2056 else if (COMPILEDP (fun))
2057 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
2058 ? Qt : if_prop);
2060 /* Strings and vectors are keyboard macros. */
2061 if (STRINGP (fun) || VECTORP (fun))
2062 return (NILP (for_call_interactively) ? Qt : Qnil);
2064 /* Lists may represent commands. */
2065 if (!CONSP (fun))
2066 return Qnil;
2067 funcar = XCAR (fun);
2068 if (EQ (funcar, Qlambda))
2069 return !NILP (Fassq (Qinteractive, Fcdr (XCDR (fun)))) ? Qt : if_prop;
2070 if (EQ (funcar, Qautoload))
2071 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun))))) ? Qt : if_prop;
2072 else
2073 return Qnil;
2076 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
2077 doc: /* Define FUNCTION to autoload from FILE.
2078 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2079 Third arg DOCSTRING is documentation for the function.
2080 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2081 Fifth arg TYPE indicates the type of the object:
2082 nil or omitted says FUNCTION is a function,
2083 `keymap' says FUNCTION is really a keymap, and
2084 `macro' or t says FUNCTION is really a macro.
2085 Third through fifth args give info about the real definition.
2086 They default to nil.
2087 If FUNCTION is already defined other than as an autoload,
2088 this does nothing and returns nil. */)
2089 (function, file, docstring, interactive, type)
2090 Lisp_Object function, file, docstring, interactive, type;
2092 Lisp_Object args[4];
2094 CHECK_SYMBOL (function);
2095 CHECK_STRING (file);
2097 /* If function is defined and not as an autoload, don't override */
2098 if (!EQ (XSYMBOL (function)->function, Qunbound)
2099 && !(CONSP (XSYMBOL (function)->function)
2100 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
2101 return Qnil;
2103 if (NILP (Vpurify_flag))
2104 /* Only add entries after dumping, because the ones before are
2105 not useful and else we get loads of them from the loaddefs.el. */
2106 LOADHIST_ATTACH (Fcons (Qautoload, function));
2107 else
2108 /* We don't want the docstring in purespace (instead,
2109 Snarf-documentation should (hopefully) overwrite it). */
2110 docstring = make_number (0);
2111 return Ffset (function,
2112 Fpurecopy (list5 (Qautoload, file, docstring,
2113 interactive, type)));
2116 Lisp_Object
2117 un_autoload (oldqueue)
2118 Lisp_Object oldqueue;
2120 register Lisp_Object queue, first, second;
2122 /* Queue to unwind is current value of Vautoload_queue.
2123 oldqueue is the shadowed value to leave in Vautoload_queue. */
2124 queue = Vautoload_queue;
2125 Vautoload_queue = oldqueue;
2126 while (CONSP (queue))
2128 first = XCAR (queue);
2129 second = Fcdr (first);
2130 first = Fcar (first);
2131 if (EQ (first, make_number (0)))
2132 Vfeatures = second;
2133 else
2134 Ffset (first, second);
2135 queue = XCDR (queue);
2137 return Qnil;
2140 /* Load an autoloaded function.
2141 FUNNAME is the symbol which is the function's name.
2142 FUNDEF is the autoload definition (a list). */
2144 void
2145 do_autoload (fundef, funname)
2146 Lisp_Object fundef, funname;
2148 int count = SPECPDL_INDEX ();
2149 Lisp_Object fun;
2150 struct gcpro gcpro1, gcpro2, gcpro3;
2152 /* This is to make sure that loadup.el gives a clear picture
2153 of what files are preloaded and when. */
2154 if (! NILP (Vpurify_flag))
2155 error ("Attempt to autoload %s while preparing to dump",
2156 SDATA (SYMBOL_NAME (funname)));
2158 fun = funname;
2159 CHECK_SYMBOL (funname);
2160 GCPRO3 (fun, funname, fundef);
2162 /* Preserve the match data. */
2163 record_unwind_save_match_data ();
2165 /* If autoloading gets an error (which includes the error of failing
2166 to define the function being called), we use Vautoload_queue
2167 to undo function definitions and `provide' calls made by
2168 the function. We do this in the specific case of autoloading
2169 because autoloading is not an explicit request "load this file",
2170 but rather a request to "call this function".
2172 The value saved here is to be restored into Vautoload_queue. */
2173 record_unwind_protect (un_autoload, Vautoload_queue);
2174 Vautoload_queue = Qt;
2175 Fload (Fcar (Fcdr (fundef)), Qnil, Qt, Qnil, Qt);
2177 /* Once loading finishes, don't undo it. */
2178 Vautoload_queue = Qt;
2179 unbind_to (count, Qnil);
2181 fun = Findirect_function (fun, Qnil);
2183 if (!NILP (Fequal (fun, fundef)))
2184 error ("Autoloading failed to define function %s",
2185 SDATA (SYMBOL_NAME (funname)));
2186 UNGCPRO;
2190 DEFUN ("eval", Feval, Seval, 1, 1, 0,
2191 doc: /* Evaluate FORM and return its value. */)
2192 (form)
2193 Lisp_Object form;
2195 Lisp_Object fun, val, original_fun, original_args;
2196 Lisp_Object funcar;
2197 struct backtrace backtrace;
2198 struct gcpro gcpro1, gcpro2, gcpro3;
2200 if (handling_signal)
2201 abort ();
2203 if (SYMBOLP (form))
2204 return Fsymbol_value (form);
2205 if (!CONSP (form))
2206 return form;
2208 QUIT;
2209 if ((consing_since_gc > gc_cons_threshold
2210 && consing_since_gc > gc_relative_threshold)
2212 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2214 GCPRO1 (form);
2215 Fgarbage_collect ();
2216 UNGCPRO;
2219 if (++lisp_eval_depth > max_lisp_eval_depth)
2221 if (max_lisp_eval_depth < 100)
2222 max_lisp_eval_depth = 100;
2223 if (lisp_eval_depth > max_lisp_eval_depth)
2224 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2227 original_fun = Fcar (form);
2228 original_args = Fcdr (form);
2230 backtrace.next = backtrace_list;
2231 backtrace_list = &backtrace;
2232 backtrace.function = &original_fun; /* This also protects them from gc */
2233 backtrace.args = &original_args;
2234 backtrace.nargs = UNEVALLED;
2235 backtrace.evalargs = 1;
2236 backtrace.debug_on_exit = 0;
2238 if (debug_on_next_call)
2239 do_debug_on_call (Qt);
2241 /* At this point, only original_fun and original_args
2242 have values that will be used below */
2243 retry:
2245 /* Optimize for no indirection. */
2246 fun = original_fun;
2247 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2248 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2249 fun = indirect_function (fun);
2251 if (SUBRP (fun))
2253 Lisp_Object numargs;
2254 Lisp_Object argvals[8];
2255 Lisp_Object args_left;
2256 register int i, maxargs;
2258 args_left = original_args;
2259 numargs = Flength (args_left);
2261 CHECK_CONS_LIST ();
2263 if (XINT (numargs) < XSUBR (fun)->min_args ||
2264 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
2265 xsignal2 (Qwrong_number_of_arguments, original_fun, numargs);
2267 if (XSUBR (fun)->max_args == UNEVALLED)
2269 backtrace.evalargs = 0;
2270 val = (*XSUBR (fun)->function) (args_left);
2271 goto done;
2274 if (XSUBR (fun)->max_args == MANY)
2276 /* Pass a vector of evaluated arguments */
2277 Lisp_Object *vals;
2278 register int argnum = 0;
2280 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
2282 GCPRO3 (args_left, fun, fun);
2283 gcpro3.var = vals;
2284 gcpro3.nvars = 0;
2286 while (!NILP (args_left))
2288 vals[argnum++] = Feval (Fcar (args_left));
2289 args_left = Fcdr (args_left);
2290 gcpro3.nvars = argnum;
2293 backtrace.args = vals;
2294 backtrace.nargs = XINT (numargs);
2296 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
2297 UNGCPRO;
2298 goto done;
2301 GCPRO3 (args_left, fun, fun);
2302 gcpro3.var = argvals;
2303 gcpro3.nvars = 0;
2305 maxargs = XSUBR (fun)->max_args;
2306 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2308 argvals[i] = Feval (Fcar (args_left));
2309 gcpro3.nvars = ++i;
2312 UNGCPRO;
2314 backtrace.args = argvals;
2315 backtrace.nargs = XINT (numargs);
2317 switch (i)
2319 case 0:
2320 val = (*XSUBR (fun)->function) ();
2321 goto done;
2322 case 1:
2323 val = (*XSUBR (fun)->function) (argvals[0]);
2324 goto done;
2325 case 2:
2326 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
2327 goto done;
2328 case 3:
2329 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2330 argvals[2]);
2331 goto done;
2332 case 4:
2333 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
2334 argvals[2], argvals[3]);
2335 goto done;
2336 case 5:
2337 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2338 argvals[3], argvals[4]);
2339 goto done;
2340 case 6:
2341 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2342 argvals[3], argvals[4], argvals[5]);
2343 goto done;
2344 case 7:
2345 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2346 argvals[3], argvals[4], argvals[5],
2347 argvals[6]);
2348 goto done;
2350 case 8:
2351 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
2352 argvals[3], argvals[4], argvals[5],
2353 argvals[6], argvals[7]);
2354 goto done;
2356 default:
2357 /* Someone has created a subr that takes more arguments than
2358 is supported by this code. We need to either rewrite the
2359 subr to use a different argument protocol, or add more
2360 cases to this switch. */
2361 abort ();
2364 if (COMPILEDP (fun))
2365 val = apply_lambda (fun, original_args, 1);
2366 else
2368 if (EQ (fun, Qunbound))
2369 xsignal1 (Qvoid_function, original_fun);
2370 if (!CONSP (fun))
2371 xsignal1 (Qinvalid_function, original_fun);
2372 funcar = XCAR (fun);
2373 if (!SYMBOLP (funcar))
2374 xsignal1 (Qinvalid_function, original_fun);
2375 if (EQ (funcar, Qautoload))
2377 do_autoload (fun, original_fun);
2378 goto retry;
2380 if (EQ (funcar, Qmacro))
2381 val = Feval (apply1 (Fcdr (fun), original_args));
2382 else if (EQ (funcar, Qlambda))
2383 val = apply_lambda (fun, original_args, 1);
2384 else
2385 xsignal1 (Qinvalid_function, original_fun);
2387 done:
2388 CHECK_CONS_LIST ();
2390 lisp_eval_depth--;
2391 if (backtrace.debug_on_exit)
2392 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2393 backtrace_list = backtrace.next;
2395 return val;
2398 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
2399 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2400 Then return the value FUNCTION returns.
2401 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2402 usage: (apply FUNCTION &rest ARGUMENTS) */)
2403 (nargs, args)
2404 int nargs;
2405 Lisp_Object *args;
2407 register int i, numargs;
2408 register Lisp_Object spread_arg;
2409 register Lisp_Object *funcall_args;
2410 Lisp_Object fun;
2411 struct gcpro gcpro1;
2413 fun = args [0];
2414 funcall_args = 0;
2415 spread_arg = args [nargs - 1];
2416 CHECK_LIST (spread_arg);
2418 numargs = XINT (Flength (spread_arg));
2420 if (numargs == 0)
2421 return Ffuncall (nargs - 1, args);
2422 else if (numargs == 1)
2424 args [nargs - 1] = XCAR (spread_arg);
2425 return Ffuncall (nargs, args);
2428 numargs += nargs - 2;
2430 /* Optimize for no indirection. */
2431 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2432 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2433 fun = indirect_function (fun);
2434 if (EQ (fun, Qunbound))
2436 /* Let funcall get the error */
2437 fun = args[0];
2438 goto funcall;
2441 if (SUBRP (fun))
2443 if (numargs < XSUBR (fun)->min_args
2444 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2445 goto funcall; /* Let funcall get the error */
2446 else if (XSUBR (fun)->max_args > numargs)
2448 /* Avoid making funcall cons up a yet another new vector of arguments
2449 by explicitly supplying nil's for optional values */
2450 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
2451 * sizeof (Lisp_Object));
2452 for (i = numargs; i < XSUBR (fun)->max_args;)
2453 funcall_args[++i] = Qnil;
2454 GCPRO1 (*funcall_args);
2455 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
2458 funcall:
2459 /* We add 1 to numargs because funcall_args includes the
2460 function itself as well as its arguments. */
2461 if (!funcall_args)
2463 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
2464 * sizeof (Lisp_Object));
2465 GCPRO1 (*funcall_args);
2466 gcpro1.nvars = 1 + numargs;
2469 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
2470 /* Spread the last arg we got. Its first element goes in
2471 the slot that it used to occupy, hence this value of I. */
2472 i = nargs - 1;
2473 while (!NILP (spread_arg))
2475 funcall_args [i++] = XCAR (spread_arg);
2476 spread_arg = XCDR (spread_arg);
2479 /* By convention, the caller needs to gcpro Ffuncall's args. */
2480 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
2483 /* Run hook variables in various ways. */
2485 enum run_hooks_condition {to_completion, until_success, until_failure};
2486 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
2487 enum run_hooks_condition));
2489 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
2490 doc: /* Run each hook in HOOKS.
2491 Each argument should be a symbol, a hook variable.
2492 These symbols are processed in the order specified.
2493 If a hook symbol has a non-nil value, that value may be a function
2494 or a list of functions to be called to run the hook.
2495 If the value is a function, it is called with no arguments.
2496 If it is a list, the elements are called, in order, with no arguments.
2498 Major modes should not use this function directly to run their mode
2499 hook; they should use `run-mode-hooks' instead.
2501 Do not use `make-local-variable' to make a hook variable buffer-local.
2502 Instead, use `add-hook' and specify t for the LOCAL argument.
2503 usage: (run-hooks &rest HOOKS) */)
2504 (nargs, args)
2505 int nargs;
2506 Lisp_Object *args;
2508 Lisp_Object hook[1];
2509 register int i;
2511 for (i = 0; i < nargs; i++)
2513 hook[0] = args[i];
2514 run_hook_with_args (1, hook, to_completion);
2517 return Qnil;
2520 DEFUN ("run-hook-with-args", Frun_hook_with_args,
2521 Srun_hook_with_args, 1, MANY, 0,
2522 doc: /* Run HOOK with the specified arguments ARGS.
2523 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2524 value, that value may be a function or a list of functions to be
2525 called to run the hook. If the value is a function, it is called with
2526 the given arguments and its return value is returned. If it is a list
2527 of functions, those functions are called, in order,
2528 with the given arguments ARGS.
2529 It is best not to depend on the value returned by `run-hook-with-args',
2530 as that may change.
2532 Do not use `make-local-variable' to make a hook variable buffer-local.
2533 Instead, use `add-hook' and specify t for the LOCAL argument.
2534 usage: (run-hook-with-args HOOK &rest ARGS) */)
2535 (nargs, args)
2536 int nargs;
2537 Lisp_Object *args;
2539 return run_hook_with_args (nargs, args, to_completion);
2542 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
2543 Srun_hook_with_args_until_success, 1, MANY, 0,
2544 doc: /* Run HOOK with the specified arguments ARGS.
2545 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2546 value, that value may be a function or a list of functions to be
2547 called to run the hook. If the value is a function, it is called with
2548 the given arguments and its return value is returned.
2549 If it is a list of functions, those functions are called, in order,
2550 with the given arguments ARGS, until one of them
2551 returns a non-nil value. Then we return that value.
2552 However, if they all return nil, we return nil.
2554 Do not use `make-local-variable' to make a hook variable buffer-local.
2555 Instead, use `add-hook' and specify t for the LOCAL argument.
2556 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2557 (nargs, args)
2558 int nargs;
2559 Lisp_Object *args;
2561 return run_hook_with_args (nargs, args, until_success);
2564 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
2565 Srun_hook_with_args_until_failure, 1, MANY, 0,
2566 doc: /* Run HOOK with the specified arguments ARGS.
2567 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2568 value, that value may be a function or a list of functions to be
2569 called to run the hook. If the value is a function, it is called with
2570 the given arguments and its return value is returned.
2571 If it is a list of functions, those functions are called, in order,
2572 with the given arguments ARGS, until one of them returns nil.
2573 Then we return nil. However, if they all return non-nil, we return non-nil.
2575 Do not use `make-local-variable' to make a hook variable buffer-local.
2576 Instead, use `add-hook' and specify t for the LOCAL argument.
2577 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2578 (nargs, args)
2579 int nargs;
2580 Lisp_Object *args;
2582 return run_hook_with_args (nargs, args, until_failure);
2585 /* ARGS[0] should be a hook symbol.
2586 Call each of the functions in the hook value, passing each of them
2587 as arguments all the rest of ARGS (all NARGS - 1 elements).
2588 COND specifies a condition to test after each call
2589 to decide whether to stop.
2590 The caller (or its caller, etc) must gcpro all of ARGS,
2591 except that it isn't necessary to gcpro ARGS[0]. */
2593 static Lisp_Object
2594 run_hook_with_args (nargs, args, cond)
2595 int nargs;
2596 Lisp_Object *args;
2597 enum run_hooks_condition cond;
2599 Lisp_Object sym, val, ret;
2600 struct gcpro gcpro1, gcpro2, gcpro3;
2602 /* If we are dying or still initializing,
2603 don't do anything--it would probably crash if we tried. */
2604 if (NILP (Vrun_hooks))
2605 return Qnil;
2607 sym = args[0];
2608 val = find_symbol_value (sym);
2609 ret = (cond == until_failure ? Qt : Qnil);
2611 if (EQ (val, Qunbound) || NILP (val))
2612 return ret;
2613 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
2615 args[0] = val;
2616 return Ffuncall (nargs, args);
2618 else
2620 Lisp_Object globals = Qnil;
2621 GCPRO3 (sym, val, globals);
2623 for (;
2624 CONSP (val) && ((cond == to_completion)
2625 || (cond == until_success ? NILP (ret)
2626 : !NILP (ret)));
2627 val = XCDR (val))
2629 if (EQ (XCAR (val), Qt))
2631 /* t indicates this hook has a local binding;
2632 it means to run the global binding too. */
2633 globals = Fdefault_value (sym);
2634 if (NILP (globals)) continue;
2636 if (!CONSP (globals) || EQ (XCAR (globals), Qlambda))
2638 args[0] = globals;
2639 ret = Ffuncall (nargs, args);
2641 else
2643 for (;
2644 CONSP (globals) && ((cond == to_completion)
2645 || (cond == until_success ? NILP (ret)
2646 : !NILP (ret)));
2647 globals = XCDR (globals))
2649 args[0] = XCAR (globals);
2650 /* In a global value, t should not occur. If it does, we
2651 must ignore it to avoid an endless loop. */
2652 if (!EQ (args[0], Qt))
2653 ret = Ffuncall (nargs, args);
2657 else
2659 args[0] = XCAR (val);
2660 ret = Ffuncall (nargs, args);
2664 UNGCPRO;
2665 return ret;
2669 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2670 present value of that symbol.
2671 Call each element of FUNLIST,
2672 passing each of them the rest of ARGS.
2673 The caller (or its caller, etc) must gcpro all of ARGS,
2674 except that it isn't necessary to gcpro ARGS[0]. */
2676 Lisp_Object
2677 run_hook_list_with_args (funlist, nargs, args)
2678 Lisp_Object funlist;
2679 int nargs;
2680 Lisp_Object *args;
2682 Lisp_Object sym;
2683 Lisp_Object val;
2684 Lisp_Object globals;
2685 struct gcpro gcpro1, gcpro2, gcpro3;
2687 sym = args[0];
2688 globals = Qnil;
2689 GCPRO3 (sym, val, globals);
2691 for (val = funlist; CONSP (val); val = XCDR (val))
2693 if (EQ (XCAR (val), Qt))
2695 /* t indicates this hook has a local binding;
2696 it means to run the global binding too. */
2698 for (globals = Fdefault_value (sym);
2699 CONSP (globals);
2700 globals = XCDR (globals))
2702 args[0] = XCAR (globals);
2703 /* In a global value, t should not occur. If it does, we
2704 must ignore it to avoid an endless loop. */
2705 if (!EQ (args[0], Qt))
2706 Ffuncall (nargs, args);
2709 else
2711 args[0] = XCAR (val);
2712 Ffuncall (nargs, args);
2715 UNGCPRO;
2716 return Qnil;
2719 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2721 void
2722 run_hook_with_args_2 (hook, arg1, arg2)
2723 Lisp_Object hook, arg1, arg2;
2725 Lisp_Object temp[3];
2726 temp[0] = hook;
2727 temp[1] = arg1;
2728 temp[2] = arg2;
2730 Frun_hook_with_args (3, temp);
2733 /* Apply fn to arg */
2734 Lisp_Object
2735 apply1 (fn, arg)
2736 Lisp_Object fn, arg;
2738 struct gcpro gcpro1;
2740 GCPRO1 (fn);
2741 if (NILP (arg))
2742 RETURN_UNGCPRO (Ffuncall (1, &fn));
2743 gcpro1.nvars = 2;
2744 #ifdef NO_ARG_ARRAY
2746 Lisp_Object args[2];
2747 args[0] = fn;
2748 args[1] = arg;
2749 gcpro1.var = args;
2750 RETURN_UNGCPRO (Fapply (2, args));
2752 #else /* not NO_ARG_ARRAY */
2753 RETURN_UNGCPRO (Fapply (2, &fn));
2754 #endif /* not NO_ARG_ARRAY */
2757 /* Call function fn on no arguments */
2758 Lisp_Object
2759 call0 (fn)
2760 Lisp_Object fn;
2762 struct gcpro gcpro1;
2764 GCPRO1 (fn);
2765 RETURN_UNGCPRO (Ffuncall (1, &fn));
2768 /* Call function fn with 1 argument arg1 */
2769 /* ARGSUSED */
2770 Lisp_Object
2771 call1 (fn, arg1)
2772 Lisp_Object fn, arg1;
2774 struct gcpro gcpro1;
2775 #ifdef NO_ARG_ARRAY
2776 Lisp_Object args[2];
2778 args[0] = fn;
2779 args[1] = arg1;
2780 GCPRO1 (args[0]);
2781 gcpro1.nvars = 2;
2782 RETURN_UNGCPRO (Ffuncall (2, args));
2783 #else /* not NO_ARG_ARRAY */
2784 GCPRO1 (fn);
2785 gcpro1.nvars = 2;
2786 RETURN_UNGCPRO (Ffuncall (2, &fn));
2787 #endif /* not NO_ARG_ARRAY */
2790 /* Call function fn with 2 arguments arg1, arg2 */
2791 /* ARGSUSED */
2792 Lisp_Object
2793 call2 (fn, arg1, arg2)
2794 Lisp_Object fn, arg1, arg2;
2796 struct gcpro gcpro1;
2797 #ifdef NO_ARG_ARRAY
2798 Lisp_Object args[3];
2799 args[0] = fn;
2800 args[1] = arg1;
2801 args[2] = arg2;
2802 GCPRO1 (args[0]);
2803 gcpro1.nvars = 3;
2804 RETURN_UNGCPRO (Ffuncall (3, args));
2805 #else /* not NO_ARG_ARRAY */
2806 GCPRO1 (fn);
2807 gcpro1.nvars = 3;
2808 RETURN_UNGCPRO (Ffuncall (3, &fn));
2809 #endif /* not NO_ARG_ARRAY */
2812 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2813 /* ARGSUSED */
2814 Lisp_Object
2815 call3 (fn, arg1, arg2, arg3)
2816 Lisp_Object fn, arg1, arg2, arg3;
2818 struct gcpro gcpro1;
2819 #ifdef NO_ARG_ARRAY
2820 Lisp_Object args[4];
2821 args[0] = fn;
2822 args[1] = arg1;
2823 args[2] = arg2;
2824 args[3] = arg3;
2825 GCPRO1 (args[0]);
2826 gcpro1.nvars = 4;
2827 RETURN_UNGCPRO (Ffuncall (4, args));
2828 #else /* not NO_ARG_ARRAY */
2829 GCPRO1 (fn);
2830 gcpro1.nvars = 4;
2831 RETURN_UNGCPRO (Ffuncall (4, &fn));
2832 #endif /* not NO_ARG_ARRAY */
2835 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2836 /* ARGSUSED */
2837 Lisp_Object
2838 call4 (fn, arg1, arg2, arg3, arg4)
2839 Lisp_Object fn, arg1, arg2, arg3, arg4;
2841 struct gcpro gcpro1;
2842 #ifdef NO_ARG_ARRAY
2843 Lisp_Object args[5];
2844 args[0] = fn;
2845 args[1] = arg1;
2846 args[2] = arg2;
2847 args[3] = arg3;
2848 args[4] = arg4;
2849 GCPRO1 (args[0]);
2850 gcpro1.nvars = 5;
2851 RETURN_UNGCPRO (Ffuncall (5, args));
2852 #else /* not NO_ARG_ARRAY */
2853 GCPRO1 (fn);
2854 gcpro1.nvars = 5;
2855 RETURN_UNGCPRO (Ffuncall (5, &fn));
2856 #endif /* not NO_ARG_ARRAY */
2859 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2860 /* ARGSUSED */
2861 Lisp_Object
2862 call5 (fn, arg1, arg2, arg3, arg4, arg5)
2863 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
2865 struct gcpro gcpro1;
2866 #ifdef NO_ARG_ARRAY
2867 Lisp_Object args[6];
2868 args[0] = fn;
2869 args[1] = arg1;
2870 args[2] = arg2;
2871 args[3] = arg3;
2872 args[4] = arg4;
2873 args[5] = arg5;
2874 GCPRO1 (args[0]);
2875 gcpro1.nvars = 6;
2876 RETURN_UNGCPRO (Ffuncall (6, args));
2877 #else /* not NO_ARG_ARRAY */
2878 GCPRO1 (fn);
2879 gcpro1.nvars = 6;
2880 RETURN_UNGCPRO (Ffuncall (6, &fn));
2881 #endif /* not NO_ARG_ARRAY */
2884 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2885 /* ARGSUSED */
2886 Lisp_Object
2887 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
2888 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
2890 struct gcpro gcpro1;
2891 #ifdef NO_ARG_ARRAY
2892 Lisp_Object args[7];
2893 args[0] = fn;
2894 args[1] = arg1;
2895 args[2] = arg2;
2896 args[3] = arg3;
2897 args[4] = arg4;
2898 args[5] = arg5;
2899 args[6] = arg6;
2900 GCPRO1 (args[0]);
2901 gcpro1.nvars = 7;
2902 RETURN_UNGCPRO (Ffuncall (7, args));
2903 #else /* not NO_ARG_ARRAY */
2904 GCPRO1 (fn);
2905 gcpro1.nvars = 7;
2906 RETURN_UNGCPRO (Ffuncall (7, &fn));
2907 #endif /* not NO_ARG_ARRAY */
2910 /* The caller should GCPRO all the elements of ARGS. */
2912 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
2913 doc: /* Call first argument as a function, passing remaining arguments to it.
2914 Return the value that function returns.
2915 Thus, (funcall 'cons 'x 'y) returns (x . y).
2916 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2917 (nargs, args)
2918 int nargs;
2919 Lisp_Object *args;
2921 Lisp_Object fun, original_fun;
2922 Lisp_Object funcar;
2923 int numargs = nargs - 1;
2924 Lisp_Object lisp_numargs;
2925 Lisp_Object val;
2926 struct backtrace backtrace;
2927 register Lisp_Object *internal_args;
2928 register int i;
2930 QUIT;
2931 if ((consing_since_gc > gc_cons_threshold
2932 && consing_since_gc > gc_relative_threshold)
2934 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
2935 Fgarbage_collect ();
2937 if (++lisp_eval_depth > max_lisp_eval_depth)
2939 if (max_lisp_eval_depth < 100)
2940 max_lisp_eval_depth = 100;
2941 if (lisp_eval_depth > max_lisp_eval_depth)
2942 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2945 backtrace.next = backtrace_list;
2946 backtrace_list = &backtrace;
2947 backtrace.function = &args[0];
2948 backtrace.args = &args[1];
2949 backtrace.nargs = nargs - 1;
2950 backtrace.evalargs = 0;
2951 backtrace.debug_on_exit = 0;
2953 if (debug_on_next_call)
2954 do_debug_on_call (Qlambda);
2956 CHECK_CONS_LIST ();
2958 original_fun = args[0];
2960 retry:
2962 /* Optimize for no indirection. */
2963 fun = original_fun;
2964 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2965 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2966 fun = indirect_function (fun);
2968 if (SUBRP (fun))
2970 if (numargs < XSUBR (fun)->min_args
2971 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2973 XSETFASTINT (lisp_numargs, numargs);
2974 xsignal2 (Qwrong_number_of_arguments, original_fun, lisp_numargs);
2977 if (XSUBR (fun)->max_args == UNEVALLED)
2978 xsignal1 (Qinvalid_function, original_fun);
2980 if (XSUBR (fun)->max_args == MANY)
2982 val = (*XSUBR (fun)->function) (numargs, args + 1);
2983 goto done;
2986 if (XSUBR (fun)->max_args > numargs)
2988 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2989 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
2990 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2991 internal_args[i] = Qnil;
2993 else
2994 internal_args = args + 1;
2995 switch (XSUBR (fun)->max_args)
2997 case 0:
2998 val = (*XSUBR (fun)->function) ();
2999 goto done;
3000 case 1:
3001 val = (*XSUBR (fun)->function) (internal_args[0]);
3002 goto done;
3003 case 2:
3004 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1]);
3005 goto done;
3006 case 3:
3007 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
3008 internal_args[2]);
3009 goto done;
3010 case 4:
3011 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
3012 internal_args[2], internal_args[3]);
3013 goto done;
3014 case 5:
3015 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
3016 internal_args[2], internal_args[3],
3017 internal_args[4]);
3018 goto done;
3019 case 6:
3020 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
3021 internal_args[2], internal_args[3],
3022 internal_args[4], internal_args[5]);
3023 goto done;
3024 case 7:
3025 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
3026 internal_args[2], internal_args[3],
3027 internal_args[4], internal_args[5],
3028 internal_args[6]);
3029 goto done;
3031 case 8:
3032 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
3033 internal_args[2], internal_args[3],
3034 internal_args[4], internal_args[5],
3035 internal_args[6], internal_args[7]);
3036 goto done;
3038 default:
3040 /* If a subr takes more than 8 arguments without using MANY
3041 or UNEVALLED, we need to extend this function to support it.
3042 Until this is done, there is no way to call the function. */
3043 abort ();
3046 if (COMPILEDP (fun))
3047 val = funcall_lambda (fun, numargs, args + 1);
3048 else
3050 if (EQ (fun, Qunbound))
3051 xsignal1 (Qvoid_function, original_fun);
3052 if (!CONSP (fun))
3053 xsignal1 (Qinvalid_function, original_fun);
3054 funcar = XCAR (fun);
3055 if (!SYMBOLP (funcar))
3056 xsignal1 (Qinvalid_function, original_fun);
3057 if (EQ (funcar, Qlambda))
3058 val = funcall_lambda (fun, numargs, args + 1);
3059 else if (EQ (funcar, Qautoload))
3061 do_autoload (fun, original_fun);
3062 CHECK_CONS_LIST ();
3063 goto retry;
3065 else
3066 xsignal1 (Qinvalid_function, original_fun);
3068 done:
3069 CHECK_CONS_LIST ();
3070 lisp_eval_depth--;
3071 if (backtrace.debug_on_exit)
3072 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
3073 backtrace_list = backtrace.next;
3074 return val;
3077 Lisp_Object
3078 apply_lambda (fun, args, eval_flag)
3079 Lisp_Object fun, args;
3080 int eval_flag;
3082 Lisp_Object args_left;
3083 Lisp_Object numargs;
3084 register Lisp_Object *arg_vector;
3085 struct gcpro gcpro1, gcpro2, gcpro3;
3086 register int i;
3087 register Lisp_Object tem;
3089 numargs = Flength (args);
3090 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
3091 args_left = args;
3093 GCPRO3 (*arg_vector, args_left, fun);
3094 gcpro1.nvars = 0;
3096 for (i = 0; i < XINT (numargs);)
3098 tem = Fcar (args_left), args_left = Fcdr (args_left);
3099 if (eval_flag) tem = Feval (tem);
3100 arg_vector[i++] = tem;
3101 gcpro1.nvars = i;
3104 UNGCPRO;
3106 if (eval_flag)
3108 backtrace_list->args = arg_vector;
3109 backtrace_list->nargs = i;
3111 backtrace_list->evalargs = 0;
3112 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
3114 /* Do the debug-on-exit now, while arg_vector still exists. */
3115 if (backtrace_list->debug_on_exit)
3116 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
3117 /* Don't do it again when we return to eval. */
3118 backtrace_list->debug_on_exit = 0;
3119 return tem;
3122 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3123 and return the result of evaluation.
3124 FUN must be either a lambda-expression or a compiled-code object. */
3126 static Lisp_Object
3127 funcall_lambda (fun, nargs, arg_vector)
3128 Lisp_Object fun;
3129 int nargs;
3130 register Lisp_Object *arg_vector;
3132 Lisp_Object val, syms_left, next;
3133 int count = SPECPDL_INDEX ();
3134 int i, optional, rest;
3136 if (CONSP (fun))
3138 syms_left = XCDR (fun);
3139 if (CONSP (syms_left))
3140 syms_left = XCAR (syms_left);
3141 else
3142 xsignal1 (Qinvalid_function, fun);
3144 else if (COMPILEDP (fun))
3145 syms_left = AREF (fun, COMPILED_ARGLIST);
3146 else
3147 abort ();
3149 i = optional = rest = 0;
3150 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
3152 QUIT;
3154 next = XCAR (syms_left);
3155 if (!SYMBOLP (next))
3156 xsignal1 (Qinvalid_function, fun);
3158 if (EQ (next, Qand_rest))
3159 rest = 1;
3160 else if (EQ (next, Qand_optional))
3161 optional = 1;
3162 else if (rest)
3164 specbind (next, Flist (nargs - i, &arg_vector[i]));
3165 i = nargs;
3167 else if (i < nargs)
3168 specbind (next, arg_vector[i++]);
3169 else if (!optional)
3170 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
3171 else
3172 specbind (next, Qnil);
3175 if (!NILP (syms_left))
3176 xsignal1 (Qinvalid_function, fun);
3177 else if (i < nargs)
3178 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
3180 if (CONSP (fun))
3181 val = Fprogn (XCDR (XCDR (fun)));
3182 else
3184 /* If we have not actually read the bytecode string
3185 and constants vector yet, fetch them from the file. */
3186 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
3187 Ffetch_bytecode (fun);
3188 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
3189 AREF (fun, COMPILED_CONSTANTS),
3190 AREF (fun, COMPILED_STACK_DEPTH));
3193 return unbind_to (count, val);
3196 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
3197 1, 1, 0,
3198 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3199 (object)
3200 Lisp_Object object;
3202 Lisp_Object tem;
3204 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
3206 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
3207 if (!CONSP (tem))
3209 tem = AREF (object, COMPILED_BYTECODE);
3210 if (CONSP (tem) && STRINGP (XCAR (tem)))
3211 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
3212 else
3213 error ("Invalid byte code");
3215 ASET (object, COMPILED_BYTECODE, XCAR (tem));
3216 ASET (object, COMPILED_CONSTANTS, XCDR (tem));
3218 return object;
3221 static void
3222 grow_specpdl ()
3224 register int count = SPECPDL_INDEX ();
3225 if (specpdl_size >= max_specpdl_size)
3227 if (max_specpdl_size < 400)
3228 max_specpdl_size = 400;
3229 if (specpdl_size >= max_specpdl_size)
3230 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil);
3232 specpdl_size *= 2;
3233 if (specpdl_size > max_specpdl_size)
3234 specpdl_size = max_specpdl_size;
3235 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
3236 specpdl_ptr = specpdl + count;
3239 void
3240 specbind (symbol, value)
3241 Lisp_Object symbol, value;
3243 Lisp_Object valcontents;
3245 CHECK_SYMBOL (symbol);
3246 if (specpdl_ptr == specpdl + specpdl_size)
3247 grow_specpdl ();
3249 /* The most common case is that of a non-constant symbol with a
3250 trivial value. Make that as fast as we can. */
3251 valcontents = SYMBOL_VALUE (symbol);
3252 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
3254 specpdl_ptr->symbol = symbol;
3255 specpdl_ptr->old_value = valcontents;
3256 specpdl_ptr->func = NULL;
3257 ++specpdl_ptr;
3258 SET_SYMBOL_VALUE (symbol, value);
3260 else
3262 Lisp_Object ovalue = find_symbol_value (symbol);
3263 specpdl_ptr->func = 0;
3264 specpdl_ptr->old_value = ovalue;
3266 valcontents = XSYMBOL (symbol)->value;
3268 if (BUFFER_LOCAL_VALUEP (valcontents)
3269 || BUFFER_OBJFWDP (valcontents))
3271 Lisp_Object where, self_buffer;
3273 self_buffer = Fcurrent_buffer ();
3275 /* For a local variable, record both the symbol and which
3276 buffer's or frame's value we are saving. */
3277 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3278 where = self_buffer;
3279 else if (BUFFER_LOCAL_VALUEP (valcontents)
3280 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
3281 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
3282 else
3283 where = Qnil;
3285 /* We're not using the `unused' slot in the specbinding
3286 structure because this would mean we have to do more
3287 work for simple variables. */
3288 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, self_buffer));
3290 /* If SYMBOL is a per-buffer variable which doesn't have a
3291 buffer-local value here, make the `let' change the global
3292 value by changing the value of SYMBOL in all buffers not
3293 having their own value. This is consistent with what
3294 happens with other buffer-local variables. */
3295 if (NILP (where)
3296 && BUFFER_OBJFWDP (valcontents))
3298 ++specpdl_ptr;
3299 Fset_default (symbol, value);
3300 return;
3303 else
3304 specpdl_ptr->symbol = symbol;
3306 specpdl_ptr++;
3307 /* We used to do
3308 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3309 store_symval_forwarding (symbol, ovalue, value, NULL);
3310 else
3311 but ovalue comes from find_symbol_value which should never return
3312 such an internal value. */
3313 eassert (!(BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue)));
3314 set_internal (symbol, value, 0, 1);
3318 void
3319 record_unwind_protect (function, arg)
3320 Lisp_Object (*function) P_ ((Lisp_Object));
3321 Lisp_Object arg;
3323 eassert (!handling_signal);
3325 if (specpdl_ptr == specpdl + specpdl_size)
3326 grow_specpdl ();
3327 specpdl_ptr->func = function;
3328 specpdl_ptr->symbol = Qnil;
3329 specpdl_ptr->old_value = arg;
3330 specpdl_ptr++;
3333 Lisp_Object
3334 unbind_to (count, value)
3335 int count;
3336 Lisp_Object value;
3338 Lisp_Object quitf = Vquit_flag;
3339 struct gcpro gcpro1, gcpro2;
3341 GCPRO2 (value, quitf);
3342 Vquit_flag = Qnil;
3344 while (specpdl_ptr != specpdl + count)
3346 /* Copy the binding, and decrement specpdl_ptr, before we do
3347 the work to unbind it. We decrement first
3348 so that an error in unbinding won't try to unbind
3349 the same entry again, and we copy the binding first
3350 in case more bindings are made during some of the code we run. */
3352 struct specbinding this_binding;
3353 this_binding = *--specpdl_ptr;
3355 if (this_binding.func != 0)
3356 (*this_binding.func) (this_binding.old_value);
3357 /* If the symbol is a list, it is really (SYMBOL WHERE
3358 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3359 frame. If WHERE is a buffer or frame, this indicates we
3360 bound a variable that had a buffer-local or frame-local
3361 binding. WHERE nil means that the variable had the default
3362 value when it was bound. CURRENT-BUFFER is the buffer that
3363 was current when the variable was bound. */
3364 else if (CONSP (this_binding.symbol))
3366 Lisp_Object symbol, where;
3368 symbol = XCAR (this_binding.symbol);
3369 where = XCAR (XCDR (this_binding.symbol));
3371 if (NILP (where))
3372 Fset_default (symbol, this_binding.old_value);
3373 else if (BUFFERP (where))
3374 set_internal (symbol, this_binding.old_value, XBUFFER (where), 1);
3375 else
3376 set_internal (symbol, this_binding.old_value, NULL, 1);
3378 else
3380 /* If variable has a trivial value (no forwarding), we can
3381 just set it. No need to check for constant symbols here,
3382 since that was already done by specbind. */
3383 if (!MISCP (SYMBOL_VALUE (this_binding.symbol)))
3384 SET_SYMBOL_VALUE (this_binding.symbol, this_binding.old_value);
3385 else
3386 set_internal (this_binding.symbol, this_binding.old_value, 0, 1);
3390 if (NILP (Vquit_flag) && !NILP (quitf))
3391 Vquit_flag = quitf;
3393 UNGCPRO;
3394 return value;
3397 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
3398 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3399 The debugger is entered when that frame exits, if the flag is non-nil. */)
3400 (level, flag)
3401 Lisp_Object level, flag;
3403 register struct backtrace *backlist = backtrace_list;
3404 register int i;
3406 CHECK_NUMBER (level);
3408 for (i = 0; backlist && i < XINT (level); i++)
3410 backlist = backlist->next;
3413 if (backlist)
3414 backlist->debug_on_exit = !NILP (flag);
3416 return flag;
3419 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
3420 doc: /* Print a trace of Lisp function calls currently active.
3421 Output stream used is value of `standard-output'. */)
3424 register struct backtrace *backlist = backtrace_list;
3425 register int i;
3426 Lisp_Object tail;
3427 Lisp_Object tem;
3428 struct gcpro gcpro1;
3430 XSETFASTINT (Vprint_level, 3);
3432 tail = Qnil;
3433 GCPRO1 (tail);
3435 while (backlist)
3437 write_string (backlist->debug_on_exit ? "* " : " ", 2);
3438 if (backlist->nargs == UNEVALLED)
3440 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
3441 write_string ("\n", -1);
3443 else
3445 tem = *backlist->function;
3446 Fprin1 (tem, Qnil); /* This can QUIT */
3447 write_string ("(", -1);
3448 if (backlist->nargs == MANY)
3450 for (tail = *backlist->args, i = 0;
3451 !NILP (tail);
3452 tail = Fcdr (tail), i++)
3454 if (i) write_string (" ", -1);
3455 Fprin1 (Fcar (tail), Qnil);
3458 else
3460 for (i = 0; i < backlist->nargs; i++)
3462 if (i) write_string (" ", -1);
3463 Fprin1 (backlist->args[i], Qnil);
3466 write_string (")\n", -1);
3468 backlist = backlist->next;
3471 Vprint_level = Qnil;
3472 UNGCPRO;
3473 return Qnil;
3476 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
3477 doc: /* Return the function and arguments NFRAMES up from current execution point.
3478 If that frame has not evaluated the arguments yet (or is a special form),
3479 the value is (nil FUNCTION ARG-FORMS...).
3480 If that frame has evaluated its arguments and called its function already,
3481 the value is (t FUNCTION ARG-VALUES...).
3482 A &rest arg is represented as the tail of the list ARG-VALUES.
3483 FUNCTION is whatever was supplied as car of evaluated list,
3484 or a lambda expression for macro calls.
3485 If NFRAMES is more than the number of frames, the value is nil. */)
3486 (nframes)
3487 Lisp_Object nframes;
3489 register struct backtrace *backlist = backtrace_list;
3490 register int i;
3491 Lisp_Object tem;
3493 CHECK_NATNUM (nframes);
3495 /* Find the frame requested. */
3496 for (i = 0; backlist && i < XFASTINT (nframes); i++)
3497 backlist = backlist->next;
3499 if (!backlist)
3500 return Qnil;
3501 if (backlist->nargs == UNEVALLED)
3502 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3503 else
3505 if (backlist->nargs == MANY)
3506 tem = *backlist->args;
3507 else
3508 tem = Flist (backlist->nargs, backlist->args);
3510 return Fcons (Qt, Fcons (*backlist->function, tem));
3515 void
3516 mark_backtrace (struct backtrace *backlist)
3518 register int i;
3520 for (; backlist; backlist = backlist->next)
3522 mark_object (*backlist->function);
3524 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
3525 i = 0;
3526 else
3527 i = backlist->nargs - 1;
3528 for (; i >= 0; i--)
3529 mark_object (backlist->args[i]);
3533 void
3534 syms_of_eval ()
3536 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
3537 doc: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3538 If Lisp code tries to increase the total number past this amount,
3539 an error is signaled.
3540 You can safely use a value considerably larger than the default value,
3541 if that proves inconveniently small. However, if you increase it too far,
3542 Emacs could run out of memory trying to make the stack bigger. */);
3544 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
3545 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3547 This limit serves to catch infinite recursions for you before they cause
3548 actual stack overflow in C, which would be fatal for Emacs.
3549 You can safely make it considerably larger than its default value,
3550 if that proves inconveniently small. However, if you increase it too far,
3551 Emacs could overflow the real C stack, and crash. */);
3553 DEFVAR_LISP ("quit-flag", &Vquit_flag,
3554 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3555 If the value is t, that means do an ordinary quit.
3556 If the value equals `throw-on-input', that means quit by throwing
3557 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3558 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3559 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3560 Vquit_flag = Qnil;
3562 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
3563 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3564 Note that `quit-flag' will still be set by typing C-g,
3565 so a quit will be signaled as soon as `inhibit-quit' is nil.
3566 To prevent this happening, set `quit-flag' to nil
3567 before making `inhibit-quit' nil. */);
3568 Vinhibit_quit = Qnil;
3570 Qinhibit_quit = intern_c_string ("inhibit-quit");
3571 staticpro (&Qinhibit_quit);
3573 Qautoload = intern_c_string ("autoload");
3574 staticpro (&Qautoload);
3576 Qdebug_on_error = intern_c_string ("debug-on-error");
3577 staticpro (&Qdebug_on_error);
3579 Qmacro = intern_c_string ("macro");
3580 staticpro (&Qmacro);
3582 Qdeclare = intern_c_string ("declare");
3583 staticpro (&Qdeclare);
3585 /* Note that the process handling also uses Qexit, but we don't want
3586 to staticpro it twice, so we just do it here. */
3587 Qexit = intern_c_string ("exit");
3588 staticpro (&Qexit);
3590 Qinteractive = intern_c_string ("interactive");
3591 staticpro (&Qinteractive);
3593 Qcommandp = intern_c_string ("commandp");
3594 staticpro (&Qcommandp);
3596 Qdefun = intern_c_string ("defun");
3597 staticpro (&Qdefun);
3599 Qand_rest = intern_c_string ("&rest");
3600 staticpro (&Qand_rest);
3602 Qand_optional = intern_c_string ("&optional");
3603 staticpro (&Qand_optional);
3605 Qdebug = intern_c_string ("debug");
3606 staticpro (&Qdebug);
3608 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
3609 doc: /* *Non-nil means errors display a backtrace buffer.
3610 More precisely, this happens for any error that is handled
3611 by the editor command loop.
3612 If the value is a list, an error only means to display a backtrace
3613 if one of its condition symbols appears in the list. */);
3614 Vstack_trace_on_error = Qnil;
3616 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
3617 doc: /* *Non-nil means enter debugger if an error is signaled.
3618 Does not apply to errors handled by `condition-case' or those
3619 matched by `debug-ignored-errors'.
3620 If the value is a list, an error only means to enter the debugger
3621 if one of its condition symbols appears in the list.
3622 When you evaluate an expression interactively, this variable
3623 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3624 The command `toggle-debug-on-error' toggles this.
3625 See also the variable `debug-on-quit'. */);
3626 Vdebug_on_error = Qnil;
3628 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
3629 doc: /* *List of errors for which the debugger should not be called.
3630 Each element may be a condition-name or a regexp that matches error messages.
3631 If any element applies to a given error, that error skips the debugger
3632 and just returns to top level.
3633 This overrides the variable `debug-on-error'.
3634 It does not apply to errors handled by `condition-case'. */);
3635 Vdebug_ignored_errors = Qnil;
3637 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
3638 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3639 Does not apply if quit is handled by a `condition-case'. */);
3640 debug_on_quit = 0;
3642 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
3643 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3645 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
3646 doc: /* Non-nil means debugger may continue execution.
3647 This is nil when the debugger is called under circumstances where it
3648 might not be safe to continue. */);
3649 debugger_may_continue = 1;
3651 DEFVAR_LISP ("debugger", &Vdebugger,
3652 doc: /* Function to call to invoke debugger.
3653 If due to frame exit, args are `exit' and the value being returned;
3654 this function's value will be returned instead of that.
3655 If due to error, args are `error' and a list of the args to `signal'.
3656 If due to `apply' or `funcall' entry, one arg, `lambda'.
3657 If due to `eval' entry, one arg, t. */);
3658 Vdebugger = Qnil;
3660 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
3661 doc: /* If non-nil, this is a function for `signal' to call.
3662 It receives the same arguments that `signal' was given.
3663 The Edebug package uses this to regain control. */);
3664 Vsignal_hook_function = Qnil;
3666 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
3667 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3668 Note that `debug-on-error', `debug-on-quit' and friends
3669 still determine whether to handle the particular condition. */);
3670 Vdebug_on_signal = Qnil;
3672 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function,
3673 doc: /* Function to process declarations in a macro definition.
3674 The function will be called with two args MACRO and DECL.
3675 MACRO is the name of the macro being defined.
3676 DECL is a list `(declare ...)' containing the declarations.
3677 The value the function returns is not used. */);
3678 Vmacro_declaration_function = Qnil;
3680 Vrun_hooks = intern_c_string ("run-hooks");
3681 staticpro (&Vrun_hooks);
3683 staticpro (&Vautoload_queue);
3684 Vautoload_queue = Qnil;
3685 staticpro (&Vsignaling_function);
3686 Vsignaling_function = Qnil;
3688 defsubr (&Sor);
3689 defsubr (&Sand);
3690 defsubr (&Sif);
3691 defsubr (&Scond);
3692 defsubr (&Sprogn);
3693 defsubr (&Sprog1);
3694 defsubr (&Sprog2);
3695 defsubr (&Ssetq);
3696 defsubr (&Squote);
3697 defsubr (&Sfunction);
3698 defsubr (&Sdefun);
3699 defsubr (&Sdefmacro);
3700 defsubr (&Sdefvar);
3701 defsubr (&Sdefvaralias);
3702 defsubr (&Sdefconst);
3703 defsubr (&Suser_variable_p);
3704 defsubr (&Slet);
3705 defsubr (&SletX);
3706 defsubr (&Swhile);
3707 defsubr (&Smacroexpand);
3708 defsubr (&Scatch);
3709 defsubr (&Sthrow);
3710 defsubr (&Sunwind_protect);
3711 defsubr (&Scondition_case);
3712 defsubr (&Ssignal);
3713 defsubr (&Sinteractive_p);
3714 defsubr (&Scalled_interactively_p);
3715 defsubr (&Scommandp);
3716 defsubr (&Sautoload);
3717 defsubr (&Seval);
3718 defsubr (&Sapply);
3719 defsubr (&Sfuncall);
3720 defsubr (&Srun_hooks);
3721 defsubr (&Srun_hook_with_args);
3722 defsubr (&Srun_hook_with_args_until_success);
3723 defsubr (&Srun_hook_with_args_until_failure);
3724 defsubr (&Sfetch_bytecode);
3725 defsubr (&Sbacktrace_debug);
3726 defsubr (&Sbacktrace);
3727 defsubr (&Sbacktrace_frame);
3730 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3731 (do not change this comment) */