1 /* Evaluator for GNU Emacs Lisp interpreter.
3 Copyright (C) 1985-1987, 1993-1995, 1999-2015 Free Software Foundation,
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/>. */
26 #include "blockinput.h"
29 #include "dispextern.h"
32 /* Chain of condition and catch handlers currently in effect. */
34 struct handler
*handlerlist
;
36 /* Non-nil means record all fset's and provide's, to be undone
37 if the file being autoloaded is not fully loaded.
38 They are recorded by being consed onto the front of Vautoload_queue:
39 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
41 Lisp_Object Vautoload_queue
;
43 /* This holds either the symbol `run-hooks' or nil.
44 It is nil at an early stage of startup, and when Emacs
46 Lisp_Object Vrun_hooks
;
48 /* Current number of specbindings allocated in specpdl, not counting
49 the dummy entry specpdl[-1]. */
51 ptrdiff_t specpdl_size
;
53 /* Pointer to beginning of specpdl. A dummy entry specpdl[-1] exists
54 only so that its address can be taken. */
56 union specbinding
*specpdl
;
58 /* Pointer to first unused element in specpdl. */
60 union specbinding
*specpdl_ptr
;
62 /* Depth in Lisp evaluations and function calls. */
64 static EMACS_INT lisp_eval_depth
;
66 /* The value of num_nonmacro_input_events as of the last time we
67 started to enter the debugger. If we decide to enter the debugger
68 again when this is still equal to num_nonmacro_input_events, then we
69 know that the debugger itself has an error, and we should just
70 signal the error instead of entering an infinite loop of debugger
73 static EMACS_INT when_entered_debugger
;
75 /* The function from which the last `signal' was called. Set in
77 /* FIXME: We should probably get rid of this! */
78 Lisp_Object Vsignaling_function
;
80 /* If non-nil, Lisp code must not be run since some part of Emacs is in
81 an inconsistent state. Currently unused. */
82 Lisp_Object inhibit_lisp_code
;
84 /* These would ordinarily be static, but they need to be visible to GDB. */
85 bool backtrace_p (union specbinding
*) EXTERNALLY_VISIBLE
;
86 Lisp_Object
*backtrace_args (union specbinding
*) EXTERNALLY_VISIBLE
;
87 Lisp_Object
backtrace_function (union specbinding
*) EXTERNALLY_VISIBLE
;
88 union specbinding
*backtrace_next (union specbinding
*) EXTERNALLY_VISIBLE
;
89 union specbinding
*backtrace_top (void) EXTERNALLY_VISIBLE
;
91 static Lisp_Object
funcall_lambda (Lisp_Object
, ptrdiff_t, Lisp_Object
*);
92 static Lisp_Object
apply_lambda (Lisp_Object
, Lisp_Object
, ptrdiff_t);
95 specpdl_symbol (union specbinding
*pdl
)
97 eassert (pdl
->kind
>= SPECPDL_LET
);
98 return pdl
->let
.symbol
;
102 specpdl_old_value (union specbinding
*pdl
)
104 eassert (pdl
->kind
>= SPECPDL_LET
);
105 return pdl
->let
.old_value
;
109 set_specpdl_old_value (union specbinding
*pdl
, Lisp_Object val
)
111 eassert (pdl
->kind
>= SPECPDL_LET
);
112 pdl
->let
.old_value
= val
;
116 specpdl_where (union specbinding
*pdl
)
118 eassert (pdl
->kind
> SPECPDL_LET
);
119 return pdl
->let
.where
;
123 specpdl_arg (union specbinding
*pdl
)
125 eassert (pdl
->kind
== SPECPDL_UNWIND
);
126 return pdl
->unwind
.arg
;
130 backtrace_function (union specbinding
*pdl
)
132 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
133 return pdl
->bt
.function
;
137 backtrace_nargs (union specbinding
*pdl
)
139 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
140 return pdl
->bt
.nargs
;
144 backtrace_args (union specbinding
*pdl
)
146 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
151 backtrace_debug_on_exit (union specbinding
*pdl
)
153 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
154 return pdl
->bt
.debug_on_exit
;
157 /* Functions to modify slots of backtrace records. */
160 set_backtrace_args (union specbinding
*pdl
, Lisp_Object
*args
, ptrdiff_t nargs
)
162 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
164 pdl
->bt
.nargs
= nargs
;
168 set_backtrace_debug_on_exit (union specbinding
*pdl
, bool doe
)
170 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
171 pdl
->bt
.debug_on_exit
= doe
;
174 /* Helper functions to scan the backtrace. */
177 backtrace_p (union specbinding
*pdl
)
178 { return pdl
>= specpdl
; }
183 union specbinding
*pdl
= specpdl_ptr
- 1;
184 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
190 backtrace_next (union specbinding
*pdl
)
193 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
198 /* Return a pointer to somewhere near the top of the C stack. */
200 near_C_stack_top (void)
202 return backtrace_args (backtrace_top ());
206 init_eval_once (void)
209 union specbinding
*pdlvec
= xmalloc ((size
+ 1) * sizeof *specpdl
);
211 specpdl
= specpdl_ptr
= pdlvec
+ 1;
212 /* Don't forget to update docs (lispref node "Local Variables"). */
213 max_specpdl_size
= 1300; /* 1000 is not enough for CEDET's c-by.el. */
214 max_lisp_eval_depth
= 800;
219 static struct handler handlerlist_sentinel
;
225 specpdl_ptr
= specpdl
;
226 { /* Put a dummy catcher at top-level so that handlerlist is never NULL.
227 This is important since handlerlist->nextfree holds the freelist
228 which would otherwise leak every time we unwind back to top-level. */
230 handlerlist
= handlerlist_sentinel
.nextfree
= &handlerlist_sentinel
;
231 PUSH_HANDLER (c
, Qunbound
, CATCHER
);
232 eassert (c
== &handlerlist_sentinel
);
233 handlerlist_sentinel
.nextfree
= NULL
;
234 handlerlist_sentinel
.next
= NULL
;
237 debug_on_next_call
= 0;
239 /* This is less than the initial value of num_nonmacro_input_events. */
240 when_entered_debugger
= -1;
243 /* Unwind-protect function used by call_debugger. */
246 restore_stack_limits (Lisp_Object data
)
248 max_specpdl_size
= XINT (XCAR (data
));
249 max_lisp_eval_depth
= XINT (XCDR (data
));
252 static void grow_specpdl (void);
254 /* Call the Lisp debugger, giving it argument ARG. */
257 call_debugger (Lisp_Object arg
)
259 bool debug_while_redisplaying
;
260 ptrdiff_t count
= SPECPDL_INDEX ();
262 EMACS_INT old_depth
= max_lisp_eval_depth
;
263 /* Do not allow max_specpdl_size less than actual depth (Bug#16603). */
264 EMACS_INT old_max
= max (max_specpdl_size
, count
);
266 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
267 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
269 /* While debugging Bug#16603, previous value of 100 was found
270 too small to avoid specpdl overflow in the debugger itself. */
271 if (max_specpdl_size
- 200 < count
)
272 max_specpdl_size
= count
+ 200;
274 if (old_max
== count
)
276 /* We can enter the debugger due to specpdl overflow (Bug#16603). */
281 /* Restore limits after leaving the debugger. */
282 record_unwind_protect (restore_stack_limits
,
283 Fcons (make_number (old_max
),
284 make_number (old_depth
)));
286 #ifdef HAVE_WINDOW_SYSTEM
287 if (display_hourglass_p
)
291 debug_on_next_call
= 0;
292 when_entered_debugger
= num_nonmacro_input_events
;
294 /* Resetting redisplaying_p to 0 makes sure that debug output is
295 displayed if the debugger is invoked during redisplay. */
296 debug_while_redisplaying
= redisplaying_p
;
298 specbind (intern ("debugger-may-continue"),
299 debug_while_redisplaying
? Qnil
: Qt
);
300 specbind (Qinhibit_redisplay
, Qnil
);
301 specbind (Qinhibit_debugger
, Qt
);
303 #if 0 /* Binding this prevents execution of Lisp code during
304 redisplay, which necessarily leads to display problems. */
305 specbind (Qinhibit_eval_during_redisplay
, Qt
);
308 val
= apply1 (Vdebugger
, arg
);
310 /* Interrupting redisplay and resuming it later is not safe under
311 all circumstances. So, when the debugger returns, abort the
312 interrupted redisplay by going back to the top-level. */
313 if (debug_while_redisplaying
)
316 return unbind_to (count
, val
);
320 do_debug_on_call (Lisp_Object code
, ptrdiff_t count
)
322 debug_on_next_call
= 0;
323 set_backtrace_debug_on_exit (specpdl
+ count
, true);
324 call_debugger (list1 (code
));
327 /* NOTE!!! Every function that can call EVAL must protect its args
328 and temporaries from garbage collection while it needs them.
329 The definition of `For' shows what you have to do. */
331 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
332 doc
: /* Eval args until one of them yields non-nil, then return that value.
333 The remaining args are not evalled at all.
334 If all args return nil, return nil.
335 usage: (or CONDITIONS...) */)
338 Lisp_Object val
= Qnil
;
342 val
= eval_sub (XCAR (args
));
351 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
352 doc
: /* Eval args until one of them yields nil, then return nil.
353 The remaining args are not evalled at all.
354 If no arg yields nil, return the last arg's value.
355 usage: (and CONDITIONS...) */)
358 Lisp_Object val
= Qt
;
362 val
= eval_sub (XCAR (args
));
371 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
372 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
373 Returns the value of THEN or the value of the last of the ELSE's.
374 THEN must be one expression, but ELSE... can be zero or more expressions.
375 If COND yields nil, and there are no ELSE's, the value is nil.
376 usage: (if COND THEN ELSE...) */)
381 cond
= eval_sub (XCAR (args
));
384 return eval_sub (Fcar (XCDR (args
)));
385 return Fprogn (XCDR (XCDR (args
)));
388 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
389 doc
: /* Try each clause until one succeeds.
390 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
391 and, if the value is non-nil, this clause succeeds:
392 then the expressions in BODY are evaluated and the last one's
393 value is the value of the cond-form.
394 If a clause has one element, as in (CONDITION), then the cond-form
395 returns CONDITION's value, if that is non-nil.
396 If no clause succeeds, cond returns nil.
397 usage: (cond CLAUSES...) */)
400 Lisp_Object val
= args
;
404 Lisp_Object clause
= XCAR (args
);
405 val
= eval_sub (Fcar (clause
));
408 if (!NILP (XCDR (clause
)))
409 val
= Fprogn (XCDR (clause
));
418 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
419 doc
: /* Eval BODY forms sequentially and return value of last one.
420 usage: (progn BODY...) */)
423 Lisp_Object val
= Qnil
;
427 val
= eval_sub (XCAR (body
));
434 /* Evaluate BODY sequentially, discarding its value. Suitable for
435 record_unwind_protect. */
438 unwind_body (Lisp_Object body
)
443 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
444 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
445 The value of FIRST is saved during the evaluation of the remaining args,
446 whose values are discarded.
447 usage: (prog1 FIRST BODY...) */)
451 Lisp_Object args_left
;
456 val
= eval_sub (XCAR (args_left
));
457 while (CONSP (args_left
= XCDR (args_left
)))
458 eval_sub (XCAR (args_left
));
463 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
464 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
465 The value of FORM2 is saved during the evaluation of the
466 remaining args, whose values are discarded.
467 usage: (prog2 FORM1 FORM2 BODY...) */)
470 eval_sub (XCAR (args
));
471 return Fprog1 (XCDR (args
));
474 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
475 doc
: /* Set each SYM to the value of its VAL.
476 The symbols SYM are variables; they are literal (not evaluated).
477 The values VAL are expressions; they are evaluated.
478 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
479 The second VAL is not computed until after the first SYM is set, and so on;
480 each VAL can use the new value of variables set earlier in the `setq'.
481 The return value of the `setq' form is the value of the last VAL.
482 usage: (setq [SYM VAL]...) */)
485 Lisp_Object val
, sym
, lex_binding
;
490 Lisp_Object args_left
= args
;
494 val
= eval_sub (Fcar (XCDR (args_left
)));
495 sym
= XCAR (args_left
);
497 /* Like for eval_sub, we do not check declared_special here since
498 it's been done when let-binding. */
499 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
501 && !NILP (lex_binding
502 = Fassq (sym
, Vinternal_interpreter_environment
)))
503 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
505 Fset (sym
, val
); /* SYM is dynamically bound. */
507 args_left
= Fcdr (XCDR (args_left
));
509 while (CONSP (args_left
));
515 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
516 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
517 Warning: `quote' does not construct its return value, but just returns
518 the value that was pre-constructed by the Lisp reader (see info node
519 `(elisp)Printed Representation').
520 This means that \\='(a . b) is not identical to (cons \\='a \\='b): the former
521 does not cons. Quoting should be reserved for constants that will
522 never be modified by side-effects, unless you like self-modifying code.
523 See the common pitfall in info node `(elisp)Rearrangement' for an example
524 of unexpected results when a quoted object is modified.
525 usage: (quote ARG) */)
528 if (CONSP (XCDR (args
)))
529 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
533 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
534 doc
: /* Like `quote', but preferred for objects which are functions.
535 In byte compilation, `function' causes its argument to be compiled.
536 `quote' cannot do that.
537 usage: (function ARG) */)
540 Lisp_Object quoted
= XCAR (args
);
542 if (CONSP (XCDR (args
)))
543 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
545 if (!NILP (Vinternal_interpreter_environment
)
547 && EQ (XCAR (quoted
), Qlambda
))
548 { /* This is a lambda expression within a lexical environment;
549 return an interpreted closure instead of a simple lambda. */
550 Lisp_Object cdr
= XCDR (quoted
);
551 Lisp_Object tmp
= cdr
;
553 && (tmp
= XCDR (tmp
), CONSP (tmp
))
554 && (tmp
= XCAR (tmp
), CONSP (tmp
))
555 && (EQ (QCdocumentation
, XCAR (tmp
))))
556 { /* Handle the special (:documentation <form>) to build the docstring
558 Lisp_Object docstring
= eval_sub (Fcar (XCDR (tmp
)));
559 CHECK_STRING (docstring
);
560 cdr
= Fcons (XCAR (cdr
), Fcons (docstring
, XCDR (XCDR (cdr
))));
562 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
,
566 /* Simply quote the argument. */
571 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
572 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
573 Aliased variables always have the same value; setting one sets the other.
574 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
575 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
576 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
577 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
578 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
579 The return value is BASE-VARIABLE. */)
580 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
582 struct Lisp_Symbol
*sym
;
584 CHECK_SYMBOL (new_alias
);
585 CHECK_SYMBOL (base_variable
);
587 sym
= XSYMBOL (new_alias
);
590 /* Not sure why, but why not? */
591 error ("Cannot make a constant an alias");
593 switch (sym
->redirect
)
595 case SYMBOL_FORWARDED
:
596 error ("Cannot make an internal variable an alias");
597 case SYMBOL_LOCALIZED
:
598 error ("Don't know how to make a localized variable an alias");
599 case SYMBOL_PLAINVAL
:
600 case SYMBOL_VARALIAS
:
606 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
607 If n_a is bound, but b_v is not, set the value of b_v to n_a,
608 so that old-code that affects n_a before the aliasing is setup
610 if (NILP (Fboundp (base_variable
)))
611 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
614 union specbinding
*p
;
616 for (p
= specpdl_ptr
; p
> specpdl
; )
617 if ((--p
)->kind
>= SPECPDL_LET
618 && (EQ (new_alias
, specpdl_symbol (p
))))
619 error ("Don't know how to make a let-bound variable an alias");
622 sym
->declared_special
= 1;
623 XSYMBOL (base_variable
)->declared_special
= 1;
624 sym
->redirect
= SYMBOL_VARALIAS
;
625 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
626 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
627 LOADHIST_ATTACH (new_alias
);
628 /* Even if docstring is nil: remove old docstring. */
629 Fput (new_alias
, Qvariable_documentation
, docstring
);
631 return base_variable
;
634 static union specbinding
*
635 default_toplevel_binding (Lisp_Object symbol
)
637 union specbinding
*binding
= NULL
;
638 union specbinding
*pdl
= specpdl_ptr
;
639 while (pdl
> specpdl
)
641 switch ((--pdl
)->kind
)
643 case SPECPDL_LET_DEFAULT
:
645 if (EQ (specpdl_symbol (pdl
), symbol
))
650 case SPECPDL_UNWIND_PTR
:
651 case SPECPDL_UNWIND_INT
:
652 case SPECPDL_UNWIND_VOID
:
653 case SPECPDL_BACKTRACE
:
654 case SPECPDL_LET_LOCAL
:
664 DEFUN ("default-toplevel-value", Fdefault_toplevel_value
, Sdefault_toplevel_value
, 1, 1, 0,
665 doc
: /* Return SYMBOL's toplevel default value.
666 "Toplevel" means outside of any let binding. */)
669 union specbinding
*binding
= default_toplevel_binding (symbol
);
671 = binding
? specpdl_old_value (binding
) : Fdefault_value (symbol
);
672 if (!EQ (value
, Qunbound
))
674 xsignal1 (Qvoid_variable
, symbol
);
677 DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value
,
678 Sset_default_toplevel_value
, 2, 2, 0,
679 doc
: /* Set SYMBOL's toplevel default value to VALUE.
680 "Toplevel" means outside of any let binding. */)
681 (Lisp_Object symbol
, Lisp_Object value
)
683 union specbinding
*binding
= default_toplevel_binding (symbol
);
685 set_specpdl_old_value (binding
, value
);
687 Fset_default (symbol
, value
);
691 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
692 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
693 You are not required to define a variable in order to use it, but
694 defining it lets you supply an initial value and documentation, which
695 can be referred to by the Emacs help facilities and other programming
696 tools. The `defvar' form also declares the variable as \"special\",
697 so that it is always dynamically bound even if `lexical-binding' is t.
699 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
700 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
701 default value is what is set; buffer-local values are not affected.
702 If INITVALUE is missing, SYMBOL's value is not set.
704 If SYMBOL has a local binding, then this form affects the local
705 binding. This is usually not what you want. Thus, if you need to
706 load a file defining variables, with this form or with `defconst' or
707 `defcustom', you should always load that file _outside_ any bindings
708 for these variables. (`defconst' and `defcustom' behave similarly in
711 The optional argument DOCSTRING is a documentation string for the
714 To define a user option, use `defcustom' instead of `defvar'.
715 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
718 Lisp_Object sym
, tem
, tail
;
725 if (CONSP (XCDR (tail
)) && CONSP (XCDR (XCDR (tail
))))
726 error ("Too many arguments");
728 tem
= Fdefault_boundp (sym
);
730 /* Do it before evaluating the initial value, for self-references. */
731 XSYMBOL (sym
)->declared_special
= 1;
734 Fset_default (sym
, eval_sub (XCAR (tail
)));
736 { /* Check if there is really a global binding rather than just a let
737 binding that shadows the global unboundness of the var. */
738 union specbinding
*binding
= default_toplevel_binding (sym
);
739 if (binding
&& EQ (specpdl_old_value (binding
), Qunbound
))
741 set_specpdl_old_value (binding
, eval_sub (XCAR (tail
)));
748 if (!NILP (Vpurify_flag
))
749 tem
= Fpurecopy (tem
);
750 Fput (sym
, Qvariable_documentation
, tem
);
752 LOADHIST_ATTACH (sym
);
754 else if (!NILP (Vinternal_interpreter_environment
)
755 && !XSYMBOL (sym
)->declared_special
)
756 /* A simple (defvar foo) with lexical scoping does "nothing" except
757 declare that var to be dynamically scoped *locally* (i.e. within
758 the current file or let-block). */
759 Vinternal_interpreter_environment
760 = Fcons (sym
, Vinternal_interpreter_environment
);
763 /* Simple (defvar <var>) should not count as a definition at all.
764 It could get in the way of other definitions, and unloading this
765 package could try to make the variable unbound. */
771 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
772 doc
: /* Define SYMBOL as a constant variable.
773 This declares that neither programs nor users should ever change the
774 value. This constancy is not actually enforced by Emacs Lisp, but
775 SYMBOL is marked as a special variable so that it is never lexically
778 The `defconst' form always sets the value of SYMBOL to the result of
779 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
780 what is set; buffer-local values are not affected. If SYMBOL has a
781 local binding, then this form sets the local binding's value.
782 However, you should normally not make local bindings for variables
783 defined with this form.
785 The optional DOCSTRING specifies the variable's documentation string.
786 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
789 Lisp_Object sym
, tem
;
792 if (CONSP (Fcdr (XCDR (XCDR (args
)))))
793 error ("Too many arguments");
795 tem
= eval_sub (Fcar (XCDR (args
)));
796 if (!NILP (Vpurify_flag
))
797 tem
= Fpurecopy (tem
);
798 Fset_default (sym
, tem
);
799 XSYMBOL (sym
)->declared_special
= 1;
800 tem
= Fcar (XCDR (XCDR (args
)));
803 if (!NILP (Vpurify_flag
))
804 tem
= Fpurecopy (tem
);
805 Fput (sym
, Qvariable_documentation
, tem
);
807 Fput (sym
, Qrisky_local_variable
, Qt
);
808 LOADHIST_ATTACH (sym
);
812 /* Make SYMBOL lexically scoped. */
813 DEFUN ("internal-make-var-non-special", Fmake_var_non_special
,
814 Smake_var_non_special
, 1, 1, 0,
815 doc
: /* Internal function. */)
818 CHECK_SYMBOL (symbol
);
819 XSYMBOL (symbol
)->declared_special
= 0;
824 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
825 doc
: /* Bind variables according to VARLIST then eval BODY.
826 The value of the last form in BODY is returned.
827 Each element of VARLIST is a symbol (which is bound to nil)
828 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
829 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
830 usage: (let* VARLIST BODY...) */)
833 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
834 ptrdiff_t count
= SPECPDL_INDEX ();
836 lexenv
= Vinternal_interpreter_environment
;
838 varlist
= XCAR (args
);
839 while (CONSP (varlist
))
843 elt
= XCAR (varlist
);
849 else if (! NILP (Fcdr (Fcdr (elt
))))
850 signal_error ("`let' bindings can have only one value-form", elt
);
854 val
= eval_sub (Fcar (Fcdr (elt
)));
857 if (!NILP (lexenv
) && SYMBOLP (var
)
858 && !XSYMBOL (var
)->declared_special
859 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
860 /* Lexically bind VAR by adding it to the interpreter's binding
864 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
865 if (EQ (Vinternal_interpreter_environment
, lexenv
))
866 /* Save the old lexical environment on the specpdl stack,
867 but only for the first lexical binding, since we'll never
868 need to revert to one of the intermediate ones. */
869 specbind (Qinternal_interpreter_environment
, newenv
);
871 Vinternal_interpreter_environment
= newenv
;
876 varlist
= XCDR (varlist
);
879 val
= Fprogn (XCDR (args
));
880 return unbind_to (count
, val
);
883 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
884 doc
: /* Bind variables according to VARLIST then eval BODY.
885 The value of the last form in BODY is returned.
886 Each element of VARLIST is a symbol (which is bound to nil)
887 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
888 All the VALUEFORMs are evalled before any symbols are bound.
889 usage: (let VARLIST BODY...) */)
892 Lisp_Object
*temps
, tem
, lexenv
;
893 Lisp_Object elt
, varlist
;
894 ptrdiff_t count
= SPECPDL_INDEX ();
898 varlist
= XCAR (args
);
900 /* Make space to hold the values to give the bound variables. */
901 elt
= Flength (varlist
);
902 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
904 /* Compute the values and store them in `temps'. */
906 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
909 elt
= XCAR (varlist
);
911 temps
[argnum
++] = Qnil
;
912 else if (! NILP (Fcdr (Fcdr (elt
))))
913 signal_error ("`let' bindings can have only one value-form", elt
);
915 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
918 lexenv
= Vinternal_interpreter_environment
;
920 varlist
= XCAR (args
);
921 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
925 elt
= XCAR (varlist
);
926 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
927 tem
= temps
[argnum
++];
929 if (!NILP (lexenv
) && SYMBOLP (var
)
930 && !XSYMBOL (var
)->declared_special
931 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
932 /* Lexically bind VAR by adding it to the lexenv alist. */
933 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
935 /* Dynamically bind VAR. */
939 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
940 /* Instantiate a new lexical environment. */
941 specbind (Qinternal_interpreter_environment
, lexenv
);
943 elt
= Fprogn (XCDR (args
));
945 return unbind_to (count
, elt
);
948 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
949 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
950 The order of execution is thus TEST, BODY, TEST, BODY and so on
951 until TEST returns nil.
952 usage: (while TEST BODY...) */)
955 Lisp_Object test
, body
;
959 while (!NILP (eval_sub (test
)))
968 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
969 doc
: /* Return result of expanding macros at top level of FORM.
970 If FORM is not a macro call, it is returned unchanged.
971 Otherwise, the macro is expanded and the expansion is considered
972 in place of FORM. When a non-macro-call results, it is returned.
974 The second optional arg ENVIRONMENT specifies an environment of macro
975 definitions to shadow the loaded ones for use in file byte-compilation. */)
976 (Lisp_Object form
, Lisp_Object environment
)
978 /* With cleanups from Hallvard Furuseth. */
979 register Lisp_Object expander
, sym
, def
, tem
;
983 /* Come back here each time we expand a macro call,
984 in case it expands into another macro call. */
987 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
988 def
= sym
= XCAR (form
);
990 /* Trace symbols aliases to other symbols
991 until we get a symbol that is not an alias. */
992 while (SYMBOLP (def
))
996 tem
= Fassq (sym
, environment
);
999 def
= XSYMBOL (sym
)->function
;
1005 /* Right now TEM is the result from SYM in ENVIRONMENT,
1006 and if TEM is nil then DEF is SYM's function definition. */
1009 /* SYM is not mentioned in ENVIRONMENT.
1010 Look at its function definition. */
1011 def
= Fautoload_do_load (def
, sym
, Qmacro
);
1013 /* Not defined or definition not suitable. */
1015 if (!EQ (XCAR (def
), Qmacro
))
1017 else expander
= XCDR (def
);
1021 expander
= XCDR (tem
);
1022 if (NILP (expander
))
1026 Lisp_Object newform
= apply1 (expander
, XCDR (form
));
1027 if (EQ (form
, newform
))
1036 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1037 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1038 TAG is evalled to get the tag to use; it must not be nil.
1040 Then the BODY is executed.
1041 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1042 If no throw happens, `catch' returns the value of the last BODY form.
1043 If a throw happens, it specifies the value to return from `catch'.
1044 usage: (catch TAG BODY...) */)
1047 Lisp_Object tag
= eval_sub (XCAR (args
));
1048 return internal_catch (tag
, Fprogn
, XCDR (args
));
1051 /* Assert that E is true, as a comment only. Use this instead of
1052 eassert (E) when E contains variables that might be clobbered by a
1055 #define clobbered_eassert(E) ((void) 0)
1057 /* Set up a catch, then call C function FUNC on argument ARG.
1058 FUNC should return a Lisp_Object.
1059 This is how catches are done from within C code. */
1062 internal_catch (Lisp_Object tag
, Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1064 /* This structure is made part of the chain `catchlist'. */
1067 /* Fill in the components of c, and put it on the list. */
1068 PUSH_HANDLER (c
, tag
, CATCHER
);
1071 if (! sys_setjmp (c
->jmp
))
1073 Lisp_Object val
= (*func
) (arg
);
1074 clobbered_eassert (handlerlist
== c
);
1075 handlerlist
= handlerlist
->next
;
1079 { /* Throw works by a longjmp that comes right here. */
1080 Lisp_Object val
= handlerlist
->val
;
1081 clobbered_eassert (handlerlist
== c
);
1082 handlerlist
= handlerlist
->next
;
1087 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1088 jump to that CATCH, returning VALUE as the value of that catch.
1090 This is the guts of Fthrow and Fsignal; they differ only in the way
1091 they choose the catch tag to throw to. A catch tag for a
1092 condition-case form has a TAG of Qnil.
1094 Before each catch is discarded, unbind all special bindings and
1095 execute all unwind-protect clauses made above that catch. Unwind
1096 the handler stack as we go, so that the proper handlers are in
1097 effect for each unwind-protect clause we run. At the end, restore
1098 some static info saved in CATCH, and longjmp to the location
1101 This is used for correct unwinding in Fthrow and Fsignal. */
1103 static _Noreturn
void
1104 unwind_to_catch (struct handler
*catch, Lisp_Object value
)
1108 eassert (catch->next
);
1110 /* Save the value in the tag. */
1113 /* Restore certain special C variables. */
1114 set_poll_suppress_count (catch->poll_suppress_count
);
1115 unblock_input_to (catch->interrupt_input_blocked
);
1120 /* Unwind the specpdl stack, and then restore the proper set of
1122 unbind_to (handlerlist
->pdlcount
, Qnil
);
1123 last_time
= handlerlist
== catch;
1125 handlerlist
= handlerlist
->next
;
1127 while (! last_time
);
1129 eassert (handlerlist
== catch);
1131 byte_stack_list
= catch->byte_stack
;
1132 lisp_eval_depth
= catch->lisp_eval_depth
;
1134 sys_longjmp (catch->jmp
, 1);
1137 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1138 doc
: /* Throw to the catch for TAG and return VALUE from it.
1139 Both TAG and VALUE are evalled. */
1140 attributes
: noreturn
)
1141 (register Lisp_Object tag
, Lisp_Object value
)
1146 for (c
= handlerlist
; c
; c
= c
->next
)
1148 if (c
->type
== CATCHER_ALL
)
1149 unwind_to_catch (c
, Fcons (tag
, value
));
1150 if (c
->type
== CATCHER
&& EQ (c
->tag_or_ch
, tag
))
1151 unwind_to_catch (c
, value
);
1153 xsignal2 (Qno_catch
, tag
, value
);
1157 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1158 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1159 If BODYFORM completes normally, its value is returned
1160 after executing the UNWINDFORMS.
1161 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1162 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1166 ptrdiff_t count
= SPECPDL_INDEX ();
1168 record_unwind_protect (unwind_body
, XCDR (args
));
1169 val
= eval_sub (XCAR (args
));
1170 return unbind_to (count
, val
);
1173 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1174 doc
: /* Regain control when an error is signaled.
1175 Executes BODYFORM and returns its value if no error happens.
1176 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1177 where the BODY is made of Lisp expressions.
1179 A handler is applicable to an error
1180 if CONDITION-NAME is one of the error's condition names.
1181 If an error happens, the first applicable handler is run.
1183 The car of a handler may be a list of condition names instead of a
1184 single condition name; then it handles all of them. If the special
1185 condition name `debug' is present in this list, it allows another
1186 condition in the list to run the debugger if `debug-on-error' and the
1187 other usual mechanisms says it should (otherwise, `condition-case'
1188 suppresses the debugger).
1190 When a handler handles an error, control returns to the `condition-case'
1191 and it executes the handler's BODY...
1192 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1193 (If VAR is nil, the handler can't access that information.)
1194 Then the value of the last BODY form is returned from the `condition-case'
1197 See also the function `signal' for more info.
1198 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1201 Lisp_Object var
= XCAR (args
);
1202 Lisp_Object bodyform
= XCAR (XCDR (args
));
1203 Lisp_Object handlers
= XCDR (XCDR (args
));
1205 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1208 /* Like Fcondition_case, but the args are separate
1209 rather than passed in a list. Used by Fbyte_code. */
1212 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1213 Lisp_Object handlers
)
1217 struct handler
*oldhandlerlist
= handlerlist
;
1222 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1224 Lisp_Object tem
= XCAR (val
);
1228 && (SYMBOLP (XCAR (tem
))
1229 || CONSP (XCAR (tem
))))))
1230 error ("Invalid condition handler: %s",
1231 SDATA (Fprin1_to_string (tem
, Qt
)));
1234 { /* The first clause is the one that should be checked first, so it should
1235 be added to handlerlist last. So we build in `clauses' a table that
1236 contains `handlers' but in reverse order. SAFE_ALLOCA won't work
1237 here due to the setjmp, so impose a MAX_ALLOCA limit. */
1238 if (MAX_ALLOCA
/ word_size
< clausenb
)
1239 memory_full (SIZE_MAX
);
1240 Lisp_Object
*clauses
= alloca (clausenb
* sizeof *clauses
);
1241 Lisp_Object
*volatile clauses_volatile
= clauses
;
1243 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1244 clauses
[--i
] = XCAR (val
);
1245 for (i
= 0; i
< clausenb
; i
++)
1247 Lisp_Object clause
= clauses
[i
];
1248 Lisp_Object condition
= XCAR (clause
);
1249 if (!CONSP (condition
))
1250 condition
= Fcons (condition
, Qnil
);
1251 PUSH_HANDLER (c
, condition
, CONDITION_CASE
);
1252 if (sys_setjmp (c
->jmp
))
1254 ptrdiff_t count
= SPECPDL_INDEX ();
1255 Lisp_Object val
= handlerlist
->val
;
1256 Lisp_Object
*chosen_clause
= clauses_volatile
;
1257 for (c
= handlerlist
->next
; c
!= oldhandlerlist
; c
= c
->next
)
1259 handlerlist
= oldhandlerlist
;
1262 if (!NILP (Vinternal_interpreter_environment
))
1263 specbind (Qinternal_interpreter_environment
,
1264 Fcons (Fcons (var
, val
),
1265 Vinternal_interpreter_environment
));
1267 specbind (var
, val
);
1269 val
= Fprogn (XCDR (*chosen_clause
));
1270 /* Note that this just undoes the binding of var; whoever
1271 longjumped to us unwound the stack to c.pdlcount before
1274 unbind_to (count
, Qnil
);
1280 val
= eval_sub (bodyform
);
1281 handlerlist
= oldhandlerlist
;
1285 /* Call the function BFUN with no arguments, catching errors within it
1286 according to HANDLERS. If there is an error, call HFUN with
1287 one argument which is the data that describes the error:
1290 HANDLERS can be a list of conditions to catch.
1291 If HANDLERS is Qt, catch all errors.
1292 If HANDLERS is Qerror, catch all errors
1293 but allow the debugger to run if that is enabled. */
1296 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1297 Lisp_Object (*hfun
) (Lisp_Object
))
1302 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1303 if (sys_setjmp (c
->jmp
))
1305 Lisp_Object val
= handlerlist
->val
;
1306 clobbered_eassert (handlerlist
== c
);
1307 handlerlist
= handlerlist
->next
;
1308 return (*hfun
) (val
);
1312 clobbered_eassert (handlerlist
== c
);
1313 handlerlist
= handlerlist
->next
;
1317 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1320 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1321 Lisp_Object handlers
, Lisp_Object (*hfun
) (Lisp_Object
))
1326 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1327 if (sys_setjmp (c
->jmp
))
1329 Lisp_Object val
= handlerlist
->val
;
1330 clobbered_eassert (handlerlist
== c
);
1331 handlerlist
= handlerlist
->next
;
1332 return (*hfun
) (val
);
1335 val
= (*bfun
) (arg
);
1336 clobbered_eassert (handlerlist
== c
);
1337 handlerlist
= handlerlist
->next
;
1341 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1345 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1348 Lisp_Object handlers
,
1349 Lisp_Object (*hfun
) (Lisp_Object
))
1354 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1355 if (sys_setjmp (c
->jmp
))
1357 Lisp_Object val
= handlerlist
->val
;
1358 clobbered_eassert (handlerlist
== c
);
1359 handlerlist
= handlerlist
->next
;
1360 return (*hfun
) (val
);
1363 val
= (*bfun
) (arg1
, arg2
);
1364 clobbered_eassert (handlerlist
== c
);
1365 handlerlist
= handlerlist
->next
;
1369 /* Like internal_condition_case but call BFUN with NARGS as first,
1370 and ARGS as second argument. */
1373 internal_condition_case_n (Lisp_Object (*bfun
) (ptrdiff_t, Lisp_Object
*),
1376 Lisp_Object handlers
,
1377 Lisp_Object (*hfun
) (Lisp_Object err
,
1384 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1385 if (sys_setjmp (c
->jmp
))
1387 Lisp_Object val
= handlerlist
->val
;
1388 clobbered_eassert (handlerlist
== c
);
1389 handlerlist
= handlerlist
->next
;
1390 return (*hfun
) (val
, nargs
, args
);
1393 val
= (*bfun
) (nargs
, args
);
1394 clobbered_eassert (handlerlist
== c
);
1395 handlerlist
= handlerlist
->next
;
1399 static void init_handler (struct handler
*c
, Lisp_Object tag_ch_val
,
1400 enum handlertype handlertype
);
1403 push_handler (struct handler
**c
, Lisp_Object tag_ch_val
,
1404 enum handlertype handlertype
)
1406 if (handlerlist
->nextfree
)
1407 *c
= handlerlist
->nextfree
;
1410 *c
= xmalloc (sizeof (struct handler
));
1411 (*c
)->nextfree
= NULL
;
1412 handlerlist
->nextfree
= *c
;
1414 init_handler (*c
, tag_ch_val
, handlertype
);
1418 push_handler_nosignal (struct handler
**c
, Lisp_Object tag_ch_val
,
1419 enum handlertype handlertype
)
1421 if (handlerlist
->nextfree
)
1422 *c
= handlerlist
->nextfree
;
1425 struct handler
*h
= malloc (sizeof (struct handler
));
1426 if (! h
) return false;
1429 handlerlist
->nextfree
= h
;
1431 init_handler (*c
, tag_ch_val
, handlertype
);
1436 init_handler (struct handler
*c
, Lisp_Object tag_ch_val
,
1437 enum handlertype handlertype
)
1439 c
->type
= handlertype
;
1440 c
->tag_or_ch
= tag_ch_val
;
1442 c
->next
= handlerlist
;
1443 c
->lisp_eval_depth
= lisp_eval_depth
;
1444 c
->pdlcount
= SPECPDL_INDEX ();
1445 c
->poll_suppress_count
= poll_suppress_count
;
1446 c
->interrupt_input_blocked
= interrupt_input_blocked
;
1447 c
->byte_stack
= byte_stack_list
;
1452 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
);
1453 static bool maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
,
1457 process_quit_flag (void)
1459 Lisp_Object flag
= Vquit_flag
;
1461 if (EQ (flag
, Qkill_emacs
))
1463 if (EQ (Vthrow_on_input
, flag
))
1464 Fthrow (Vthrow_on_input
, Qt
);
1465 Fsignal (Qquit
, Qnil
);
1468 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1469 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1470 This function does not return.
1472 An error symbol is a symbol with an `error-conditions' property
1473 that is a list of condition names.
1474 A handler for any of those names will get to handle this signal.
1475 The symbol `error' should normally be one of them.
1477 DATA should be a list. Its elements are printed as part of the error message.
1478 See Info anchor `(elisp)Definition of signal' for some details on how this
1479 error message is constructed.
1480 If the signal is handled, DATA is made available to the handler.
1481 See also the function `condition-case'. */)
1482 (Lisp_Object error_symbol
, Lisp_Object data
)
1484 /* When memory is full, ERROR-SYMBOL is nil,
1485 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1486 That is a special case--don't do this in other situations. */
1487 Lisp_Object conditions
;
1489 Lisp_Object real_error_symbol
1490 = (NILP (error_symbol
) ? Fcar (data
) : error_symbol
);
1491 register Lisp_Object clause
= Qnil
;
1496 if (gc_in_progress
|| waiting_for_input
)
1499 #if 0 /* rms: I don't know why this was here,
1500 but it is surely wrong for an error that is handled. */
1501 #ifdef HAVE_WINDOW_SYSTEM
1502 if (display_hourglass_p
)
1503 cancel_hourglass ();
1507 /* This hook is used by edebug. */
1508 if (! NILP (Vsignal_hook_function
)
1509 && ! NILP (error_symbol
))
1511 /* Edebug takes care of restoring these variables when it exits. */
1512 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1513 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1515 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1516 max_specpdl_size
= SPECPDL_INDEX () + 40;
1518 call2 (Vsignal_hook_function
, error_symbol
, data
);
1521 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1523 /* Remember from where signal was called. Skip over the frame for
1524 `signal' itself. If a frame for `error' follows, skip that,
1525 too. Don't do this when ERROR_SYMBOL is nil, because that
1526 is a memory-full error. */
1527 Vsignaling_function
= Qnil
;
1528 if (!NILP (error_symbol
))
1530 union specbinding
*pdl
= backtrace_next (backtrace_top ());
1531 if (backtrace_p (pdl
) && EQ (backtrace_function (pdl
), Qerror
))
1532 pdl
= backtrace_next (pdl
);
1533 if (backtrace_p (pdl
))
1534 Vsignaling_function
= backtrace_function (pdl
);
1537 for (h
= handlerlist
; h
; h
= h
->next
)
1539 if (h
->type
!= CONDITION_CASE
)
1541 clause
= find_handler_clause (h
->tag_or_ch
, conditions
);
1546 if (/* Don't run the debugger for a memory-full error.
1547 (There is no room in memory to do that!) */
1548 !NILP (error_symbol
)
1549 && (!NILP (Vdebug_on_signal
)
1550 /* If no handler is present now, try to run the debugger. */
1552 /* A `debug' symbol in the handler list disables the normal
1553 suppression of the debugger. */
1554 || (CONSP (clause
) && !NILP (Fmemq (Qdebug
, clause
)))
1555 /* Special handler that means "print a message and run debugger
1557 || EQ (h
->tag_or_ch
, Qerror
)))
1559 bool debugger_called
1560 = maybe_call_debugger (conditions
, error_symbol
, data
);
1561 /* We can't return values to code which signaled an error, but we
1562 can continue code which has signaled a quit. */
1563 if (debugger_called
&& EQ (real_error_symbol
, Qquit
))
1569 Lisp_Object unwind_data
1570 = (NILP (error_symbol
) ? data
: Fcons (error_symbol
, data
));
1572 unwind_to_catch (h
, unwind_data
);
1576 if (handlerlist
!= &handlerlist_sentinel
)
1577 /* FIXME: This will come right back here if there's no `top-level'
1578 catcher. A better solution would be to abort here, and instead
1579 add a catch-all condition handler so we never come here. */
1580 Fthrow (Qtop_level
, Qt
);
1583 if (! NILP (error_symbol
))
1584 data
= Fcons (error_symbol
, data
);
1586 string
= Ferror_message_string (data
);
1587 fatal ("%s", SDATA (string
));
1590 /* Internal version of Fsignal that never returns.
1591 Used for anything but Qquit (which can return from Fsignal). */
1594 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1596 Fsignal (error_symbol
, data
);
1600 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1603 xsignal0 (Lisp_Object error_symbol
)
1605 xsignal (error_symbol
, Qnil
);
1609 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1611 xsignal (error_symbol
, list1 (arg
));
1615 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1617 xsignal (error_symbol
, list2 (arg1
, arg2
));
1621 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1623 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1626 /* Signal `error' with message S, and additional arg ARG.
1627 If ARG is not a genuine list, make it a one-element list. */
1630 signal_error (const char *s
, Lisp_Object arg
)
1632 Lisp_Object tortoise
, hare
;
1634 hare
= tortoise
= arg
;
1635 while (CONSP (hare
))
1642 tortoise
= XCDR (tortoise
);
1644 if (EQ (hare
, tortoise
))
1651 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1655 /* Return true if LIST is a non-nil atom or
1656 a list containing one of CONDITIONS. */
1659 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1666 while (CONSP (conditions
))
1668 Lisp_Object
this, tail
;
1669 this = XCAR (conditions
);
1670 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1671 if (EQ (XCAR (tail
), this))
1673 conditions
= XCDR (conditions
);
1678 /* Return true if an error with condition-symbols CONDITIONS,
1679 and described by SIGNAL-DATA, should skip the debugger
1680 according to debugger-ignored-errors. */
1683 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1686 bool first_string
= 1;
1687 Lisp_Object error_message
;
1689 error_message
= Qnil
;
1690 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1692 if (STRINGP (XCAR (tail
)))
1696 error_message
= Ferror_message_string (data
);
1700 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1705 Lisp_Object contail
;
1707 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1708 if (EQ (XCAR (tail
), XCAR (contail
)))
1716 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1717 SIG and DATA describe the signal. There are two ways to pass them:
1718 = SIG is the error symbol, and DATA is the rest of the data.
1719 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1720 This is for memory-full errors only. */
1722 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1724 Lisp_Object combined_data
;
1726 combined_data
= Fcons (sig
, data
);
1729 /* Don't try to run the debugger with interrupts blocked.
1730 The editing loop would return anyway. */
1731 ! input_blocked_p ()
1732 && NILP (Vinhibit_debugger
)
1733 /* Does user want to enter debugger for this kind of error? */
1736 : wants_debugger (Vdebug_on_error
, conditions
))
1737 && ! skip_debugger (conditions
, combined_data
)
1738 /* RMS: What's this for? */
1739 && when_entered_debugger
< num_nonmacro_input_events
)
1741 call_debugger (list2 (Qerror
, combined_data
));
1749 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
)
1751 register Lisp_Object h
;
1753 /* t is used by handlers for all conditions, set up by C code. */
1754 if (EQ (handlers
, Qt
))
1757 /* error is used similarly, but means print an error message
1758 and run the debugger if that is enabled. */
1759 if (EQ (handlers
, Qerror
))
1762 for (h
= handlers
; CONSP (h
); h
= XCDR (h
))
1764 Lisp_Object handler
= XCAR (h
);
1765 if (!NILP (Fmemq (handler
, conditions
)))
1773 /* Dump an error message; called like vprintf. */
1775 verror (const char *m
, va_list ap
)
1778 ptrdiff_t size
= sizeof buf
;
1779 ptrdiff_t size_max
= STRING_BYTES_BOUND
+ 1;
1784 used
= evxprintf (&buffer
, &size
, buf
, size_max
, m
, ap
);
1785 string
= make_string (buffer
, used
);
1789 xsignal1 (Qerror
, string
);
1793 /* Dump an error message; called like printf. */
1797 error (const char *m
, ...)
1804 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1805 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1806 This means it contains a description for how to read arguments to give it.
1807 The value is nil for an invalid function or a symbol with no function
1810 Interactively callable functions include strings and vectors (treated
1811 as keyboard macros), lambda-expressions that contain a top-level call
1812 to `interactive', autoload definitions made by `autoload' with non-nil
1813 fourth argument, and some of the built-in functions of Lisp.
1815 Also, a symbol satisfies `commandp' if its function definition does so.
1817 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1818 then strings and vectors are not accepted. */)
1819 (Lisp_Object function
, Lisp_Object for_call_interactively
)
1821 register Lisp_Object fun
;
1822 register Lisp_Object funcar
;
1823 Lisp_Object if_prop
= Qnil
;
1827 fun
= indirect_function (fun
); /* Check cycles. */
1831 /* Check an `interactive-form' property if present, analogous to the
1832 function-documentation property. */
1834 while (SYMBOLP (fun
))
1836 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
1839 fun
= Fsymbol_function (fun
);
1842 /* Emacs primitives are interactive if their DEFUN specifies an
1843 interactive spec. */
1845 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
1847 /* Bytecode objects are interactive if they are long enough to
1848 have an element whose index is COMPILED_INTERACTIVE, which is
1849 where the interactive spec is stored. */
1850 else if (COMPILEDP (fun
))
1851 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1854 /* Strings and vectors are keyboard macros. */
1855 if (STRINGP (fun
) || VECTORP (fun
))
1856 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
1858 /* Lists may represent commands. */
1861 funcar
= XCAR (fun
);
1862 if (EQ (funcar
, Qclosure
))
1863 return (!NILP (Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
)))))
1865 else if (EQ (funcar
, Qlambda
))
1866 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
1867 else if (EQ (funcar
, Qautoload
))
1868 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
1873 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1874 doc
: /* Define FUNCTION to autoload from FILE.
1875 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1876 Third arg DOCSTRING is documentation for the function.
1877 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1878 Fifth arg TYPE indicates the type of the object:
1879 nil or omitted says FUNCTION is a function,
1880 `keymap' says FUNCTION is really a keymap, and
1881 `macro' or t says FUNCTION is really a macro.
1882 Third through fifth args give info about the real definition.
1883 They default to nil.
1884 If FUNCTION is already defined other than as an autoload,
1885 this does nothing and returns nil. */)
1886 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
1888 CHECK_SYMBOL (function
);
1889 CHECK_STRING (file
);
1891 /* If function is defined and not as an autoload, don't override. */
1892 if (!NILP (XSYMBOL (function
)->function
)
1893 && !AUTOLOADP (XSYMBOL (function
)->function
))
1896 if (!NILP (Vpurify_flag
) && EQ (docstring
, make_number (0)))
1897 /* `read1' in lread.c has found the docstring starting with "\
1898 and assumed the docstring will be provided by Snarf-documentation, so it
1899 passed us 0 instead. But that leads to accidental sharing in purecopy's
1900 hash-consing, so we use a (hopefully) unique integer instead. */
1901 docstring
= make_number (XHASH (function
));
1902 return Fdefalias (function
,
1903 list5 (Qautoload
, file
, docstring
, interactive
, type
),
1908 un_autoload (Lisp_Object oldqueue
)
1910 Lisp_Object queue
, first
, second
;
1912 /* Queue to unwind is current value of Vautoload_queue.
1913 oldqueue is the shadowed value to leave in Vautoload_queue. */
1914 queue
= Vautoload_queue
;
1915 Vautoload_queue
= oldqueue
;
1916 while (CONSP (queue
))
1918 first
= XCAR (queue
);
1919 second
= Fcdr (first
);
1920 first
= Fcar (first
);
1921 if (EQ (first
, make_number (0)))
1924 Ffset (first
, second
);
1925 queue
= XCDR (queue
);
1929 /* Load an autoloaded function.
1930 FUNNAME is the symbol which is the function's name.
1931 FUNDEF is the autoload definition (a list). */
1933 DEFUN ("autoload-do-load", Fautoload_do_load
, Sautoload_do_load
, 1, 3, 0,
1934 doc
: /* Load FUNDEF which should be an autoload.
1935 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1936 in which case the function returns the new autoloaded function value.
1937 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1938 it defines a macro. */)
1939 (Lisp_Object fundef
, Lisp_Object funname
, Lisp_Object macro_only
)
1941 ptrdiff_t count
= SPECPDL_INDEX ();
1943 if (!CONSP (fundef
) || !EQ (Qautoload
, XCAR (fundef
)))
1946 if (EQ (macro_only
, Qmacro
))
1948 Lisp_Object kind
= Fnth (make_number (4), fundef
);
1949 if (! (EQ (kind
, Qt
) || EQ (kind
, Qmacro
)))
1953 /* This is to make sure that loadup.el gives a clear picture
1954 of what files are preloaded and when. */
1955 if (! NILP (Vpurify_flag
))
1956 error ("Attempt to autoload %s while preparing to dump",
1957 SDATA (SYMBOL_NAME (funname
)));
1959 CHECK_SYMBOL (funname
);
1961 /* Preserve the match data. */
1962 record_unwind_save_match_data ();
1964 /* If autoloading gets an error (which includes the error of failing
1965 to define the function being called), we use Vautoload_queue
1966 to undo function definitions and `provide' calls made by
1967 the function. We do this in the specific case of autoloading
1968 because autoloading is not an explicit request "load this file",
1969 but rather a request to "call this function".
1971 The value saved here is to be restored into Vautoload_queue. */
1972 record_unwind_protect (un_autoload
, Vautoload_queue
);
1973 Vautoload_queue
= Qt
;
1974 /* If `macro_only', assume this autoload to be a "best-effort",
1975 so don't signal an error if autoloading fails. */
1976 Fload (Fcar (Fcdr (fundef
)), macro_only
, Qt
, Qnil
, Qt
);
1978 /* Once loading finishes, don't undo it. */
1979 Vautoload_queue
= Qt
;
1980 unbind_to (count
, Qnil
);
1986 Lisp_Object fun
= Findirect_function (funname
, Qnil
);
1988 if (!NILP (Fequal (fun
, fundef
)))
1989 error ("Autoloading failed to define function %s",
1990 SDATA (SYMBOL_NAME (funname
)));
1997 DEFUN ("eval", Feval
, Seval
, 1, 2, 0,
1998 doc
: /* Evaluate FORM and return its value.
1999 If LEXICAL is t, evaluate using lexical scoping.
2000 LEXICAL can also be an actual lexical environment, in the form of an
2001 alist mapping symbols to their value. */)
2002 (Lisp_Object form
, Lisp_Object lexical
)
2004 ptrdiff_t count
= SPECPDL_INDEX ();
2005 specbind (Qinternal_interpreter_environment
,
2006 CONSP (lexical
) || NILP (lexical
) ? lexical
: list1 (Qt
));
2007 return unbind_to (count
, eval_sub (form
));
2010 /* Grow the specpdl stack by one entry.
2011 The caller should have already initialized the entry.
2012 Signal an error on stack overflow.
2014 Make sure that there is always one unused entry past the top of the
2015 stack, so that the just-initialized entry is safely unwound if
2016 memory exhausted and an error is signaled here. Also, allocate a
2017 never-used entry just before the bottom of the stack; sometimes its
2018 address is taken. */
2025 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2027 ptrdiff_t count
= SPECPDL_INDEX ();
2028 ptrdiff_t max_size
= min (max_specpdl_size
, PTRDIFF_MAX
- 1000);
2029 union specbinding
*pdlvec
= specpdl
- 1;
2030 ptrdiff_t pdlvecsize
= specpdl_size
+ 1;
2031 if (max_size
<= specpdl_size
)
2033 if (max_specpdl_size
< 400)
2034 max_size
= max_specpdl_size
= 400;
2035 if (max_size
<= specpdl_size
)
2036 signal_error ("Variable binding depth exceeds max-specpdl-size",
2039 pdlvec
= xpalloc (pdlvec
, &pdlvecsize
, 1, max_size
+ 1, sizeof *specpdl
);
2040 specpdl
= pdlvec
+ 1;
2041 specpdl_size
= pdlvecsize
- 1;
2042 specpdl_ptr
= specpdl
+ count
;
2047 record_in_backtrace (Lisp_Object function
, Lisp_Object
*args
, ptrdiff_t nargs
)
2049 ptrdiff_t count
= SPECPDL_INDEX ();
2051 eassert (nargs
>= UNEVALLED
);
2052 specpdl_ptr
->bt
.kind
= SPECPDL_BACKTRACE
;
2053 specpdl_ptr
->bt
.debug_on_exit
= false;
2054 specpdl_ptr
->bt
.function
= function
;
2055 specpdl_ptr
->bt
.args
= args
;
2056 specpdl_ptr
->bt
.nargs
= nargs
;
2062 /* Eval a sub-expression of the current expression (i.e. in the same
2065 eval_sub (Lisp_Object form
)
2067 Lisp_Object fun
, val
, original_fun
, original_args
;
2071 /* Declare here, as this array may be accessed by call_debugger near
2072 the end of this function. See Bug#21245. */
2073 Lisp_Object argvals
[8];
2077 /* Look up its binding in the lexical environment.
2078 We do not pay attention to the declared_special flag here, since we
2079 already did that when let-binding the variable. */
2080 Lisp_Object lex_binding
2081 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2082 ? Fassq (form
, Vinternal_interpreter_environment
)
2084 if (CONSP (lex_binding
))
2085 return XCDR (lex_binding
);
2087 return Fsymbol_value (form
);
2097 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2099 if (max_lisp_eval_depth
< 100)
2100 max_lisp_eval_depth
= 100;
2101 if (lisp_eval_depth
> max_lisp_eval_depth
)
2102 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2105 original_fun
= XCAR (form
);
2106 original_args
= XCDR (form
);
2108 /* This also protects them from gc. */
2109 count
= record_in_backtrace (original_fun
, &original_args
, UNEVALLED
);
2111 if (debug_on_next_call
)
2112 do_debug_on_call (Qt
, count
);
2114 /* At this point, only original_fun and original_args
2115 have values that will be used below. */
2118 /* Optimize for no indirection. */
2121 fun
= Ffunction (Fcons (fun
, Qnil
));
2122 else if (!NILP (fun
) && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2123 fun
= indirect_function (fun
);
2127 Lisp_Object args_left
= original_args
;
2128 Lisp_Object numargs
= Flength (args_left
);
2132 if (XINT (numargs
) < XSUBR (fun
)->min_args
2133 || (XSUBR (fun
)->max_args
>= 0
2134 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2135 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2137 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2138 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2139 else if (XSUBR (fun
)->max_args
== MANY
)
2141 /* Pass a vector of evaluated arguments. */
2143 ptrdiff_t argnum
= 0;
2146 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2148 while (!NILP (args_left
))
2150 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2151 args_left
= Fcdr (args_left
);
2154 set_backtrace_args (specpdl
+ count
, vals
, XINT (numargs
));
2156 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2160 /* Do the debug-on-exit now, while VALS still exists. */
2161 if (backtrace_debug_on_exit (specpdl
+ count
))
2162 val
= call_debugger (list2 (Qexit
, val
));
2169 int i
, maxargs
= XSUBR (fun
)->max_args
;
2171 for (i
= 0; i
< maxargs
; i
++)
2173 argvals
[i
] = eval_sub (Fcar (args_left
));
2174 args_left
= Fcdr (args_left
);
2177 set_backtrace_args (specpdl
+ count
, argvals
, XINT (numargs
));
2182 val
= (XSUBR (fun
)->function
.a0 ());
2185 val
= (XSUBR (fun
)->function
.a1 (argvals
[0]));
2188 val
= (XSUBR (fun
)->function
.a2 (argvals
[0], argvals
[1]));
2191 val
= (XSUBR (fun
)->function
.a3
2192 (argvals
[0], argvals
[1], argvals
[2]));
2195 val
= (XSUBR (fun
)->function
.a4
2196 (argvals
[0], argvals
[1], argvals
[2], argvals
[3]));
2199 val
= (XSUBR (fun
)->function
.a5
2200 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2204 val
= (XSUBR (fun
)->function
.a6
2205 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2206 argvals
[4], argvals
[5]));
2209 val
= (XSUBR (fun
)->function
.a7
2210 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2211 argvals
[4], argvals
[5], argvals
[6]));
2215 val
= (XSUBR (fun
)->function
.a8
2216 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2217 argvals
[4], argvals
[5], argvals
[6], argvals
[7]));
2221 /* Someone has created a subr that takes more arguments than
2222 is supported by this code. We need to either rewrite the
2223 subr to use a different argument protocol, or add more
2224 cases to this switch. */
2229 else if (COMPILEDP (fun
))
2230 return apply_lambda (fun
, original_args
, count
);
2234 xsignal1 (Qvoid_function
, original_fun
);
2236 xsignal1 (Qinvalid_function
, original_fun
);
2237 funcar
= XCAR (fun
);
2238 if (!SYMBOLP (funcar
))
2239 xsignal1 (Qinvalid_function
, original_fun
);
2240 if (EQ (funcar
, Qautoload
))
2242 Fautoload_do_load (fun
, original_fun
, Qnil
);
2245 if (EQ (funcar
, Qmacro
))
2247 ptrdiff_t count1
= SPECPDL_INDEX ();
2249 /* Bind lexical-binding during expansion of the macro, so the
2250 macro can know reliably if the code it outputs will be
2251 interpreted using lexical-binding or not. */
2252 specbind (Qlexical_binding
,
2253 NILP (Vinternal_interpreter_environment
) ? Qnil
: Qt
);
2254 exp
= apply1 (Fcdr (fun
), original_args
);
2255 unbind_to (count1
, Qnil
);
2256 val
= eval_sub (exp
);
2258 else if (EQ (funcar
, Qlambda
)
2259 || EQ (funcar
, Qclosure
))
2260 return apply_lambda (fun
, original_args
, count
);
2262 xsignal1 (Qinvalid_function
, original_fun
);
2267 if (backtrace_debug_on_exit (specpdl
+ count
))
2268 val
= call_debugger (list2 (Qexit
, val
));
2274 DEFUN ("apply", Fapply
, Sapply
, 1, MANY
, 0,
2275 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2276 Then return the value FUNCTION returns.
2277 Thus, (apply \\='+ 1 2 \\='(3 4)) returns 10.
2278 usage: (apply FUNCTION &rest ARGUMENTS) */)
2279 (ptrdiff_t nargs
, Lisp_Object
*args
)
2281 ptrdiff_t i
, numargs
, funcall_nargs
;
2282 register Lisp_Object
*funcall_args
= NULL
;
2283 register Lisp_Object spread_arg
= args
[nargs
- 1];
2284 Lisp_Object fun
= args
[0];
2288 CHECK_LIST (spread_arg
);
2290 numargs
= XINT (Flength (spread_arg
));
2293 return Ffuncall (nargs
- 1, args
);
2294 else if (numargs
== 1)
2296 args
[nargs
- 1] = XCAR (spread_arg
);
2297 return Ffuncall (nargs
, args
);
2300 numargs
+= nargs
- 2;
2302 /* Optimize for no indirection. */
2303 if (SYMBOLP (fun
) && !NILP (fun
)
2304 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2306 fun
= indirect_function (fun
);
2308 /* Let funcall get the error. */
2312 if (SUBRP (fun
) && XSUBR (fun
)->max_args
> numargs
2313 /* Don't hide an error by adding missing arguments. */
2314 && numargs
>= XSUBR (fun
)->min_args
)
2316 /* Avoid making funcall cons up a yet another new vector of arguments
2317 by explicitly supplying nil's for optional values. */
2318 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2319 memclear (funcall_args
+ numargs
+ 1,
2320 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2321 funcall_nargs
= 1 + XSUBR (fun
)->max_args
;
2324 { /* We add 1 to numargs because funcall_args includes the
2325 function itself as well as its arguments. */
2326 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2327 funcall_nargs
= 1 + numargs
;
2330 memcpy (funcall_args
, args
, nargs
* word_size
);
2331 /* Spread the last arg we got. Its first element goes in
2332 the slot that it used to occupy, hence this value of I. */
2334 while (!NILP (spread_arg
))
2336 funcall_args
[i
++] = XCAR (spread_arg
);
2337 spread_arg
= XCDR (spread_arg
);
2340 retval
= Ffuncall (funcall_nargs
, funcall_args
);
2346 /* Run hook variables in various ways. */
2349 funcall_nil (ptrdiff_t nargs
, Lisp_Object
*args
)
2351 Ffuncall (nargs
, args
);
2355 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2356 doc
: /* Run each hook in HOOKS.
2357 Each argument should be a symbol, a hook variable.
2358 These symbols are processed in the order specified.
2359 If a hook symbol has a non-nil value, that value may be a function
2360 or a list of functions to be called to run the hook.
2361 If the value is a function, it is called with no arguments.
2362 If it is a list, the elements are called, in order, with no arguments.
2364 Major modes should not use this function directly to run their mode
2365 hook; they should use `run-mode-hooks' instead.
2367 Do not use `make-local-variable' to make a hook variable buffer-local.
2368 Instead, use `add-hook' and specify t for the LOCAL argument.
2369 usage: (run-hooks &rest HOOKS) */)
2370 (ptrdiff_t nargs
, Lisp_Object
*args
)
2374 for (i
= 0; i
< nargs
; i
++)
2380 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2381 Srun_hook_with_args
, 1, MANY
, 0,
2382 doc
: /* Run HOOK with the specified arguments ARGS.
2383 HOOK should be a symbol, a hook variable. The value of HOOK
2384 may be nil, a function, or a list of functions. Call each
2385 function in order with arguments ARGS. The final return value
2388 Do not use `make-local-variable' to make a hook variable buffer-local.
2389 Instead, use `add-hook' and specify t for the LOCAL argument.
2390 usage: (run-hook-with-args HOOK &rest ARGS) */)
2391 (ptrdiff_t nargs
, Lisp_Object
*args
)
2393 return run_hook_with_args (nargs
, args
, funcall_nil
);
2396 /* NB this one still documents a specific non-nil return value.
2397 (As did run-hook-with-args and run-hook-with-args-until-failure
2398 until they were changed in 24.1.) */
2399 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2400 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2401 doc
: /* Run HOOK with the specified arguments ARGS.
2402 HOOK should be a symbol, a hook variable. The value of HOOK
2403 may be nil, a function, or a list of functions. Call each
2404 function in order with arguments ARGS, stopping at the first
2405 one that returns non-nil, and return that value. Otherwise (if
2406 all functions return nil, or if there are no functions to call),
2409 Do not use `make-local-variable' to make a hook variable buffer-local.
2410 Instead, use `add-hook' and specify t for the LOCAL argument.
2411 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2412 (ptrdiff_t nargs
, Lisp_Object
*args
)
2414 return run_hook_with_args (nargs
, args
, Ffuncall
);
2418 funcall_not (ptrdiff_t nargs
, Lisp_Object
*args
)
2420 return NILP (Ffuncall (nargs
, args
)) ? Qt
: Qnil
;
2423 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2424 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2425 doc
: /* Run HOOK with the specified arguments ARGS.
2426 HOOK should be a symbol, a hook variable. The value of HOOK
2427 may be nil, a function, or a list of functions. Call each
2428 function in order with arguments ARGS, stopping at the first
2429 one that returns nil, and return nil. Otherwise (if all functions
2430 return non-nil, or if there are no functions to call), return non-nil
2431 (do not rely on the precise return value in this case).
2433 Do not use `make-local-variable' to make a hook variable buffer-local.
2434 Instead, use `add-hook' and specify t for the LOCAL argument.
2435 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2436 (ptrdiff_t nargs
, Lisp_Object
*args
)
2438 return NILP (run_hook_with_args (nargs
, args
, funcall_not
)) ? Qt
: Qnil
;
2442 run_hook_wrapped_funcall (ptrdiff_t nargs
, Lisp_Object
*args
)
2444 Lisp_Object tmp
= args
[0], ret
;
2447 ret
= Ffuncall (nargs
, args
);
2453 DEFUN ("run-hook-wrapped", Frun_hook_wrapped
, Srun_hook_wrapped
, 2, MANY
, 0,
2454 doc
: /* Run HOOK, passing each function through WRAP-FUNCTION.
2455 I.e. instead of calling each function FUN directly with arguments ARGS,
2456 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2457 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2458 aborts and returns that value.
2459 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2460 (ptrdiff_t nargs
, Lisp_Object
*args
)
2462 return run_hook_with_args (nargs
, args
, run_hook_wrapped_funcall
);
2465 /* ARGS[0] should be a hook symbol.
2466 Call each of the functions in the hook value, passing each of them
2467 as arguments all the rest of ARGS (all NARGS - 1 elements).
2468 FUNCALL specifies how to call each function on the hook. */
2471 run_hook_with_args (ptrdiff_t nargs
, Lisp_Object
*args
,
2472 Lisp_Object (*funcall
) (ptrdiff_t nargs
, Lisp_Object
*args
))
2474 Lisp_Object sym
, val
, ret
= Qnil
;
2476 /* If we are dying or still initializing,
2477 don't do anything--it would probably crash if we tried. */
2478 if (NILP (Vrun_hooks
))
2482 val
= find_symbol_value (sym
);
2484 if (EQ (val
, Qunbound
) || NILP (val
))
2486 else if (!CONSP (val
) || FUNCTIONP (val
))
2489 return funcall (nargs
, args
);
2493 Lisp_Object global_vals
= Qnil
;
2496 CONSP (val
) && NILP (ret
);
2499 if (EQ (XCAR (val
), Qt
))
2501 /* t indicates this hook has a local binding;
2502 it means to run the global binding too. */
2503 global_vals
= Fdefault_value (sym
);
2504 if (NILP (global_vals
)) continue;
2506 if (!CONSP (global_vals
) || EQ (XCAR (global_vals
), Qlambda
))
2508 args
[0] = global_vals
;
2509 ret
= funcall (nargs
, args
);
2514 CONSP (global_vals
) && NILP (ret
);
2515 global_vals
= XCDR (global_vals
))
2517 args
[0] = XCAR (global_vals
);
2518 /* In a global value, t should not occur. If it does, we
2519 must ignore it to avoid an endless loop. */
2520 if (!EQ (args
[0], Qt
))
2521 ret
= funcall (nargs
, args
);
2527 args
[0] = XCAR (val
);
2528 ret
= funcall (nargs
, args
);
2536 /* Run the hook HOOK, giving each function no args. */
2539 run_hook (Lisp_Object hook
)
2541 Frun_hook_with_args (1, &hook
);
2544 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2547 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2549 CALLN (Frun_hook_with_args
, hook
, arg1
, arg2
);
2552 /* Apply fn to arg. */
2554 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2556 return NILP (arg
) ? Ffuncall (1, &fn
) : CALLN (Fapply
, fn
, arg
);
2559 /* Call function fn on no arguments. */
2561 call0 (Lisp_Object fn
)
2563 return Ffuncall (1, &fn
);
2566 /* Call function fn with 1 argument arg1. */
2569 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2571 return CALLN (Ffuncall
, fn
, arg1
);
2574 /* Call function fn with 2 arguments arg1, arg2. */
2577 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2579 return CALLN (Ffuncall
, fn
, arg1
, arg2
);
2582 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2585 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2587 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
);
2590 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2593 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2596 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
);
2599 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2602 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2603 Lisp_Object arg4
, Lisp_Object arg5
)
2605 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
);
2608 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2611 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2612 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2614 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
2617 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2620 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2621 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
2623 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
2626 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
2627 doc
: /* Non-nil if OBJECT is a function. */)
2628 (Lisp_Object object
)
2630 if (FUNCTIONP (object
))
2635 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2636 doc
: /* Call first argument as a function, passing remaining arguments to it.
2637 Return the value that function returns.
2638 Thus, (funcall \\='cons \\='x \\='y) returns (x . y).
2639 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2640 (ptrdiff_t nargs
, Lisp_Object
*args
)
2642 Lisp_Object fun
, original_fun
;
2644 ptrdiff_t numargs
= nargs
- 1;
2645 Lisp_Object lisp_numargs
;
2647 Lisp_Object
*internal_args
;
2652 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2654 if (max_lisp_eval_depth
< 100)
2655 max_lisp_eval_depth
= 100;
2656 if (lisp_eval_depth
> max_lisp_eval_depth
)
2657 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2660 count
= record_in_backtrace (args
[0], &args
[1], nargs
- 1);
2664 if (debug_on_next_call
)
2665 do_debug_on_call (Qlambda
, count
);
2669 original_fun
= args
[0];
2673 /* Optimize for no indirection. */
2675 if (SYMBOLP (fun
) && !NILP (fun
)
2676 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2677 fun
= indirect_function (fun
);
2681 if (numargs
< XSUBR (fun
)->min_args
2682 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2684 XSETFASTINT (lisp_numargs
, numargs
);
2685 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2688 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2689 xsignal1 (Qinvalid_function
, original_fun
);
2691 else if (XSUBR (fun
)->max_args
== MANY
)
2692 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
2695 Lisp_Object internal_argbuf
[8];
2696 if (XSUBR (fun
)->max_args
> numargs
)
2698 eassert (XSUBR (fun
)->max_args
<= ARRAYELTS (internal_argbuf
));
2699 internal_args
= internal_argbuf
;
2700 memcpy (internal_args
, args
+ 1, numargs
* word_size
);
2701 memclear (internal_args
+ numargs
,
2702 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2705 internal_args
= args
+ 1;
2706 switch (XSUBR (fun
)->max_args
)
2709 val
= (XSUBR (fun
)->function
.a0 ());
2712 val
= (XSUBR (fun
)->function
.a1 (internal_args
[0]));
2715 val
= (XSUBR (fun
)->function
.a2
2716 (internal_args
[0], internal_args
[1]));
2719 val
= (XSUBR (fun
)->function
.a3
2720 (internal_args
[0], internal_args
[1], internal_args
[2]));
2723 val
= (XSUBR (fun
)->function
.a4
2724 (internal_args
[0], internal_args
[1], internal_args
[2],
2728 val
= (XSUBR (fun
)->function
.a5
2729 (internal_args
[0], internal_args
[1], internal_args
[2],
2730 internal_args
[3], internal_args
[4]));
2733 val
= (XSUBR (fun
)->function
.a6
2734 (internal_args
[0], internal_args
[1], internal_args
[2],
2735 internal_args
[3], internal_args
[4], internal_args
[5]));
2738 val
= (XSUBR (fun
)->function
.a7
2739 (internal_args
[0], internal_args
[1], internal_args
[2],
2740 internal_args
[3], internal_args
[4], internal_args
[5],
2745 val
= (XSUBR (fun
)->function
.a8
2746 (internal_args
[0], internal_args
[1], internal_args
[2],
2747 internal_args
[3], internal_args
[4], internal_args
[5],
2748 internal_args
[6], internal_args
[7]));
2753 /* If a subr takes more than 8 arguments without using MANY
2754 or UNEVALLED, we need to extend this function to support it.
2755 Until this is done, there is no way to call the function. */
2760 else if (COMPILEDP (fun
))
2761 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2765 xsignal1 (Qvoid_function
, original_fun
);
2767 xsignal1 (Qinvalid_function
, original_fun
);
2768 funcar
= XCAR (fun
);
2769 if (!SYMBOLP (funcar
))
2770 xsignal1 (Qinvalid_function
, original_fun
);
2771 if (EQ (funcar
, Qlambda
)
2772 || EQ (funcar
, Qclosure
))
2773 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2774 else if (EQ (funcar
, Qautoload
))
2776 Fautoload_do_load (fun
, original_fun
, Qnil
);
2781 xsignal1 (Qinvalid_function
, original_fun
);
2785 if (backtrace_debug_on_exit (specpdl
+ count
))
2786 val
= call_debugger (list2 (Qexit
, val
));
2792 apply_lambda (Lisp_Object fun
, Lisp_Object args
, ptrdiff_t count
)
2794 Lisp_Object args_left
;
2797 Lisp_Object
*arg_vector
;
2801 numargs
= XFASTINT (Flength (args
));
2802 SAFE_ALLOCA_LISP (arg_vector
, numargs
);
2805 for (i
= 0; i
< numargs
; )
2807 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2808 tem
= eval_sub (tem
);
2809 arg_vector
[i
++] = tem
;
2812 set_backtrace_args (specpdl
+ count
, arg_vector
, i
);
2813 tem
= funcall_lambda (fun
, numargs
, arg_vector
);
2817 /* Do the debug-on-exit now, while arg_vector still exists. */
2818 if (backtrace_debug_on_exit (specpdl
+ count
))
2819 tem
= call_debugger (list2 (Qexit
, tem
));
2825 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2826 and return the result of evaluation.
2827 FUN must be either a lambda-expression or a compiled-code object. */
2830 funcall_lambda (Lisp_Object fun
, ptrdiff_t nargs
,
2831 register Lisp_Object
*arg_vector
)
2833 Lisp_Object val
, syms_left
, next
, lexenv
;
2834 ptrdiff_t count
= SPECPDL_INDEX ();
2836 bool optional
, rest
;
2840 if (EQ (XCAR (fun
), Qclosure
))
2842 fun
= XCDR (fun
); /* Drop `closure'. */
2843 lexenv
= XCAR (fun
);
2844 CHECK_LIST_CONS (fun
, fun
);
2848 syms_left
= XCDR (fun
);
2849 if (CONSP (syms_left
))
2850 syms_left
= XCAR (syms_left
);
2852 xsignal1 (Qinvalid_function
, fun
);
2854 else if (COMPILEDP (fun
))
2856 ptrdiff_t size
= ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
;
2857 if (size
<= COMPILED_STACK_DEPTH
)
2858 xsignal1 (Qinvalid_function
, fun
);
2859 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2860 if (INTEGERP (syms_left
))
2861 /* A byte-code object with a non-nil `push args' slot means we
2862 shouldn't bind any arguments, instead just call the byte-code
2863 interpreter directly; it will push arguments as necessary.
2865 Byte-code objects with either a non-existent, or a nil value for
2866 the `push args' slot (the default), have dynamically-bound
2867 arguments, and use the argument-binding code below instead (as do
2868 all interpreted functions, even lexically bound ones). */
2870 /* If we have not actually read the bytecode string
2871 and constants vector yet, fetch them from the file. */
2872 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2873 Ffetch_bytecode (fun
);
2874 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2875 AREF (fun
, COMPILED_CONSTANTS
),
2876 AREF (fun
, COMPILED_STACK_DEPTH
),
2885 i
= optional
= rest
= 0;
2886 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2890 next
= XCAR (syms_left
);
2891 if (!SYMBOLP (next
))
2892 xsignal1 (Qinvalid_function
, fun
);
2894 if (EQ (next
, Qand_rest
))
2896 else if (EQ (next
, Qand_optional
))
2903 arg
= Flist (nargs
- i
, &arg_vector
[i
]);
2907 arg
= arg_vector
[i
++];
2909 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2913 /* Bind the argument. */
2914 if (!NILP (lexenv
) && SYMBOLP (next
))
2915 /* Lexically bind NEXT by adding it to the lexenv alist. */
2916 lexenv
= Fcons (Fcons (next
, arg
), lexenv
);
2918 /* Dynamically bind NEXT. */
2919 specbind (next
, arg
);
2923 if (!NILP (syms_left
))
2924 xsignal1 (Qinvalid_function
, fun
);
2926 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2928 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
2929 /* Instantiate a new lexical environment. */
2930 specbind (Qinternal_interpreter_environment
, lexenv
);
2933 val
= Fprogn (XCDR (XCDR (fun
)));
2936 /* If we have not actually read the bytecode string
2937 and constants vector yet, fetch them from the file. */
2938 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2939 Ffetch_bytecode (fun
);
2940 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2941 AREF (fun
, COMPILED_CONSTANTS
),
2942 AREF (fun
, COMPILED_STACK_DEPTH
),
2946 return unbind_to (count
, val
);
2949 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2951 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2952 (Lisp_Object object
)
2956 if (COMPILEDP (object
))
2958 ptrdiff_t size
= ASIZE (object
) & PSEUDOVECTOR_SIZE_MASK
;
2959 if (size
<= COMPILED_STACK_DEPTH
)
2960 xsignal1 (Qinvalid_function
, object
);
2961 if (CONSP (AREF (object
, COMPILED_BYTECODE
)))
2963 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2966 tem
= AREF (object
, COMPILED_BYTECODE
);
2967 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2968 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2970 error ("Invalid byte code");
2972 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
2973 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
2979 /* Return true if SYMBOL currently has a let-binding
2980 which was made in the buffer that is now current. */
2983 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
2985 union specbinding
*p
;
2986 Lisp_Object buf
= Fcurrent_buffer ();
2988 for (p
= specpdl_ptr
; p
> specpdl
; )
2989 if ((--p
)->kind
> SPECPDL_LET
)
2991 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (specpdl_symbol (p
));
2992 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
2993 if (symbol
== let_bound_symbol
2994 && EQ (specpdl_where (p
), buf
))
3002 let_shadows_global_binding_p (Lisp_Object symbol
)
3004 union specbinding
*p
;
3006 for (p
= specpdl_ptr
; p
> specpdl
; )
3007 if ((--p
)->kind
>= SPECPDL_LET
&& EQ (specpdl_symbol (p
), symbol
))
3013 /* `specpdl_ptr' describes which variable is
3014 let-bound, so it can be properly undone when we unbind_to.
3015 It can be either a plain SPECPDL_LET or a SPECPDL_LET_LOCAL/DEFAULT.
3016 - SYMBOL is the variable being bound. Note that it should not be
3017 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3019 - WHERE tells us in which buffer the binding took place.
3020 This is used for SPECPDL_LET_LOCAL bindings (i.e. bindings to a
3021 buffer-local variable) as well as for SPECPDL_LET_DEFAULT bindings,
3022 i.e. bindings to the default value of a variable which can be
3026 specbind (Lisp_Object symbol
, Lisp_Object value
)
3028 struct Lisp_Symbol
*sym
;
3030 CHECK_SYMBOL (symbol
);
3031 sym
= XSYMBOL (symbol
);
3034 switch (sym
->redirect
)
3036 case SYMBOL_VARALIAS
:
3037 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3038 case SYMBOL_PLAINVAL
:
3039 /* The most common case is that of a non-constant symbol with a
3040 trivial value. Make that as fast as we can. */
3041 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3042 specpdl_ptr
->let
.symbol
= symbol
;
3043 specpdl_ptr
->let
.old_value
= SYMBOL_VAL (sym
);
3046 SET_SYMBOL_VAL (sym
, value
);
3048 set_internal (symbol
, value
, Qnil
, 1);
3050 case SYMBOL_LOCALIZED
:
3051 if (SYMBOL_BLV (sym
)->frame_local
)
3052 error ("Frame-local vars cannot be let-bound");
3053 case SYMBOL_FORWARDED
:
3055 Lisp_Object ovalue
= find_symbol_value (symbol
);
3056 specpdl_ptr
->let
.kind
= SPECPDL_LET_LOCAL
;
3057 specpdl_ptr
->let
.symbol
= symbol
;
3058 specpdl_ptr
->let
.old_value
= ovalue
;
3059 specpdl_ptr
->let
.where
= Fcurrent_buffer ();
3061 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3062 || (EQ (SYMBOL_BLV (sym
)->where
, Fcurrent_buffer ())));
3064 if (sym
->redirect
== SYMBOL_LOCALIZED
)
3066 if (!blv_found (SYMBOL_BLV (sym
)))
3067 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3069 else if (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3071 /* If SYMBOL is a per-buffer variable which doesn't have a
3072 buffer-local value here, make the `let' change the global
3073 value by changing the value of SYMBOL in all buffers not
3074 having their own value. This is consistent with what
3075 happens with other buffer-local variables. */
3076 if (NILP (Flocal_variable_p (symbol
, Qnil
)))
3078 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3080 Fset_default (symbol
, value
);
3085 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3088 set_internal (symbol
, value
, Qnil
, 1);
3091 default: emacs_abort ();
3095 /* Push unwind-protect entries of various types. */
3098 record_unwind_protect (void (*function
) (Lisp_Object
), Lisp_Object arg
)
3100 specpdl_ptr
->unwind
.kind
= SPECPDL_UNWIND
;
3101 specpdl_ptr
->unwind
.func
= function
;
3102 specpdl_ptr
->unwind
.arg
= arg
;
3107 record_unwind_protect_ptr (void (*function
) (void *), void *arg
)
3109 specpdl_ptr
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3110 specpdl_ptr
->unwind_ptr
.func
= function
;
3111 specpdl_ptr
->unwind_ptr
.arg
= arg
;
3116 record_unwind_protect_int (void (*function
) (int), int arg
)
3118 specpdl_ptr
->unwind_int
.kind
= SPECPDL_UNWIND_INT
;
3119 specpdl_ptr
->unwind_int
.func
= function
;
3120 specpdl_ptr
->unwind_int
.arg
= arg
;
3125 record_unwind_protect_void (void (*function
) (void))
3127 specpdl_ptr
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3128 specpdl_ptr
->unwind_void
.func
= function
;
3136 /* Push an unwind-protect entry that does nothing, so that
3137 set_unwind_protect_ptr can overwrite it later. */
3140 record_unwind_protect_nothing (void)
3142 record_unwind_protect_void (do_nothing
);
3145 /* Clear the unwind-protect entry COUNT, so that it does nothing.
3146 It need not be at the top of the stack. */
3149 clear_unwind_protect (ptrdiff_t count
)
3151 union specbinding
*p
= specpdl
+ count
;
3152 p
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3153 p
->unwind_void
.func
= do_nothing
;
3156 /* Set the unwind-protect entry COUNT so that it invokes FUNC (ARG).
3157 It need not be at the top of the stack. Discard the entry's
3158 previous value without invoking it. */
3161 set_unwind_protect (ptrdiff_t count
, void (*func
) (Lisp_Object
),
3164 union specbinding
*p
= specpdl
+ count
;
3165 p
->unwind
.kind
= SPECPDL_UNWIND
;
3166 p
->unwind
.func
= func
;
3167 p
->unwind
.arg
= arg
;
3171 set_unwind_protect_ptr (ptrdiff_t count
, void (*func
) (void *), void *arg
)
3173 union specbinding
*p
= specpdl
+ count
;
3174 p
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3175 p
->unwind_ptr
.func
= func
;
3176 p
->unwind_ptr
.arg
= arg
;
3179 /* Pop and execute entries from the unwind-protect stack until the
3180 depth COUNT is reached. Return VALUE. */
3183 unbind_to (ptrdiff_t count
, Lisp_Object value
)
3185 Lisp_Object quitf
= Vquit_flag
;
3189 while (specpdl_ptr
!= specpdl
+ count
)
3191 /* Decrement specpdl_ptr before we do the work to unbind it, so
3192 that an error in unbinding won't try to unbind the same entry
3193 again. Take care to copy any parts of the binding needed
3194 before invoking any code that can make more bindings. */
3198 switch (specpdl_ptr
->kind
)
3200 case SPECPDL_UNWIND
:
3201 specpdl_ptr
->unwind
.func (specpdl_ptr
->unwind
.arg
);
3203 case SPECPDL_UNWIND_PTR
:
3204 specpdl_ptr
->unwind_ptr
.func (specpdl_ptr
->unwind_ptr
.arg
);
3206 case SPECPDL_UNWIND_INT
:
3207 specpdl_ptr
->unwind_int
.func (specpdl_ptr
->unwind_int
.arg
);
3209 case SPECPDL_UNWIND_VOID
:
3210 specpdl_ptr
->unwind_void
.func ();
3212 case SPECPDL_BACKTRACE
:
3215 { /* If variable has a trivial value (no forwarding), we can
3216 just set it. No need to check for constant symbols here,
3217 since that was already done by specbind. */
3218 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (specpdl_ptr
));
3219 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3221 SET_SYMBOL_VAL (sym
, specpdl_old_value (specpdl_ptr
));
3226 NOTE: we only ever come here if make_local_foo was used for
3227 the first time on this var within this let. */
3230 case SPECPDL_LET_DEFAULT
:
3231 Fset_default (specpdl_symbol (specpdl_ptr
),
3232 specpdl_old_value (specpdl_ptr
));
3234 case SPECPDL_LET_LOCAL
:
3236 Lisp_Object symbol
= specpdl_symbol (specpdl_ptr
);
3237 Lisp_Object where
= specpdl_where (specpdl_ptr
);
3238 Lisp_Object old_value
= specpdl_old_value (specpdl_ptr
);
3239 eassert (BUFFERP (where
));
3241 /* If this was a local binding, reset the value in the appropriate
3242 buffer, but only if that buffer's binding still exists. */
3243 if (!NILP (Flocal_variable_p (symbol
, where
)))
3244 set_internal (symbol
, old_value
, where
, 1);
3250 if (NILP (Vquit_flag
) && !NILP (quitf
))
3256 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3257 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3258 A special variable is one that will be bound dynamically, even in a
3259 context where binding is lexical by default. */)
3260 (Lisp_Object symbol
)
3262 CHECK_SYMBOL (symbol
);
3263 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3267 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3268 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3269 The debugger is entered when that frame exits, if the flag is non-nil. */)
3270 (Lisp_Object level
, Lisp_Object flag
)
3272 union specbinding
*pdl
= backtrace_top ();
3273 register EMACS_INT i
;
3275 CHECK_NUMBER (level
);
3277 for (i
= 0; backtrace_p (pdl
) && i
< XINT (level
); i
++)
3278 pdl
= backtrace_next (pdl
);
3280 if (backtrace_p (pdl
))
3281 set_backtrace_debug_on_exit (pdl
, !NILP (flag
));
3286 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3287 doc
: /* Print a trace of Lisp function calls currently active.
3288 Output stream used is value of `standard-output'. */)
3291 union specbinding
*pdl
= backtrace_top ();
3293 Lisp_Object old_print_level
= Vprint_level
;
3295 if (NILP (Vprint_level
))
3296 XSETFASTINT (Vprint_level
, 8);
3298 while (backtrace_p (pdl
))
3300 write_string (backtrace_debug_on_exit (pdl
) ? "* " : " ");
3301 if (backtrace_nargs (pdl
) == UNEVALLED
)
3303 Fprin1 (Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)),
3305 write_string ("\n");
3309 tem
= backtrace_function (pdl
);
3310 Fprin1 (tem
, Qnil
); /* This can QUIT. */
3314 for (i
= 0; i
< backtrace_nargs (pdl
); i
++)
3316 if (i
) write_string (" ");
3317 Fprin1 (backtrace_args (pdl
)[i
], Qnil
);
3320 write_string (")\n");
3322 pdl
= backtrace_next (pdl
);
3325 Vprint_level
= old_print_level
;
3329 static union specbinding
*
3330 get_backtrace_frame (Lisp_Object nframes
, Lisp_Object base
)
3332 union specbinding
*pdl
= backtrace_top ();
3333 register EMACS_INT i
;
3335 CHECK_NATNUM (nframes
);
3338 { /* Skip up to `base'. */
3339 base
= Findirect_function (base
, Qt
);
3340 while (backtrace_p (pdl
)
3341 && !EQ (base
, Findirect_function (backtrace_function (pdl
), Qt
)))
3342 pdl
= backtrace_next (pdl
);
3345 /* Find the frame requested. */
3346 for (i
= XFASTINT (nframes
); i
> 0 && backtrace_p (pdl
); i
--)
3347 pdl
= backtrace_next (pdl
);
3352 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 2, NULL
,
3353 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3354 If that frame has not evaluated the arguments yet (or is a special form),
3355 the value is (nil FUNCTION ARG-FORMS...).
3356 If that frame has evaluated its arguments and called its function already,
3357 the value is (t FUNCTION ARG-VALUES...).
3358 A &rest arg is represented as the tail of the list ARG-VALUES.
3359 FUNCTION is whatever was supplied as car of evaluated list,
3360 or a lambda expression for macro calls.
3361 If NFRAMES is more than the number of frames, the value is nil.
3362 If BASE is non-nil, it should be a function and NFRAMES counts from its
3363 nearest activation frame. */)
3364 (Lisp_Object nframes
, Lisp_Object base
)
3366 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3368 if (!backtrace_p (pdl
))
3370 if (backtrace_nargs (pdl
) == UNEVALLED
)
3372 Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)));
3375 Lisp_Object tem
= Flist (backtrace_nargs (pdl
), backtrace_args (pdl
));
3377 return Fcons (Qt
, Fcons (backtrace_function (pdl
), tem
));
3381 /* For backtrace-eval, we want to temporarily unwind the last few elements of
3382 the specpdl stack, and then rewind them. We store the pre-unwind values
3383 directly in the pre-existing specpdl elements (i.e. we swap the current
3384 value and the old value stored in the specpdl), kind of like the inplace
3385 pointer-reversal trick. As it turns out, the rewind does the same as the
3386 unwind, except it starts from the other end of the specpdl stack, so we use
3387 the same function for both unwind and rewind. */
3389 backtrace_eval_unrewind (int distance
)
3391 union specbinding
*tmp
= specpdl_ptr
;
3394 { /* It's a rewind rather than unwind. */
3395 tmp
+= distance
- 1;
3397 distance
= -distance
;
3400 for (; distance
> 0; distance
--)
3405 /* FIXME: Ideally we'd like to "temporarily unwind" (some of) those
3406 unwind_protect, but the problem is that we don't know how to
3407 rewind them afterwards. */
3408 case SPECPDL_UNWIND
:
3410 Lisp_Object oldarg
= tmp
->unwind
.arg
;
3411 if (tmp
->unwind
.func
== set_buffer_if_live
)
3412 tmp
->unwind
.arg
= Fcurrent_buffer ();
3413 else if (tmp
->unwind
.func
== save_excursion_restore
)
3414 tmp
->unwind
.arg
= save_excursion_save ();
3417 tmp
->unwind
.func (oldarg
);
3421 case SPECPDL_UNWIND_PTR
:
3422 case SPECPDL_UNWIND_INT
:
3423 case SPECPDL_UNWIND_VOID
:
3424 case SPECPDL_BACKTRACE
:
3427 { /* If variable has a trivial value (no forwarding), we can
3428 just set it. No need to check for constant symbols here,
3429 since that was already done by specbind. */
3430 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (tmp
));
3431 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3433 Lisp_Object old_value
= specpdl_old_value (tmp
);
3434 set_specpdl_old_value (tmp
, SYMBOL_VAL (sym
));
3435 SET_SYMBOL_VAL (sym
, old_value
);
3440 NOTE: we only ever come here if make_local_foo was used for
3441 the first time on this var within this let. */
3444 case SPECPDL_LET_DEFAULT
:
3446 Lisp_Object sym
= specpdl_symbol (tmp
);
3447 Lisp_Object old_value
= specpdl_old_value (tmp
);
3448 set_specpdl_old_value (tmp
, Fdefault_value (sym
));
3449 Fset_default (sym
, old_value
);
3452 case SPECPDL_LET_LOCAL
:
3454 Lisp_Object symbol
= specpdl_symbol (tmp
);
3455 Lisp_Object where
= specpdl_where (tmp
);
3456 Lisp_Object old_value
= specpdl_old_value (tmp
);
3457 eassert (BUFFERP (where
));
3459 /* If this was a local binding, reset the value in the appropriate
3460 buffer, but only if that buffer's binding still exists. */
3461 if (!NILP (Flocal_variable_p (symbol
, where
)))
3463 set_specpdl_old_value
3464 (tmp
, Fbuffer_local_value (symbol
, where
));
3465 set_internal (symbol
, old_value
, where
, 1);
3473 DEFUN ("backtrace-eval", Fbacktrace_eval
, Sbacktrace_eval
, 2, 3, NULL
,
3474 doc
: /* Evaluate EXP in the context of some activation frame.
3475 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3476 (Lisp_Object exp
, Lisp_Object nframes
, Lisp_Object base
)
3478 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3479 ptrdiff_t count
= SPECPDL_INDEX ();
3480 ptrdiff_t distance
= specpdl_ptr
- pdl
;
3481 eassert (distance
>= 0);
3483 if (!backtrace_p (pdl
))
3484 error ("Activation frame not found!");
3486 backtrace_eval_unrewind (distance
);
3487 record_unwind_protect_int (backtrace_eval_unrewind
, -distance
);
3489 /* Use eval_sub rather than Feval since the main motivation behind
3490 backtrace-eval is to be able to get/set the value of lexical variables
3491 from the debugger. */
3492 return unbind_to (count
, eval_sub (exp
));
3495 DEFUN ("backtrace--locals", Fbacktrace__locals
, Sbacktrace__locals
, 1, 2, NULL
,
3496 doc
: /* Return names and values of local variables of a stack frame.
3497 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3498 (Lisp_Object nframes
, Lisp_Object base
)
3500 union specbinding
*frame
= get_backtrace_frame (nframes
, base
);
3501 union specbinding
*prevframe
3502 = get_backtrace_frame (make_number (XFASTINT (nframes
) - 1), base
);
3503 ptrdiff_t distance
= specpdl_ptr
- frame
;
3504 Lisp_Object result
= Qnil
;
3505 eassert (distance
>= 0);
3507 if (!backtrace_p (prevframe
))
3508 error ("Activation frame not found!");
3509 if (!backtrace_p (frame
))
3510 error ("Activation frame not found!");
3512 /* The specpdl entries normally contain the symbol being bound along with its
3513 `old_value', so it can be restored. The new value to which it is bound is
3514 available in one of two places: either in the current value of the
3515 variable (if it hasn't been rebound yet) or in the `old_value' slot of the
3516 next specpdl entry for it.
3517 `backtrace_eval_unrewind' happens to swap the role of `old_value'
3518 and "new value", so we abuse it here, to fetch the new value.
3519 It's ugly (we'd rather not modify global data) and a bit inefficient,
3520 but it does the job for now. */
3521 backtrace_eval_unrewind (distance
);
3525 union specbinding
*tmp
= prevframe
;
3526 for (; tmp
> frame
; tmp
--)
3531 case SPECPDL_LET_DEFAULT
:
3532 case SPECPDL_LET_LOCAL
:
3534 Lisp_Object sym
= specpdl_symbol (tmp
);
3535 Lisp_Object val
= specpdl_old_value (tmp
);
3536 if (EQ (sym
, Qinternal_interpreter_environment
))
3538 Lisp_Object env
= val
;
3539 for (; CONSP (env
); env
= XCDR (env
))
3541 Lisp_Object binding
= XCAR (env
);
3542 if (CONSP (binding
))
3543 result
= Fcons (Fcons (XCAR (binding
),
3549 result
= Fcons (Fcons (sym
, val
), result
);
3553 case SPECPDL_UNWIND
:
3554 case SPECPDL_UNWIND_PTR
:
3555 case SPECPDL_UNWIND_INT
:
3556 case SPECPDL_UNWIND_VOID
:
3557 case SPECPDL_BACKTRACE
:
3566 /* Restore values from specpdl to original place. */
3567 backtrace_eval_unrewind (-distance
);
3576 union specbinding
*pdl
;
3577 for (pdl
= specpdl
; pdl
!= specpdl_ptr
; pdl
++)
3581 case SPECPDL_UNWIND
:
3582 mark_object (specpdl_arg (pdl
));
3585 case SPECPDL_BACKTRACE
:
3587 ptrdiff_t nargs
= backtrace_nargs (pdl
);
3588 mark_object (backtrace_function (pdl
));
3589 if (nargs
== UNEVALLED
)
3592 mark_object (backtrace_args (pdl
)[nargs
]);
3596 case SPECPDL_LET_DEFAULT
:
3597 case SPECPDL_LET_LOCAL
:
3598 mark_object (specpdl_where (pdl
));
3601 mark_object (specpdl_symbol (pdl
));
3602 mark_object (specpdl_old_value (pdl
));
3605 case SPECPDL_UNWIND_PTR
:
3606 case SPECPDL_UNWIND_INT
:
3607 case SPECPDL_UNWIND_VOID
:
3617 get_backtrace (Lisp_Object array
)
3619 union specbinding
*pdl
= backtrace_next (backtrace_top ());
3620 ptrdiff_t i
= 0, asize
= ASIZE (array
);
3622 /* Copy the backtrace contents into working memory. */
3623 for (; i
< asize
; i
++)
3625 if (backtrace_p (pdl
))
3627 ASET (array
, i
, backtrace_function (pdl
));
3628 pdl
= backtrace_next (pdl
);
3631 ASET (array
, i
, Qnil
);
3635 Lisp_Object
backtrace_top_function (void)
3637 union specbinding
*pdl
= backtrace_top ();
3638 return (backtrace_p (pdl
) ? backtrace_function (pdl
) : Qnil
);
3644 DEFVAR_INT ("max-specpdl-size", max_specpdl_size
,
3645 doc
: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3646 If Lisp code tries to increase the total number past this amount,
3647 an error is signaled.
3648 You can safely use a value considerably larger than the default value,
3649 if that proves inconveniently small. However, if you increase it too far,
3650 Emacs could run out of memory trying to make the stack bigger.
3651 Note that this limit may be silently increased by the debugger
3652 if `debug-on-error' or `debug-on-quit' is set. */);
3654 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth
,
3655 doc
: /* Limit on depth in `eval', `apply' and `funcall' before error.
3657 This limit serves to catch infinite recursions for you before they cause
3658 actual stack overflow in C, which would be fatal for Emacs.
3659 You can safely make it considerably larger than its default value,
3660 if that proves inconveniently small. However, if you increase it too far,
3661 Emacs could overflow the real C stack, and crash. */);
3663 DEFVAR_LISP ("quit-flag", Vquit_flag
,
3664 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3665 If the value is t, that means do an ordinary quit.
3666 If the value equals `throw-on-input', that means quit by throwing
3667 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3668 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3669 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3672 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit
,
3673 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3674 Note that `quit-flag' will still be set by typing C-g,
3675 so a quit will be signaled as soon as `inhibit-quit' is nil.
3676 To prevent this happening, set `quit-flag' to nil
3677 before making `inhibit-quit' nil. */);
3678 Vinhibit_quit
= Qnil
;
3680 DEFSYM (Qinhibit_quit
, "inhibit-quit");
3681 DEFSYM (Qautoload
, "autoload");
3682 DEFSYM (Qinhibit_debugger
, "inhibit-debugger");
3683 DEFSYM (Qmacro
, "macro");
3685 /* Note that the process handling also uses Qexit, but we don't want
3686 to staticpro it twice, so we just do it here. */
3687 DEFSYM (Qexit
, "exit");
3689 DEFSYM (Qinteractive
, "interactive");
3690 DEFSYM (Qcommandp
, "commandp");
3691 DEFSYM (Qand_rest
, "&rest");
3692 DEFSYM (Qand_optional
, "&optional");
3693 DEFSYM (Qclosure
, "closure");
3694 DEFSYM (QCdocumentation
, ":documentation");
3695 DEFSYM (Qdebug
, "debug");
3697 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger
,
3698 doc
: /* Non-nil means never enter the debugger.
3699 Normally set while the debugger is already active, to avoid recursive
3701 Vinhibit_debugger
= Qnil
;
3703 DEFVAR_LISP ("debug-on-error", Vdebug_on_error
,
3704 doc
: /* Non-nil means enter debugger if an error is signaled.
3705 Does not apply to errors handled by `condition-case' or those
3706 matched by `debug-ignored-errors'.
3707 If the value is a list, an error only means to enter the debugger
3708 if one of its condition symbols appears in the list.
3709 When you evaluate an expression interactively, this variable
3710 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3711 The command `toggle-debug-on-error' toggles this.
3712 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3713 Vdebug_on_error
= Qnil
;
3715 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors
,
3716 doc
: /* List of errors for which the debugger should not be called.
3717 Each element may be a condition-name or a regexp that matches error messages.
3718 If any element applies to a given error, that error skips the debugger
3719 and just returns to top level.
3720 This overrides the variable `debug-on-error'.
3721 It does not apply to errors handled by `condition-case'. */);
3722 Vdebug_ignored_errors
= Qnil
;
3724 DEFVAR_BOOL ("debug-on-quit", debug_on_quit
,
3725 doc
: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3726 Does not apply if quit is handled by a `condition-case'. */);
3729 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call
,
3730 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3732 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue
,
3733 doc
: /* Non-nil means debugger may continue execution.
3734 This is nil when the debugger is called under circumstances where it
3735 might not be safe to continue. */);
3736 debugger_may_continue
= 1;
3738 DEFVAR_LISP ("debugger", Vdebugger
,
3739 doc
: /* Function to call to invoke debugger.
3740 If due to frame exit, args are `exit' and the value being returned;
3741 this function's value will be returned instead of that.
3742 If due to error, args are `error' and a list of the args to `signal'.
3743 If due to `apply' or `funcall' entry, one arg, `lambda'.
3744 If due to `eval' entry, one arg, t. */);
3747 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function
,
3748 doc
: /* If non-nil, this is a function for `signal' to call.
3749 It receives the same arguments that `signal' was given.
3750 The Edebug package uses this to regain control. */);
3751 Vsignal_hook_function
= Qnil
;
3753 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal
,
3754 doc
: /* Non-nil means call the debugger regardless of condition handlers.
3755 Note that `debug-on-error', `debug-on-quit' and friends
3756 still determine whether to handle the particular condition. */);
3757 Vdebug_on_signal
= Qnil
;
3759 /* When lexical binding is being used,
3760 Vinternal_interpreter_environment is non-nil, and contains an alist
3761 of lexically-bound variable, or (t), indicating an empty
3762 environment. The lisp name of this variable would be
3763 `internal-interpreter-environment' if it weren't hidden.
3764 Every element of this list can be either a cons (VAR . VAL)
3765 specifying a lexical binding, or a single symbol VAR indicating
3766 that this variable should use dynamic scoping. */
3767 DEFSYM (Qinternal_interpreter_environment
,
3768 "internal-interpreter-environment");
3769 DEFVAR_LISP ("internal-interpreter-environment",
3770 Vinternal_interpreter_environment
,
3771 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3772 When lexical binding is not being used, this variable is nil.
3773 A value of `(t)' indicates an empty environment, otherwise it is an
3774 alist of active lexical bindings. */);
3775 Vinternal_interpreter_environment
= Qnil
;
3776 /* Don't export this variable to Elisp, so no one can mess with it
3777 (Just imagine if someone makes it buffer-local). */
3778 Funintern (Qinternal_interpreter_environment
, Qnil
);
3780 Vrun_hooks
= intern_c_string ("run-hooks");
3781 staticpro (&Vrun_hooks
);
3783 staticpro (&Vautoload_queue
);
3784 Vautoload_queue
= Qnil
;
3785 staticpro (&Vsignaling_function
);
3786 Vsignaling_function
= Qnil
;
3788 inhibit_lisp_code
= Qnil
;
3799 defsubr (&Sfunction
);
3800 defsubr (&Sdefault_toplevel_value
);
3801 defsubr (&Sset_default_toplevel_value
);
3803 defsubr (&Sdefvaralias
);
3804 defsubr (&Sdefconst
);
3805 defsubr (&Smake_var_non_special
);
3809 defsubr (&Smacroexpand
);
3812 defsubr (&Sunwind_protect
);
3813 defsubr (&Scondition_case
);
3815 defsubr (&Scommandp
);
3816 defsubr (&Sautoload
);
3817 defsubr (&Sautoload_do_load
);
3820 defsubr (&Sfuncall
);
3821 defsubr (&Srun_hooks
);
3822 defsubr (&Srun_hook_with_args
);
3823 defsubr (&Srun_hook_with_args_until_success
);
3824 defsubr (&Srun_hook_with_args_until_failure
);
3825 defsubr (&Srun_hook_wrapped
);
3826 defsubr (&Sfetch_bytecode
);
3827 defsubr (&Sbacktrace_debug
);
3828 defsubr (&Sbacktrace
);
3829 defsubr (&Sbacktrace_frame
);
3830 defsubr (&Sbacktrace_eval
);
3831 defsubr (&Sbacktrace__locals
);
3832 defsubr (&Sspecial_variable_p
);
3833 defsubr (&Sfunctionp
);