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
)
205 init_eval_once (void)
208 union specbinding
*pdlvec
= xmalloc ((size
+ 1) * sizeof *specpdl
);
210 specpdl
= specpdl_ptr
= pdlvec
+ 1;
211 /* Don't forget to update docs (lispref node "Local Variables"). */
212 max_specpdl_size
= 1300; /* 1000 is not enough for CEDET's c-by.el. */
213 max_lisp_eval_depth
= 600;
218 static struct handler handlerlist_sentinel
;
223 specpdl_ptr
= specpdl
;
224 { /* Put a dummy catcher at top-level so that handlerlist is never NULL.
225 This is important since handlerlist->nextfree holds the freelist
226 which would otherwise leak every time we unwind back to top-level. */
228 handlerlist
= handlerlist_sentinel
.nextfree
= &handlerlist_sentinel
;
229 PUSH_HANDLER (c
, Qunbound
, CATCHER
);
230 eassert (c
== &handlerlist_sentinel
);
231 handlerlist_sentinel
.nextfree
= NULL
;
232 handlerlist_sentinel
.next
= NULL
;
235 debug_on_next_call
= 0;
240 /* This is less than the initial value of num_nonmacro_input_events. */
241 when_entered_debugger
= -1;
244 /* Unwind-protect function used by call_debugger. */
247 restore_stack_limits (Lisp_Object data
)
249 max_specpdl_size
= XINT (XCAR (data
));
250 max_lisp_eval_depth
= XINT (XCDR (data
));
253 static void grow_specpdl (void);
255 /* Call the Lisp debugger, giving it argument ARG. */
258 call_debugger (Lisp_Object arg
)
260 bool debug_while_redisplaying
;
261 ptrdiff_t count
= SPECPDL_INDEX ();
263 EMACS_INT old_depth
= max_lisp_eval_depth
;
264 /* Do not allow max_specpdl_size less than actual depth (Bug#16603). */
265 EMACS_INT old_max
= max (max_specpdl_size
, count
);
267 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
268 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
270 /* While debugging Bug#16603, previous value of 100 was found
271 too small to avoid specpdl overflow in the debugger itself. */
272 if (max_specpdl_size
- 200 < count
)
273 max_specpdl_size
= count
+ 200;
275 if (old_max
== count
)
277 /* We can enter the debugger due to specpdl overflow (Bug#16603). */
282 /* Restore limits after leaving the debugger. */
283 record_unwind_protect (restore_stack_limits
,
284 Fcons (make_number (old_max
),
285 make_number (old_depth
)));
287 #ifdef HAVE_WINDOW_SYSTEM
288 if (display_hourglass_p
)
292 debug_on_next_call
= 0;
293 when_entered_debugger
= num_nonmacro_input_events
;
295 /* Resetting redisplaying_p to 0 makes sure that debug output is
296 displayed if the debugger is invoked during redisplay. */
297 debug_while_redisplaying
= redisplaying_p
;
299 specbind (intern ("debugger-may-continue"),
300 debug_while_redisplaying
? Qnil
: Qt
);
301 specbind (Qinhibit_redisplay
, Qnil
);
302 specbind (Qinhibit_debugger
, Qt
);
304 #if 0 /* Binding this prevents execution of Lisp code during
305 redisplay, which necessarily leads to display problems. */
306 specbind (Qinhibit_eval_during_redisplay
, Qt
);
309 val
= apply1 (Vdebugger
, arg
);
311 /* Interrupting redisplay and resuming it later is not safe under
312 all circumstances. So, when the debugger returns, abort the
313 interrupted redisplay by going back to the top-level. */
314 if (debug_while_redisplaying
)
317 return unbind_to (count
, val
);
321 do_debug_on_call (Lisp_Object code
, ptrdiff_t count
)
323 debug_on_next_call
= 0;
324 set_backtrace_debug_on_exit (specpdl
+ count
, true);
325 call_debugger (list1 (code
));
328 /* NOTE!!! Every function that can call EVAL must protect its args
329 and temporaries from garbage collection while it needs them.
330 The definition of `For' shows what you have to do. */
332 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
333 doc
: /* Eval args until one of them yields non-nil, then return that value.
334 The remaining args are not evalled at all.
335 If all args return nil, return nil.
336 usage: (or CONDITIONS...) */)
339 register Lisp_Object val
= Qnil
;
346 val
= eval_sub (XCAR (args
));
356 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
357 doc
: /* Eval args until one of them yields nil, then return nil.
358 The remaining args are not evalled at all.
359 If no arg yields nil, return the last arg's value.
360 usage: (and CONDITIONS...) */)
363 register Lisp_Object val
= Qt
;
370 val
= eval_sub (XCAR (args
));
380 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
381 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
382 Returns the value of THEN or the value of the last of the ELSE's.
383 THEN must be one expression, but ELSE... can be zero or more expressions.
384 If COND yields nil, and there are no ELSE's, the value is nil.
385 usage: (if COND THEN ELSE...) */)
392 cond
= eval_sub (XCAR (args
));
396 return eval_sub (Fcar (XCDR (args
)));
397 return Fprogn (XCDR (XCDR (args
)));
400 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
401 doc
: /* Try each clause until one succeeds.
402 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
403 and, if the value is non-nil, this clause succeeds:
404 then the expressions in BODY are evaluated and the last one's
405 value is the value of the cond-form.
406 If a clause has one element, as in (CONDITION), then the cond-form
407 returns CONDITION's value, if that is non-nil.
408 If no clause succeeds, cond returns nil.
409 usage: (cond CLAUSES...) */)
412 Lisp_Object val
= args
;
418 Lisp_Object clause
= XCAR (args
);
419 val
= eval_sub (Fcar (clause
));
422 if (!NILP (XCDR (clause
)))
423 val
= Fprogn (XCDR (clause
));
433 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
434 doc
: /* Eval BODY forms sequentially and return value of last one.
435 usage: (progn BODY...) */)
438 Lisp_Object val
= Qnil
;
445 val
= eval_sub (XCAR (body
));
453 /* Evaluate BODY sequentially, discarding its value. Suitable for
454 record_unwind_protect. */
457 unwind_body (Lisp_Object body
)
462 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
463 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
464 The value of FIRST is saved during the evaluation of the remaining args,
465 whose values are discarded.
466 usage: (prog1 FIRST BODY...) */)
470 Lisp_Object args_left
;
471 struct gcpro gcpro1
, gcpro2
;
477 val
= eval_sub (XCAR (args_left
));
478 while (CONSP (args_left
= XCDR (args_left
)))
479 eval_sub (XCAR (args_left
));
485 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
486 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
487 The value of FORM2 is saved during the evaluation of the
488 remaining args, whose values are discarded.
489 usage: (prog2 FORM1 FORM2 BODY...) */)
495 eval_sub (XCAR (args
));
497 return Fprog1 (XCDR (args
));
500 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
501 doc
: /* Set each SYM to the value of its VAL.
502 The symbols SYM are variables; they are literal (not evaluated).
503 The values VAL are expressions; they are evaluated.
504 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
505 The second VAL is not computed until after the first SYM is set, and so on;
506 each VAL can use the new value of variables set earlier in the `setq'.
507 The return value of the `setq' form is the value of the last VAL.
508 usage: (setq [SYM VAL]...) */)
511 Lisp_Object val
, sym
, lex_binding
;
516 Lisp_Object args_left
= args
;
522 val
= eval_sub (Fcar (XCDR (args_left
)));
523 sym
= XCAR (args_left
);
525 /* Like for eval_sub, we do not check declared_special here since
526 it's been done when let-binding. */
527 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
529 && !NILP (lex_binding
530 = Fassq (sym
, Vinternal_interpreter_environment
)))
531 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
533 Fset (sym
, val
); /* SYM is dynamically bound. */
535 args_left
= Fcdr (XCDR (args_left
));
537 while (CONSP (args_left
));
545 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
546 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
547 Warning: `quote' does not construct its return value, but just returns
548 the value that was pre-constructed by the Lisp reader (see info node
549 `(elisp)Printed Representation').
550 This means that '(a . b) is not identical to (cons 'a 'b): the former
551 does not cons. Quoting should be reserved for constants that will
552 never be modified by side-effects, unless you like self-modifying code.
553 See the common pitfall in info node `(elisp)Rearrangement' for an example
554 of unexpected results when a quoted object is modified.
555 usage: (quote ARG) */)
558 if (CONSP (XCDR (args
)))
559 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
563 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
564 doc
: /* Like `quote', but preferred for objects which are functions.
565 In byte compilation, `function' causes its argument to be compiled.
566 `quote' cannot do that.
567 usage: (function ARG) */)
570 Lisp_Object quoted
= XCAR (args
);
572 if (CONSP (XCDR (args
)))
573 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
575 if (!NILP (Vinternal_interpreter_environment
)
577 && EQ (XCAR (quoted
), Qlambda
))
578 /* This is a lambda expression within a lexical environment;
579 return an interpreted closure instead of a simple lambda. */
580 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
,
583 /* Simply quote the argument. */
588 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
589 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
590 Aliased variables always have the same value; setting one sets the other.
591 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
592 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
593 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
594 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
595 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
596 The return value is BASE-VARIABLE. */)
597 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
599 struct Lisp_Symbol
*sym
;
601 CHECK_SYMBOL (new_alias
);
602 CHECK_SYMBOL (base_variable
);
604 sym
= XSYMBOL (new_alias
);
607 /* Not sure why, but why not? */
608 error ("Cannot make a constant an alias");
610 switch (sym
->redirect
)
612 case SYMBOL_FORWARDED
:
613 error ("Cannot make an internal variable an alias");
614 case SYMBOL_LOCALIZED
:
615 error ("Don't know how to make a localized variable an alias");
618 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
619 If n_a is bound, but b_v is not, set the value of b_v to n_a,
620 so that old-code that affects n_a before the aliasing is setup
622 if (NILP (Fboundp (base_variable
)))
623 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
626 union specbinding
*p
;
628 for (p
= specpdl_ptr
; p
> specpdl
; )
629 if ((--p
)->kind
>= SPECPDL_LET
630 && (EQ (new_alias
, specpdl_symbol (p
))))
631 error ("Don't know how to make a let-bound variable an alias");
634 sym
->declared_special
= 1;
635 XSYMBOL (base_variable
)->declared_special
= 1;
636 sym
->redirect
= SYMBOL_VARALIAS
;
637 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
638 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
639 LOADHIST_ATTACH (new_alias
);
640 /* Even if docstring is nil: remove old docstring. */
641 Fput (new_alias
, Qvariable_documentation
, docstring
);
643 return base_variable
;
646 static union specbinding
*
647 default_toplevel_binding (Lisp_Object symbol
)
649 union specbinding
*binding
= NULL
;
650 union specbinding
*pdl
= specpdl_ptr
;
651 while (pdl
> specpdl
)
653 switch ((--pdl
)->kind
)
655 case SPECPDL_LET_DEFAULT
:
657 if (EQ (specpdl_symbol (pdl
), symbol
))
665 DEFUN ("default-toplevel-value", Fdefault_toplevel_value
, Sdefault_toplevel_value
, 1, 1, 0,
666 doc
: /* Return SYMBOL's toplevel default value.
667 "Toplevel" means outside of any let binding. */)
670 union specbinding
*binding
= default_toplevel_binding (symbol
);
672 = binding
? specpdl_old_value (binding
) : Fdefault_value (symbol
);
673 if (!EQ (value
, Qunbound
))
675 xsignal1 (Qvoid_variable
, symbol
);
678 DEFUN ("set-default-toplevel-value", Fset_default_toplevel_value
,
679 Sset_default_toplevel_value
, 2, 2, 0,
680 doc
: /* Set SYMBOL's toplevel default value to VALUE.
681 "Toplevel" means outside of any let binding. */)
682 (Lisp_Object symbol
, Lisp_Object value
)
684 union specbinding
*binding
= default_toplevel_binding (symbol
);
686 set_specpdl_old_value (binding
, value
);
688 Fset_default (symbol
, value
);
692 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
693 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
694 You are not required to define a variable in order to use it, but
695 defining it lets you supply an initial value and documentation, which
696 can be referred to by the Emacs help facilities and other programming
697 tools. The `defvar' form also declares the variable as \"special\",
698 so that it is always dynamically bound even if `lexical-binding' is t.
700 The optional argument INITVALUE is evaluated, and used to set SYMBOL,
701 only if SYMBOL's value is void. If SYMBOL is buffer-local, its
702 default value is what is set; buffer-local values are not affected.
703 If INITVALUE is missing, SYMBOL's value is not set.
705 If SYMBOL has a local binding, then this form affects the local
706 binding. This is usually not what you want. Thus, if you need to
707 load a file defining variables, with this form or with `defconst' or
708 `defcustom', you should always load that file _outside_ any bindings
709 for these variables. \(`defconst' and `defcustom' behave similarly in
712 The optional argument DOCSTRING is a documentation string for the
715 To define a user option, use `defcustom' instead of `defvar'.
716 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
719 Lisp_Object sym
, tem
, tail
;
726 if (CONSP (XCDR (tail
)) && CONSP (XCDR (XCDR (tail
))))
727 error ("Too many arguments");
729 tem
= Fdefault_boundp (sym
);
731 /* Do it before evaluating the initial value, for self-references. */
732 XSYMBOL (sym
)->declared_special
= 1;
735 Fset_default (sym
, eval_sub (XCAR (tail
)));
737 { /* Check if there is really a global binding rather than just a let
738 binding that shadows the global unboundness of the var. */
739 union specbinding
*binding
= default_toplevel_binding (sym
);
740 if (binding
&& EQ (specpdl_old_value (binding
), Qunbound
))
742 set_specpdl_old_value (binding
, eval_sub (XCAR (tail
)));
749 if (!NILP (Vpurify_flag
))
750 tem
= Fpurecopy (tem
);
751 Fput (sym
, Qvariable_documentation
, tem
);
753 LOADHIST_ATTACH (sym
);
755 else if (!NILP (Vinternal_interpreter_environment
)
756 && !XSYMBOL (sym
)->declared_special
)
757 /* A simple (defvar foo) with lexical scoping does "nothing" except
758 declare that var to be dynamically scoped *locally* (i.e. within
759 the current file or let-block). */
760 Vinternal_interpreter_environment
761 = Fcons (sym
, Vinternal_interpreter_environment
);
764 /* Simple (defvar <var>) should not count as a definition at all.
765 It could get in the way of other definitions, and unloading this
766 package could try to make the variable unbound. */
772 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
773 doc
: /* Define SYMBOL as a constant variable.
774 This declares that neither programs nor users should ever change the
775 value. This constancy is not actually enforced by Emacs Lisp, but
776 SYMBOL is marked as a special variable so that it is never lexically
779 The `defconst' form always sets the value of SYMBOL to the result of
780 evalling INITVALUE. If SYMBOL is buffer-local, its default value is
781 what is set; buffer-local values are not affected. If SYMBOL has a
782 local binding, then this form sets the local binding's value.
783 However, you should normally not make local bindings for variables
784 defined with this form.
786 The optional DOCSTRING specifies the variable's documentation string.
787 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
790 Lisp_Object sym
, tem
;
793 if (CONSP (Fcdr (XCDR (XCDR (args
)))))
794 error ("Too many arguments");
796 tem
= eval_sub (Fcar (XCDR (args
)));
797 if (!NILP (Vpurify_flag
))
798 tem
= Fpurecopy (tem
);
799 Fset_default (sym
, tem
);
800 XSYMBOL (sym
)->declared_special
= 1;
801 tem
= Fcar (XCDR (XCDR (args
)));
804 if (!NILP (Vpurify_flag
))
805 tem
= Fpurecopy (tem
);
806 Fput (sym
, Qvariable_documentation
, tem
);
808 Fput (sym
, Qrisky_local_variable
, Qt
);
809 LOADHIST_ATTACH (sym
);
813 /* Make SYMBOL lexically scoped. */
814 DEFUN ("internal-make-var-non-special", Fmake_var_non_special
,
815 Smake_var_non_special
, 1, 1, 0,
816 doc
: /* Internal function. */)
819 CHECK_SYMBOL (symbol
);
820 XSYMBOL (symbol
)->declared_special
= 0;
825 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
826 doc
: /* Bind variables according to VARLIST then eval BODY.
827 The value of the last form in BODY is returned.
828 Each element of VARLIST is a symbol (which is bound to nil)
829 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
830 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
831 usage: (let* VARLIST BODY...) */)
834 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
835 ptrdiff_t count
= SPECPDL_INDEX ();
836 struct gcpro gcpro1
, gcpro2
, gcpro3
;
838 GCPRO3 (args
, elt
, varlist
);
840 lexenv
= Vinternal_interpreter_environment
;
842 varlist
= XCAR (args
);
843 while (CONSP (varlist
))
847 elt
= XCAR (varlist
);
853 else if (! NILP (Fcdr (Fcdr (elt
))))
854 signal_error ("`let' bindings can have only one value-form", elt
);
858 val
= eval_sub (Fcar (Fcdr (elt
)));
861 if (!NILP (lexenv
) && SYMBOLP (var
)
862 && !XSYMBOL (var
)->declared_special
863 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
864 /* Lexically bind VAR by adding it to the interpreter's binding
868 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
869 if (EQ (Vinternal_interpreter_environment
, lexenv
))
870 /* Save the old lexical environment on the specpdl stack,
871 but only for the first lexical binding, since we'll never
872 need to revert to one of the intermediate ones. */
873 specbind (Qinternal_interpreter_environment
, newenv
);
875 Vinternal_interpreter_environment
= newenv
;
880 varlist
= XCDR (varlist
);
883 val
= Fprogn (XCDR (args
));
884 return unbind_to (count
, val
);
887 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
888 doc
: /* Bind variables according to VARLIST then eval BODY.
889 The value of the last form in BODY is returned.
890 Each element of VARLIST is a symbol (which is bound to nil)
891 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
892 All the VALUEFORMs are evalled before any symbols are bound.
893 usage: (let VARLIST BODY...) */)
896 Lisp_Object
*temps
, tem
, lexenv
;
897 register Lisp_Object elt
, varlist
;
898 ptrdiff_t count
= SPECPDL_INDEX ();
900 struct gcpro gcpro1
, gcpro2
;
903 varlist
= XCAR (args
);
905 /* Make space to hold the values to give the bound variables. */
906 elt
= Flength (varlist
);
907 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
909 /* Compute the values and store them in `temps'. */
911 GCPRO2 (args
, *temps
);
914 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
917 elt
= XCAR (varlist
);
919 temps
[argnum
++] = Qnil
;
920 else if (! NILP (Fcdr (Fcdr (elt
))))
921 signal_error ("`let' bindings can have only one value-form", elt
);
923 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
924 gcpro2
.nvars
= argnum
;
928 lexenv
= Vinternal_interpreter_environment
;
930 varlist
= XCAR (args
);
931 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
935 elt
= XCAR (varlist
);
936 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
937 tem
= temps
[argnum
++];
939 if (!NILP (lexenv
) && SYMBOLP (var
)
940 && !XSYMBOL (var
)->declared_special
941 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
942 /* Lexically bind VAR by adding it to the lexenv alist. */
943 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
945 /* Dynamically bind VAR. */
949 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
950 /* Instantiate a new lexical environment. */
951 specbind (Qinternal_interpreter_environment
, lexenv
);
953 elt
= Fprogn (XCDR (args
));
955 return unbind_to (count
, elt
);
958 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
959 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
960 The order of execution is thus TEST, BODY, TEST, BODY and so on
961 until TEST returns nil.
962 usage: (while TEST BODY...) */)
965 Lisp_Object test
, body
;
966 struct gcpro gcpro1
, gcpro2
;
972 while (!NILP (eval_sub (test
)))
982 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
983 doc
: /* Return result of expanding macros at top level of FORM.
984 If FORM is not a macro call, it is returned unchanged.
985 Otherwise, the macro is expanded and the expansion is considered
986 in place of FORM. When a non-macro-call results, it is returned.
988 The second optional arg ENVIRONMENT specifies an environment of macro
989 definitions to shadow the loaded ones for use in file byte-compilation. */)
990 (Lisp_Object form
, Lisp_Object environment
)
992 /* With cleanups from Hallvard Furuseth. */
993 register Lisp_Object expander
, sym
, def
, tem
;
997 /* Come back here each time we expand a macro call,
998 in case it expands into another macro call. */
1001 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1002 def
= sym
= XCAR (form
);
1004 /* Trace symbols aliases to other symbols
1005 until we get a symbol that is not an alias. */
1006 while (SYMBOLP (def
))
1010 tem
= Fassq (sym
, environment
);
1013 def
= XSYMBOL (sym
)->function
;
1019 /* Right now TEM is the result from SYM in ENVIRONMENT,
1020 and if TEM is nil then DEF is SYM's function definition. */
1023 /* SYM is not mentioned in ENVIRONMENT.
1024 Look at its function definition. */
1025 struct gcpro gcpro1
;
1027 def
= Fautoload_do_load (def
, sym
, Qmacro
);
1030 /* Not defined or definition not suitable. */
1032 if (!EQ (XCAR (def
), Qmacro
))
1034 else expander
= XCDR (def
);
1038 expander
= XCDR (tem
);
1039 if (NILP (expander
))
1043 Lisp_Object newform
= apply1 (expander
, XCDR (form
));
1044 if (EQ (form
, newform
))
1053 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1054 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1055 TAG is evalled to get the tag to use; it must not be nil.
1057 Then the BODY is executed.
1058 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1059 If no throw happens, `catch' returns the value of the last BODY form.
1060 If a throw happens, it specifies the value to return from `catch'.
1061 usage: (catch TAG BODY...) */)
1064 register Lisp_Object tag
;
1065 struct gcpro gcpro1
;
1068 tag
= eval_sub (XCAR (args
));
1070 return internal_catch (tag
, Fprogn
, XCDR (args
));
1073 /* Assert that E is true, as a comment only. Use this instead of
1074 eassert (E) when E contains variables that might be clobbered by a
1077 #define clobbered_eassert(E) ((void) 0)
1079 /* Set up a catch, then call C function FUNC on argument ARG.
1080 FUNC should return a Lisp_Object.
1081 This is how catches are done from within C code. */
1084 internal_catch (Lisp_Object tag
, Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1086 /* This structure is made part of the chain `catchlist'. */
1089 /* Fill in the components of c, and put it on the list. */
1090 PUSH_HANDLER (c
, tag
, CATCHER
);
1093 if (! sys_setjmp (c
->jmp
))
1095 Lisp_Object val
= (*func
) (arg
);
1096 clobbered_eassert (handlerlist
== c
);
1097 handlerlist
= handlerlist
->next
;
1101 { /* Throw works by a longjmp that comes right here. */
1102 Lisp_Object val
= handlerlist
->val
;
1103 clobbered_eassert (handlerlist
== c
);
1104 handlerlist
= handlerlist
->next
;
1109 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1110 jump to that CATCH, returning VALUE as the value of that catch.
1112 This is the guts of Fthrow and Fsignal; they differ only in the way
1113 they choose the catch tag to throw to. A catch tag for a
1114 condition-case form has a TAG of Qnil.
1116 Before each catch is discarded, unbind all special bindings and
1117 execute all unwind-protect clauses made above that catch. Unwind
1118 the handler stack as we go, so that the proper handlers are in
1119 effect for each unwind-protect clause we run. At the end, restore
1120 some static info saved in CATCH, and longjmp to the location
1123 This is used for correct unwinding in Fthrow and Fsignal. */
1125 static _Noreturn
void
1126 unwind_to_catch (struct handler
*catch, Lisp_Object value
)
1130 eassert (catch->next
);
1132 /* Save the value in the tag. */
1135 /* Restore certain special C variables. */
1136 set_poll_suppress_count (catch->poll_suppress_count
);
1137 unblock_input_to (catch->interrupt_input_blocked
);
1142 /* Unwind the specpdl stack, and then restore the proper set of
1144 unbind_to (handlerlist
->pdlcount
, Qnil
);
1145 last_time
= handlerlist
== catch;
1147 handlerlist
= handlerlist
->next
;
1149 while (! last_time
);
1151 eassert (handlerlist
== catch);
1153 byte_stack_list
= catch->byte_stack
;
1154 gcprolist
= catch->gcpro
;
1156 gcpro_level
= gcprolist
? gcprolist
->level
+ 1 : 0;
1158 lisp_eval_depth
= catch->lisp_eval_depth
;
1160 sys_longjmp (catch->jmp
, 1);
1163 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1164 doc
: /* Throw to the catch for TAG and return VALUE from it.
1165 Both TAG and VALUE are evalled. */
1166 attributes
: noreturn
)
1167 (register Lisp_Object tag
, Lisp_Object value
)
1172 for (c
= handlerlist
; c
; c
= c
->next
)
1174 if (c
->type
== CATCHER
&& EQ (c
->tag_or_ch
, tag
))
1175 unwind_to_catch (c
, value
);
1177 xsignal2 (Qno_catch
, tag
, value
);
1181 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1182 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1183 If BODYFORM completes normally, its value is returned
1184 after executing the UNWINDFORMS.
1185 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1186 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1190 ptrdiff_t count
= SPECPDL_INDEX ();
1192 record_unwind_protect (unwind_body
, XCDR (args
));
1193 val
= eval_sub (XCAR (args
));
1194 return unbind_to (count
, val
);
1197 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1198 doc
: /* Regain control when an error is signaled.
1199 Executes BODYFORM and returns its value if no error happens.
1200 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1201 where the BODY is made of Lisp expressions.
1203 A handler is applicable to an error
1204 if CONDITION-NAME is one of the error's condition names.
1205 If an error happens, the first applicable handler is run.
1207 The car of a handler may be a list of condition names instead of a
1208 single condition name; then it handles all of them. If the special
1209 condition name `debug' is present in this list, it allows another
1210 condition in the list to run the debugger if `debug-on-error' and the
1211 other usual mechanisms says it should (otherwise, `condition-case'
1212 suppresses the debugger).
1214 When a handler handles an error, control returns to the `condition-case'
1215 and it executes the handler's BODY...
1216 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1217 \(If VAR is nil, the handler can't access that information.)
1218 Then the value of the last BODY form is returned from the `condition-case'
1221 See also the function `signal' for more info.
1222 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1225 Lisp_Object var
= XCAR (args
);
1226 Lisp_Object bodyform
= XCAR (XCDR (args
));
1227 Lisp_Object handlers
= XCDR (XCDR (args
));
1229 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1232 /* Like Fcondition_case, but the args are separate
1233 rather than passed in a list. Used by Fbyte_code. */
1236 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1237 Lisp_Object handlers
)
1241 struct handler
*oldhandlerlist
= handlerlist
;
1246 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1248 Lisp_Object tem
= XCAR (val
);
1252 && (SYMBOLP (XCAR (tem
))
1253 || CONSP (XCAR (tem
))))))
1254 error ("Invalid condition handler: %s",
1255 SDATA (Fprin1_to_string (tem
, Qt
)));
1258 { /* The first clause is the one that should be checked first, so it should
1259 be added to handlerlist last. So we build in `clauses' a table that
1260 contains `handlers' but in reverse order. SAFE_ALLOCA won't work
1261 here due to the setjmp, so impose a MAX_ALLOCA limit. */
1262 if (MAX_ALLOCA
/ word_size
< clausenb
)
1263 memory_full (SIZE_MAX
);
1264 Lisp_Object
*clauses
= alloca (clausenb
* sizeof *clauses
);
1265 Lisp_Object
*volatile clauses_volatile
= clauses
;
1267 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1268 clauses
[--i
] = XCAR (val
);
1269 for (i
= 0; i
< clausenb
; i
++)
1271 Lisp_Object clause
= clauses
[i
];
1272 Lisp_Object condition
= XCAR (clause
);
1273 if (!CONSP (condition
))
1274 condition
= Fcons (condition
, Qnil
);
1275 PUSH_HANDLER (c
, condition
, CONDITION_CASE
);
1276 if (sys_setjmp (c
->jmp
))
1278 ptrdiff_t count
= SPECPDL_INDEX ();
1279 Lisp_Object val
= handlerlist
->val
;
1280 Lisp_Object
*chosen_clause
= clauses_volatile
;
1281 for (c
= handlerlist
->next
; c
!= oldhandlerlist
; c
= c
->next
)
1283 handlerlist
= oldhandlerlist
;
1286 if (!NILP (Vinternal_interpreter_environment
))
1287 specbind (Qinternal_interpreter_environment
,
1288 Fcons (Fcons (var
, val
),
1289 Vinternal_interpreter_environment
));
1291 specbind (var
, val
);
1293 val
= Fprogn (XCDR (*chosen_clause
));
1294 /* Note that this just undoes the binding of var; whoever
1295 longjumped to us unwound the stack to c.pdlcount before
1298 unbind_to (count
, Qnil
);
1304 val
= eval_sub (bodyform
);
1305 handlerlist
= oldhandlerlist
;
1309 /* Call the function BFUN with no arguments, catching errors within it
1310 according to HANDLERS. If there is an error, call HFUN with
1311 one argument which is the data that describes the error:
1314 HANDLERS can be a list of conditions to catch.
1315 If HANDLERS is Qt, catch all errors.
1316 If HANDLERS is Qerror, catch all errors
1317 but allow the debugger to run if that is enabled. */
1320 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1321 Lisp_Object (*hfun
) (Lisp_Object
))
1326 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1327 if (sys_setjmp (c
->jmp
))
1329 Lisp_Object val
= handlerlist
->val
;
1330 clobbered_eassert (handlerlist
== c
);
1331 handlerlist
= handlerlist
->next
;
1332 return (*hfun
) (val
);
1336 clobbered_eassert (handlerlist
== c
);
1337 handlerlist
= handlerlist
->next
;
1341 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1344 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1345 Lisp_Object handlers
, Lisp_Object (*hfun
) (Lisp_Object
))
1350 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1351 if (sys_setjmp (c
->jmp
))
1353 Lisp_Object val
= handlerlist
->val
;
1354 clobbered_eassert (handlerlist
== c
);
1355 handlerlist
= handlerlist
->next
;
1356 return (*hfun
) (val
);
1359 val
= (*bfun
) (arg
);
1360 clobbered_eassert (handlerlist
== c
);
1361 handlerlist
= handlerlist
->next
;
1365 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1369 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1372 Lisp_Object handlers
,
1373 Lisp_Object (*hfun
) (Lisp_Object
))
1378 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1379 if (sys_setjmp (c
->jmp
))
1381 Lisp_Object val
= handlerlist
->val
;
1382 clobbered_eassert (handlerlist
== c
);
1383 handlerlist
= handlerlist
->next
;
1384 return (*hfun
) (val
);
1387 val
= (*bfun
) (arg1
, arg2
);
1388 clobbered_eassert (handlerlist
== c
);
1389 handlerlist
= handlerlist
->next
;
1393 /* Like internal_condition_case but call BFUN with NARGS as first,
1394 and ARGS as second argument. */
1397 internal_condition_case_n (Lisp_Object (*bfun
) (ptrdiff_t, Lisp_Object
*),
1400 Lisp_Object handlers
,
1401 Lisp_Object (*hfun
) (Lisp_Object err
,
1408 PUSH_HANDLER (c
, handlers
, CONDITION_CASE
);
1409 if (sys_setjmp (c
->jmp
))
1411 Lisp_Object val
= handlerlist
->val
;
1412 clobbered_eassert (handlerlist
== c
);
1413 handlerlist
= handlerlist
->next
;
1414 return (*hfun
) (val
, nargs
, args
);
1417 val
= (*bfun
) (nargs
, args
);
1418 clobbered_eassert (handlerlist
== c
);
1419 handlerlist
= handlerlist
->next
;
1424 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
);
1425 static bool maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
,
1429 process_quit_flag (void)
1431 Lisp_Object flag
= Vquit_flag
;
1433 if (EQ (flag
, Qkill_emacs
))
1435 if (EQ (Vthrow_on_input
, flag
))
1436 Fthrow (Vthrow_on_input
, Qt
);
1437 Fsignal (Qquit
, Qnil
);
1440 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1441 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1442 This function does not return.
1444 An error symbol is a symbol with an `error-conditions' property
1445 that is a list of condition names.
1446 A handler for any of those names will get to handle this signal.
1447 The symbol `error' should normally be one of them.
1449 DATA should be a list. Its elements are printed as part of the error message.
1450 See Info anchor `(elisp)Definition of signal' for some details on how this
1451 error message is constructed.
1452 If the signal is handled, DATA is made available to the handler.
1453 See also the function `condition-case'. */)
1454 (Lisp_Object error_symbol
, Lisp_Object data
)
1456 /* When memory is full, ERROR-SYMBOL is nil,
1457 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1458 That is a special case--don't do this in other situations. */
1459 Lisp_Object conditions
;
1461 Lisp_Object real_error_symbol
1462 = (NILP (error_symbol
) ? Fcar (data
) : error_symbol
);
1463 register Lisp_Object clause
= Qnil
;
1468 if (gc_in_progress
|| waiting_for_input
)
1471 #if 0 /* rms: I don't know why this was here,
1472 but it is surely wrong for an error that is handled. */
1473 #ifdef HAVE_WINDOW_SYSTEM
1474 if (display_hourglass_p
)
1475 cancel_hourglass ();
1479 /* This hook is used by edebug. */
1480 if (! NILP (Vsignal_hook_function
)
1481 && ! NILP (error_symbol
))
1483 /* Edebug takes care of restoring these variables when it exits. */
1484 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1485 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1487 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1488 max_specpdl_size
= SPECPDL_INDEX () + 40;
1490 call2 (Vsignal_hook_function
, error_symbol
, data
);
1493 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1495 /* Remember from where signal was called. Skip over the frame for
1496 `signal' itself. If a frame for `error' follows, skip that,
1497 too. Don't do this when ERROR_SYMBOL is nil, because that
1498 is a memory-full error. */
1499 Vsignaling_function
= Qnil
;
1500 if (!NILP (error_symbol
))
1502 union specbinding
*pdl
= backtrace_next (backtrace_top ());
1503 if (backtrace_p (pdl
) && EQ (backtrace_function (pdl
), Qerror
))
1504 pdl
= backtrace_next (pdl
);
1505 if (backtrace_p (pdl
))
1506 Vsignaling_function
= backtrace_function (pdl
);
1509 for (h
= handlerlist
; h
; h
= h
->next
)
1511 if (h
->type
!= CONDITION_CASE
)
1513 clause
= find_handler_clause (h
->tag_or_ch
, conditions
);
1518 if (/* Don't run the debugger for a memory-full error.
1519 (There is no room in memory to do that!) */
1520 !NILP (error_symbol
)
1521 && (!NILP (Vdebug_on_signal
)
1522 /* If no handler is present now, try to run the debugger. */
1524 /* A `debug' symbol in the handler list disables the normal
1525 suppression of the debugger. */
1526 || (CONSP (clause
) && !NILP (Fmemq (Qdebug
, clause
)))
1527 /* Special handler that means "print a message and run debugger
1529 || EQ (h
->tag_or_ch
, Qerror
)))
1531 bool debugger_called
1532 = maybe_call_debugger (conditions
, error_symbol
, data
);
1533 /* We can't return values to code which signaled an error, but we
1534 can continue code which has signaled a quit. */
1535 if (debugger_called
&& EQ (real_error_symbol
, Qquit
))
1541 Lisp_Object unwind_data
1542 = (NILP (error_symbol
) ? data
: Fcons (error_symbol
, data
));
1544 unwind_to_catch (h
, unwind_data
);
1548 if (handlerlist
!= &handlerlist_sentinel
)
1549 /* FIXME: This will come right back here if there's no `top-level'
1550 catcher. A better solution would be to abort here, and instead
1551 add a catch-all condition handler so we never come here. */
1552 Fthrow (Qtop_level
, Qt
);
1555 if (! NILP (error_symbol
))
1556 data
= Fcons (error_symbol
, data
);
1558 string
= Ferror_message_string (data
);
1559 fatal ("%s", SDATA (string
));
1562 /* Internal version of Fsignal that never returns.
1563 Used for anything but Qquit (which can return from Fsignal). */
1566 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1568 Fsignal (error_symbol
, data
);
1572 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1575 xsignal0 (Lisp_Object error_symbol
)
1577 xsignal (error_symbol
, Qnil
);
1581 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1583 xsignal (error_symbol
, list1 (arg
));
1587 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1589 xsignal (error_symbol
, list2 (arg1
, arg2
));
1593 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1595 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1598 /* Signal `error' with message S, and additional arg ARG.
1599 If ARG is not a genuine list, make it a one-element list. */
1602 signal_error (const char *s
, Lisp_Object arg
)
1604 Lisp_Object tortoise
, hare
;
1606 hare
= tortoise
= arg
;
1607 while (CONSP (hare
))
1614 tortoise
= XCDR (tortoise
);
1616 if (EQ (hare
, tortoise
))
1623 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1627 /* Return true if LIST is a non-nil atom or
1628 a list containing one of CONDITIONS. */
1631 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1638 while (CONSP (conditions
))
1640 Lisp_Object
this, tail
;
1641 this = XCAR (conditions
);
1642 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1643 if (EQ (XCAR (tail
), this))
1645 conditions
= XCDR (conditions
);
1650 /* Return true if an error with condition-symbols CONDITIONS,
1651 and described by SIGNAL-DATA, should skip the debugger
1652 according to debugger-ignored-errors. */
1655 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1658 bool first_string
= 1;
1659 Lisp_Object error_message
;
1661 error_message
= Qnil
;
1662 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1664 if (STRINGP (XCAR (tail
)))
1668 error_message
= Ferror_message_string (data
);
1672 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1677 Lisp_Object contail
;
1679 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1680 if (EQ (XCAR (tail
), XCAR (contail
)))
1688 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1689 SIG and DATA describe the signal. There are two ways to pass them:
1690 = SIG is the error symbol, and DATA is the rest of the data.
1691 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1692 This is for memory-full errors only. */
1694 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1696 Lisp_Object combined_data
;
1698 combined_data
= Fcons (sig
, data
);
1701 /* Don't try to run the debugger with interrupts blocked.
1702 The editing loop would return anyway. */
1703 ! input_blocked_p ()
1704 && NILP (Vinhibit_debugger
)
1705 /* Does user want to enter debugger for this kind of error? */
1708 : wants_debugger (Vdebug_on_error
, conditions
))
1709 && ! skip_debugger (conditions
, combined_data
)
1710 /* RMS: What's this for? */
1711 && when_entered_debugger
< num_nonmacro_input_events
)
1713 call_debugger (list2 (Qerror
, combined_data
));
1721 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
)
1723 register Lisp_Object h
;
1725 /* t is used by handlers for all conditions, set up by C code. */
1726 if (EQ (handlers
, Qt
))
1729 /* error is used similarly, but means print an error message
1730 and run the debugger if that is enabled. */
1731 if (EQ (handlers
, Qerror
))
1734 for (h
= handlers
; CONSP (h
); h
= XCDR (h
))
1736 Lisp_Object handler
= XCAR (h
);
1737 if (!NILP (Fmemq (handler
, conditions
)))
1745 /* Dump an error message; called like vprintf. */
1747 verror (const char *m
, va_list ap
)
1750 ptrdiff_t size
= sizeof buf
;
1751 ptrdiff_t size_max
= STRING_BYTES_BOUND
+ 1;
1756 used
= evxprintf (&buffer
, &size
, buf
, size_max
, m
, ap
);
1757 string
= make_string (buffer
, used
);
1761 xsignal1 (Qerror
, string
);
1765 /* Dump an error message; called like printf. */
1769 error (const char *m
, ...)
1776 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1777 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1778 This means it contains a description for how to read arguments to give it.
1779 The value is nil for an invalid function or a symbol with no function
1782 Interactively callable functions include strings and vectors (treated
1783 as keyboard macros), lambda-expressions that contain a top-level call
1784 to `interactive', autoload definitions made by `autoload' with non-nil
1785 fourth argument, and some of the built-in functions of Lisp.
1787 Also, a symbol satisfies `commandp' if its function definition does so.
1789 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1790 then strings and vectors are not accepted. */)
1791 (Lisp_Object function
, Lisp_Object for_call_interactively
)
1793 register Lisp_Object fun
;
1794 register Lisp_Object funcar
;
1795 Lisp_Object if_prop
= Qnil
;
1799 fun
= indirect_function (fun
); /* Check cycles. */
1803 /* Check an `interactive-form' property if present, analogous to the
1804 function-documentation property. */
1806 while (SYMBOLP (fun
))
1808 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
1811 fun
= Fsymbol_function (fun
);
1814 /* Emacs primitives are interactive if their DEFUN specifies an
1815 interactive spec. */
1817 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
1819 /* Bytecode objects are interactive if they are long enough to
1820 have an element whose index is COMPILED_INTERACTIVE, which is
1821 where the interactive spec is stored. */
1822 else if (COMPILEDP (fun
))
1823 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1826 /* Strings and vectors are keyboard macros. */
1827 if (STRINGP (fun
) || VECTORP (fun
))
1828 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
1830 /* Lists may represent commands. */
1833 funcar
= XCAR (fun
);
1834 if (EQ (funcar
, Qclosure
))
1835 return (!NILP (Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
)))))
1837 else if (EQ (funcar
, Qlambda
))
1838 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
1839 else if (EQ (funcar
, Qautoload
))
1840 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
1845 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1846 doc
: /* Define FUNCTION to autoload from FILE.
1847 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1848 Third arg DOCSTRING is documentation for the function.
1849 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1850 Fifth arg TYPE indicates the type of the object:
1851 nil or omitted says FUNCTION is a function,
1852 `keymap' says FUNCTION is really a keymap, and
1853 `macro' or t says FUNCTION is really a macro.
1854 Third through fifth args give info about the real definition.
1855 They default to nil.
1856 If FUNCTION is already defined other than as an autoload,
1857 this does nothing and returns nil. */)
1858 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
1860 CHECK_SYMBOL (function
);
1861 CHECK_STRING (file
);
1863 /* If function is defined and not as an autoload, don't override. */
1864 if (!NILP (XSYMBOL (function
)->function
)
1865 && !AUTOLOADP (XSYMBOL (function
)->function
))
1868 if (!NILP (Vpurify_flag
) && EQ (docstring
, make_number (0)))
1869 /* `read1' in lread.c has found the docstring starting with "\
1870 and assumed the docstring will be provided by Snarf-documentation, so it
1871 passed us 0 instead. But that leads to accidental sharing in purecopy's
1872 hash-consing, so we use a (hopefully) unique integer instead. */
1873 docstring
= make_number (XHASH (function
));
1874 return Fdefalias (function
,
1875 list5 (Qautoload
, file
, docstring
, interactive
, type
),
1880 un_autoload (Lisp_Object oldqueue
)
1882 Lisp_Object queue
, first
, second
;
1884 /* Queue to unwind is current value of Vautoload_queue.
1885 oldqueue is the shadowed value to leave in Vautoload_queue. */
1886 queue
= Vautoload_queue
;
1887 Vautoload_queue
= oldqueue
;
1888 while (CONSP (queue
))
1890 first
= XCAR (queue
);
1891 second
= Fcdr (first
);
1892 first
= Fcar (first
);
1893 if (EQ (first
, make_number (0)))
1896 Ffset (first
, second
);
1897 queue
= XCDR (queue
);
1901 /* Load an autoloaded function.
1902 FUNNAME is the symbol which is the function's name.
1903 FUNDEF is the autoload definition (a list). */
1905 DEFUN ("autoload-do-load", Fautoload_do_load
, Sautoload_do_load
, 1, 3, 0,
1906 doc
: /* Load FUNDEF which should be an autoload.
1907 If non-nil, FUNNAME should be the symbol whose function value is FUNDEF,
1908 in which case the function returns the new autoloaded function value.
1909 If equal to `macro', MACRO-ONLY specifies that FUNDEF should only be loaded if
1910 it defines a macro. */)
1911 (Lisp_Object fundef
, Lisp_Object funname
, Lisp_Object macro_only
)
1913 ptrdiff_t count
= SPECPDL_INDEX ();
1914 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1916 if (!CONSP (fundef
) || !EQ (Qautoload
, XCAR (fundef
)))
1919 if (EQ (macro_only
, Qmacro
))
1921 Lisp_Object kind
= Fnth (make_number (4), fundef
);
1922 if (! (EQ (kind
, Qt
) || EQ (kind
, Qmacro
)))
1926 /* This is to make sure that loadup.el gives a clear picture
1927 of what files are preloaded and when. */
1928 if (! NILP (Vpurify_flag
))
1929 error ("Attempt to autoload %s while preparing to dump",
1930 SDATA (SYMBOL_NAME (funname
)));
1932 CHECK_SYMBOL (funname
);
1933 GCPRO3 (funname
, fundef
, macro_only
);
1935 /* Preserve the match data. */
1936 record_unwind_save_match_data ();
1938 /* If autoloading gets an error (which includes the error of failing
1939 to define the function being called), we use Vautoload_queue
1940 to undo function definitions and `provide' calls made by
1941 the function. We do this in the specific case of autoloading
1942 because autoloading is not an explicit request "load this file",
1943 but rather a request to "call this function".
1945 The value saved here is to be restored into Vautoload_queue. */
1946 record_unwind_protect (un_autoload
, Vautoload_queue
);
1947 Vautoload_queue
= Qt
;
1948 /* If `macro_only', assume this autoload to be a "best-effort",
1949 so don't signal an error if autoloading fails. */
1950 Fload (Fcar (Fcdr (fundef
)), macro_only
, Qt
, Qnil
, Qt
);
1952 /* Once loading finishes, don't undo it. */
1953 Vautoload_queue
= Qt
;
1954 unbind_to (count
, Qnil
);
1962 Lisp_Object fun
= Findirect_function (funname
, Qnil
);
1964 if (!NILP (Fequal (fun
, fundef
)))
1965 error ("Autoloading failed to define function %s",
1966 SDATA (SYMBOL_NAME (funname
)));
1973 DEFUN ("eval", Feval
, Seval
, 1, 2, 0,
1974 doc
: /* Evaluate FORM and return its value.
1975 If LEXICAL is t, evaluate using lexical scoping.
1976 LEXICAL can also be an actual lexical environment, in the form of an
1977 alist mapping symbols to their value. */)
1978 (Lisp_Object form
, Lisp_Object lexical
)
1980 ptrdiff_t count
= SPECPDL_INDEX ();
1981 specbind (Qinternal_interpreter_environment
,
1982 CONSP (lexical
) || NILP (lexical
) ? lexical
: list1 (Qt
));
1983 return unbind_to (count
, eval_sub (form
));
1986 /* Grow the specpdl stack by one entry.
1987 The caller should have already initialized the entry.
1988 Signal an error on stack overflow.
1990 Make sure that there is always one unused entry past the top of the
1991 stack, so that the just-initialized entry is safely unwound if
1992 memory exhausted and an error is signaled here. Also, allocate a
1993 never-used entry just before the bottom of the stack; sometimes its
1994 address is taken. */
2001 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2003 ptrdiff_t count
= SPECPDL_INDEX ();
2004 ptrdiff_t max_size
= min (max_specpdl_size
, PTRDIFF_MAX
- 1000);
2005 union specbinding
*pdlvec
= specpdl
- 1;
2006 ptrdiff_t pdlvecsize
= specpdl_size
+ 1;
2007 if (max_size
<= specpdl_size
)
2009 if (max_specpdl_size
< 400)
2010 max_size
= max_specpdl_size
= 400;
2011 if (max_size
<= specpdl_size
)
2012 signal_error ("Variable binding depth exceeds max-specpdl-size",
2015 pdlvec
= xpalloc (pdlvec
, &pdlvecsize
, 1, max_size
+ 1, sizeof *specpdl
);
2016 specpdl
= pdlvec
+ 1;
2017 specpdl_size
= pdlvecsize
- 1;
2018 specpdl_ptr
= specpdl
+ count
;
2023 record_in_backtrace (Lisp_Object function
, Lisp_Object
*args
, ptrdiff_t nargs
)
2025 ptrdiff_t count
= SPECPDL_INDEX ();
2027 eassert (nargs
>= UNEVALLED
);
2028 specpdl_ptr
->bt
.kind
= SPECPDL_BACKTRACE
;
2029 specpdl_ptr
->bt
.debug_on_exit
= false;
2030 specpdl_ptr
->bt
.function
= function
;
2031 specpdl_ptr
->bt
.args
= args
;
2032 specpdl_ptr
->bt
.nargs
= nargs
;
2038 /* Eval a sub-expression of the current expression (i.e. in the same
2041 eval_sub (Lisp_Object form
)
2043 Lisp_Object fun
, val
, original_fun
, original_args
;
2045 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2050 /* Look up its binding in the lexical environment.
2051 We do not pay attention to the declared_special flag here, since we
2052 already did that when let-binding the variable. */
2053 Lisp_Object lex_binding
2054 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2055 ? Fassq (form
, Vinternal_interpreter_environment
)
2057 if (CONSP (lex_binding
))
2058 return XCDR (lex_binding
);
2060 return Fsymbol_value (form
);
2072 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2074 if (max_lisp_eval_depth
< 100)
2075 max_lisp_eval_depth
= 100;
2076 if (lisp_eval_depth
> max_lisp_eval_depth
)
2077 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2080 original_fun
= XCAR (form
);
2081 original_args
= XCDR (form
);
2083 /* This also protects them from gc. */
2084 count
= record_in_backtrace (original_fun
, &original_args
, UNEVALLED
);
2086 if (debug_on_next_call
)
2087 do_debug_on_call (Qt
, count
);
2089 /* At this point, only original_fun and original_args
2090 have values that will be used below. */
2093 /* Optimize for no indirection. */
2096 fun
= Ffunction (Fcons (fun
, Qnil
));
2097 else if (!NILP (fun
) && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2098 fun
= indirect_function (fun
);
2102 Lisp_Object numargs
;
2103 Lisp_Object argvals
[8];
2104 Lisp_Object args_left
;
2105 register int i
, maxargs
;
2107 args_left
= original_args
;
2108 numargs
= Flength (args_left
);
2112 if (XINT (numargs
) < XSUBR (fun
)->min_args
2113 || (XSUBR (fun
)->max_args
>= 0
2114 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2115 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2117 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2118 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2119 else if (XSUBR (fun
)->max_args
== MANY
)
2121 /* Pass a vector of evaluated arguments. */
2123 ptrdiff_t argnum
= 0;
2126 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2128 GCPRO3 (args_left
, fun
, fun
);
2132 while (!NILP (args_left
))
2134 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2135 args_left
= Fcdr (args_left
);
2136 gcpro3
.nvars
= argnum
;
2139 set_backtrace_args (specpdl
+ count
, vals
, XINT (numargs
));
2141 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2147 GCPRO3 (args_left
, fun
, fun
);
2148 gcpro3
.var
= argvals
;
2151 maxargs
= XSUBR (fun
)->max_args
;
2152 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2154 argvals
[i
] = eval_sub (Fcar (args_left
));
2160 set_backtrace_args (specpdl
+ count
, argvals
, XINT (numargs
));
2165 val
= (XSUBR (fun
)->function
.a0 ());
2168 val
= (XSUBR (fun
)->function
.a1 (argvals
[0]));
2171 val
= (XSUBR (fun
)->function
.a2 (argvals
[0], argvals
[1]));
2174 val
= (XSUBR (fun
)->function
.a3
2175 (argvals
[0], argvals
[1], argvals
[2]));
2178 val
= (XSUBR (fun
)->function
.a4
2179 (argvals
[0], argvals
[1], argvals
[2], argvals
[3]));
2182 val
= (XSUBR (fun
)->function
.a5
2183 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2187 val
= (XSUBR (fun
)->function
.a6
2188 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2189 argvals
[4], argvals
[5]));
2192 val
= (XSUBR (fun
)->function
.a7
2193 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2194 argvals
[4], argvals
[5], argvals
[6]));
2198 val
= (XSUBR (fun
)->function
.a8
2199 (argvals
[0], argvals
[1], argvals
[2], argvals
[3],
2200 argvals
[4], argvals
[5], argvals
[6], argvals
[7]));
2204 /* Someone has created a subr that takes more arguments than
2205 is supported by this code. We need to either rewrite the
2206 subr to use a different argument protocol, or add more
2207 cases to this switch. */
2212 else if (COMPILEDP (fun
))
2213 val
= apply_lambda (fun
, original_args
, count
);
2217 xsignal1 (Qvoid_function
, original_fun
);
2219 xsignal1 (Qinvalid_function
, original_fun
);
2220 funcar
= XCAR (fun
);
2221 if (!SYMBOLP (funcar
))
2222 xsignal1 (Qinvalid_function
, original_fun
);
2223 if (EQ (funcar
, Qautoload
))
2225 Fautoload_do_load (fun
, original_fun
, Qnil
);
2228 if (EQ (funcar
, Qmacro
))
2230 ptrdiff_t count1
= SPECPDL_INDEX ();
2232 /* Bind lexical-binding during expansion of the macro, so the
2233 macro can know reliably if the code it outputs will be
2234 interpreted using lexical-binding or not. */
2235 specbind (Qlexical_binding
,
2236 NILP (Vinternal_interpreter_environment
) ? Qnil
: Qt
);
2237 exp
= apply1 (Fcdr (fun
), original_args
);
2238 unbind_to (count1
, Qnil
);
2239 val
= eval_sub (exp
);
2241 else if (EQ (funcar
, Qlambda
)
2242 || EQ (funcar
, Qclosure
))
2243 val
= apply_lambda (fun
, original_args
, count
);
2245 xsignal1 (Qinvalid_function
, original_fun
);
2250 if (backtrace_debug_on_exit (specpdl
+ count
))
2251 val
= call_debugger (list2 (Qexit
, val
));
2257 DEFUN ("apply", Fapply
, Sapply
, 1, MANY
, 0,
2258 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2259 Then return the value FUNCTION returns.
2260 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2261 usage: (apply FUNCTION &rest ARGUMENTS) */)
2262 (ptrdiff_t nargs
, Lisp_Object
*args
)
2264 ptrdiff_t i
, numargs
, funcall_nargs
;
2265 register Lisp_Object
*funcall_args
= NULL
;
2266 register Lisp_Object spread_arg
= args
[nargs
- 1];
2267 Lisp_Object fun
= args
[0];
2271 CHECK_LIST (spread_arg
);
2273 numargs
= XINT (Flength (spread_arg
));
2276 return Ffuncall (nargs
- 1, args
);
2277 else if (numargs
== 1)
2279 args
[nargs
- 1] = XCAR (spread_arg
);
2280 return Ffuncall (nargs
, args
);
2283 numargs
+= nargs
- 2;
2285 /* Optimize for no indirection. */
2286 if (SYMBOLP (fun
) && !NILP (fun
)
2287 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2289 fun
= indirect_function (fun
);
2291 /* Let funcall get the error. */
2295 if (SUBRP (fun
) && XSUBR (fun
)->max_args
> numargs
2296 /* Don't hide an error by adding missing arguments. */
2297 && numargs
>= XSUBR (fun
)->min_args
)
2299 /* Avoid making funcall cons up a yet another new vector of arguments
2300 by explicitly supplying nil's for optional values. */
2301 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2302 memclear (funcall_args
+ numargs
+ 1,
2303 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2304 funcall_nargs
= 1 + XSUBR (fun
)->max_args
;
2307 { /* We add 1 to numargs because funcall_args includes the
2308 function itself as well as its arguments. */
2309 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2310 funcall_nargs
= 1 + numargs
;
2313 memcpy (funcall_args
, args
, nargs
* word_size
);
2314 /* Spread the last arg we got. Its first element goes in
2315 the slot that it used to occupy, hence this value of I. */
2317 while (!NILP (spread_arg
))
2319 funcall_args
[i
++] = XCAR (spread_arg
);
2320 spread_arg
= XCDR (spread_arg
);
2323 /* Ffuncall gcpro's all of its args. */
2324 retval
= Ffuncall (funcall_nargs
, funcall_args
);
2330 /* Run hook variables in various ways. */
2333 funcall_nil (ptrdiff_t nargs
, Lisp_Object
*args
)
2335 Ffuncall (nargs
, args
);
2339 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2340 doc
: /* Run each hook in HOOKS.
2341 Each argument should be a symbol, a hook variable.
2342 These symbols are processed in the order specified.
2343 If a hook symbol has a non-nil value, that value may be a function
2344 or a list of functions to be called to run the hook.
2345 If the value is a function, it is called with no arguments.
2346 If it is a list, the elements are called, in order, with no arguments.
2348 Major modes should not use this function directly to run their mode
2349 hook; they should use `run-mode-hooks' instead.
2351 Do not use `make-local-variable' to make a hook variable buffer-local.
2352 Instead, use `add-hook' and specify t for the LOCAL argument.
2353 usage: (run-hooks &rest HOOKS) */)
2354 (ptrdiff_t nargs
, Lisp_Object
*args
)
2358 for (i
= 0; i
< nargs
; i
++)
2364 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2365 Srun_hook_with_args
, 1, MANY
, 0,
2366 doc
: /* Run HOOK with the specified arguments ARGS.
2367 HOOK should be a symbol, a hook variable. The value of HOOK
2368 may be nil, a function, or a list of functions. Call each
2369 function in order with arguments ARGS. The final return value
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-hook-with-args HOOK &rest ARGS) */)
2375 (ptrdiff_t nargs
, Lisp_Object
*args
)
2377 return run_hook_with_args (nargs
, args
, funcall_nil
);
2380 /* NB this one still documents a specific non-nil return value.
2381 (As did run-hook-with-args and run-hook-with-args-until-failure
2382 until they were changed in 24.1.) */
2383 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2384 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2385 doc
: /* Run HOOK with the specified arguments ARGS.
2386 HOOK should be a symbol, a hook variable. The value of HOOK
2387 may be nil, a function, or a list of functions. Call each
2388 function in order with arguments ARGS, stopping at the first
2389 one that returns non-nil, and return that value. Otherwise (if
2390 all functions return nil, or if there are no functions to call),
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-until-success HOOK &rest ARGS) */)
2396 (ptrdiff_t nargs
, Lisp_Object
*args
)
2398 return run_hook_with_args (nargs
, args
, Ffuncall
);
2402 funcall_not (ptrdiff_t nargs
, Lisp_Object
*args
)
2404 return NILP (Ffuncall (nargs
, args
)) ? Qt
: Qnil
;
2407 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2408 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2409 doc
: /* Run HOOK with the specified arguments ARGS.
2410 HOOK should be a symbol, a hook variable. The value of HOOK
2411 may be nil, a function, or a list of functions. Call each
2412 function in order with arguments ARGS, stopping at the first
2413 one that returns nil, and return nil. Otherwise (if all functions
2414 return non-nil, or if there are no functions to call), return non-nil
2415 \(do not rely on the precise return value in this case).
2417 Do not use `make-local-variable' to make a hook variable buffer-local.
2418 Instead, use `add-hook' and specify t for the LOCAL argument.
2419 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2420 (ptrdiff_t nargs
, Lisp_Object
*args
)
2422 return NILP (run_hook_with_args (nargs
, args
, funcall_not
)) ? Qt
: Qnil
;
2426 run_hook_wrapped_funcall (ptrdiff_t nargs
, Lisp_Object
*args
)
2428 Lisp_Object tmp
= args
[0], ret
;
2431 ret
= Ffuncall (nargs
, args
);
2437 DEFUN ("run-hook-wrapped", Frun_hook_wrapped
, Srun_hook_wrapped
, 2, MANY
, 0,
2438 doc
: /* Run HOOK, passing each function through WRAP-FUNCTION.
2439 I.e. instead of calling each function FUN directly with arguments ARGS,
2440 it calls WRAP-FUNCTION with arguments FUN and ARGS.
2441 As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2442 aborts and returns that value.
2443 usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
2444 (ptrdiff_t nargs
, Lisp_Object
*args
)
2446 return run_hook_with_args (nargs
, args
, run_hook_wrapped_funcall
);
2449 /* ARGS[0] should be a hook symbol.
2450 Call each of the functions in the hook value, passing each of them
2451 as arguments all the rest of ARGS (all NARGS - 1 elements).
2452 FUNCALL specifies how to call each function on the hook.
2453 The caller (or its caller, etc) must gcpro all of ARGS,
2454 except that it isn't necessary to gcpro ARGS[0]. */
2457 run_hook_with_args (ptrdiff_t nargs
, Lisp_Object
*args
,
2458 Lisp_Object (*funcall
) (ptrdiff_t nargs
, Lisp_Object
*args
))
2460 Lisp_Object sym
, val
, ret
= Qnil
;
2461 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2463 /* If we are dying or still initializing,
2464 don't do anything--it would probably crash if we tried. */
2465 if (NILP (Vrun_hooks
))
2469 val
= find_symbol_value (sym
);
2471 if (EQ (val
, Qunbound
) || NILP (val
))
2473 else if (!CONSP (val
) || FUNCTIONP (val
))
2476 return funcall (nargs
, args
);
2480 Lisp_Object global_vals
= Qnil
;
2481 GCPRO3 (sym
, val
, global_vals
);
2484 CONSP (val
) && NILP (ret
);
2487 if (EQ (XCAR (val
), Qt
))
2489 /* t indicates this hook has a local binding;
2490 it means to run the global binding too. */
2491 global_vals
= Fdefault_value (sym
);
2492 if (NILP (global_vals
)) continue;
2494 if (!CONSP (global_vals
) || EQ (XCAR (global_vals
), Qlambda
))
2496 args
[0] = global_vals
;
2497 ret
= funcall (nargs
, args
);
2502 CONSP (global_vals
) && NILP (ret
);
2503 global_vals
= XCDR (global_vals
))
2505 args
[0] = XCAR (global_vals
);
2506 /* In a global value, t should not occur. If it does, we
2507 must ignore it to avoid an endless loop. */
2508 if (!EQ (args
[0], Qt
))
2509 ret
= funcall (nargs
, args
);
2515 args
[0] = XCAR (val
);
2516 ret
= funcall (nargs
, args
);
2525 /* Run the hook HOOK, giving each function no args. */
2528 run_hook (Lisp_Object hook
)
2530 Frun_hook_with_args (1, &hook
);
2533 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2536 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2538 CALLN (Frun_hook_with_args
, hook
, arg1
, arg2
);
2541 /* Apply fn to arg. */
2543 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2545 return NILP (arg
) ? Ffuncall (1, &fn
) : CALLN (Fapply
, fn
, arg
);
2548 /* Call function fn on no arguments. */
2550 call0 (Lisp_Object fn
)
2552 return Ffuncall (1, &fn
);
2555 /* Call function fn with 1 argument arg1. */
2558 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2560 return CALLN (Ffuncall
, fn
, arg1
);
2563 /* Call function fn with 2 arguments arg1, arg2. */
2566 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2568 return CALLN (Ffuncall
, fn
, arg1
, arg2
);
2571 /* Call function fn with 3 arguments arg1, arg2, arg3. */
2574 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2576 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
);
2579 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
2582 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2585 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
);
2588 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
2591 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2592 Lisp_Object arg4
, Lisp_Object arg5
)
2594 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
);
2597 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
2600 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2601 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2603 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
);
2606 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
2609 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2610 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
2612 return CALLN (Ffuncall
, fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
, arg7
);
2615 /* The caller should GCPRO all the elements of ARGS. */
2617 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
2618 doc
: /* Non-nil if OBJECT is a function. */)
2619 (Lisp_Object object
)
2621 if (FUNCTIONP (object
))
2626 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2627 doc
: /* Call first argument as a function, passing remaining arguments to it.
2628 Return the value that function returns.
2629 Thus, (funcall 'cons 'x 'y) returns (x . y).
2630 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2631 (ptrdiff_t nargs
, Lisp_Object
*args
)
2633 Lisp_Object fun
, original_fun
;
2635 ptrdiff_t numargs
= nargs
- 1;
2636 Lisp_Object lisp_numargs
;
2638 Lisp_Object
*internal_args
;
2643 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2645 if (max_lisp_eval_depth
< 100)
2646 max_lisp_eval_depth
= 100;
2647 if (lisp_eval_depth
> max_lisp_eval_depth
)
2648 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2651 /* This also GCPROs them. */
2652 count
= record_in_backtrace (args
[0], &args
[1], nargs
- 1);
2654 /* Call GC after setting up the backtrace, so the latter GCPROs the args. */
2657 if (debug_on_next_call
)
2658 do_debug_on_call (Qlambda
, count
);
2662 original_fun
= args
[0];
2666 /* Optimize for no indirection. */
2668 if (SYMBOLP (fun
) && !NILP (fun
)
2669 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2670 fun
= indirect_function (fun
);
2674 if (numargs
< XSUBR (fun
)->min_args
2675 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2677 XSETFASTINT (lisp_numargs
, numargs
);
2678 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2681 else if (XSUBR (fun
)->max_args
== UNEVALLED
)
2682 xsignal1 (Qinvalid_function
, original_fun
);
2684 else if (XSUBR (fun
)->max_args
== MANY
)
2685 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
2688 Lisp_Object internal_argbuf
[8];
2689 if (XSUBR (fun
)->max_args
> numargs
)
2691 eassert (XSUBR (fun
)->max_args
<= ARRAYELTS (internal_argbuf
));
2692 internal_args
= internal_argbuf
;
2693 memcpy (internal_args
, args
+ 1, numargs
* word_size
);
2694 memclear (internal_args
+ numargs
,
2695 (XSUBR (fun
)->max_args
- numargs
) * word_size
);
2698 internal_args
= args
+ 1;
2699 switch (XSUBR (fun
)->max_args
)
2702 val
= (XSUBR (fun
)->function
.a0 ());
2705 val
= (XSUBR (fun
)->function
.a1 (internal_args
[0]));
2708 val
= (XSUBR (fun
)->function
.a2
2709 (internal_args
[0], internal_args
[1]));
2712 val
= (XSUBR (fun
)->function
.a3
2713 (internal_args
[0], internal_args
[1], internal_args
[2]));
2716 val
= (XSUBR (fun
)->function
.a4
2717 (internal_args
[0], internal_args
[1], internal_args
[2],
2721 val
= (XSUBR (fun
)->function
.a5
2722 (internal_args
[0], internal_args
[1], internal_args
[2],
2723 internal_args
[3], internal_args
[4]));
2726 val
= (XSUBR (fun
)->function
.a6
2727 (internal_args
[0], internal_args
[1], internal_args
[2],
2728 internal_args
[3], internal_args
[4], internal_args
[5]));
2731 val
= (XSUBR (fun
)->function
.a7
2732 (internal_args
[0], internal_args
[1], internal_args
[2],
2733 internal_args
[3], internal_args
[4], internal_args
[5],
2738 val
= (XSUBR (fun
)->function
.a8
2739 (internal_args
[0], internal_args
[1], internal_args
[2],
2740 internal_args
[3], internal_args
[4], internal_args
[5],
2741 internal_args
[6], internal_args
[7]));
2746 /* If a subr takes more than 8 arguments without using MANY
2747 or UNEVALLED, we need to extend this function to support it.
2748 Until this is done, there is no way to call the function. */
2753 else if (COMPILEDP (fun
))
2754 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2758 xsignal1 (Qvoid_function
, original_fun
);
2760 xsignal1 (Qinvalid_function
, original_fun
);
2761 funcar
= XCAR (fun
);
2762 if (!SYMBOLP (funcar
))
2763 xsignal1 (Qinvalid_function
, original_fun
);
2764 if (EQ (funcar
, Qlambda
)
2765 || EQ (funcar
, Qclosure
))
2766 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2767 else if (EQ (funcar
, Qautoload
))
2769 Fautoload_do_load (fun
, original_fun
, Qnil
);
2774 xsignal1 (Qinvalid_function
, original_fun
);
2778 if (backtrace_debug_on_exit (specpdl
+ count
))
2779 val
= call_debugger (list2 (Qexit
, val
));
2785 apply_lambda (Lisp_Object fun
, Lisp_Object args
, ptrdiff_t count
)
2787 Lisp_Object args_left
;
2790 register Lisp_Object
*arg_vector
;
2791 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2792 register Lisp_Object tem
;
2795 numargs
= XFASTINT (Flength (args
));
2796 SAFE_ALLOCA_LISP (arg_vector
, numargs
);
2799 GCPRO3 (*arg_vector
, args_left
, fun
);
2802 for (i
= 0; i
< numargs
; )
2804 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2805 tem
= eval_sub (tem
);
2806 arg_vector
[i
++] = tem
;
2812 set_backtrace_args (specpdl
+ count
, arg_vector
, i
);
2813 tem
= funcall_lambda (fun
, numargs
, arg_vector
);
2815 /* Do the debug-on-exit now, while arg_vector still exists. */
2816 if (backtrace_debug_on_exit (specpdl
+ count
))
2818 /* Don't do it again when we return to eval. */
2819 set_backtrace_debug_on_exit (specpdl
+ count
, false);
2820 tem
= call_debugger (list2 (Qexit
, tem
));
2826 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2827 and return the result of evaluation.
2828 FUN must be either a lambda-expression or a compiled-code object. */
2831 funcall_lambda (Lisp_Object fun
, ptrdiff_t nargs
,
2832 register Lisp_Object
*arg_vector
)
2834 Lisp_Object val
, syms_left
, next
, lexenv
;
2835 ptrdiff_t count
= SPECPDL_INDEX ();
2837 bool optional
, rest
;
2841 if (EQ (XCAR (fun
), Qclosure
))
2843 fun
= XCDR (fun
); /* Drop `closure'. */
2844 lexenv
= XCAR (fun
);
2845 CHECK_LIST_CONS (fun
, fun
);
2849 syms_left
= XCDR (fun
);
2850 if (CONSP (syms_left
))
2851 syms_left
= XCAR (syms_left
);
2853 xsignal1 (Qinvalid_function
, fun
);
2855 else if (COMPILEDP (fun
))
2857 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2858 if (INTEGERP (syms_left
))
2859 /* A byte-code object with a non-nil `push args' slot means we
2860 shouldn't bind any arguments, instead just call the byte-code
2861 interpreter directly; it will push arguments as necessary.
2863 Byte-code objects with either a non-existent, or a nil value for
2864 the `push args' slot (the default), have dynamically-bound
2865 arguments, and use the argument-binding code below instead (as do
2866 all interpreted functions, even lexically bound ones). */
2868 /* If we have not actually read the bytecode string
2869 and constants vector yet, fetch them from the file. */
2870 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2871 Ffetch_bytecode (fun
);
2872 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2873 AREF (fun
, COMPILED_CONSTANTS
),
2874 AREF (fun
, COMPILED_STACK_DEPTH
),
2883 i
= optional
= rest
= 0;
2884 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2888 next
= XCAR (syms_left
);
2889 if (!SYMBOLP (next
))
2890 xsignal1 (Qinvalid_function
, fun
);
2892 if (EQ (next
, Qand_rest
))
2894 else if (EQ (next
, Qand_optional
))
2901 arg
= Flist (nargs
- i
, &arg_vector
[i
]);
2905 arg
= arg_vector
[i
++];
2907 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2911 /* Bind the argument. */
2912 if (!NILP (lexenv
) && SYMBOLP (next
))
2913 /* Lexically bind NEXT by adding it to the lexenv alist. */
2914 lexenv
= Fcons (Fcons (next
, arg
), lexenv
);
2916 /* Dynamically bind NEXT. */
2917 specbind (next
, arg
);
2921 if (!NILP (syms_left
))
2922 xsignal1 (Qinvalid_function
, fun
);
2924 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
2926 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
2927 /* Instantiate a new lexical environment. */
2928 specbind (Qinternal_interpreter_environment
, lexenv
);
2931 val
= Fprogn (XCDR (XCDR (fun
)));
2934 /* If we have not actually read the bytecode string
2935 and constants vector yet, fetch them from the file. */
2936 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2937 Ffetch_bytecode (fun
);
2938 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
2939 AREF (fun
, COMPILED_CONSTANTS
),
2940 AREF (fun
, COMPILED_STACK_DEPTH
),
2944 return unbind_to (count
, val
);
2947 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2949 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2950 (Lisp_Object object
)
2954 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
2956 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2959 tem
= AREF (object
, COMPILED_BYTECODE
);
2960 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2961 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2963 error ("Invalid byte code");
2965 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
2966 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
2971 /* Return true if SYMBOL currently has a let-binding
2972 which was made in the buffer that is now current. */
2975 let_shadows_buffer_binding_p (struct Lisp_Symbol
*symbol
)
2977 union specbinding
*p
;
2978 Lisp_Object buf
= Fcurrent_buffer ();
2980 for (p
= specpdl_ptr
; p
> specpdl
; )
2981 if ((--p
)->kind
> SPECPDL_LET
)
2983 struct Lisp_Symbol
*let_bound_symbol
= XSYMBOL (specpdl_symbol (p
));
2984 eassert (let_bound_symbol
->redirect
!= SYMBOL_VARALIAS
);
2985 if (symbol
== let_bound_symbol
2986 && EQ (specpdl_where (p
), buf
))
2994 let_shadows_global_binding_p (Lisp_Object symbol
)
2996 union specbinding
*p
;
2998 for (p
= specpdl_ptr
; p
> specpdl
; )
2999 if ((--p
)->kind
>= SPECPDL_LET
&& EQ (specpdl_symbol (p
), symbol
))
3005 /* `specpdl_ptr' describes which variable is
3006 let-bound, so it can be properly undone when we unbind_to.
3007 It can be either a plain SPECPDL_LET or a SPECPDL_LET_LOCAL/DEFAULT.
3008 - SYMBOL is the variable being bound. Note that it should not be
3009 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3011 - WHERE tells us in which buffer the binding took place.
3012 This is used for SPECPDL_LET_LOCAL bindings (i.e. bindings to a
3013 buffer-local variable) as well as for SPECPDL_LET_DEFAULT bindings,
3014 i.e. bindings to the default value of a variable which can be
3018 specbind (Lisp_Object symbol
, Lisp_Object value
)
3020 struct Lisp_Symbol
*sym
;
3022 CHECK_SYMBOL (symbol
);
3023 sym
= XSYMBOL (symbol
);
3026 switch (sym
->redirect
)
3028 case SYMBOL_VARALIAS
:
3029 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3030 case SYMBOL_PLAINVAL
:
3031 /* The most common case is that of a non-constant symbol with a
3032 trivial value. Make that as fast as we can. */
3033 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3034 specpdl_ptr
->let
.symbol
= symbol
;
3035 specpdl_ptr
->let
.old_value
= SYMBOL_VAL (sym
);
3038 SET_SYMBOL_VAL (sym
, value
);
3040 set_internal (symbol
, value
, Qnil
, 1);
3042 case SYMBOL_LOCALIZED
:
3043 if (SYMBOL_BLV (sym
)->frame_local
)
3044 error ("Frame-local vars cannot be let-bound");
3045 case SYMBOL_FORWARDED
:
3047 Lisp_Object ovalue
= find_symbol_value (symbol
);
3048 specpdl_ptr
->let
.kind
= SPECPDL_LET_LOCAL
;
3049 specpdl_ptr
->let
.symbol
= symbol
;
3050 specpdl_ptr
->let
.old_value
= ovalue
;
3051 specpdl_ptr
->let
.where
= Fcurrent_buffer ();
3053 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3054 || (EQ (SYMBOL_BLV (sym
)->where
, Fcurrent_buffer ())));
3056 if (sym
->redirect
== SYMBOL_LOCALIZED
)
3058 if (!blv_found (SYMBOL_BLV (sym
)))
3059 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3061 else if (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3063 /* If SYMBOL is a per-buffer variable which doesn't have a
3064 buffer-local value here, make the `let' change the global
3065 value by changing the value of SYMBOL in all buffers not
3066 having their own value. This is consistent with what
3067 happens with other buffer-local variables. */
3068 if (NILP (Flocal_variable_p (symbol
, Qnil
)))
3070 specpdl_ptr
->let
.kind
= SPECPDL_LET_DEFAULT
;
3072 Fset_default (symbol
, value
);
3077 specpdl_ptr
->let
.kind
= SPECPDL_LET
;
3080 set_internal (symbol
, value
, Qnil
, 1);
3083 default: emacs_abort ();
3087 /* Push unwind-protect entries of various types. */
3090 record_unwind_protect (void (*function
) (Lisp_Object
), Lisp_Object arg
)
3092 specpdl_ptr
->unwind
.kind
= SPECPDL_UNWIND
;
3093 specpdl_ptr
->unwind
.func
= function
;
3094 specpdl_ptr
->unwind
.arg
= arg
;
3099 record_unwind_protect_ptr (void (*function
) (void *), void *arg
)
3101 specpdl_ptr
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3102 specpdl_ptr
->unwind_ptr
.func
= function
;
3103 specpdl_ptr
->unwind_ptr
.arg
= arg
;
3108 record_unwind_protect_int (void (*function
) (int), int arg
)
3110 specpdl_ptr
->unwind_int
.kind
= SPECPDL_UNWIND_INT
;
3111 specpdl_ptr
->unwind_int
.func
= function
;
3112 specpdl_ptr
->unwind_int
.arg
= arg
;
3117 record_unwind_protect_void (void (*function
) (void))
3119 specpdl_ptr
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3120 specpdl_ptr
->unwind_void
.func
= function
;
3128 /* Push an unwind-protect entry that does nothing, so that
3129 set_unwind_protect_ptr can overwrite it later. */
3132 record_unwind_protect_nothing (void)
3134 record_unwind_protect_void (do_nothing
);
3137 /* Clear the unwind-protect entry COUNT, so that it does nothing.
3138 It need not be at the top of the stack. */
3141 clear_unwind_protect (ptrdiff_t count
)
3143 union specbinding
*p
= specpdl
+ count
;
3144 p
->unwind_void
.kind
= SPECPDL_UNWIND_VOID
;
3145 p
->unwind_void
.func
= do_nothing
;
3148 /* Set the unwind-protect entry COUNT so that it invokes FUNC (ARG).
3149 It need not be at the top of the stack. Discard the entry's
3150 previous value without invoking it. */
3153 set_unwind_protect (ptrdiff_t count
, void (*func
) (Lisp_Object
),
3156 union specbinding
*p
= specpdl
+ count
;
3157 p
->unwind
.kind
= SPECPDL_UNWIND
;
3158 p
->unwind
.func
= func
;
3159 p
->unwind
.arg
= arg
;
3163 set_unwind_protect_ptr (ptrdiff_t count
, void (*func
) (void *), void *arg
)
3165 union specbinding
*p
= specpdl
+ count
;
3166 p
->unwind_ptr
.kind
= SPECPDL_UNWIND_PTR
;
3167 p
->unwind_ptr
.func
= func
;
3168 p
->unwind_ptr
.arg
= arg
;
3171 /* Pop and execute entries from the unwind-protect stack until the
3172 depth COUNT is reached. Return VALUE. */
3175 unbind_to (ptrdiff_t count
, Lisp_Object value
)
3177 Lisp_Object quitf
= Vquit_flag
;
3178 struct gcpro gcpro1
, gcpro2
;
3180 GCPRO2 (value
, quitf
);
3183 while (specpdl_ptr
!= specpdl
+ count
)
3185 /* Decrement specpdl_ptr before we do the work to unbind it, so
3186 that an error in unbinding won't try to unbind the same entry
3187 again. Take care to copy any parts of the binding needed
3188 before invoking any code that can make more bindings. */
3192 switch (specpdl_ptr
->kind
)
3194 case SPECPDL_UNWIND
:
3195 specpdl_ptr
->unwind
.func (specpdl_ptr
->unwind
.arg
);
3197 case SPECPDL_UNWIND_PTR
:
3198 specpdl_ptr
->unwind_ptr
.func (specpdl_ptr
->unwind_ptr
.arg
);
3200 case SPECPDL_UNWIND_INT
:
3201 specpdl_ptr
->unwind_int
.func (specpdl_ptr
->unwind_int
.arg
);
3203 case SPECPDL_UNWIND_VOID
:
3204 specpdl_ptr
->unwind_void
.func ();
3206 case SPECPDL_BACKTRACE
:
3209 { /* If variable has a trivial value (no forwarding), we can
3210 just set it. No need to check for constant symbols here,
3211 since that was already done by specbind. */
3212 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (specpdl_ptr
));
3213 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3215 SET_SYMBOL_VAL (sym
, specpdl_old_value (specpdl_ptr
));
3220 NOTE: we only ever come here if make_local_foo was used for
3221 the first time on this var within this let. */
3224 case SPECPDL_LET_DEFAULT
:
3225 Fset_default (specpdl_symbol (specpdl_ptr
),
3226 specpdl_old_value (specpdl_ptr
));
3228 case SPECPDL_LET_LOCAL
:
3230 Lisp_Object symbol
= specpdl_symbol (specpdl_ptr
);
3231 Lisp_Object where
= specpdl_where (specpdl_ptr
);
3232 Lisp_Object old_value
= specpdl_old_value (specpdl_ptr
);
3233 eassert (BUFFERP (where
));
3235 /* If this was a local binding, reset the value in the appropriate
3236 buffer, but only if that buffer's binding still exists. */
3237 if (!NILP (Flocal_variable_p (symbol
, where
)))
3238 set_internal (symbol
, old_value
, where
, 1);
3244 if (NILP (Vquit_flag
) && !NILP (quitf
))
3251 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3252 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3253 A special variable is one that will be bound dynamically, even in a
3254 context where binding is lexical by default. */)
3255 (Lisp_Object symbol
)
3257 CHECK_SYMBOL (symbol
);
3258 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3262 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3263 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3264 The debugger is entered when that frame exits, if the flag is non-nil. */)
3265 (Lisp_Object level
, Lisp_Object flag
)
3267 union specbinding
*pdl
= backtrace_top ();
3268 register EMACS_INT i
;
3270 CHECK_NUMBER (level
);
3272 for (i
= 0; backtrace_p (pdl
) && i
< XINT (level
); i
++)
3273 pdl
= backtrace_next (pdl
);
3275 if (backtrace_p (pdl
))
3276 set_backtrace_debug_on_exit (pdl
, !NILP (flag
));
3281 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3282 doc
: /* Print a trace of Lisp function calls currently active.
3283 Output stream used is value of `standard-output'. */)
3286 union specbinding
*pdl
= backtrace_top ();
3288 Lisp_Object old_print_level
= Vprint_level
;
3290 if (NILP (Vprint_level
))
3291 XSETFASTINT (Vprint_level
, 8);
3293 while (backtrace_p (pdl
))
3295 write_string (backtrace_debug_on_exit (pdl
) ? "* " : " ", 2);
3296 if (backtrace_nargs (pdl
) == UNEVALLED
)
3298 Fprin1 (Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)),
3300 write_string ("\n", -1);
3304 tem
= backtrace_function (pdl
);
3305 Fprin1 (tem
, Qnil
); /* This can QUIT. */
3306 write_string ("(", -1);
3309 for (i
= 0; i
< backtrace_nargs (pdl
); i
++)
3311 if (i
) write_string (" ", -1);
3312 Fprin1 (backtrace_args (pdl
)[i
], Qnil
);
3315 write_string (")\n", -1);
3317 pdl
= backtrace_next (pdl
);
3320 Vprint_level
= old_print_level
;
3324 static union specbinding
*
3325 get_backtrace_frame (Lisp_Object nframes
, Lisp_Object base
)
3327 union specbinding
*pdl
= backtrace_top ();
3328 register EMACS_INT i
;
3330 CHECK_NATNUM (nframes
);
3333 { /* Skip up to `base'. */
3334 base
= Findirect_function (base
, Qt
);
3335 while (backtrace_p (pdl
)
3336 && !EQ (base
, Findirect_function (backtrace_function (pdl
), Qt
)))
3337 pdl
= backtrace_next (pdl
);
3340 /* Find the frame requested. */
3341 for (i
= XFASTINT (nframes
); i
> 0 && backtrace_p (pdl
); i
--)
3342 pdl
= backtrace_next (pdl
);
3347 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 2, NULL
,
3348 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3349 If that frame has not evaluated the arguments yet (or is a special form),
3350 the value is (nil FUNCTION ARG-FORMS...).
3351 If that frame has evaluated its arguments and called its function already,
3352 the value is (t FUNCTION ARG-VALUES...).
3353 A &rest arg is represented as the tail of the list ARG-VALUES.
3354 FUNCTION is whatever was supplied as car of evaluated list,
3355 or a lambda expression for macro calls.
3356 If NFRAMES is more than the number of frames, the value is nil.
3357 If BASE is non-nil, it should be a function and NFRAMES counts from its
3358 nearest activation frame. */)
3359 (Lisp_Object nframes
, Lisp_Object base
)
3361 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3363 if (!backtrace_p (pdl
))
3365 if (backtrace_nargs (pdl
) == UNEVALLED
)
3367 Fcons (backtrace_function (pdl
), *backtrace_args (pdl
)));
3370 Lisp_Object tem
= Flist (backtrace_nargs (pdl
), backtrace_args (pdl
));
3372 return Fcons (Qt
, Fcons (backtrace_function (pdl
), tem
));
3376 /* For backtrace-eval, we want to temporarily unwind the last few elements of
3377 the specpdl stack, and then rewind them. We store the pre-unwind values
3378 directly in the pre-existing specpdl elements (i.e. we swap the current
3379 value and the old value stored in the specpdl), kind of like the inplace
3380 pointer-reversal trick. As it turns out, the rewind does the same as the
3381 unwind, except it starts from the other end of the specpdl stack, so we use
3382 the same function for both unwind and rewind. */
3384 backtrace_eval_unrewind (int distance
)
3386 union specbinding
*tmp
= specpdl_ptr
;
3389 { /* It's a rewind rather than unwind. */
3390 tmp
+= distance
- 1;
3392 distance
= -distance
;
3395 for (; distance
> 0; distance
--)
3400 /* FIXME: Ideally we'd like to "temporarily unwind" (some of) those
3401 unwind_protect, but the problem is that we don't know how to
3402 rewind them afterwards. */
3403 case SPECPDL_UNWIND
:
3405 Lisp_Object oldarg
= tmp
->unwind
.arg
;
3406 if (tmp
->unwind
.func
== set_buffer_if_live
)
3407 tmp
->unwind
.arg
= Fcurrent_buffer ();
3408 else if (tmp
->unwind
.func
== save_excursion_restore
)
3409 tmp
->unwind
.arg
= save_excursion_save ();
3412 tmp
->unwind
.func (oldarg
);
3416 case SPECPDL_UNWIND_PTR
:
3417 case SPECPDL_UNWIND_INT
:
3418 case SPECPDL_UNWIND_VOID
:
3419 case SPECPDL_BACKTRACE
:
3422 { /* If variable has a trivial value (no forwarding), we can
3423 just set it. No need to check for constant symbols here,
3424 since that was already done by specbind. */
3425 struct Lisp_Symbol
*sym
= XSYMBOL (specpdl_symbol (tmp
));
3426 if (sym
->redirect
== SYMBOL_PLAINVAL
)
3428 Lisp_Object old_value
= specpdl_old_value (tmp
);
3429 set_specpdl_old_value (tmp
, SYMBOL_VAL (sym
));
3430 SET_SYMBOL_VAL (sym
, old_value
);
3435 NOTE: we only ever come here if make_local_foo was used for
3436 the first time on this var within this let. */
3439 case SPECPDL_LET_DEFAULT
:
3441 Lisp_Object sym
= specpdl_symbol (tmp
);
3442 Lisp_Object old_value
= specpdl_old_value (tmp
);
3443 set_specpdl_old_value (tmp
, Fdefault_value (sym
));
3444 Fset_default (sym
, old_value
);
3447 case SPECPDL_LET_LOCAL
:
3449 Lisp_Object symbol
= specpdl_symbol (tmp
);
3450 Lisp_Object where
= specpdl_where (tmp
);
3451 Lisp_Object old_value
= specpdl_old_value (tmp
);
3452 eassert (BUFFERP (where
));
3454 /* If this was a local binding, reset the value in the appropriate
3455 buffer, but only if that buffer's binding still exists. */
3456 if (!NILP (Flocal_variable_p (symbol
, where
)))
3458 set_specpdl_old_value
3459 (tmp
, Fbuffer_local_value (symbol
, where
));
3460 set_internal (symbol
, old_value
, where
, 1);
3468 DEFUN ("backtrace-eval", Fbacktrace_eval
, Sbacktrace_eval
, 2, 3, NULL
,
3469 doc
: /* Evaluate EXP in the context of some activation frame.
3470 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3471 (Lisp_Object exp
, Lisp_Object nframes
, Lisp_Object base
)
3473 union specbinding
*pdl
= get_backtrace_frame (nframes
, base
);
3474 ptrdiff_t count
= SPECPDL_INDEX ();
3475 ptrdiff_t distance
= specpdl_ptr
- pdl
;
3476 eassert (distance
>= 0);
3478 if (!backtrace_p (pdl
))
3479 error ("Activation frame not found!");
3481 backtrace_eval_unrewind (distance
);
3482 record_unwind_protect_int (backtrace_eval_unrewind
, -distance
);
3484 /* Use eval_sub rather than Feval since the main motivation behind
3485 backtrace-eval is to be able to get/set the value of lexical variables
3486 from the debugger. */
3487 return unbind_to (count
, eval_sub (exp
));
3490 DEFUN ("backtrace--locals", Fbacktrace__locals
, Sbacktrace__locals
, 1, 2, NULL
,
3491 doc
: /* Return names and values of local variables of a stack frame.
3492 NFRAMES and BASE specify the activation frame to use, as in `backtrace-frame'. */)
3493 (Lisp_Object nframes
, Lisp_Object base
)
3495 union specbinding
*frame
= get_backtrace_frame (nframes
, base
);
3496 union specbinding
*prevframe
3497 = get_backtrace_frame (make_number (XFASTINT (nframes
) - 1), base
);
3498 ptrdiff_t distance
= specpdl_ptr
- frame
;
3499 Lisp_Object result
= Qnil
;
3500 eassert (distance
>= 0);
3502 if (!backtrace_p (prevframe
))
3503 error ("Activation frame not found!");
3504 if (!backtrace_p (frame
))
3505 error ("Activation frame not found!");
3507 /* The specpdl entries normally contain the symbol being bound along with its
3508 `old_value', so it can be restored. The new value to which it is bound is
3509 available in one of two places: either in the current value of the
3510 variable (if it hasn't been rebound yet) or in the `old_value' slot of the
3511 next specpdl entry for it.
3512 `backtrace_eval_unrewind' happens to swap the role of `old_value'
3513 and "new value", so we abuse it here, to fetch the new value.
3514 It's ugly (we'd rather not modify global data) and a bit inefficient,
3515 but it does the job for now. */
3516 backtrace_eval_unrewind (distance
);
3520 union specbinding
*tmp
= prevframe
;
3521 for (; tmp
> frame
; tmp
--)
3526 case SPECPDL_LET_DEFAULT
:
3527 case SPECPDL_LET_LOCAL
:
3529 Lisp_Object sym
= specpdl_symbol (tmp
);
3530 Lisp_Object val
= specpdl_old_value (tmp
);
3531 if (EQ (sym
, Qinternal_interpreter_environment
))
3533 Lisp_Object env
= val
;
3534 for (; CONSP (env
); env
= XCDR (env
))
3536 Lisp_Object binding
= XCAR (env
);
3537 if (CONSP (binding
))
3538 result
= Fcons (Fcons (XCAR (binding
),
3544 result
= Fcons (Fcons (sym
, val
), result
);
3550 /* Restore values from specpdl to original place. */
3551 backtrace_eval_unrewind (-distance
);
3560 union specbinding
*pdl
;
3561 for (pdl
= specpdl
; pdl
!= specpdl_ptr
; pdl
++)
3565 case SPECPDL_UNWIND
:
3566 mark_object (specpdl_arg (pdl
));
3569 case SPECPDL_BACKTRACE
:
3571 ptrdiff_t nargs
= backtrace_nargs (pdl
);
3572 mark_object (backtrace_function (pdl
));
3573 if (nargs
== UNEVALLED
)
3576 mark_object (backtrace_args (pdl
)[nargs
]);
3580 case SPECPDL_LET_DEFAULT
:
3581 case SPECPDL_LET_LOCAL
:
3582 mark_object (specpdl_where (pdl
));
3585 mark_object (specpdl_symbol (pdl
));
3586 mark_object (specpdl_old_value (pdl
));
3593 get_backtrace (Lisp_Object array
)
3595 union specbinding
*pdl
= backtrace_next (backtrace_top ());
3596 ptrdiff_t i
= 0, asize
= ASIZE (array
);
3598 /* Copy the backtrace contents into working memory. */
3599 for (; i
< asize
; i
++)
3601 if (backtrace_p (pdl
))
3603 ASET (array
, i
, backtrace_function (pdl
));
3604 pdl
= backtrace_next (pdl
);
3607 ASET (array
, i
, Qnil
);
3611 Lisp_Object
backtrace_top_function (void)
3613 union specbinding
*pdl
= backtrace_top ();
3614 return (backtrace_p (pdl
) ? backtrace_function (pdl
) : Qnil
);
3620 DEFVAR_INT ("max-specpdl-size", max_specpdl_size
,
3621 doc
: /* Limit on number of Lisp variable bindings and `unwind-protect's.
3622 If Lisp code tries to increase the total number past this amount,
3623 an error is signaled.
3624 You can safely use a value considerably larger than the default value,
3625 if that proves inconveniently small. However, if you increase it too far,
3626 Emacs could run out of memory trying to make the stack bigger.
3627 Note that this limit may be silently increased by the debugger
3628 if `debug-on-error' or `debug-on-quit' is set. */);
3630 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth
,
3631 doc
: /* Limit on depth in `eval', `apply' and `funcall' before error.
3633 This limit serves to catch infinite recursions for you before they cause
3634 actual stack overflow in C, which would be fatal for Emacs.
3635 You can safely make it considerably larger than its default value,
3636 if that proves inconveniently small. However, if you increase it too far,
3637 Emacs could overflow the real C stack, and crash. */);
3639 DEFVAR_LISP ("quit-flag", Vquit_flag
,
3640 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3641 If the value is t, that means do an ordinary quit.
3642 If the value equals `throw-on-input', that means quit by throwing
3643 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3644 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3645 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3648 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit
,
3649 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3650 Note that `quit-flag' will still be set by typing C-g,
3651 so a quit will be signaled as soon as `inhibit-quit' is nil.
3652 To prevent this happening, set `quit-flag' to nil
3653 before making `inhibit-quit' nil. */);
3654 Vinhibit_quit
= Qnil
;
3656 DEFSYM (Qinhibit_quit
, "inhibit-quit");
3657 DEFSYM (Qautoload
, "autoload");
3658 DEFSYM (Qinhibit_debugger
, "inhibit-debugger");
3659 DEFSYM (Qmacro
, "macro");
3660 DEFSYM (Qdeclare
, "declare");
3662 /* Note that the process handling also uses Qexit, but we don't want
3663 to staticpro it twice, so we just do it here. */
3664 DEFSYM (Qexit
, "exit");
3666 DEFSYM (Qinteractive
, "interactive");
3667 DEFSYM (Qcommandp
, "commandp");
3668 DEFSYM (Qand_rest
, "&rest");
3669 DEFSYM (Qand_optional
, "&optional");
3670 DEFSYM (Qclosure
, "closure");
3671 DEFSYM (Qdebug
, "debug");
3673 DEFVAR_LISP ("inhibit-debugger", Vinhibit_debugger
,
3674 doc
: /* Non-nil means never enter the debugger.
3675 Normally set while the debugger is already active, to avoid recursive
3677 Vinhibit_debugger
= Qnil
;
3679 DEFVAR_LISP ("debug-on-error", Vdebug_on_error
,
3680 doc
: /* Non-nil means enter debugger if an error is signaled.
3681 Does not apply to errors handled by `condition-case' or those
3682 matched by `debug-ignored-errors'.
3683 If the value is a list, an error only means to enter the debugger
3684 if one of its condition symbols appears in the list.
3685 When you evaluate an expression interactively, this variable
3686 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3687 The command `toggle-debug-on-error' toggles this.
3688 See also the variable `debug-on-quit' and `inhibit-debugger'. */);
3689 Vdebug_on_error
= Qnil
;
3691 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors
,
3692 doc
: /* List of errors for which the debugger should not be called.
3693 Each element may be a condition-name or a regexp that matches error messages.
3694 If any element applies to a given error, that error skips the debugger
3695 and just returns to top level.
3696 This overrides the variable `debug-on-error'.
3697 It does not apply to errors handled by `condition-case'. */);
3698 Vdebug_ignored_errors
= Qnil
;
3700 DEFVAR_BOOL ("debug-on-quit", debug_on_quit
,
3701 doc
: /* Non-nil means enter debugger if quit is signaled (C-g, for example).
3702 Does not apply if quit is handled by a `condition-case'. */);
3705 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call
,
3706 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3708 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue
,
3709 doc
: /* Non-nil means debugger may continue execution.
3710 This is nil when the debugger is called under circumstances where it
3711 might not be safe to continue. */);
3712 debugger_may_continue
= 1;
3714 DEFVAR_LISP ("debugger", Vdebugger
,
3715 doc
: /* Function to call to invoke debugger.
3716 If due to frame exit, args are `exit' and the value being returned;
3717 this function's value will be returned instead of that.
3718 If due to error, args are `error' and a list of the args to `signal'.
3719 If due to `apply' or `funcall' entry, one arg, `lambda'.
3720 If due to `eval' entry, one arg, t. */);
3723 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function
,
3724 doc
: /* If non-nil, this is a function for `signal' to call.
3725 It receives the same arguments that `signal' was given.
3726 The Edebug package uses this to regain control. */);
3727 Vsignal_hook_function
= Qnil
;
3729 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal
,
3730 doc
: /* Non-nil means call the debugger regardless of condition handlers.
3731 Note that `debug-on-error', `debug-on-quit' and friends
3732 still determine whether to handle the particular condition. */);
3733 Vdebug_on_signal
= Qnil
;
3735 /* When lexical binding is being used,
3736 Vinternal_interpreter_environment is non-nil, and contains an alist
3737 of lexically-bound variable, or (t), indicating an empty
3738 environment. The lisp name of this variable would be
3739 `internal-interpreter-environment' if it weren't hidden.
3740 Every element of this list can be either a cons (VAR . VAL)
3741 specifying a lexical binding, or a single symbol VAR indicating
3742 that this variable should use dynamic scoping. */
3743 DEFSYM (Qinternal_interpreter_environment
,
3744 "internal-interpreter-environment");
3745 DEFVAR_LISP ("internal-interpreter-environment",
3746 Vinternal_interpreter_environment
,
3747 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3748 When lexical binding is not being used, this variable is nil.
3749 A value of `(t)' indicates an empty environment, otherwise it is an
3750 alist of active lexical bindings. */);
3751 Vinternal_interpreter_environment
= Qnil
;
3752 /* Don't export this variable to Elisp, so no one can mess with it
3753 (Just imagine if someone makes it buffer-local). */
3754 Funintern (Qinternal_interpreter_environment
, Qnil
);
3756 Vrun_hooks
= intern_c_string ("run-hooks");
3757 staticpro (&Vrun_hooks
);
3759 staticpro (&Vautoload_queue
);
3760 Vautoload_queue
= Qnil
;
3761 staticpro (&Vsignaling_function
);
3762 Vsignaling_function
= Qnil
;
3764 inhibit_lisp_code
= Qnil
;
3775 defsubr (&Sfunction
);
3776 defsubr (&Sdefault_toplevel_value
);
3777 defsubr (&Sset_default_toplevel_value
);
3779 defsubr (&Sdefvaralias
);
3780 defsubr (&Sdefconst
);
3781 defsubr (&Smake_var_non_special
);
3785 defsubr (&Smacroexpand
);
3788 defsubr (&Sunwind_protect
);
3789 defsubr (&Scondition_case
);
3791 defsubr (&Scommandp
);
3792 defsubr (&Sautoload
);
3793 defsubr (&Sautoload_do_load
);
3796 defsubr (&Sfuncall
);
3797 defsubr (&Srun_hooks
);
3798 defsubr (&Srun_hook_with_args
);
3799 defsubr (&Srun_hook_with_args_until_success
);
3800 defsubr (&Srun_hook_with_args_until_failure
);
3801 defsubr (&Srun_hook_wrapped
);
3802 defsubr (&Sfetch_bytecode
);
3803 defsubr (&Sbacktrace_debug
);
3804 defsubr (&Sbacktrace
);
3805 defsubr (&Sbacktrace_frame
);
3806 defsubr (&Sbacktrace_eval
);
3807 defsubr (&Sbacktrace__locals
);
3808 defsubr (&Sspecial_variable_p
);
3809 defsubr (&Sfunctionp
);