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
;
37 /* Count levels of GCPRO to detect failure to UNGCPRO. */
41 /* Non-nil means record all fset's and provide's, to be undone
42 if the file being autoloaded is not fully loaded.
43 They are recorded by being consed onto the front of Vautoload_queue:
44 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
46 Lisp_Object Vautoload_queue
;
48 /* This holds either the symbol `run-hooks' or nil.
49 It is nil at an early stage of startup, and when Emacs
51 Lisp_Object Vrun_hooks
;
53 /* Current number of specbindings allocated in specpdl, not counting
54 the dummy entry specpdl[-1]. */
56 ptrdiff_t specpdl_size
;
58 /* Pointer to beginning of specpdl. A dummy entry specpdl[-1] exists
59 only so that its address can be taken. */
61 union specbinding
*specpdl
;
63 /* Pointer to first unused element in specpdl. */
65 union specbinding
*specpdl_ptr
;
67 /* Depth in Lisp evaluations and function calls. */
69 EMACS_INT lisp_eval_depth
;
71 /* The value of num_nonmacro_input_events as of the last time we
72 started to enter the debugger. If we decide to enter the debugger
73 again when this is still equal to num_nonmacro_input_events, then we
74 know that the debugger itself has an error, and we should just
75 signal the error instead of entering an infinite loop of debugger
78 static EMACS_INT when_entered_debugger
;
80 /* The function from which the last `signal' was called. Set in
82 /* FIXME: We should probably get rid of this! */
83 Lisp_Object Vsignaling_function
;
85 /* If non-nil, Lisp code must not be run since some part of Emacs is in
86 an inconsistent state. Currently unused. */
87 Lisp_Object inhibit_lisp_code
;
89 /* These would ordinarily be static, but they need to be visible to GDB. */
90 bool backtrace_p (union specbinding
*) EXTERNALLY_VISIBLE
;
91 Lisp_Object
*backtrace_args (union specbinding
*) EXTERNALLY_VISIBLE
;
92 Lisp_Object
backtrace_function (union specbinding
*) EXTERNALLY_VISIBLE
;
93 union specbinding
*backtrace_next (union specbinding
*) EXTERNALLY_VISIBLE
;
94 union specbinding
*backtrace_top (void) EXTERNALLY_VISIBLE
;
96 static Lisp_Object
funcall_lambda (Lisp_Object
, ptrdiff_t, Lisp_Object
*);
97 static Lisp_Object
apply_lambda (Lisp_Object
, Lisp_Object
, ptrdiff_t);
100 specpdl_symbol (union specbinding
*pdl
)
102 eassert (pdl
->kind
>= SPECPDL_LET
);
103 return pdl
->let
.symbol
;
107 specpdl_old_value (union specbinding
*pdl
)
109 eassert (pdl
->kind
>= SPECPDL_LET
);
110 return pdl
->let
.old_value
;
114 set_specpdl_old_value (union specbinding
*pdl
, Lisp_Object val
)
116 eassert (pdl
->kind
>= SPECPDL_LET
);
117 pdl
->let
.old_value
= val
;
121 specpdl_where (union specbinding
*pdl
)
123 eassert (pdl
->kind
> SPECPDL_LET
);
124 return pdl
->let
.where
;
128 specpdl_arg (union specbinding
*pdl
)
130 eassert (pdl
->kind
== SPECPDL_UNWIND
);
131 return pdl
->unwind
.arg
;
135 backtrace_function (union specbinding
*pdl
)
137 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
138 return pdl
->bt
.function
;
142 backtrace_nargs (union specbinding
*pdl
)
144 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
145 return pdl
->bt
.nargs
;
149 backtrace_args (union specbinding
*pdl
)
151 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
156 backtrace_debug_on_exit (union specbinding
*pdl
)
158 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
159 return pdl
->bt
.debug_on_exit
;
162 /* Functions to modify slots of backtrace records. */
165 set_backtrace_args (union specbinding
*pdl
, Lisp_Object
*args
, ptrdiff_t nargs
)
167 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
169 pdl
->bt
.nargs
= nargs
;
173 set_backtrace_debug_on_exit (union specbinding
*pdl
, bool doe
)
175 eassert (pdl
->kind
== SPECPDL_BACKTRACE
);
176 pdl
->bt
.debug_on_exit
= doe
;
179 /* Helper functions to scan the backtrace. */
182 backtrace_p (union specbinding
*pdl
)
183 { return pdl
>= specpdl
; }
188 union specbinding
*pdl
= specpdl_ptr
- 1;
189 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
195 backtrace_next (union specbinding
*pdl
)
198 while (backtrace_p (pdl
) && pdl
->kind
!= SPECPDL_BACKTRACE
)
203 /* Return a pointer to somewhere near the top of the C stack. */
205 near_C_stack_top (void)
207 return backtrace_args (backtrace_top ());
211 init_eval_once (void)
214 union specbinding
*pdlvec
= xmalloc ((size
+ 1) * sizeof *specpdl
);
216 specpdl
= specpdl_ptr
= pdlvec
+ 1;
217 /* Don't forget to update docs (lispref node "Local Variables"). */
218 max_specpdl_size
= 1300; /* 1000 is not enough for CEDET's c-by.el. */
219 max_lisp_eval_depth
= 800;
224 static struct handler handlerlist_sentinel
;
231 specpdl_ptr
= specpdl
;
232 { /* Put a dummy catcher at top-level so that handlerlist is never NULL.
233 This is important since handlerlist->nextfree holds the freelist
234 which would otherwise leak every time we unwind back to top-level. */
236 handlerlist
= handlerlist_sentinel
.nextfree
= &handlerlist_sentinel
;
237 PUSH_HANDLER (c
, Qunbound
, CATCHER
);
238 eassert (c
== &handlerlist_sentinel
);
239 handlerlist_sentinel
.nextfree
= NULL
;
240 handlerlist_sentinel
.next
= NULL
;
243 debug_on_next_call
= 0;
248 /* This is less than the initial value of num_nonmacro_input_events. */
249 when_entered_debugger
= -1;
252 /* Unwind-protect function used by call_debugger. */
255 restore_stack_limits (Lisp_Object data
)
257 max_specpdl_size
= XINT (XCAR (data
));
258 max_lisp_eval_depth
= XINT (XCDR (data
));
261 static void grow_specpdl (void);
263 /* Call the Lisp debugger, giving it argument ARG. */
266 call_debugger (Lisp_Object arg
)
268 bool debug_while_redisplaying
;
269 ptrdiff_t count
= SPECPDL_INDEX ();
271 EMACS_INT old_depth
= max_lisp_eval_depth
;
272 /* Do not allow max_specpdl_size less than actual depth (Bug#16603). */
273 EMACS_INT old_max
= max (max_specpdl_size
, count
);
275 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
276 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
278 /* While debugging Bug#16603, previous value of 100 was found
279 too small to avoid specpdl overflow in the debugger itself. */
280 if (max_specpdl_size
- 200 < count
)
281 max_specpdl_size
= count
+ 200;
283 if (old_max
== count
)
285 /* We can enter the debugger due to specpdl overflow (Bug#16603). */
290 /* Restore limits after leaving the debugger. */
291 record_unwind_protect (restore_stack_limits
,
292 Fcons (make_number (old_max
),
293 make_number (old_depth
)));
295 #ifdef HAVE_WINDOW_SYSTEM
296 if (display_hourglass_p
)
300 debug_on_next_call
= 0;
301 when_entered_debugger
= num_nonmacro_input_events
;
303 /* Resetting redisplaying_p to 0 makes sure that debug output is
304 displayed if the debugger is invoked during redisplay. */
305 debug_while_redisplaying
= redisplaying_p
;
307 specbind (intern ("debugger-may-continue"),
308 debug_while_redisplaying
? Qnil
: Qt
);
309 specbind (Qinhibit_redisplay
, Qnil
);
310 specbind (Qinhibit_debugger
, Qt
);
312 #if 0 /* Binding this prevents execution of Lisp code during
313 redisplay, which necessarily leads to display problems. */
314 specbind (Qinhibit_eval_during_redisplay
, Qt
);
317 val
= apply1 (Vdebugger
, arg
);
319 /* Interrupting redisplay and resuming it later is not safe under
320 all circumstances. So, when the debugger returns, abort the
321 interrupted redisplay by going back to the top-level. */
322 if (debug_while_redisplaying
)
325 return unbind_to (count
, val
);
329 do_debug_on_call (Lisp_Object code
, ptrdiff_t count
)
331 debug_on_next_call
= 0;
332 set_backtrace_debug_on_exit (specpdl
+ count
, true);
333 call_debugger (list1 (code
));
336 /* NOTE!!! Every function that can call EVAL must protect its args
337 and temporaries from garbage collection while it needs them.
338 The definition of `For' shows what you have to do. */
340 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
341 doc
: /* Eval args until one of them yields non-nil, then return that value.
342 The remaining args are not evalled at all.
343 If all args return nil, return nil.
344 usage: (or CONDITIONS...) */)
347 register Lisp_Object val
= Qnil
;
354 val
= eval_sub (XCAR (args
));
364 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
365 doc
: /* Eval args until one of them yields nil, then return nil.
366 The remaining args are not evalled at all.
367 If no arg yields nil, return the last arg's value.
368 usage: (and CONDITIONS...) */)
371 register Lisp_Object val
= Qt
;
378 val
= eval_sub (XCAR (args
));
388 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
389 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
390 Returns the value of THEN or the value of the last of the ELSE's.
391 THEN must be one expression, but ELSE... can be zero or more expressions.
392 If COND yields nil, and there are no ELSE's, the value is nil.
393 usage: (if COND THEN ELSE...) */)
400 cond
= eval_sub (XCAR (args
));
404 return eval_sub (Fcar (XCDR (args
)));
405 return Fprogn (XCDR (XCDR (args
)));
408 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
409 doc
: /* Try each clause until one succeeds.
410 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
411 and, if the value is non-nil, this clause succeeds:
412 then the expressions in BODY are evaluated and the last one's
413 value is the value of the cond-form.
414 If a clause has one element, as in (CONDITION), then the cond-form
415 returns CONDITION's value, if that is non-nil.
416 If no clause succeeds, cond returns nil.
417 usage: (cond CLAUSES...) */)
420 Lisp_Object val
= args
;
426 Lisp_Object clause
= XCAR (args
);
427 val
= eval_sub (Fcar (clause
));
430 if (!NILP (XCDR (clause
)))
431 val
= Fprogn (XCDR (clause
));
441 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
442 doc
: /* Eval BODY forms sequentially and return value of last one.
443 usage: (progn BODY...) */)
446 Lisp_Object val
= Qnil
;
453 val
= eval_sub (XCAR (body
));
461 /* Evaluate BODY sequentially, discarding its value. Suitable for
462 record_unwind_protect. */
465 unwind_body (Lisp_Object body
)
470 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
471 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
472 The value of FIRST is saved during the evaluation of the remaining args,
473 whose values are discarded.
474 usage: (prog1 FIRST BODY...) */)
478 Lisp_Object args_left
;
479 struct gcpro gcpro1
, gcpro2
;
485 val
= eval_sub (XCAR (args_left
));
486 while (CONSP (args_left
= XCDR (args_left
)))
487 eval_sub (XCAR (args_left
));
493 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
494 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
495 The value of FORM2 is saved during the evaluation of the
496 remaining args, whose values are discarded.
497 usage: (prog2 FORM1 FORM2 BODY...) */)
503 eval_sub (XCAR (args
));
505 return Fprog1 (XCDR (args
));
508 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
509 doc
: /* Set each SYM to the value of its VAL.
510 The symbols SYM are variables; they are literal (not evaluated).
511 The values VAL are expressions; they are evaluated.
512 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
513 The second VAL is not computed until after the first SYM is set, and so on;
514 each VAL can use the new value of variables set earlier in the `setq'.
515 The return value of the `setq' form is the value of the last VAL.
516 usage: (setq [SYM VAL]...) */)
519 Lisp_Object val
, sym
, lex_binding
;
524 Lisp_Object args_left
= args
;
530 val
= eval_sub (Fcar (XCDR (args_left
)));
531 sym
= XCAR (args_left
);
533 /* Like for eval_sub, we do not check declared_special here since
534 it's been done when let-binding. */
535 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
537 && !NILP (lex_binding
538 = Fassq (sym
, Vinternal_interpreter_environment
)))
539 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
541 Fset (sym
, val
); /* SYM is dynamically bound. */
543 args_left
= Fcdr (XCDR (args_left
));
545 while (CONSP (args_left
));
553 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
554 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
555 Warning: `quote' does not construct its return value, but just returns
556 the value that was pre-constructed by the Lisp reader (see info node
557 `(elisp)Printed Representation').
558 This means that '(a . b) is not identical to (cons 'a 'b): the former
559 does not cons. Quoting should be reserved for constants that will
560 never be modified by side-effects, unless you like self-modifying code.
561 See the common pitfall in info node `(elisp)Rearrangement' for an example
562 of unexpected results when a quoted object is modified.
563 usage: (quote ARG) */)
566 if (CONSP (XCDR (args
)))
567 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
571 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
572 doc
: /* Like `quote', but preferred for objects which are functions.
573 In byte compilation, `function' causes its argument to be compiled.
574 `quote' cannot do that.
575 usage: (function ARG) */)
578 Lisp_Object quoted
= XCAR (args
);
580 if (CONSP (XCDR (args
)))
581 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
583 if (!NILP (Vinternal_interpreter_environment
)
585 && EQ (XCAR (quoted
), Qlambda
))
586 { /* This is a lambda expression within a lexical environment;
587 return an interpreted closure instead of a simple lambda. */
588 Lisp_Object cdr
= XCDR (quoted
);
589 Lisp_Object tmp
= cdr
;
591 && (tmp
= XCDR (tmp
), CONSP (tmp
))
592 && (tmp
= XCAR (tmp
), CONSP (tmp
))
593 && (EQ (QCdocumentation
, XCAR (tmp
))))
594 { /* Handle the special (:documentation <form>) to build the docstring
596 Lisp_Object docstring
= eval_sub (Fcar (XCDR (tmp
)));
597 CHECK_STRING (docstring
);
598 cdr
= Fcons (XCAR (cdr
), Fcons (docstring
, XCDR (XCDR (cdr
))));
600 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
,
604 /* Simply quote the argument. */
609 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
610 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
611 Aliased variables always have the same value; setting one sets the other.
612 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
613 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
614 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
615 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
616 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
617 The return value is BASE-VARIABLE. */)
618 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
620 struct Lisp_Symbol
*sym
;
622 CHECK_SYMBOL (new_alias
);
623 CHECK_SYMBOL (base_variable
);
625 sym
= XSYMBOL (new_alias
);
628 /* Not sure why, but why not? */
629 error ("Cannot make a constant an alias");
631 switch (sym
->redirect
)
633 case SYMBOL_FORWARDED
:
634 error ("Cannot make an internal variable an alias");
635 case SYMBOL_LOCALIZED
:
636 error ("Don't know how to make a localized variable an alias");
639 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
640 If n_a is bound, but b_v is not, set the value of b_v to n_a,
641 so that old-code that affects n_a before the aliasing is setup
643 if (NILP (Fboundp (base_variable
)))
644 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
647 union specbinding
*p
;
649 for (p
= specpdl_ptr
; p
> specpdl
; )
650 if ((--p
)->kind
>= SPECPDL_LET
651 && (EQ (new_alias
, specpdl_symbol (p
))))
652 error ("Don't know how to make a let-bound variable an alias");
655 sym
->declared_special
= 1;
656 XSYMBOL (base_variable
)->declared_special
= 1;
657 sym
->redirect
= SYMBOL_VARALIAS
;
658 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
659 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
660 LOADHIST_ATTACH (new_alias
);
661 /* Even if docstring is nil: remove old docstring. */
662 Fput (new_alias
, Qvariable_documentation
, docstring
);
664 return base_variable
;
667 static union specbinding
*
668 default_toplevel_binding (Lisp_Object symbol
)
670 union specbinding
*binding
= NULL
;
671 union specbinding
*pdl
= specpdl_ptr
;
672 while (pdl
> specpdl
)
674 switch ((--pdl
)->kind
)
676 case SPECPDL_LET_DEFAULT
:
678 if (EQ (specpdl_symbol (pdl
), symbol
))
686 DEFUN ("default-toplevel-value", Fdefault_toplevel_value
, Sdefault_toplevel_value
, 1, 1, 0,
687 doc
: /* Return SYMBOL's toplevel default value.
688 "Toplevel" means outside of any let binding. */)
691 union specbinding
*binding
= default_toplevel_binding (symbol
);
693 = binding
? specpdl_old_value (binding
) : Fdefault_value (symbol
);
694 if (!EQ (value
, Qunbound
))
696 xsignal1 (Qvoid_variable
, symbol
);
699 DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value
,
700 Sset_default_toplevel_value
, 2, 2, 0,
701 doc
: /* Set SYMBOL's toplevel default value to VALUE.
702 "Toplevel" means outside of any let binding. */)
703 (Lisp_Object symbol
, Lisp_Object value
)
705 union specbinding
*binding
= default_toplevel_binding (symbol
);
707 set_specpdl_old_value (binding
, value
);
709 Fset_default (symbol
, value
);
713 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
714 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
715 You are not required to define a variable in order to use it, but
716 defining it lets you supply an initial value and documentation, which
717 can be referred to by the Emacs help facilities and other programming
718 tools. The `defvar' form also declares the variable as \"special\",
719 so that it is always dynamically bound even if `lexical-binding' is t.
721 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
722 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
723 default value is what is set; buffer-local values are not affected.
724 If INITVALUE is missing, SYMBOL's value is not set.
726 If SYMBOL has a local binding, then this form affects the local
727 binding. This is usually not what you want. Thus, if you need to
728 load a file defining variables, with this form or with `defconst' or
729 `defcustom', you should always load that file _outside_ any bindings
730 for these variables. \(`defconst' and `defcustom' behave similarly in
733 The optional argument DOCSTRING is a documentation string for the
736 To define a user option, use `defcustom' instead of `defvar'.
737 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
740 Lisp_Object sym
, tem
, tail
;
747 if (CONSP (XCDR (tail
)) && CONSP (XCDR (XCDR (tail
))))
748 error ("Too many arguments");
750 tem
= Fdefault_boundp (sym
);
752 /* Do it before evaluating the initial value, for self-references. */
753 XSYMBOL (sym
)->declared_special
= 1;
756 Fset_default (sym
, eval_sub (XCAR (tail
)));
758 { /* Check if there is really a global binding rather than just a let
759 binding that shadows the global unboundness of the var. */
760 union specbinding
*binding
= default_toplevel_binding (sym
);
761 if (binding
&& EQ (specpdl_old_value (binding
), Qunbound
))
763 set_specpdl_old_value (binding
, eval_sub (XCAR (tail
)));
770 if (!NILP (Vpurify_flag
))
771 tem
= Fpurecopy (tem
);
772 Fput (sym
, Qvariable_documentation
, tem
);
774 LOADHIST_ATTACH (sym
);
776 else if (!NILP (Vinternal_interpreter_environment
)
777 && !XSYMBOL (sym
)->declared_special
)
778 /* A simple (defvar foo) with lexical scoping does "nothing" except
779 declare that var to be dynamically scoped *locally* (i.e. within
780 the current file or let-block). */
781 Vinternal_interpreter_environment
782 = Fcons (sym
, Vinternal_interpreter_environment
);
785 /* Simple (defvar <var>) should not count as a definition at all.
786 It could get in the way of other definitions, and unloading this
787 package could try to make the variable unbound. */
793 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
794 doc
: /* Define SYMBOL as a constant variable.
795 This declares that neither programs nor users should ever change the
796 value. This constancy is not actually enforced by Emacs Lisp, but
797 SYMBOL is marked as a special variable so that it is never lexically
800 The `defconst' form always sets the value of SYMBOL to the result of
801 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
802 what is set; buffer-local values are not affected. If SYMBOL has a
803 local binding, then this form sets the local binding's value.
804 However, you should normally not make local bindings for variables
805 defined with this form.
807 The optional DOCSTRING specifies the variable's documentation string.
808 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
811 Lisp_Object sym
, tem
;
814 if (CONSP (Fcdr (XCDR (XCDR (args
)))))
815 error ("Too many arguments");
817 tem
= eval_sub (Fcar (XCDR (args
)));
818 if (!NILP (Vpurify_flag
))
819 tem
= Fpurecopy (tem
);
820 Fset_default (sym
, tem
);
821 XSYMBOL (sym
)->declared_special
= 1;
822 tem
= Fcar (XCDR (XCDR (args
)));
825 if (!NILP (Vpurify_flag
))
826 tem
= Fpurecopy (tem
);
827 Fput (sym
, Qvariable_documentation
, tem
);
829 Fput (sym
, Qrisky_local_variable
, Qt
);
830 LOADHIST_ATTACH (sym
);
834 /* Make SYMBOL lexically scoped. */
835 DEFUN ("internal-make-var-non-special", Fmake_var_non_special
,
836 Smake_var_non_special
, 1, 1, 0,
837 doc
: /* Internal function. */)
840 CHECK_SYMBOL (symbol
);
841 XSYMBOL (symbol
)->declared_special
= 0;
846 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
847 doc
: /* Bind variables according to VARLIST then eval BODY.
848 The value of the last form in BODY is returned.
849 Each element of VARLIST is a symbol (which is bound to nil)
850 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
851 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
852 usage: (let* VARLIST BODY...) */)
855 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
856 ptrdiff_t count
= SPECPDL_INDEX ();
857 struct gcpro gcpro1
, gcpro2
, gcpro3
;
859 GCPRO3 (args
, elt
, varlist
);
861 lexenv
= Vinternal_interpreter_environment
;
863 varlist
= XCAR (args
);
864 while (CONSP (varlist
))
868 elt
= XCAR (varlist
);
874 else if (! NILP (Fcdr (Fcdr (elt
))))
875 signal_error ("`let' bindings can have only one value-form", elt
);
879 val
= eval_sub (Fcar (Fcdr (elt
)));
882 if (!NILP (lexenv
) && SYMBOLP (var
)
883 && !XSYMBOL (var
)->declared_special
884 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
885 /* Lexically bind VAR by adding it to the interpreter's binding
889 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
890 if (EQ (Vinternal_interpreter_environment
, lexenv
))
891 /* Save the old lexical environment on the specpdl stack,
892 but only for the first lexical binding, since we'll never
893 need to revert to one of the intermediate ones. */
894 specbind (Qinternal_interpreter_environment
, newenv
);
896 Vinternal_interpreter_environment
= newenv
;
901 varlist
= XCDR (varlist
);
904 val
= Fprogn (XCDR (args
));
905 return unbind_to (count
, val
);
908 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
909 doc
: /* Bind variables according to VARLIST then eval BODY.
910 The value of the last form in BODY is returned.
911 Each element of VARLIST is a symbol (which is bound to nil)
912 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
913 All the VALUEFORMs are evalled before any symbols are bound.
914 usage: (let VARLIST BODY...) */)
917 Lisp_Object
*temps
, tem
, lexenv
;
918 register Lisp_Object elt
, varlist
;
919 ptrdiff_t count
= SPECPDL_INDEX ();
921 struct gcpro gcpro1
, gcpro2
;
924 varlist
= XCAR (args
);
926 /* Make space to hold the values to give the bound variables. */
927 elt
= Flength (varlist
);
928 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
930 /* Compute the values and store them in `temps'. */
932 GCPRO2 (args
, *temps
);
935 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
938 elt
= XCAR (varlist
);
940 temps
[argnum
++] = Qnil
;
941 else if (! NILP (Fcdr (Fcdr (elt
))))
942 signal_error ("`let' bindings can have only one value-form", elt
);
944 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
945 gcpro2
.nvars
= argnum
;
949 lexenv
= Vinternal_interpreter_environment
;
951 varlist
= XCAR (args
);
952 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
956 elt
= XCAR (varlist
);
957 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
958 tem
= temps
[argnum
++];
960 if (!NILP (lexenv
) && SYMBOLP (var
)
961 && !XSYMBOL (var
)->declared_special
962 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
963 /* Lexically bind VAR by adding it to the lexenv alist. */
964 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
966 /* Dynamically bind VAR. */
970 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
971 /* Instantiate a new lexical environment. */
972 specbind (Qinternal_interpreter_environment
, lexenv
);
974 elt
= Fprogn (XCDR (args
));
976 return unbind_to (count
, elt
);
979 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
980 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
981 The order of execution is thus TEST, BODY, TEST, BODY and so on
982 until TEST returns nil.
983 usage: (while TEST BODY...) */)
986 Lisp_Object test
, body
;
987 struct gcpro gcpro1
, gcpro2
;
993 while (!NILP (eval_sub (test
)))
1003 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1004 doc
: /* Return result of expanding macros at top level of FORM.
1005 If FORM is not a macro call, it is returned unchanged.
1006 Otherwise, the macro is expanded and the expansion is considered
1007 in place of FORM. When a non-macro-call results, it is returned.
1009 The second optional arg ENVIRONMENT specifies an environment of macro
1010 definitions to shadow the loaded ones for use in file byte-compilation. */)
1011 (Lisp_Object form
, Lisp_Object environment
)
1013 /* With cleanups from Hallvard Furuseth. */
1014 register Lisp_Object expander
, sym
, def
, tem
;
1018 /* Come back here each time we expand a macro call,
1019 in case it expands into another macro call. */
1022 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1023 def
= sym
= XCAR (form
);
1025 /* Trace symbols aliases to other symbols
1026 until we get a symbol that is not an alias. */
1027 while (SYMBOLP (def
))
1031 tem
= Fassq (sym
, environment
);
1034 def
= XSYMBOL (sym
)->function
;
1040 /* Right now TEM is the result from SYM in ENVIRONMENT,
1041 and if TEM is nil then DEF is SYM's function definition. */
1044 /* SYM is not mentioned in ENVIRONMENT.
1045 Look at its function definition. */
1046 struct gcpro gcpro1
;
1048 def
= Fautoload_do_load (def
, sym
, Qmacro
);
1051 /* Not defined or definition not suitable. */
1053 if (!EQ (XCAR (def
), Qmacro
))
1055 else expander
= XCDR (def
);
1059 expander
= XCDR (tem
);
1060 if (NILP (expander
))
1064 Lisp_Object newform
= apply1 (expander
, XCDR (form
));
1065 if (EQ (form
, newform
))
1074 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1075 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1076 TAG is evalled to get the tag to use; it must not be nil.
1078 Then the BODY is executed.
1079 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1080 If no throw happens, `catch' returns the value of the last BODY form.
1081 If a throw happens, it specifies the value to return from `catch'.
1082 usage: (catch TAG BODY...) */)
1085 register Lisp_Object tag
;
1086 struct gcpro gcpro1
;
1089 tag
= eval_sub (XCAR (args
));
1091 return internal_catch (tag
, Fprogn
, XCDR (args
));
1094 /* Assert that E is true, as a comment only. Use this instead of
1095 eassert (E) when E contains variables that might be clobbered by a
1098 #define clobbered_eassert(E) ((void) 0)
1100 /* Set up a catch, then call C function FUNC on argument ARG.
1101 FUNC should return a Lisp_Object.
1102 This is how catches are done from within C code. */
1105 internal_catch (Lisp_Object tag
, Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1107 /* This structure is made part of the chain `catchlist'. */
1110 /* Fill in the components of c, and put it on the list. */
1111 PUSH_HANDLER (c
, tag
, CATCHER
);
1114 if (! sys_setjmp (c
->jmp
))
1116 Lisp_Object val
= (*func
) (arg
);
1117 clobbered_eassert (handlerlist
== c
);
1118 handlerlist
= handlerlist
->next
;
1122 { /* Throw works by a longjmp that comes right here. */
1123 Lisp_Object val
= handlerlist
->val
;
1124 clobbered_eassert (handlerlist
== c
);
1125 handlerlist
= handlerlist
->next
;
1130 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1131 jump to that CATCH, returning VALUE as the value of that catch.
1133 This is the guts of Fthrow and Fsignal; they differ only in the way
1134 they choose the catch tag to throw to. A catch tag for a
1135 condition-case form has a TAG of Qnil.
1137 Before each catch is discarded, unbind all special bindings and
1138 execute all unwind-protect clauses made above that catch. Unwind
1139 the handler stack as we go, so that the proper handlers are in
1140 effect for each unwind-protect clause we run. At the end, restore
1141 some static info saved in CATCH, and longjmp to the location
1144 This is used for correct unwinding in Fthrow and Fsignal. */
1146 static _Noreturn
void
1147 unwind_to_catch (struct handler
*catch, Lisp_Object value
)
1151 eassert (catch->next
);
1153 /* Save the value in the tag. */
1156 /* Restore certain special C variables. */
1157 set_poll_suppress_count (catch->poll_suppress_count
);
1158 unblock_input_to (catch->interrupt_input_blocked
);
1163 /* Unwind the specpdl stack, and then restore the proper set of
1165 unbind_to (handlerlist
->pdlcount
, Qnil
);
1166 last_time
= handlerlist
== catch;
1168 handlerlist
= handlerlist
->next
;
1170 while (! last_time
);
1172 eassert (handlerlist
== catch);
1174 byte_stack_list
= catch->byte_stack
;
1175 gcprolist
= catch->gcpro
;
1177 gcpro_level
= gcprolist
? gcprolist
->level
+ 1 : 0;
1179 lisp_eval_depth
= catch->lisp_eval_depth
;
1181 sys_longjmp (catch->jmp
, 1);
1184 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1185 doc
: /* Throw to the catch for TAG and return VALUE from it.
1186 Both TAG and VALUE are evalled. */
1187 attributes
: noreturn
)
1188 (register Lisp_Object tag
, Lisp_Object value
)
1193 for (c
= handlerlist
; c
; c
= c
->next
)
1195 if (c
->type
== CATCHER
&& EQ (c
->tag_or_ch
, tag
))
1196 unwind_to_catch (c
, value
);
1198 xsignal2 (Qno_catch
, tag
, value
);
1202 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1203 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1204 If BODYFORM completes normally, its value is returned
1205 after executing the UNWINDFORMS.
1206 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1207 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1211 ptrdiff_t count
= SPECPDL_INDEX ();
1213 record_unwind_protect (unwind_body
, XCDR (args
));
1214 val
= eval_sub (XCAR (args
));
1215 return unbind_to (count
, val
);
1218 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1219 doc
: /* Regain control when an error is signaled.
1220 Executes BODYFORM and returns its value if no error happens.
1221 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1222 where the BODY is made of Lisp expressions.
1224 A handler is applicable to an error
1225 if CONDITION-NAME is one of the error's condition names.
1226 If an error happens, the first applicable handler is run.
1228 The car of a handler may be a list of condition names instead of a
1229 single condition name; then it handles all of them. If the special
1230 condition name `debug' is present in this list, it allows another
1231 condition in the list to run the debugger if `debug-on-error' and the
1232 other usual mechanisms says it should (otherwise, `condition-case'
1233 suppresses the debugger).
1235 When a handler handles an error, control returns to the `condition-case'
1236 and it executes the handler's BODY...
1237 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1238 \(If VAR is nil, the handler can't access that information.)
1239 Then the value of the last BODY form is returned from the `condition-case'
1242 See also the function `signal' for more info.
1243 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1246 Lisp_Object var
= XCAR (args
);
1247 Lisp_Object bodyform
= XCAR (XCDR (args
));
1248 Lisp_Object handlers
= XCDR (XCDR (args
));
1250 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1253 /* Like Fcondition_case, but the args are separate
1254 rather than passed in a list. Used by Fbyte_code. */
1257 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1258 Lisp_Object handlers
)
1262 struct handler
*oldhandlerlist
= handlerlist
;
1267 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1269 Lisp_Object tem
= XCAR (val
);
1273 && (SYMBOLP (XCAR (tem
))
1274 || CONSP (XCAR (tem
))))))
1275 error ("Invalid condition handler: %s",
1276 SDATA (Fprin1_to_string (tem
, Qt
)));
1279 { /* The first clause is the one that should be checked first, so it should
1280 be added to handlerlist last. So we build in `clauses' a table that
1281 contains `handlers' but in reverse order. SAFE_ALLOCA won't work
1282 here due to the setjmp, so impose a MAX_ALLOCA limit. */
1283 if (MAX_ALLOCA
/ word_size
< clausenb
)
1284 memory_full (SIZE_MAX
);
1285 Lisp_Object
*clauses
= alloca (clausenb
* sizeof *clauses
);
1286 Lisp_Object
*volatile clauses_volatile
= clauses
;
1288 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1289 clauses
[--i
] = XCAR (val
);
1290 for (i
= 0; i
< clausenb
; i
++)
1292 Lisp_Object clause
= clauses
[i
];
1293 Lisp_Object condition
= XCAR (clause
);
1294 if (!CONSP (condition
))
1295 condition
= Fcons (condition
, Qnil
);
1296 PUSH_HANDLER (c
, condition
, CONDITION_CASE
);
1297 if (sys_setjmp (c
->jmp
))
1299 ptrdiff_t count
= SPECPDL_INDEX ();
1300 Lisp_Object val
= handlerlist
->val
;
1301 Lisp_Object
*chosen_clause
= clauses_volatile
;
1302 for (c
= handlerlist
->next
; c
!= oldhandlerlist
; c
= c
->next
)
1304 handlerlist
= oldhandlerlist
;
1307 if (!NILP (Vinternal_interpreter_environment
))
1308 specbind (Qinternal_interpreter_environment
,
1309 Fcons (Fcons (var
, val
),
1310 Vinternal_interpreter_environment
));
1312 specbind (var
, val
);
1314 val
= Fprogn (XCDR (*chosen_clause
));
1315 /* Note that this just undoes the binding of var; whoever
1316 longjumped to us unwound the stack to c.pdlcount before
1319 unbind_to (count
, Qnil
);
1325 val
= eval_sub (bodyform
);
1326 handlerlist
= oldhandlerlist
;
1330 /* Call the function BFUN with no arguments, catching errors within it
1331 according to HANDLERS. If there is an error, call HFUN with
1332 one argument which is the data that describes the error:
1335 HANDLERS can be a list of conditions to catch.
1336 If HANDLERS is Qt, catch all errors.
1337 If HANDLERS is Qerror, catch all errors
1338 but allow the debugger to run if that is enabled. */
1341 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1342 Lisp_Object (*hfun
) (Lisp_Object
))
1347 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1348 if (sys_setjmp (c
->jmp
))
1350 Lisp_Object val
= handlerlist
->val
;
1351 clobbered_eassert (handlerlist
== c
);
1352 handlerlist
= handlerlist
->next
;
1353 return (*hfun
) (val
);
1357 clobbered_eassert (handlerlist
== c
);
1358 handlerlist
= handlerlist
->next
;
1362 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1365 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1366 Lisp_Object handlers
, Lisp_Object (*hfun
) (Lisp_Object
))
1371 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1372 if (sys_setjmp (c
->jmp
))
1374 Lisp_Object val
= handlerlist
->val
;
1375 clobbered_eassert (handlerlist
== c
);
1376 handlerlist
= handlerlist
->next
;
1377 return (*hfun
) (val
);
1380 val
= (*bfun
) (arg
);
1381 clobbered_eassert (handlerlist
== c
);
1382 handlerlist
= handlerlist
->next
;
1386 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1390 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1393 Lisp_Object handlers
,
1394 Lisp_Object (*hfun
) (Lisp_Object
))
1399 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1400 if (sys_setjmp (c
->jmp
))
1402 Lisp_Object val
= handlerlist
->val
;
1403 clobbered_eassert (handlerlist
== c
);
1404 handlerlist
= handlerlist
->next
;
1405 return (*hfun
) (val
);
1408 val
= (*bfun
) (arg1
, arg2
);
1409 clobbered_eassert (handlerlist
== c
);
1410 handlerlist
= handlerlist
->next
;
1414 /* Like internal_condition_case but call BFUN with NARGS as first,
1415 and ARGS as second argument. */
1418 internal_condition_case_n (Lisp_Object (*bfun
) (ptrdiff_t, Lisp_Object
*),
1421 Lisp_Object handlers
,
1422 Lisp_Object (*hfun
) (Lisp_Object err
,
1429 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1430 if (sys_setjmp (c
->jmp
))
1432 Lisp_Object val
= handlerlist
->val
;
1433 clobbered_eassert (handlerlist
== c
);
1434 handlerlist
= handlerlist
->next
;
1435 return (*hfun
) (val
, nargs
, args
);
1438 val
= (*bfun
) (nargs
, args
);
1439 clobbered_eassert (handlerlist
== c
);
1440 handlerlist
= handlerlist
->next
;
1445 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
);
1446 static bool maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
,
1450 process_quit_flag (void)
1452 Lisp_Object flag
= Vquit_flag
;
1454 if (EQ (flag
, Qkill_emacs
))
1456 if (EQ (Vthrow_on_input
, flag
))
1457 Fthrow (Vthrow_on_input
, Qt
);
1458 Fsignal (Qquit
, Qnil
);
1461 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1462 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1463 This function does not return.
1465 An error symbol is a symbol with an `error-conditions' property
1466 that is a list of condition names.
1467 A handler for any of those names will get to handle this signal.
1468 The symbol `error' should normally be one of them.
1470 DATA should be a list. Its elements are printed as part of the error message.
1471 See Info anchor `(elisp)Definition of signal' for some details on how this
1472 error message is constructed.
1473 If the signal is handled, DATA is made available to the handler.
1474 See also the function `condition-case'. */)
1475 (Lisp_Object error_symbol
, Lisp_Object data
)
1477 /* When memory is full, ERROR-SYMBOL is nil,
1478 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1479 That is a special case--don't do this in other situations. */
1480 Lisp_Object conditions
;
1482 Lisp_Object real_error_symbol
1483 = (NILP (error_symbol
) ? Fcar (data
) : error_symbol
);
1484 register Lisp_Object clause
= Qnil
;
1489 if (gc_in_progress
|| waiting_for_input
)
1492 #if 0 /* rms: I don't know why this was here,
1493 but it is surely wrong for an error that is handled. */
1494 #ifdef HAVE_WINDOW_SYSTEM
1495 if (display_hourglass_p
)
1496 cancel_hourglass ();
1500 /* This hook is used by edebug. */
1501 if (! NILP (Vsignal_hook_function
)
1502 && ! NILP (error_symbol
))
1504 /* Edebug takes care of restoring these variables when it exits. */
1505 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1506 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1508 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1509 max_specpdl_size
= SPECPDL_INDEX () + 40;
1511 call2 (Vsignal_hook_function
, error_symbol
, data
);
1514 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1516 /* Remember from where signal was called. Skip over the frame for
1517 `signal' itself. If a frame for `error' follows, skip that,
1518 too. Don't do this when ERROR_SYMBOL is nil, because that
1519 is a memory-full error. */
1520 Vsignaling_function
= Qnil
;
1521 if (!NILP (error_symbol
))
1523 union specbinding
*pdl
= backtrace_next (backtrace_top ());
1524 if (backtrace_p (pdl
) && EQ (backtrace_function (pdl
), Qerror
))
1525 pdl
= backtrace_next (pdl
);
1526 if (backtrace_p (pdl
))
1527 Vsignaling_function
= backtrace_function (pdl
);
1530 for (h
= handlerlist
; h
; h
= h
->next
)
1532 if (h
->type
!= CONDITION_CASE
)
1534 clause
= find_handler_clause (h
->tag_or_ch
, conditions
);
1539 if (/* Don't run the debugger for a memory-full error.
1540 (There is no room in memory to do that!) */
1541 !NILP (error_symbol
)
1542 && (!NILP (Vdebug_on_signal
)
1543 /* If no handler is present now, try to run the debugger. */
1545 /* A `debug' symbol in the handler list disables the normal
1546 suppression of the debugger. */
1547 || (CONSP (clause
) && !NILP (Fmemq (Qdebug
, clause
)))
1548 /* Special handler that means "print a message and run debugger
1550 || EQ (h
->tag_or_ch
, Qerror
)))
1552 bool debugger_called
1553 = maybe_call_debugger (conditions
, error_symbol
, data
);
1554 /* We can't return values to code which signaled an error, but we
1555 can continue code which has signaled a quit. */
1556 if (debugger_called
&& EQ (real_error_symbol
, Qquit
))
1562 Lisp_Object unwind_data
1563 = (NILP (error_symbol
) ? data
: Fcons (error_symbol
, data
));
1565 unwind_to_catch (h
, unwind_data
);
1569 if (handlerlist
!= &handlerlist_sentinel
)
1570 /* FIXME: This will come right back here if there's no `top-level'
1571 catcher. A better solution would be to abort here, and instead
1572 add a catch-all condition handler so we never come here. */
1573 Fthrow (Qtop_level
, Qt
);
1576 if (! NILP (error_symbol
))
1577 data
= Fcons (error_symbol
, data
);
1579 string
= Ferror_message_string (data
);
1580 fatal ("%s", SDATA (string
));
1583 /* Internal version of Fsignal that never returns.
1584 Used for anything but Qquit (which can return from Fsignal). */
1587 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1589 Fsignal (error_symbol
, data
);
1593 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1596 xsignal0 (Lisp_Object error_symbol
)
1598 xsignal (error_symbol
, Qnil
);
1602 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1604 xsignal (error_symbol
, list1 (arg
));
1608 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1610 xsignal (error_symbol
, list2 (arg1
, arg2
));
1614 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1616 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1619 /* Signal `error' with message S, and additional arg ARG.
1620 If ARG is not a genuine list, make it a one-element list. */
1623 signal_error (const char *s
, Lisp_Object arg
)
1625 Lisp_Object tortoise
, hare
;
1627 hare
= tortoise
= arg
;
1628 while (CONSP (hare
))
1635 tortoise
= XCDR (tortoise
);
1637 if (EQ (hare
, tortoise
))
1644 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1648 /* Return true if LIST is a non-nil atom or
1649 a list containing one of CONDITIONS. */
1652 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1659 while (CONSP (conditions
))
1661 Lisp_Object
this, tail
;
1662 this = XCAR (conditions
);
1663 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1664 if (EQ (XCAR (tail
), this))
1666 conditions
= XCDR (conditions
);
1671 /* Return true if an error with condition-symbols CONDITIONS,
1672 and described by SIGNAL-DATA, should skip the debugger
1673 according to debugger-ignored-errors. */
1676 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1679 bool first_string
= 1;
1680 Lisp_Object error_message
;
1682 error_message
= Qnil
;
1683 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1685 if (STRINGP (XCAR (tail
)))
1689 error_message
= Ferror_message_string (data
);
1693 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1698 Lisp_Object contail
;
1700 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1701 if (EQ (XCAR (tail
), XCAR (contail
)))
1709 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1710 SIG and DATA describe the signal. There are two ways to pass them:
1711 = SIG is the error symbol, and DATA is the rest of the data.
1712 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1713 This is for memory-full errors only. */
1715 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1717 Lisp_Object combined_data
;
1719 combined_data
= Fcons (sig
, data
);
1722 /* Don't try to run the debugger with interrupts blocked.
1723 The editing loop would return anyway. */
1724 ! input_blocked_p ()
1725 && NILP (Vinhibit_debugger
)
1726 /* Does user want to enter debugger for this kind of error? */
1729 : wants_debugger (Vdebug_on_error
, conditions
))
1730 && ! skip_debugger (conditions
, combined_data
)
1731 /* RMS: What's this for? */
1732 && when_entered_debugger
< num_nonmacro_input_events
)
1734 call_debugger (list2 (Qerror
, combined_data
));
1742 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
)
1744 register Lisp_Object h
;
1746 /* t is used by handlers for all conditions, set up by C code. */
1747 if (EQ (handlers
, Qt
))
1750 /* error is used similarly, but means print an error message
1751 and run the debugger if that is enabled. */
1752 if (EQ (handlers
, Qerror
))
1755 for (h
= handlers
; CONSP (h
); h
= XCDR (h
))
1757 Lisp_Object handler
= XCAR (h
);
1758 if (!NILP (Fmemq (handler
, conditions
)))
1766 /* Dump an error message; called like vprintf. */
1768 verror (const char *m
, va_list ap
)
1771 ptrdiff_t size
= sizeof buf
;
1772 ptrdiff_t size_max
= STRING_BYTES_BOUND
+ 1;
1777 used
= evxprintf (&buffer
, &size
, buf
, size_max
, m
, ap
);
1778 string
= make_string (buffer
, used
);
1782 xsignal1 (Qerror
, string
);
1786 /* Dump an error message; called like printf. */
1790 error (const char *m
, ...)
1797 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1798 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1799 This means it contains a description for how to read arguments to give it.
1800 The value is nil for an invalid function or a symbol with no function
1803 Interactively callable functions include strings and vectors (treated
1804 as keyboard macros), lambda-expressions that contain a top-level call
1805 to `interactive', autoload definitions made by `autoload' with non-nil
1806 fourth argument, and some of the built-in functions of Lisp.
1808 Also, a symbol satisfies `commandp' if its function definition does so.
1810 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1811 then strings and vectors are not accepted. */)
1812 (Lisp_Object function
, Lisp_Object for_call_interactively
)
1814 register Lisp_Object fun
;
1815 register Lisp_Object funcar
;
1816 Lisp_Object if_prop
= Qnil
;
1820 fun
= indirect_function (fun
); /* Check cycles. */
1824 /* Check an `interactive-form' property if present, analogous to the
1825 function-documentation property. */
1827 while (SYMBOLP (fun
))
1829 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
1832 fun
= Fsymbol_function (fun
);
1835 /* Emacs primitives are interactive if their DEFUN specifies an
1836 interactive spec. */
1838 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
1840 /* Bytecode objects are interactive if they are long enough to
1841 have an element whose index is COMPILED_INTERACTIVE, which is
1842 where the interactive spec is stored. */
1843 else if (COMPILEDP (fun
))
1844 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1847 /* Strings and vectors are keyboard macros. */
1848 if (STRINGP (fun
) || VECTORP (fun
))
1849 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
1851 /* Lists may represent commands. */
1854 funcar
= XCAR (fun
);
1855 if (EQ (funcar
, Qclosure
))
1856 return (!NILP (Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
)))))
1858 else if (EQ (funcar
, Qlambda
))
1859 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
1860 else if (EQ (funcar
, Qautoload
))
1861 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
1866 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1867 doc
: /* Define FUNCTION to autoload from FILE.
1868 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1869 Third arg DOCSTRING is documentation for the function.
1870 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1871 Fifth arg TYPE indicates the type of the object:
1872 nil or omitted says FUNCTION is a function,
1873 `keymap' says FUNCTION is really a keymap, and
1874 `macro' or t says FUNCTION is really a macro.
1875 Third through fifth args give info about the real definition.
1876 They default to nil.
1877 If FUNCTION is already defined other than as an autoload,
1878 this does nothing and returns nil. */)
1879 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
1881 CHECK_SYMBOL (function
);
1882 CHECK_STRING (file
);
1884 /* If function is defined and not as an autoload, don't override. */
1885 if (!NILP (XSYMBOL (function
)->function
)
1886 && !AUTOLOADP (XSYMBOL (function
)->function
))
1889 if (!NILP (Vpurify_flag
) && EQ (docstring
, make_number (0)))
1890 /* `read1' in lread.c has found the docstring starting with "\
1891 and assumed the docstring will be provided by Snarf-documentation, so it
1892 passed us 0 instead. But that leads to accidental sharing in purecopy's
1893 hash-consing, so we use a (hopefully) unique integer instead. */
1894 docstring
= make_number (XHASH (function
));
1895 return Fdefalias (function
,
1896 list5 (Qautoload
, file
, docstring
, interactive
, type
),
1901 un_autoload (Lisp_Object oldqueue
)
1903 Lisp_Object queue
, first
, second
;
1905 /* Queue to unwind is current value of Vautoload_queue.
1906 oldqueue is the shadowed value to leave in Vautoload_queue. */
1907 queue
= Vautoload_queue
;
1908 Vautoload_queue
= oldqueue
;
1909 while (CONSP (queue
))
1911 first
= XCAR (queue
);
1912 second
= Fcdr (first
);
1913 first
= Fcar (first
);
1914 if (EQ (first
, make_number (0)))
1917 Ffset (first
, second
);
1918 queue
= XCDR (queue
);
1922 /* Load an autoloaded function.
1923 FUNNAME is the symbol which is the function's name.
1924 FUNDEF is the autoload definition (a list). */
1926 DEFUN ("autoload-do-load", Fautoload_do_load
, Sautoload_do_load
, 1, 3, 0,
1927 doc
: /* Load FUNDEF which should be an autoload.
1928 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1929 in which case the function returns the new autoloaded function value.
1930 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1931 it defines a macro. */)
1932 (Lisp_Object fundef
, Lisp_Object funname
, Lisp_Object macro_only
)
1934 ptrdiff_t count
= SPECPDL_INDEX ();
1935 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1937 if (!CONSP (fundef
) || !EQ (Qautoload
, XCAR (fundef
)))
1940 if (EQ (macro_only
, Qmacro
))
1942 Lisp_Object kind
= Fnth (make_number (4), fundef
);
1943 if (! (EQ (kind
, Qt
) || EQ (kind
, Qmacro
)))
1947 /* This is to make sure that loadup.el gives a clear picture
1948 of what files are preloaded and when. */
1949 if (! NILP (Vpurify_flag
))
1950 error ("Attempt to autoload %s while preparing to dump",
1951 SDATA (SYMBOL_NAME (funname
)));
1953 CHECK_SYMBOL (funname
);
1954 GCPRO3 (funname
, fundef
, macro_only
);
1956 /* Preserve the match data. */
1957 record_unwind_save_match_data ();
1959 /* If autoloading gets an error (which includes the error of failing
1960 to define the function being called), we use Vautoload_queue
1961 to undo function definitions and `provide' calls made by
1962 the function. We do this in the specific case of autoloading
1963 because autoloading is not an explicit request "load this file",
1964 but rather a request to "call this function".
1966 The value saved here is to be restored into Vautoload_queue. */
1967 record_unwind_protect (un_autoload
, Vautoload_queue
);
1968 Vautoload_queue
= Qt
;
1969 /* If `macro_only', assume this autoload to be a "best-effort",
1970 so don't signal an error if autoloading fails. */
1971 Fload (Fcar (Fcdr (fundef
)), macro_only
, Qt
, Qnil
, Qt
);
1973 /* Once loading finishes, don't undo it. */
1974 Vautoload_queue
= Qt
;
1975 unbind_to (count
, Qnil
);
1983 Lisp_Object fun
= Findirect_function (funname
, Qnil
);
1985 if (!NILP (Fequal (fun
, fundef
)))
1986 error ("Autoloading failed to define function %s",
1987 SDATA (SYMBOL_NAME (funname
)));
1994 DEFUN ("eval", Feval
, Seval
, 1, 2, 0,
1995 doc
: /* Evaluate FORM and return its value.
1996 If LEXICAL is t, evaluate using lexical scoping.
1997 LEXICAL can also be an actual lexical environment, in the form of an
1998 alist mapping symbols to their value. */)
1999 (Lisp_Object form
, Lisp_Object lexical
)
2001 ptrdiff_t count
= SPECPDL_INDEX ();
2002 specbind (Qinternal_interpreter_environment
,
2003 CONSP (lexical
) || NILP (lexical
) ? lexical
: list1 (Qt
));
2004 return unbind_to (count
, eval_sub (form
));
2007 /* Grow the specpdl stack by one entry.
2008 The caller should have already initialized the entry.
2009 Signal an error on stack overflow.
2011 Make sure that there is always one unused entry past the top of the
2012 stack, so that the just-initialized entry is safely unwound if
2013 memory exhausted and an error is signaled here. Also, allocate a
2014 never-used entry just before the bottom of the stack; sometimes its
2015 address is taken. */
2022 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2024 ptrdiff_t count
= SPECPDL_INDEX ();
2025 ptrdiff_t max_size
= min (max_specpdl_size
, PTRDIFF_MAX
- 1000);
2026 union specbinding
*pdlvec
= specpdl
- 1;
2027 ptrdiff_t pdlvecsize
= specpdl_size
+ 1;
2028 if (max_size
<= specpdl_size
)
2030 if (max_specpdl_size
< 400)
2031 max_size
= max_specpdl_size
= 400;
2032 if (max_size
<= specpdl_size
)
2033 signal_error ("Variable binding depth exceeds max-specpdl-size",
2036 pdlvec
= xpalloc (pdlvec
, &pdlvecsize
, 1, max_size
+ 1, sizeof *specpdl
);
2037 specpdl
= pdlvec
+ 1;
2038 specpdl_size
= pdlvecsize
- 1;
2039 specpdl_ptr
= specpdl
+ count
;
2044 record_in_backtrace (Lisp_Object function
, Lisp_Object
*args
, ptrdiff_t nargs
)
2046 ptrdiff_t count
= SPECPDL_INDEX ();
2048 eassert (nargs
>= UNEVALLED
);
2049 specpdl_ptr
->bt
.kind
= SPECPDL_BACKTRACE
;
2050 specpdl_ptr
->bt
.debug_on_exit
= false;
2051 specpdl_ptr
->bt
.function
= function
;
2052 specpdl_ptr
->bt
.args
= args
;
2053 specpdl_ptr
->bt
.nargs
= nargs
;
2059 /* Eval a sub-expression of the current expression (i.e. in the same
2062 eval_sub (Lisp_Object form
)
2064 Lisp_Object fun
, val
, original_fun
, original_args
;
2066 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2071 /* Look up its binding in the lexical environment.
2072 We do not pay attention to the declared_special flag here, since we
2073 already did that when let-binding the variable. */
2074 Lisp_Object lex_binding
2075 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2076 ? Fassq (form
, Vinternal_interpreter_environment
)
2078 if (CONSP (lex_binding
))
2079 return XCDR (lex_binding
);
2081 return Fsymbol_value (form
);
2093 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2095 if (max_lisp_eval_depth
< 100)
2096 max_lisp_eval_depth
= 100;
2097 if (lisp_eval_depth
> max_lisp_eval_depth
)
2098 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2101 original_fun
= XCAR (form
);
2102 original_args
= XCDR (form
);
2104 /* This also protects them from gc. */
2105 count
= record_in_backtrace (original_fun
, &original_args
, UNEVALLED
);
2107 if (debug_on_next_call
)
2108 do_debug_on_call (Qt
, count
);
2110 /* At this point, only original_fun and original_args
2111 have values that will be used below. */
2114 /* Optimize for no indirection. */
2117 fun
= Ffunction (Fcons (fun
, Qnil
));
2118 else if (!NILP (fun
) && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2119 fun
= indirect_function (fun
);
2123 Lisp_Object numargs
;
2124 Lisp_Object argvals
[8];
2125 Lisp_Object args_left
;
2126 register int i
, maxargs
;
2128 args_left
= original_args
;
2129 numargs
= Flength (args_left
);
2133 if (XINT (numargs
) < XSUBR (fun
)->min_args
2134 || (XSUBR (fun
)->max_args
>= 0
2135 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2136 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2138 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2139 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2140 else if (XSUBR (fun
)->max_args
== MANY
)
2142 /* Pass a vector of evaluated arguments. */
2144 ptrdiff_t argnum
= 0;
2147 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2149 GCPRO3 (args_left
, fun
, fun
);
2153 while (!NILP (args_left
))
2155 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2156 args_left
= Fcdr (args_left
);
2157 gcpro3
.nvars
= argnum
;
2160 set_backtrace_args (specpdl
+ count
, vals
, XINT (numargs
));
2162 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2168 GCPRO3 (args_left
, fun
, fun
);
2169 gcpro3
.var
= argvals
;
2172 maxargs
= XSUBR (fun
)->max_args
;
2173 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2175 argvals
[i
] = eval_sub (Fcar (args_left
));
2181 set_backtrace_args (specpdl
+ count
, argvals
, XINT (numargs
));
2186 val
= (XSUBR (fun
)->function
.a0 ());
2189 val
= (XSUBR (fun
)->function
.a1 (argvals
[0]));
2192 val
= (XSUBR (fun
)->function
.a2 (argvals
[0], argvals
[1]));
2195 val
= (XSUBR (fun
)->function
.a3
2196 (argvals
[0], argvals
[1], argvals
[2]));
2199 val
= (XSUBR (fun
)->function
.a4
2200 (argvals
[0], argvals
[1], argvals
[2], argvals
[3]));
2203 val
= (XSUBR (fun
)->function
.a5
2204 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2208 val
= (XSUBR (fun
)->function
.a6
2209 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2210 argvals
[4], argvals
[5]));
2213 val
= (XSUBR (fun
)->function
.a7
2214 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2215 argvals
[4], argvals
[5], argvals
[6]));
2219 val
= (XSUBR (fun
)->function
.a8
2220 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2221 argvals
[4], argvals
[5], argvals
[6], argvals
[7]));
2225 /* Someone has created a subr that takes more arguments than
2226 is supported by this code. We need to either rewrite the
2227 subr to use a different argument protocol, or add more
2228 cases to this switch. */
2233 else if (COMPILEDP (fun
))
2234 val
= apply_lambda (fun
, original_args
, count
);
2238 xsignal1 (Qvoid_function
, original_fun
);
2240 xsignal1 (Qinvalid_function
, original_fun
);
2241 funcar
= XCAR (fun
);
2242 if (!SYMBOLP (funcar
))
2243 xsignal1 (Qinvalid_function
, original_fun
);
2244 if (EQ (funcar
, Qautoload
))
2246 Fautoload_do_load (fun
, original_fun
, Qnil
);
2249 if (EQ (funcar
, Qmacro
))
2251 ptrdiff_t count1
= SPECPDL_INDEX ();
2253 /* Bind lexical-binding during expansion of the macro, so the
2254 macro can know reliably if the code it outputs will be
2255 interpreted using lexical-binding or not. */
2256 specbind (Qlexical_binding
,
2257 NILP (Vinternal_interpreter_environment
) ? Qnil
: Qt
);
2258 exp
= apply1 (Fcdr (fun
), original_args
);
2259 unbind_to (count1
, Qnil
);
2260 val
= eval_sub (exp
);
2262 else if (EQ (funcar
, Qlambda
)
2263 || EQ (funcar
, Qclosure
))
2264 val
= apply_lambda (fun
, original_args
, count
);
2266 xsignal1 (Qinvalid_function
, original_fun
);
2271 if (backtrace_debug_on_exit (specpdl
+ count
))
2272 val
= call_debugger (list2 (Qexit
, val
));
2278 DEFUN ("apply", Fapply
, Sapply
, 1, MANY
, 0,
2279 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2280 Then return the value FUNCTION returns.
2281 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2282 usage: (apply FUNCTION &rest ARGUMENTS) */)
2283 (ptrdiff_t nargs
, Lisp_Object
*args
)
2285 ptrdiff_t i
, numargs
, funcall_nargs
;
2286 register Lisp_Object
*funcall_args
= NULL
;
2287 register Lisp_Object spread_arg
= args
[nargs
- 1];
2288 Lisp_Object fun
= args
[0];
2292 CHECK_LIST (spread_arg
);
2294 numargs
= XINT (Flength (spread_arg
));
2297 return Ffuncall (nargs
- 1, args
);
2298 else if (numargs
== 1)
2300 args
[nargs
- 1] = XCAR (spread_arg
);
2301 return Ffuncall (nargs
, args
);
2304 numargs
+= nargs
- 2;
2306 /* Optimize for no indirection. */
2307 if (SYMBOLP (fun
) && !NILP (fun
)
2308 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2310 fun
= indirect_function (fun
);
2312 /* Let funcall get the error. */
2316 if (SUBRP (fun
) && XSUBR (fun
)->max_args
> numargs
2317 /* Don't hide an error by adding missing arguments. */
2318 && numargs
>= XSUBR (fun
)->min_args
)
2320 /* Avoid making funcall cons up a yet another new vector of arguments
2321 by explicitly supplying nil's for optional values. */
2322 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2323 memclear (funcall_args
+ numargs
+ 1,
2324 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2325 funcall_nargs
= 1 + XSUBR (fun
)->max_args
;
2328 { /* We add 1 to numargs because funcall_args includes the
2329 function itself as well as its arguments. */
2330 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2331 funcall_nargs
= 1 + numargs
;
2334 memcpy (funcall_args
, args
, nargs
* word_size
);
2335 /* Spread the last arg we got. Its first element goes in
2336 the slot that it used to occupy, hence this value of I. */
2338 while (!NILP (spread_arg
))
2340 funcall_args
[i
++] = XCAR (spread_arg
);
2341 spread_arg
= XCDR (spread_arg
);
2344 /* Ffuncall gcpro's all of its args. */
2345 retval
= Ffuncall (funcall_nargs
, funcall_args
);
2351 /* Run hook variables in various ways. */
2354 funcall_nil (ptrdiff_t nargs
, Lisp_Object
*args
)
2356 Ffuncall (nargs
, args
);
2360 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2361 doc
: /* Run each hook in HOOKS.
2362 Each argument should be a symbol, a hook variable.
2363 These symbols are processed in the order specified.
2364 If a hook symbol has a non-nil value, that value may be a function
2365 or a list of functions to be called to run the hook.
2366 If the value is a function, it is called with no arguments.
2367 If it is a list, the elements are called, in order, with no arguments.
2369 Major modes should not use this function directly to run their mode
2370 hook; they should use `run-mode-hooks' instead.
2372 Do not use `make-local-variable' to make a hook variable buffer-local.
2373 Instead, use `add-hook' and specify t for the LOCAL argument.
2374 usage: (run-hooks &rest HOOKS) */)
2375 (ptrdiff_t nargs
, Lisp_Object
*args
)
2379 for (i
= 0; i
< nargs
; i
++)
2385 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2386 Srun_hook_with_args
, 1, MANY
, 0,
2387 doc
: /* Run HOOK with the specified arguments ARGS.
2388 HOOK should be a symbol, a hook variable. The value of HOOK
2389 may be nil, a function, or a list of functions. Call each
2390 function in order with arguments ARGS. The final return value
2393 Do not use `make-local-variable' to make a hook variable buffer-local.
2394 Instead, use `add-hook' and specify t for the LOCAL argument.
2395 usage: (run-hook-with-args HOOK &rest ARGS) */)
2396 (ptrdiff_t nargs
, Lisp_Object
*args
)
2398 return run_hook_with_args (nargs
, args
, funcall_nil
);
2401 /* NB this one still documents a specific non-nil return value.
2402 (As did run-hook-with-args and run-hook-with-args-until-failure
2403 until they were changed in 24.1.) */
2404 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2405 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2406 doc
: /* Run HOOK with the specified arguments ARGS.
2407 HOOK should be a symbol, a hook variable. The value of HOOK
2408 may be nil, a function, or a list of functions. Call each
2409 function in order with arguments ARGS, stopping at the first
2410 one that returns non-nil, and return that value. Otherwise (if
2411 all functions return nil, or if there are no functions to call),
2414 Do not use `make-local-variable' to make a hook variable buffer-local.
2415 Instead, use `add-hook' and specify t for the LOCAL argument.
2416 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2417 (ptrdiff_t nargs
, Lisp_Object
*args
)
2419 return run_hook_with_args (nargs
, args
, Ffuncall
);
2423 funcall_not (ptrdiff_t nargs
, Lisp_Object
*args
)
2425 return NILP (Ffuncall (nargs
, args
)) ? Qt
: Qnil
;
2428 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2429 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2430 doc
: /* Run HOOK with the specified arguments ARGS.
2431 HOOK should be a symbol, a hook variable. The value of HOOK
2432 may be nil, a function, or a list of functions. Call each
2433 function in order with arguments ARGS, stopping at the first
2434 one that returns nil, and return nil. Otherwise (if all functions
2435 return non-nil, or if there are no functions to call), return non-nil
2436 \(do not rely on the precise return value in this case).
2438 Do not use `make-local-variable' to make a hook variable buffer-local.
2439 Instead, use `add-hook' and specify t for the LOCAL argument.
2440 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2441 (ptrdiff_t nargs
, Lisp_Object
*args
)
2443 return NILP (run_hook_with_args (nargs
, args
, funcall_not
)) ? Qt
: Qnil
;
2447 run_hook_wrapped_funcall (ptrdiff_t nargs
, Lisp_Object
*args
)
2449 Lisp_Object tmp
= args
[0], ret
;
2452 ret
= Ffuncall (nargs
, args
);
2458 DEFUN ("run-hook-wrapped", Frun_hook_wrapped
, Srun_hook_wrapped
, 2, MANY
, 0,
2459 doc
: /* Run HOOK, passing each function through WRAP-FUNCTION.
2460 I.e. instead of calling each function FUN directly with arguments ARGS,
2461 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2462 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2463 aborts and returns that value.
2464 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2465 (ptrdiff_t nargs
, Lisp_Object
*args
)
2467 return run_hook_with_args (nargs
, args
, run_hook_wrapped_funcall
);
2470 /* ARGS[0] should be a hook symbol.
2471 Call each of the functions in the hook value, passing each of them
2472 as arguments all the rest of ARGS (all NARGS - 1 elements).
2473 FUNCALL specifies how to call each function on the hook.
2474 The caller (or its caller, etc) must gcpro all of ARGS,
2475 except that it isn't necessary to gcpro ARGS[0]. */
2478 run_hook_with_args (ptrdiff_t nargs
, Lisp_Object
*args
,
2479 Lisp_Object (*funcall
) (ptrdiff_t nargs
, Lisp_Object
*args
))
2481 Lisp_Object sym
, val
, ret
= Qnil
;
2482 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2484 /* If we are dying or still initializing,
2485 don't do anything--it would probably crash if we tried. */
2486 if (NILP (Vrun_hooks
))
2490 val
= find_symbol_value (sym
);
2492 if (EQ (val
, Qunbound
) || NILP (val
))
2494 else if (!CONSP (val
) || FUNCTIONP (val
))
2497 return funcall (nargs
, args
);
2501 Lisp_Object global_vals
= Qnil
;
2502 GCPRO3 (sym
, val
, global_vals
);
2505 CONSP (val
) && NILP (ret
);
2508 if (EQ (XCAR (val
), Qt
))
2510 /* t indicates this hook has a local binding;
2511 it means to run the global binding too. */
2512 global_vals
= Fdefault_value (sym
);
2513 if (NILP (global_vals
)) continue;
2515 if (!CONSP (global_vals
) || EQ (XCAR (global_vals
), Qlambda
))
2517 args
[0] = global_vals
;
2518 ret
= funcall (nargs
, args
);
2523 CONSP (global_vals
) && NILP (ret
);
2524 global_vals
= XCDR (global_vals
))
2526 args
[0] = XCAR (global_vals
);
2527 /* In a global value, t should not occur. If it does, we
2528 must ignore it to avoid an endless loop. */
2529 if (!EQ (args
[0], Qt
))
2530 ret
= funcall (nargs
, args
);
2536 args
[0] = XCAR (val
);
2537 ret
= funcall (nargs
, args
);
2546 /* Run the hook HOOK, giving each function no args. */
2549 run_hook (Lisp_Object hook
)
2551 Frun_hook_with_args (1, &hook
);
2554 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2557 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2559 CALLN (Frun_hook_with_args
, hook
, arg1
, arg2
);
2562 /* Apply fn to arg. */
2564 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2566 return NILP (arg
) ? Ffuncall (1, &fn
) : CALLN (Fapply
, fn
, arg
);
2569 /* Call function fn on no arguments. */
2571 call0 (Lisp_Object fn
)
2573 return Ffuncall (1, &fn
);
2576 /* Call function fn with 1 argument arg1. */
2579 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2581 return CALLN (Ffuncall
, fn
, arg1
);
2584 /* Call function fn with 2 arguments arg1, arg2. */
2587 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2589 return CALLN (Ffuncall
, fn
, arg1
, arg2
);
2592 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2595 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2597 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
);
2600 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2603 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2606 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
);
2609 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2612 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2613 Lisp_Object arg4
, Lisp_Object arg5
)
2615 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
);
2618 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2621 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2622 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2624 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
2627 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2630 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2631 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
2633 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
2636 /* The caller should GCPRO all the elements of ARGS. */
2638 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
2639 doc
: /* Non-nil if OBJECT is a function. */)
2640 (Lisp_Object object
)
2642 if (FUNCTIONP (object
))
2647 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2648 doc
: /* Call first argument as a function, passing remaining arguments to it.
2649 Return the value that function returns.
2650 Thus, (funcall 'cons 'x 'y) returns (x . y).
2651 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2652 (ptrdiff_t nargs
, Lisp_Object
*args
)
2654 Lisp_Object fun
, original_fun
;
2656 ptrdiff_t numargs
= nargs
- 1;
2657 Lisp_Object lisp_numargs
;
2659 Lisp_Object
*internal_args
;
2664 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2666 if (max_lisp_eval_depth
< 100)
2667 max_lisp_eval_depth
= 100;
2668 if (lisp_eval_depth
> max_lisp_eval_depth
)
2669 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2672 /* This also GCPROs them. */
2673 count
= record_in_backtrace (args
[0], &args
[1], nargs
- 1);
2675 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2678 if (debug_on_next_call
)
2679 do_debug_on_call (Qlambda
, count
);
2683 original_fun
= args
[0];
2687 /* Optimize for no indirection. */
2689 if (SYMBOLP (fun
) && !NILP (fun
)
2690 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2691 fun
= indirect_function (fun
);
2695 if (numargs
< XSUBR (fun
)->min_args
2696 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2698 XSETFASTINT (lisp_numargs
, numargs
);
2699 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2702 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2703 xsignal1 (Qinvalid_function
, original_fun
);
2705 else if (XSUBR (fun
)->max_args
== MANY
)
2706 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
2709 Lisp_Object internal_argbuf
[8];
2710 if (XSUBR (fun
)->max_args
> numargs
)
2712 eassert (XSUBR (fun
)->max_args
<= ARRAYELTS (internal_argbuf
));
2713 internal_args
= internal_argbuf
;
2714 memcpy (internal_args
, args
+ 1, numargs
* word_size
);
2715 memclear (internal_args
+ numargs
,
2716 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2719 internal_args
= args
+ 1;
2720 switch (XSUBR (fun
)->max_args
)
2723 val
= (XSUBR (fun
)->function
.a0 ());
2726 val
= (XSUBR (fun
)->function
.a1 (internal_args
[0]));
2729 val
= (XSUBR (fun
)->function
.a2
2730 (internal_args
[0], internal_args
[1]));
2733 val
= (XSUBR (fun
)->function
.a3
2734 (internal_args
[0], internal_args
[1], internal_args
[2]));
2737 val
= (XSUBR (fun
)->function
.a4
2738 (internal_args
[0], internal_args
[1], internal_args
[2],
2742 val
= (XSUBR (fun
)->function
.a5
2743 (internal_args
[0], internal_args
[1], internal_args
[2],
2744 internal_args
[3], internal_args
[4]));
2747 val
= (XSUBR (fun
)->function
.a6
2748 (internal_args
[0], internal_args
[1], internal_args
[2],
2749 internal_args
[3], internal_args
[4], internal_args
[5]));
2752 val
= (XSUBR (fun
)->function
.a7
2753 (internal_args
[0], internal_args
[1], internal_args
[2],
2754 internal_args
[3], internal_args
[4], internal_args
[5],
2759 val
= (XSUBR (fun
)->function
.a8
2760 (internal_args
[0], internal_args
[1], internal_args
[2],
2761 internal_args
[3], internal_args
[4], internal_args
[5],
2762 internal_args
[6], internal_args
[7]));
2767 /* If a subr takes more than 8 arguments without using MANY
2768 or UNEVALLED, we need to extend this function to support it.
2769 Until this is done, there is no way to call the function. */
2774 else if (COMPILEDP (fun
))
2775 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2779 xsignal1 (Qvoid_function
, original_fun
);
2781 xsignal1 (Qinvalid_function
, original_fun
);
2782 funcar
= XCAR (fun
);
2783 if (!SYMBOLP (funcar
))
2784 xsignal1 (Qinvalid_function
, original_fun
);
2785 if (EQ (funcar
, Qlambda
)
2786 || EQ (funcar
, Qclosure
))
2787 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2788 else if (EQ (funcar
, Qautoload
))
2790 Fautoload_do_load (fun
, original_fun
, Qnil
);
2795 xsignal1 (Qinvalid_function
, original_fun
);
2799 if (backtrace_debug_on_exit (specpdl
+ count
))
2800 val
= call_debugger (list2 (Qexit
, val
));
2806 apply_lambda (Lisp_Object fun
, Lisp_Object args
, ptrdiff_t count
)
2808 Lisp_Object args_left
;
2811 register Lisp_Object
*arg_vector
;
2812 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2813 register Lisp_Object tem
;
2816 numargs
= XFASTINT (Flength (args
));
2817 SAFE_ALLOCA_LISP (arg_vector
, numargs
);
2820 GCPRO3 (*arg_vector
, args_left
, fun
);
2823 for (i
= 0; i
< numargs
; )
2825 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2826 tem
= eval_sub (tem
);
2827 arg_vector
[i
++] = tem
;
2833 set_backtrace_args (specpdl
+ count
, arg_vector
, i
);
2834 tem
= funcall_lambda (fun
, numargs
, arg_vector
);
2836 /* Do the debug-on-exit now, while arg_vector still exists. */
2837 if (backtrace_debug_on_exit (specpdl
+ count
))
2839 /* Don't do it again when we return to eval. */
2840 set_backtrace_debug_on_exit (specpdl
+ count
, false);
2841 tem
= call_debugger (list2 (Qexit
, tem
));
2847 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2848 and return the result of evaluation.
2849 FUN must be either a lambda-expression or a compiled-code object. */
2852 funcall_lambda (Lisp_Object fun
, ptrdiff_t nargs
,
2853 register Lisp_Object
*arg_vector
)
2855 Lisp_Object val
, syms_left
, next
, lexenv
;
2856 ptrdiff_t count
= SPECPDL_INDEX ();
2858 bool optional
, rest
;
2862 if (EQ (XCAR (fun
), Qclosure
))
2864 fun
= XCDR (fun
); /* Drop `closure'. */
2865 lexenv
= XCAR (fun
);
2866 CHECK_LIST_CONS (fun
, fun
);
2870 syms_left
= XCDR (fun
);
2871 if (CONSP (syms_left
))
2872 syms_left
= XCAR (syms_left
);
2874 xsignal1 (Qinvalid_function
, fun
);
2876 else if (COMPILEDP (fun
))
2878 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2879 if (INTEGERP (syms_left
))
2880 /* A byte-code object with a non-nil `push args' slot means we
2881 shouldn't bind any arguments, instead just call the byte-code
2882 interpreter directly; it will push arguments as necessary.
2884 Byte-code objects with either a non-existent, or a nil value for
2885 the `push args' slot (the default), have dynamically-bound
2886 arguments, and use the argument-binding code below instead (as do
2887 all interpreted functions, even lexically bound ones). */
2889 /* If we have not actually read the bytecode string
2890 and constants vector yet, fetch them from the file. */
2891 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2892 Ffetch_bytecode (fun
);
2893 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2894 AREF (fun
, COMPILED_CONSTANTS
),
2895 AREF (fun
, COMPILED_STACK_DEPTH
),
2904 i
= optional
= rest
= 0;
2905 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2909 next
= XCAR (syms_left
);
2910 if (!SYMBOLP (next
))
2911 xsignal1 (Qinvalid_function
, fun
);
2913 if (EQ (next
, Qand_rest
))
2915 else if (EQ (next
, Qand_optional
))
2922 arg
= Flist (nargs
- i
, &arg_vector
[i
]);
2926 arg
= arg_vector
[i
++];
2928 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2932 /* Bind the argument. */
2933 if (!NILP (lexenv
) && SYMBOLP (next
))
2934 /* Lexically bind NEXT by adding it to the lexenv alist. */
2935 lexenv
= Fcons (Fcons (next
, arg
), lexenv
);
2937 /* Dynamically bind NEXT. */
2938 specbind (next
, arg
);
2942 if (!NILP (syms_left
))
2943 xsignal1 (Qinvalid_function
, fun
);
2945 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2947 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
2948 /* Instantiate a new lexical environment. */
2949 specbind (Qinternal_interpreter_environment
, lexenv
);
2952 val
= Fprogn (XCDR (XCDR (fun
)));
2955 /* If we have not actually read the bytecode string
2956 and constants vector yet, fetch them from the file. */
2957 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2958 Ffetch_bytecode (fun
);
2959 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2960 AREF (fun
, COMPILED_CONSTANTS
),
2961 AREF (fun
, COMPILED_STACK_DEPTH
),
2965 return unbind_to (count
, val
);
2968 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2970 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2971 (Lisp_Object object
)
2975 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
2977 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2980 tem
= AREF (object
, COMPILED_BYTECODE
);
2981 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2982 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2984 error ("Invalid byte code");
2986 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
2987 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
2992 /* Return true if SYMBOL currently has a let-binding
2993 which was made in the buffer that is now current. */
2996 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
2998 union specbinding
*p
;
2999 Lisp_Object buf
= Fcurrent_buffer ();
3001 for (p
= specpdl_ptr
; p
> specpdl
; )
3002 if ((--p
)->kind
> SPECPDL_LET
)
3004 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (specpdl_symbol (p
));
3005 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
3006 if (symbol
== let_bound_symbol
3007 && EQ (specpdl_where (p
), buf
))
3015 let_shadows_global_binding_p (Lisp_Object symbol
)
3017 union specbinding
*p
;
3019 for (p
= specpdl_ptr
; p
> specpdl
; )
3020 if ((--p
)->kind
>= SPECPDL_LET
&& EQ (specpdl_symbol (p
), symbol
))
3026 /* `specpdl_ptr' describes which variable is
3027 let-bound, so it can be properly undone when we unbind_to.
3028 It can be either a plain SPECPDL_LET or a SPECPDL_LET_LOCAL/DEFAULT.
3029 - SYMBOL is the variable being bound. Note that it should not be
3030 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3032 - WHERE tells us in which buffer the binding took place.
3033 This is used for SPECPDL_LET_LOCAL bindings (i.e. bindings to a
3034 buffer-local variable) as well as for SPECPDL_LET_DEFAULT bindings,
3035 i.e. bindings to the default value of a variable which can be
3039 specbind (Lisp_Object symbol
, Lisp_Object value
)
3041 struct Lisp_Symbol
*sym
;
3043 CHECK_SYMBOL (symbol
);
3044 sym
= XSYMBOL (symbol
);
3047 switch (sym
->redirect
)
3049 case SYMBOL_VARALIAS
:
3050 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3051 case SYMBOL_PLAINVAL
:
3052 /* The most common case is that of a non-constant symbol with a
3053 trivial value. Make that as fast as we can. */
3054 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3055 specpdl_ptr
->let
.symbol
= symbol
;
3056 specpdl_ptr
->let
.old_value
= SYMBOL_VAL (sym
);
3059 SET_SYMBOL_VAL (sym
, value
);
3061 set_internal (symbol
, value
, Qnil
, 1);
3063 case SYMBOL_LOCALIZED
:
3064 if (SYMBOL_BLV (sym
)->frame_local
)
3065 error ("Frame-local vars cannot be let-bound");
3066 case SYMBOL_FORWARDED
:
3068 Lisp_Object ovalue
= find_symbol_value (symbol
);
3069 specpdl_ptr
->let
.kind
= SPECPDL_LET_LOCAL
;
3070 specpdl_ptr
->let
.symbol
= symbol
;
3071 specpdl_ptr
->let
.old_value
= ovalue
;
3072 specpdl_ptr
->let
.where
= Fcurrent_buffer ();
3074 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3075 || (EQ (SYMBOL_BLV (sym
)->where
, Fcurrent_buffer ())));
3077 if (sym
->redirect
== SYMBOL_LOCALIZED
)
3079 if (!blv_found (SYMBOL_BLV (sym
)))
3080 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3082 else if (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3084 /* If SYMBOL is a per-buffer variable which doesn't have a
3085 buffer-local value here, make the `let' change the global
3086 value by changing the value of SYMBOL in all buffers not
3087 having their own value. This is consistent with what
3088 happens with other buffer-local variables. */
3089 if (NILP (Flocal_variable_p (symbol
, Qnil
)))
3091 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3093 Fset_default (symbol
, value
);
3098 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3101 set_internal (symbol
, value
, Qnil
, 1);
3104 default: emacs_abort ();
3108 /* Push unwind-protect entries of various types. */
3111 record_unwind_protect (void (*function
) (Lisp_Object
), Lisp_Object arg
)
3113 specpdl_ptr
->unwind
.kind
= SPECPDL_UNWIND
;
3114 specpdl_ptr
->unwind
.func
= function
;
3115 specpdl_ptr
->unwind
.arg
= arg
;
3120 record_unwind_protect_ptr (void (*function
) (void *), void *arg
)
3122 specpdl_ptr
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3123 specpdl_ptr
->unwind_ptr
.func
= function
;
3124 specpdl_ptr
->unwind_ptr
.arg
= arg
;
3129 record_unwind_protect_int (void (*function
) (int), int arg
)
3131 specpdl_ptr
->unwind_int
.kind
= SPECPDL_UNWIND_INT
;
3132 specpdl_ptr
->unwind_int
.func
= function
;
3133 specpdl_ptr
->unwind_int
.arg
= arg
;
3138 record_unwind_protect_void (void (*function
) (void))
3140 specpdl_ptr
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3141 specpdl_ptr
->unwind_void
.func
= function
;
3149 /* Push an unwind-protect entry that does nothing, so that
3150 set_unwind_protect_ptr can overwrite it later. */
3153 record_unwind_protect_nothing (void)
3155 record_unwind_protect_void (do_nothing
);
3158 /* Clear the unwind-protect entry COUNT, so that it does nothing.
3159 It need not be at the top of the stack. */
3162 clear_unwind_protect (ptrdiff_t count
)
3164 union specbinding
*p
= specpdl
+ count
;
3165 p
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3166 p
->unwind_void
.func
= do_nothing
;
3169 /* Set the unwind-protect entry COUNT so that it invokes FUNC (ARG).
3170 It need not be at the top of the stack. Discard the entry's
3171 previous value without invoking it. */
3174 set_unwind_protect (ptrdiff_t count
, void (*func
) (Lisp_Object
),
3177 union specbinding
*p
= specpdl
+ count
;
3178 p
->unwind
.kind
= SPECPDL_UNWIND
;
3179 p
->unwind
.func
= func
;
3180 p
->unwind
.arg
= arg
;
3184 set_unwind_protect_ptr (ptrdiff_t count
, void (*func
) (void *), void *arg
)
3186 union specbinding
*p
= specpdl
+ count
;
3187 p
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3188 p
->unwind_ptr
.func
= func
;
3189 p
->unwind_ptr
.arg
= arg
;
3192 /* Pop and execute entries from the unwind-protect stack until the
3193 depth COUNT is reached. Return VALUE. */
3196 unbind_to (ptrdiff_t count
, Lisp_Object value
)
3198 Lisp_Object quitf
= Vquit_flag
;
3199 struct gcpro gcpro1
, gcpro2
;
3201 GCPRO2 (value
, quitf
);
3204 while (specpdl_ptr
!= specpdl
+ count
)
3206 /* Decrement specpdl_ptr before we do the work to unbind it, so
3207 that an error in unbinding won't try to unbind the same entry
3208 again. Take care to copy any parts of the binding needed
3209 before invoking any code that can make more bindings. */
3213 switch (specpdl_ptr
->kind
)
3215 case SPECPDL_UNWIND
:
3216 specpdl_ptr
->unwind
.func (specpdl_ptr
->unwind
.arg
);
3218 case SPECPDL_UNWIND_PTR
:
3219 specpdl_ptr
->unwind_ptr
.func (specpdl_ptr
->unwind_ptr
.arg
);
3221 case SPECPDL_UNWIND_INT
:
3222 specpdl_ptr
->unwind_int
.func (specpdl_ptr
->unwind_int
.arg
);
3224 case SPECPDL_UNWIND_VOID
:
3225 specpdl_ptr
->unwind_void
.func ();
3227 case SPECPDL_BACKTRACE
:
3230 { /* If variable has a trivial value (no forwarding), we can
3231 just set it. No need to check for constant symbols here,
3232 since that was already done by specbind. */
3233 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (specpdl_ptr
));
3234 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3236 SET_SYMBOL_VAL (sym
, specpdl_old_value (specpdl_ptr
));
3241 NOTE: we only ever come here if make_local_foo was used for
3242 the first time on this var within this let. */
3245 case SPECPDL_LET_DEFAULT
:
3246 Fset_default (specpdl_symbol (specpdl_ptr
),
3247 specpdl_old_value (specpdl_ptr
));
3249 case SPECPDL_LET_LOCAL
:
3251 Lisp_Object symbol
= specpdl_symbol (specpdl_ptr
);
3252 Lisp_Object where
= specpdl_where (specpdl_ptr
);
3253 Lisp_Object old_value
= specpdl_old_value (specpdl_ptr
);
3254 eassert (BUFFERP (where
));
3256 /* If this was a local binding, reset the value in the appropriate
3257 buffer, but only if that buffer's binding still exists. */
3258 if (!NILP (Flocal_variable_p (symbol
, where
)))
3259 set_internal (symbol
, old_value
, where
, 1);
3265 if (NILP (Vquit_flag
) && !NILP (quitf
))
3272 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3273 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3274 A special variable is one that will be bound dynamically, even in a
3275 context where binding is lexical by default. */)
3276 (Lisp_Object symbol
)
3278 CHECK_SYMBOL (symbol
);
3279 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3283 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3284 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3285 The debugger is entered when that frame exits, if the flag is non-nil. */)
3286 (Lisp_Object level
, Lisp_Object flag
)
3288 union specbinding
*pdl
= backtrace_top ();
3289 register EMACS_INT i
;
3291 CHECK_NUMBER (level
);
3293 for (i
= 0; backtrace_p (pdl
) && i
< XINT (level
); i
++)
3294 pdl
= backtrace_next (pdl
);
3296 if (backtrace_p (pdl
))
3297 set_backtrace_debug_on_exit (pdl
, !NILP (flag
));
3302 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3303 doc
: /* Print a trace of Lisp function calls currently active.
3304 Output stream used is value of `standard-output'. */)
3307 union specbinding
*pdl
= backtrace_top ();
3309 Lisp_Object old_print_level
= Vprint_level
;
3311 if (NILP (Vprint_level
))
3312 XSETFASTINT (Vprint_level
, 8);
3314 while (backtrace_p (pdl
))
3316 write_string (backtrace_debug_on_exit (pdl
) ? "* " : " ");
3317 if (backtrace_nargs (pdl
) == UNEVALLED
)
3319 Fprin1 (Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)),
3321 write_string ("\n");
3325 tem
= backtrace_function (pdl
);
3326 Fprin1 (tem
, Qnil
); /* This can QUIT. */
3330 for (i
= 0; i
< backtrace_nargs (pdl
); i
++)
3332 if (i
) write_string (" ");
3333 Fprin1 (backtrace_args (pdl
)[i
], Qnil
);
3336 write_string (")\n");
3338 pdl
= backtrace_next (pdl
);
3341 Vprint_level
= old_print_level
;
3345 static union specbinding
*
3346 get_backtrace_frame (Lisp_Object nframes
, Lisp_Object base
)
3348 union specbinding
*pdl
= backtrace_top ();
3349 register EMACS_INT i
;
3351 CHECK_NATNUM (nframes
);
3354 { /* Skip up to `base'. */
3355 base
= Findirect_function (base
, Qt
);
3356 while (backtrace_p (pdl
)
3357 && !EQ (base
, Findirect_function (backtrace_function (pdl
), Qt
)))
3358 pdl
= backtrace_next (pdl
);
3361 /* Find the frame requested. */
3362 for (i
= XFASTINT (nframes
); i
> 0 && backtrace_p (pdl
); i
--)
3363 pdl
= backtrace_next (pdl
);
3368 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 2, NULL
,
3369 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3370 If that frame has not evaluated the arguments yet (or is a special form),
3371 the value is (nil FUNCTION ARG-FORMS...).
3372 If that frame has evaluated its arguments and called its function already,
3373 the value is (t FUNCTION ARG-VALUES...).
3374 A &rest arg is represented as the tail of the list ARG-VALUES.
3375 FUNCTION is whatever was supplied as car of evaluated list,
3376 or a lambda expression for macro calls.
3377 If NFRAMES is more than the number of frames, the value is nil.
3378 If BASE is non-nil, it should be a function and NFRAMES counts from its
3379 nearest activation frame. */)
3380 (Lisp_Object nframes
, Lisp_Object base
)
3382 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3384 if (!backtrace_p (pdl
))
3386 if (backtrace_nargs (pdl
) == UNEVALLED
)
3388 Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)));
3391 Lisp_Object tem
= Flist (backtrace_nargs (pdl
), backtrace_args (pdl
));
3393 return Fcons (Qt
, Fcons (backtrace_function (pdl
), tem
));
3397 /* For backtrace-eval, we want to temporarily unwind the last few elements of
3398 the specpdl stack, and then rewind them. We store the pre-unwind values
3399 directly in the pre-existing specpdl elements (i.e. we swap the current
3400 value and the old value stored in the specpdl), kind of like the inplace
3401 pointer-reversal trick. As it turns out, the rewind does the same as the
3402 unwind, except it starts from the other end of the specpdl stack, so we use
3403 the same function for both unwind and rewind. */
3405 backtrace_eval_unrewind (int distance
)
3407 union specbinding
*tmp
= specpdl_ptr
;
3410 { /* It's a rewind rather than unwind. */
3411 tmp
+= distance
- 1;
3413 distance
= -distance
;
3416 for (; distance
> 0; distance
--)
3421 /* FIXME: Ideally we'd like to "temporarily unwind" (some of) those
3422 unwind_protect, but the problem is that we don't know how to
3423 rewind them afterwards. */
3424 case SPECPDL_UNWIND
:
3426 Lisp_Object oldarg
= tmp
->unwind
.arg
;
3427 if (tmp
->unwind
.func
== set_buffer_if_live
)
3428 tmp
->unwind
.arg
= Fcurrent_buffer ();
3429 else if (tmp
->unwind
.func
== save_excursion_restore
)
3430 tmp
->unwind
.arg
= save_excursion_save ();
3433 tmp
->unwind
.func (oldarg
);
3437 case SPECPDL_UNWIND_PTR
:
3438 case SPECPDL_UNWIND_INT
:
3439 case SPECPDL_UNWIND_VOID
:
3440 case SPECPDL_BACKTRACE
:
3443 { /* If variable has a trivial value (no forwarding), we can
3444 just set it. No need to check for constant symbols here,
3445 since that was already done by specbind. */
3446 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (tmp
));
3447 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3449 Lisp_Object old_value
= specpdl_old_value (tmp
);
3450 set_specpdl_old_value (tmp
, SYMBOL_VAL (sym
));
3451 SET_SYMBOL_VAL (sym
, old_value
);
3456 NOTE: we only ever come here if make_local_foo was used for
3457 the first time on this var within this let. */
3460 case SPECPDL_LET_DEFAULT
:
3462 Lisp_Object sym
= specpdl_symbol (tmp
);
3463 Lisp_Object old_value
= specpdl_old_value (tmp
);
3464 set_specpdl_old_value (tmp
, Fdefault_value (sym
));
3465 Fset_default (sym
, old_value
);
3468 case SPECPDL_LET_LOCAL
:
3470 Lisp_Object symbol
= specpdl_symbol (tmp
);
3471 Lisp_Object where
= specpdl_where (tmp
);
3472 Lisp_Object old_value
= specpdl_old_value (tmp
);
3473 eassert (BUFFERP (where
));
3475 /* If this was a local binding, reset the value in the appropriate
3476 buffer, but only if that buffer's binding still exists. */
3477 if (!NILP (Flocal_variable_p (symbol
, where
)))
3479 set_specpdl_old_value
3480 (tmp
, Fbuffer_local_value (symbol
, where
));
3481 set_internal (symbol
, old_value
, where
, 1);
3489 DEFUN ("backtrace-eval", Fbacktrace_eval
, Sbacktrace_eval
, 2, 3, NULL
,
3490 doc
: /* Evaluate EXP in the context of some activation frame.
3491 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3492 (Lisp_Object exp
, Lisp_Object nframes
, Lisp_Object base
)
3494 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3495 ptrdiff_t count
= SPECPDL_INDEX ();
3496 ptrdiff_t distance
= specpdl_ptr
- pdl
;
3497 eassert (distance
>= 0);
3499 if (!backtrace_p (pdl
))
3500 error ("Activation frame not found!");
3502 backtrace_eval_unrewind (distance
);
3503 record_unwind_protect_int (backtrace_eval_unrewind
, -distance
);
3505 /* Use eval_sub rather than Feval since the main motivation behind
3506 backtrace-eval is to be able to get/set the value of lexical variables
3507 from the debugger. */
3508 return unbind_to (count
, eval_sub (exp
));
3511 DEFUN ("backtrace--locals", Fbacktrace__locals
, Sbacktrace__locals
, 1, 2, NULL
,
3512 doc
: /* Return names and values of local variables of a stack frame.
3513 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3514 (Lisp_Object nframes
, Lisp_Object base
)
3516 union specbinding
*frame
= get_backtrace_frame (nframes
, base
);
3517 union specbinding
*prevframe
3518 = get_backtrace_frame (make_number (XFASTINT (nframes
) - 1), base
);
3519 ptrdiff_t distance
= specpdl_ptr
- frame
;
3520 Lisp_Object result
= Qnil
;
3521 eassert (distance
>= 0);
3523 if (!backtrace_p (prevframe
))
3524 error ("Activation frame not found!");
3525 if (!backtrace_p (frame
))
3526 error ("Activation frame not found!");
3528 /* The specpdl entries normally contain the symbol being bound along with its
3529 `old_value', so it can be restored. The new value to which it is bound is
3530 available in one of two places: either in the current value of the
3531 variable (if it hasn't been rebound yet) or in the `old_value' slot of the
3532 next specpdl entry for it.
3533 `backtrace_eval_unrewind' happens to swap the role of `old_value'
3534 and "new value", so we abuse it here, to fetch the new value.
3535 It's ugly (we'd rather not modify global data) and a bit inefficient,
3536 but it does the job for now. */
3537 backtrace_eval_unrewind (distance
);
3541 union specbinding
*tmp
= prevframe
;
3542 for (; tmp
> frame
; tmp
--)
3547 case SPECPDL_LET_DEFAULT
:
3548 case SPECPDL_LET_LOCAL
:
3550 Lisp_Object sym
= specpdl_symbol (tmp
);
3551 Lisp_Object val
= specpdl_old_value (tmp
);
3552 if (EQ (sym
, Qinternal_interpreter_environment
))
3554 Lisp_Object env
= val
;
3555 for (; CONSP (env
); env
= XCDR (env
))
3557 Lisp_Object binding
= XCAR (env
);
3558 if (CONSP (binding
))
3559 result
= Fcons (Fcons (XCAR (binding
),
3565 result
= Fcons (Fcons (sym
, val
), result
);
3571 /* Restore values from specpdl to original place. */
3572 backtrace_eval_unrewind (-distance
);
3581 union specbinding
*pdl
;
3582 for (pdl
= specpdl
; pdl
!= specpdl_ptr
; pdl
++)
3586 case SPECPDL_UNWIND
:
3587 mark_object (specpdl_arg (pdl
));
3590 case SPECPDL_BACKTRACE
:
3592 ptrdiff_t nargs
= backtrace_nargs (pdl
);
3593 mark_object (backtrace_function (pdl
));
3594 if (nargs
== UNEVALLED
)
3597 mark_object (backtrace_args (pdl
)[nargs
]);
3601 case SPECPDL_LET_DEFAULT
:
3602 case SPECPDL_LET_LOCAL
:
3603 mark_object (specpdl_where (pdl
));
3606 mark_object (specpdl_symbol (pdl
));
3607 mark_object (specpdl_old_value (pdl
));
3614 get_backtrace (Lisp_Object array
)
3616 union specbinding
*pdl
= backtrace_next (backtrace_top ());
3617 ptrdiff_t i
= 0, asize
= ASIZE (array
);
3619 /* Copy the backtrace contents into working memory. */
3620 for (; i
< asize
; i
++)
3622 if (backtrace_p (pdl
))
3624 ASET (array
, i
, backtrace_function (pdl
));
3625 pdl
= backtrace_next (pdl
);
3628 ASET (array
, i
, Qnil
);
3632 Lisp_Object
backtrace_top_function (void)
3634 union specbinding
*pdl
= backtrace_top ();
3635 return (backtrace_p (pdl
) ? backtrace_function (pdl
) : Qnil
);
3641 DEFVAR_INT ("max-specpdl-size", max_specpdl_size
,
3642 doc
: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3643 If Lisp code tries to increase the total number past this amount,
3644 an error is signaled.
3645 You can safely use a value considerably larger than the default value,
3646 if that proves inconveniently small. However, if you increase it too far,
3647 Emacs could run out of memory trying to make the stack bigger.
3648 Note that this limit may be silently increased by the debugger
3649 if `debug-on-error' or `debug-on-quit' is set. */);
3651 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth
,
3652 doc
: /* Limit on depth in `eval', `apply' and `funcall' before error.
3654 This limit serves to catch infinite recursions for you before they cause
3655 actual stack overflow in C, which would be fatal for Emacs.
3656 You can safely make it considerably larger than its default value,
3657 if that proves inconveniently small. However, if you increase it too far,
3658 Emacs could overflow the real C stack, and crash. */);
3660 DEFVAR_LISP ("quit-flag", Vquit_flag
,
3661 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3662 If the value is t, that means do an ordinary quit.
3663 If the value equals `throw-on-input', that means quit by throwing
3664 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3665 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3666 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3669 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit
,
3670 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3671 Note that `quit-flag' will still be set by typing C-g,
3672 so a quit will be signaled as soon as `inhibit-quit' is nil.
3673 To prevent this happening, set `quit-flag' to nil
3674 before making `inhibit-quit' nil. */);
3675 Vinhibit_quit
= Qnil
;
3677 DEFSYM (Qinhibit_quit
, "inhibit-quit");
3678 DEFSYM (Qautoload
, "autoload");
3679 DEFSYM (Qinhibit_debugger
, "inhibit-debugger");
3680 DEFSYM (Qmacro
, "macro");
3682 /* Note that the process handling also uses Qexit, but we don't want
3683 to staticpro it twice, so we just do it here. */
3684 DEFSYM (Qexit
, "exit");
3686 DEFSYM (Qinteractive
, "interactive");
3687 DEFSYM (Qcommandp
, "commandp");
3688 DEFSYM (Qand_rest
, "&rest");
3689 DEFSYM (Qand_optional
, "&optional");
3690 DEFSYM (Qclosure
, "closure");
3691 DEFSYM (QCdocumentation
, ":documentation");
3692 DEFSYM (Qdebug
, "debug");
3694 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger
,
3695 doc
: /* Non-nil means never enter the debugger.
3696 Normally set while the debugger is already active, to avoid recursive
3698 Vinhibit_debugger
= Qnil
;
3700 DEFVAR_LISP ("debug-on-error", Vdebug_on_error
,
3701 doc
: /* Non-nil means enter debugger if an error is signaled.
3702 Does not apply to errors handled by `condition-case' or those
3703 matched by `debug-ignored-errors'.
3704 If the value is a list, an error only means to enter the debugger
3705 if one of its condition symbols appears in the list.
3706 When you evaluate an expression interactively, this variable
3707 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3708 The command `toggle-debug-on-error' toggles this.
3709 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3710 Vdebug_on_error
= Qnil
;
3712 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors
,
3713 doc
: /* List of errors for which the debugger should not be called.
3714 Each element may be a condition-name or a regexp that matches error messages.
3715 If any element applies to a given error, that error skips the debugger
3716 and just returns to top level.
3717 This overrides the variable `debug-on-error'.
3718 It does not apply to errors handled by `condition-case'. */);
3719 Vdebug_ignored_errors
= Qnil
;
3721 DEFVAR_BOOL ("debug-on-quit", debug_on_quit
,
3722 doc
: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3723 Does not apply if quit is handled by a `condition-case'. */);
3726 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call
,
3727 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3729 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue
,
3730 doc
: /* Non-nil means debugger may continue execution.
3731 This is nil when the debugger is called under circumstances where it
3732 might not be safe to continue. */);
3733 debugger_may_continue
= 1;
3735 DEFVAR_LISP ("debugger", Vdebugger
,
3736 doc
: /* Function to call to invoke debugger.
3737 If due to frame exit, args are `exit' and the value being returned;
3738 this function's value will be returned instead of that.
3739 If due to error, args are `error' and a list of the args to `signal'.
3740 If due to `apply' or `funcall' entry, one arg, `lambda'.
3741 If due to `eval' entry, one arg, t. */);
3744 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function
,
3745 doc
: /* If non-nil, this is a function for `signal' to call.
3746 It receives the same arguments that `signal' was given.
3747 The Edebug package uses this to regain control. */);
3748 Vsignal_hook_function
= Qnil
;
3750 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal
,
3751 doc
: /* Non-nil means call the debugger regardless of condition handlers.
3752 Note that `debug-on-error', `debug-on-quit' and friends
3753 still determine whether to handle the particular condition. */);
3754 Vdebug_on_signal
= Qnil
;
3756 /* When lexical binding is being used,
3757 Vinternal_interpreter_environment is non-nil, and contains an alist
3758 of lexically-bound variable, or (t), indicating an empty
3759 environment. The lisp name of this variable would be
3760 `internal-interpreter-environment' if it weren't hidden.
3761 Every element of this list can be either a cons (VAR . VAL)
3762 specifying a lexical binding, or a single symbol VAR indicating
3763 that this variable should use dynamic scoping. */
3764 DEFSYM (Qinternal_interpreter_environment
,
3765 "internal-interpreter-environment");
3766 DEFVAR_LISP ("internal-interpreter-environment",
3767 Vinternal_interpreter_environment
,
3768 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3769 When lexical binding is not being used, this variable is nil.
3770 A value of `(t)' indicates an empty environment, otherwise it is an
3771 alist of active lexical bindings. */);
3772 Vinternal_interpreter_environment
= Qnil
;
3773 /* Don't export this variable to Elisp, so no one can mess with it
3774 (Just imagine if someone makes it buffer-local). */
3775 Funintern (Qinternal_interpreter_environment
, Qnil
);
3777 Vrun_hooks
= intern_c_string ("run-hooks");
3778 staticpro (&Vrun_hooks
);
3780 staticpro (&Vautoload_queue
);
3781 Vautoload_queue
= Qnil
;
3782 staticpro (&Vsignaling_function
);
3783 Vsignaling_function
= Qnil
;
3785 inhibit_lisp_code
= Qnil
;
3796 defsubr (&Sfunction
);
3797 defsubr (&Sdefault_toplevel_value
);
3798 defsubr (&Sset_default_toplevel_value
);
3800 defsubr (&Sdefvaralias
);
3801 defsubr (&Sdefconst
);
3802 defsubr (&Smake_var_non_special
);
3806 defsubr (&Smacroexpand
);
3809 defsubr (&Sunwind_protect
);
3810 defsubr (&Scondition_case
);
3812 defsubr (&Scommandp
);
3813 defsubr (&Sautoload
);
3814 defsubr (&Sautoload_do_load
);
3817 defsubr (&Sfuncall
);
3818 defsubr (&Srun_hooks
);
3819 defsubr (&Srun_hook_with_args
);
3820 defsubr (&Srun_hook_with_args_until_success
);
3821 defsubr (&Srun_hook_with_args_until_failure
);
3822 defsubr (&Srun_hook_wrapped
);
3823 defsubr (&Sfetch_bytecode
);
3824 defsubr (&Sbacktrace_debug
);
3825 defsubr (&Sbacktrace
);
3826 defsubr (&Sbacktrace_frame
);
3827 defsubr (&Sbacktrace_eval
);
3828 defsubr (&Sbacktrace__locals
);
3829 defsubr (&Sspecial_variable_p
);
3830 defsubr (&Sfunctionp
);