1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "blockinput.h"
28 #include "dispextern.h"
31 /* This definition is duplicated in alloc.c and keyboard.c */
32 /* Putting it in lisp.h makes cc bomb out! */
36 struct backtrace
*next
;
37 Lisp_Object
*function
;
38 Lisp_Object
*args
; /* Points to vector of args. */
39 int nargs
; /* Length of vector.
40 If nargs is UNEVALLED, args points to slot holding
41 list of unevalled args */
43 /* Nonzero means call value of debugger when done with this operation. */
47 struct backtrace
*backtrace_list
;
49 /* This structure helps implement the `catch' and `throw' control
50 structure. A struct catchtag contains all the information needed
51 to restore the state of the interpreter after a non-local jump.
53 Handlers for error conditions (represented by `struct handler'
54 structures) just point to a catch tag to do the cleanup required
57 catchtag structures are chained together in the C calling stack;
58 the `next' member points to the next outer catchtag.
60 A call like (throw TAG VAL) searches for a catchtag whose `tag'
61 member is TAG, and then unbinds to it. The `val' member is used to
62 hold VAL while the stack is unwound; `val' is returned as the value
65 All the other members are concerned with restoring the interpreter
72 struct catchtag
*next
;
75 struct backtrace
*backlist
;
76 struct handler
*handlerlist
;
79 int poll_suppress_count
;
80 struct byte_stack
*byte_stack
;
83 struct catchtag
*catchlist
;
86 /* Count levels of GCPRO to detect failure to UNGCPRO. */
90 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
, Qdefun
;
91 Lisp_Object Qinhibit_quit
, Vinhibit_quit
, Vquit_flag
;
92 Lisp_Object Qmocklisp_arguments
, Vmocklisp_arguments
, Qmocklisp
;
93 Lisp_Object Qand_rest
, Qand_optional
;
94 Lisp_Object Qdebug_on_error
;
96 /* This holds either the symbol `run-hooks' or nil.
97 It is nil at an early stage of startup, and when Emacs
100 Lisp_Object Vrun_hooks
;
102 /* Non-nil means record all fset's and provide's, to be undone
103 if the file being autoloaded is not fully loaded.
104 They are recorded by being consed onto the front of Vautoload_queue:
105 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
107 Lisp_Object Vautoload_queue
;
109 /* Current number of specbindings allocated in specpdl. */
113 /* Pointer to beginning of specpdl. */
115 struct specbinding
*specpdl
;
117 /* Pointer to first unused element in specpdl. */
119 struct specbinding
*specpdl_ptr
;
121 /* Maximum size allowed for specpdl allocation */
123 int max_specpdl_size
;
125 /* Depth in Lisp evaluations and function calls. */
129 /* Maximum allowed depth in Lisp evaluations and function calls. */
131 int max_lisp_eval_depth
;
133 /* Nonzero means enter debugger before next function call */
135 int debug_on_next_call
;
137 /* Non-zero means debugger may continue. This is zero when the
138 debugger is called during redisplay, where it might not be safe to
139 continue the interrupted redisplay. */
141 int debugger_may_continue
;
143 /* List of conditions (non-nil atom means all) which cause a backtrace
144 if an error is handled by the command loop's error handler. */
146 Lisp_Object Vstack_trace_on_error
;
148 /* List of conditions (non-nil atom means all) which enter the debugger
149 if an error is handled by the command loop's error handler. */
151 Lisp_Object Vdebug_on_error
;
153 /* List of conditions and regexps specifying error messages which
154 do not enter the debugger even if Vdebug_on_error says they should. */
156 Lisp_Object Vdebug_ignored_errors
;
158 /* Non-nil means call the debugger even if the error will be handled. */
160 Lisp_Object Vdebug_on_signal
;
162 /* Hook for edebug to use. */
164 Lisp_Object Vsignal_hook_function
;
166 /* Nonzero means enter debugger if a quit signal
167 is handled by the command loop's error handler. */
171 /* The value of num_nonmacro_input_events as of the last time we
172 started to enter the debugger. If we decide to enter the debugger
173 again when this is still equal to num_nonmacro_input_events, then we
174 know that the debugger itself has an error, and we should just
175 signal the error instead of entering an infinite loop of debugger
178 int when_entered_debugger
;
180 Lisp_Object Vdebugger
;
182 /* The function from which the last `signal' was called. Set in
185 Lisp_Object Vsignaling_function
;
187 /* Set to non-zero while processing X events. Checked in Feval to
188 make sure the Lisp interpreter isn't called from a signal handler,
189 which is unsafe because the interpreter isn't reentrant. */
193 void specbind (), record_unwind_protect ();
195 Lisp_Object
run_hook_with_args ();
197 Lisp_Object
funcall_lambda ();
198 extern Lisp_Object
ml_apply (); /* Apply a mocklisp function to unevaluated argument list */
204 specpdl
= (struct specbinding
*) xmalloc (specpdl_size
* sizeof (struct specbinding
));
205 specpdl_ptr
= specpdl
;
206 max_specpdl_size
= 600;
207 max_lisp_eval_depth
= 300;
215 specpdl_ptr
= specpdl
;
220 debug_on_next_call
= 0;
225 /* This is less than the initial value of num_nonmacro_input_events. */
226 when_entered_debugger
= -1;
233 int debug_while_redisplaying
;
234 int count
= specpdl_ptr
- specpdl
;
237 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
238 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
240 if (specpdl_size
+ 40 > max_specpdl_size
)
241 max_specpdl_size
= specpdl_size
+ 40;
243 #ifdef HAVE_X_WINDOWS
244 if (display_hourglass_p
)
248 debug_on_next_call
= 0;
249 when_entered_debugger
= num_nonmacro_input_events
;
251 /* Resetting redisplaying_p to 0 makes sure that debug output is
252 displayed if the debugger is invoked during redisplay. */
253 debug_while_redisplaying
= redisplaying_p
;
255 specbind (intern ("debugger-may-continue"),
256 debug_while_redisplaying
? Qnil
: Qt
);
257 specbind (Qinhibit_redisplay
, Qnil
);
259 #if 0 /* Binding this prevents execution of Lisp code during
260 redisplay, which necessarily leads to display problems. */
261 specbind (Qinhibit_eval_during_redisplay
, Qt
);
264 val
= apply1 (Vdebugger
, arg
);
266 /* Interrupting redisplay and resuming it later is not safe under
267 all circumstances. So, when the debugger returns, abort the
268 interrupted redisplay by going back to the top-level. */
269 if (debug_while_redisplaying
)
272 return unbind_to (count
, val
);
276 do_debug_on_call (code
)
279 debug_on_next_call
= 0;
280 backtrace_list
->debug_on_exit
= 1;
281 call_debugger (Fcons (code
, Qnil
));
284 /* NOTE!!! Every function that can call EVAL must protect its args
285 and temporaries from garbage collection while it needs them.
286 The definition of `For' shows what you have to do. */
288 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
289 doc
: /* Eval args until one of them yields non-nil, then return that value.
290 The remaining args are not evalled at all.
291 If all args return nil, return nil.
292 usage: (or CONDITIONS ...) */)
296 register Lisp_Object val
;
297 Lisp_Object args_left
;
308 val
= Feval (Fcar (args_left
));
311 args_left
= Fcdr (args_left
);
313 while (!NILP(args_left
));
319 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
320 doc
: /* Eval args until one of them yields nil, then return nil.
321 The remaining args are not evalled at all.
322 If no arg yields nil, return the last arg's value.
323 usage: (and CONDITIONS ...) */)
327 register Lisp_Object val
;
328 Lisp_Object args_left
;
339 val
= Feval (Fcar (args_left
));
342 args_left
= Fcdr (args_left
);
344 while (!NILP(args_left
));
350 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
351 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
352 Returns the value of THEN or the value of the last of the ELSE's.
353 THEN must be one expression, but ELSE... can be zero or more expressions.
354 If COND yields nil, and there are no ELSE's, the value is nil.
355 usage: (if COND THEN ELSE...) */)
359 register Lisp_Object cond
;
363 cond
= Feval (Fcar (args
));
367 return Feval (Fcar (Fcdr (args
)));
368 return Fprogn (Fcdr (Fcdr (args
)));
371 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
372 doc
: /* Try each clause until one succeeds.
373 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
374 and, if the value is non-nil, this clause succeeds:
375 then the expressions in BODY are evaluated and the last one's
376 value is the value of the cond-form.
377 If no clause succeeds, cond returns nil.
378 If a clause has one element, as in (CONDITION),
379 CONDITION's value if non-nil is returned from the cond-form.
380 usage: (cond CLAUSES...) */)
384 register Lisp_Object clause
, val
;
391 clause
= Fcar (args
);
392 val
= Feval (Fcar (clause
));
395 if (!EQ (XCDR (clause
), Qnil
))
396 val
= Fprogn (XCDR (clause
));
406 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
407 doc
: /* Eval BODY forms sequentially and return value of last one.
408 usage: (progn BODY ...) */)
412 register Lisp_Object val
, tem
;
413 Lisp_Object args_left
;
416 /* In Mocklisp code, symbols at the front of the progn arglist
417 are to be bound to zero. */
418 if (!EQ (Vmocklisp_arguments
, Qt
))
420 val
= make_number (0);
421 while (!NILP (args
) && (tem
= Fcar (args
), SYMBOLP (tem
)))
424 specbind (tem
, val
), args
= Fcdr (args
);
436 val
= Feval (Fcar (args_left
));
437 args_left
= Fcdr (args_left
);
439 while (!NILP(args_left
));
445 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
446 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
447 The value of FIRST is saved during the evaluation of the remaining args,
448 whose values are discarded.
449 usage: (prog1 FIRST BODY...) */)
454 register Lisp_Object args_left
;
455 struct gcpro gcpro1
, gcpro2
;
456 register int argnum
= 0;
468 val
= Feval (Fcar (args_left
));
470 Feval (Fcar (args_left
));
471 args_left
= Fcdr (args_left
);
473 while (!NILP(args_left
));
479 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
480 doc
: /* Eval X, Y and BODY sequentially; value from Y.
481 The value of Y is saved during the evaluation of the remaining args,
482 whose values are discarded.
483 usage: (prog2 X Y BODY...) */)
488 register Lisp_Object args_left
;
489 struct gcpro gcpro1
, gcpro2
;
490 register int argnum
= -1;
504 val
= Feval (Fcar (args_left
));
506 Feval (Fcar (args_left
));
507 args_left
= Fcdr (args_left
);
509 while (!NILP (args_left
));
515 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
516 doc
: /* Set each SYM to the value of its VAL.
517 The symbols SYM are variables; they are literal (not evaluated).
518 The values VAL are expressions; they are evaluated.
519 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
520 The second VAL is not computed until after the first SYM is set, and so on;
521 each VAL can use the new value of variables set earlier in the `setq'.
522 The return value of the `setq' form is the value of the last VAL.
523 usage: (setq SYM VAL SYM VAL ...) */)
527 register Lisp_Object args_left
;
528 register Lisp_Object val
, sym
;
539 val
= Feval (Fcar (Fcdr (args_left
)));
540 sym
= Fcar (args_left
);
542 args_left
= Fcdr (Fcdr (args_left
));
544 while (!NILP(args_left
));
550 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
551 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
552 usage: (quote ARG) */)
559 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
560 doc
: /* Like `quote', but preferred for objects which are functions.
561 In byte compilation, `function' causes its argument to be compiled.
562 `quote' cannot do that.
563 usage: (function ARG) */)
571 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
572 doc
: /* Return t if function in which this appears was called interactively.
573 This means that the function was called with call-interactively (which
574 includes being called as the binding of a key)
575 and input is currently coming from the keyboard (not in keyboard macro). */)
578 return interactive_p (1) ? Qt
: Qnil
;
582 /* Return 1 if function in which this appears was called
583 interactively. This means that the function was called with
584 call-interactively (which includes being called as the binding of
585 a key) and input is currently coming from the keyboard (not in
588 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
589 called is a built-in. */
592 interactive_p (exclude_subrs_p
)
595 struct backtrace
*btp
;
601 btp
= backtrace_list
;
603 /* If this isn't a byte-compiled function, there may be a frame at
604 the top for Finteractive_p. If so, skip it. */
605 fun
= Findirect_function (*btp
->function
);
606 if (SUBRP (fun
) && XSUBR (fun
) == &Sinteractive_p
)
609 /* If we're running an Emacs 18-style byte-compiled function, there
610 may be a frame for Fbytecode. Now, given the strictest
611 definition, this function isn't really being called
612 interactively, but because that's the way Emacs 18 always builds
613 byte-compiled functions, we'll accept it for now. */
614 if (EQ (*btp
->function
, Qbytecode
))
617 /* If this isn't a byte-compiled function, then we may now be
618 looking at several frames for special forms. Skip past them. */
620 btp
->nargs
== UNEVALLED
)
623 /* btp now points at the frame of the innermost function that isn't
624 a special form, ignoring frames for Finteractive_p and/or
625 Fbytecode at the top. If this frame is for a built-in function
626 (such as load or eval-region) return nil. */
627 fun
= Findirect_function (*btp
->function
);
628 if (exclude_subrs_p
&& SUBRP (fun
))
631 /* btp points to the frame of a Lisp function that called interactive-p.
632 Return t if that function was called interactively. */
633 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
639 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
640 doc
: /* Define NAME as a function.
641 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
642 See also the function `interactive'.
643 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
647 register Lisp_Object fn_name
;
648 register Lisp_Object defn
;
650 fn_name
= Fcar (args
);
651 defn
= Fcons (Qlambda
, Fcdr (args
));
652 if (!NILP (Vpurify_flag
))
653 defn
= Fpurecopy (defn
);
654 Ffset (fn_name
, defn
);
655 LOADHIST_ATTACH (fn_name
);
659 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
660 doc
: /* Define NAME as a macro.
661 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).
662 When the macro is called, as in (NAME ARGS...),
663 the function (lambda ARGLIST BODY...) is applied to
664 the list ARGS... as it appears in the expression,
665 and the result should be a form to be evaluated instead of the original.
666 usage: (defmacro NAME ARGLIST [DOCSTRING] BODY...) */)
670 register Lisp_Object fn_name
;
671 register Lisp_Object defn
;
673 fn_name
= Fcar (args
);
674 defn
= Fcons (Qmacro
, Fcons (Qlambda
, Fcdr (args
)));
675 if (!NILP (Vpurify_flag
))
676 defn
= Fpurecopy (defn
);
677 Ffset (fn_name
, defn
);
678 LOADHIST_ATTACH (fn_name
);
683 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 2, 0,
684 doc
: /* Make SYMBOL a variable alias for symbol ALIASED.
685 Setting the value of SYMBOL will subsequently set the value of ALIASED,
686 and getting the value of SYMBOL will return the value ALIASED has.
687 ALIASED nil means remove the alias; SYMBOL is unbound after that. */)
689 Lisp_Object symbol
, aliased
;
691 struct Lisp_Symbol
*sym
;
693 CHECK_SYMBOL (symbol
);
694 CHECK_SYMBOL (aliased
);
696 if (SYMBOL_CONSTANT_P (symbol
))
697 error ("Cannot make a constant an alias");
699 sym
= XSYMBOL (symbol
);
700 sym
->indirect_variable
= 1;
701 sym
->value
= aliased
;
702 sym
->constant
= SYMBOL_CONSTANT_P (aliased
);
703 LOADHIST_ATTACH (symbol
);
709 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
710 doc
: /* Define SYMBOL as a variable.
711 You are not required to define a variable in order to use it,
712 but the definition can supply documentation and an initial value
713 in a way that tags can recognize.
715 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
716 If SYMBOL is buffer-local, its default value is what is set;
717 buffer-local values are not affected.
718 INITVALUE and DOCSTRING are optional.
719 If DOCSTRING starts with *, this variable is identified as a user option.
720 This means that M-x set-variable recognizes it.
721 See also `user-variable-p'.
722 If INITVALUE is missing, SYMBOL's value is not set.
723 usage: (defvar SYMBOL [INITVALUE DOCSTRING]) */)
727 register Lisp_Object sym
, tem
, tail
;
731 if (!NILP (Fcdr (Fcdr (tail
))))
732 error ("too many arguments");
734 tem
= Fdefault_boundp (sym
);
738 Fset_default (sym
, Feval (Fcar (tail
)));
740 if (!NILP (Fcar (tail
)))
743 if (!NILP (Vpurify_flag
))
744 tem
= Fpurecopy (tem
);
745 Fput (sym
, Qvariable_documentation
, tem
);
747 LOADHIST_ATTACH (sym
);
750 /* A (defvar <var>) should not take precedence in the load-history over
751 an earlier (defvar <var> <val>), so only add to history if the default
752 value is still unbound. */
754 LOADHIST_ATTACH (sym
);
759 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
760 doc
: /* Define SYMBOL as a constant variable.
761 The intent is that neither programs nor users should ever change this value.
762 Always sets the value of SYMBOL to the result of evalling INITVALUE.
763 If SYMBOL is buffer-local, its default value is what is set;
764 buffer-local values are not affected.
765 DOCSTRING is optional.
766 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
770 register Lisp_Object sym
, tem
;
773 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
774 error ("too many arguments");
776 tem
= Feval (Fcar (Fcdr (args
)));
777 if (!NILP (Vpurify_flag
))
778 tem
= Fpurecopy (tem
);
779 Fset_default (sym
, tem
);
780 tem
= Fcar (Fcdr (Fcdr (args
)));
783 if (!NILP (Vpurify_flag
))
784 tem
= Fpurecopy (tem
);
785 Fput (sym
, Qvariable_documentation
, tem
);
787 LOADHIST_ATTACH (sym
);
791 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
792 doc
: /* Returns t if VARIABLE is intended to be set and modified by users.
793 \(The alternative is a variable used internally in a Lisp program.)
794 Determined by whether the first character of the documentation
795 for the variable is `*' or if the variable is customizable (has a non-nil
796 value of any of `custom-type', `custom-loads' or `standard-value'
797 on its property list). */)
799 Lisp_Object variable
;
801 Lisp_Object documentation
;
803 if (!SYMBOLP (variable
))
806 documentation
= Fget (variable
, Qvariable_documentation
);
807 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
809 if (STRINGP (documentation
)
810 && ((unsigned char) XSTRING (documentation
)->data
[0] == '*'))
812 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
813 if (CONSP (documentation
)
814 && STRINGP (XCAR (documentation
))
815 && INTEGERP (XCDR (documentation
))
816 && XINT (XCDR (documentation
)) < 0)
819 if ((!NILP (Fget (variable
, intern ("custom-type"))))
820 || (!NILP (Fget (variable
, intern ("custom-loads"))))
821 || (!NILP (Fget (variable
, intern ("standard-value")))))
826 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
827 doc
: /* Bind variables according to VARLIST then eval BODY.
828 The value of the last form in BODY is returned.
829 Each element of VARLIST is a symbol (which is bound to nil)
830 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
831 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
832 usage: (let* VARLIST BODY...) */)
836 Lisp_Object varlist
, val
, elt
;
837 int count
= specpdl_ptr
- specpdl
;
838 struct gcpro gcpro1
, gcpro2
, gcpro3
;
840 GCPRO3 (args
, elt
, varlist
);
842 varlist
= Fcar (args
);
843 while (!NILP (varlist
))
846 elt
= Fcar (varlist
);
848 specbind (elt
, Qnil
);
849 else if (! NILP (Fcdr (Fcdr (elt
))))
851 Fcons (build_string ("`let' bindings can have only one value-form"),
855 val
= Feval (Fcar (Fcdr (elt
)));
856 specbind (Fcar (elt
), val
);
858 varlist
= Fcdr (varlist
);
861 val
= Fprogn (Fcdr (args
));
862 return unbind_to (count
, val
);
865 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
866 doc
: /* Bind variables according to VARLIST then eval BODY.
867 The value of the last form in BODY is returned.
868 Each element of VARLIST is a symbol (which is bound to nil)
869 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
870 All the VALUEFORMs are evalled before any symbols are bound.
871 usage: (let VARLIST BODY...) */)
875 Lisp_Object
*temps
, tem
;
876 register Lisp_Object elt
, varlist
;
877 int count
= specpdl_ptr
- specpdl
;
879 struct gcpro gcpro1
, gcpro2
;
881 varlist
= Fcar (args
);
883 /* Make space to hold the values to give the bound variables */
884 elt
= Flength (varlist
);
885 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
887 /* Compute the values and store them in `temps' */
889 GCPRO2 (args
, *temps
);
892 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
895 elt
= Fcar (varlist
);
897 temps
[argnum
++] = Qnil
;
898 else if (! NILP (Fcdr (Fcdr (elt
))))
900 Fcons (build_string ("`let' bindings can have only one value-form"),
903 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
904 gcpro2
.nvars
= argnum
;
908 varlist
= Fcar (args
);
909 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
911 elt
= Fcar (varlist
);
912 tem
= temps
[argnum
++];
916 specbind (Fcar (elt
), tem
);
919 elt
= Fprogn (Fcdr (args
));
920 return unbind_to (count
, elt
);
923 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
924 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
925 The order of execution is thus TEST, BODY, TEST, BODY and so on
926 until TEST returns nil.
927 usage: (while TEST BODY...) */)
931 Lisp_Object test
, body
, tem
;
932 struct gcpro gcpro1
, gcpro2
;
938 while (tem
= Feval (test
),
939 (!EQ (Vmocklisp_arguments
, Qt
) ? XINT (tem
) : !NILP (tem
)))
949 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
950 doc
: /* Return result of expanding macros at top level of FORM.
951 If FORM is not a macro call, it is returned unchanged.
952 Otherwise, the macro is expanded and the expansion is considered
953 in place of FORM. When a non-macro-call results, it is returned.
955 The second optional arg ENVIRONMENT specifies an environment of macro
956 definitions to shadow the loaded ones for use in file byte-compilation. */)
959 Lisp_Object environment
;
961 /* With cleanups from Hallvard Furuseth. */
962 register Lisp_Object expander
, sym
, def
, tem
;
966 /* Come back here each time we expand a macro call,
967 in case it expands into another macro call. */
970 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
971 def
= sym
= XCAR (form
);
973 /* Trace symbols aliases to other symbols
974 until we get a symbol that is not an alias. */
975 while (SYMBOLP (def
))
979 tem
= Fassq (sym
, environment
);
982 def
= XSYMBOL (sym
)->function
;
983 if (!EQ (def
, Qunbound
))
988 /* Right now TEM is the result from SYM in ENVIRONMENT,
989 and if TEM is nil then DEF is SYM's function definition. */
992 /* SYM is not mentioned in ENVIRONMENT.
993 Look at its function definition. */
994 if (EQ (def
, Qunbound
) || !CONSP (def
))
995 /* Not defined or definition not suitable */
997 if (EQ (XCAR (def
), Qautoload
))
999 /* Autoloading function: will it be a macro when loaded? */
1000 tem
= Fnth (make_number (4), def
);
1001 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1002 /* Yes, load it and try again. */
1004 struct gcpro gcpro1
;
1006 do_autoload (def
, sym
);
1013 else if (!EQ (XCAR (def
), Qmacro
))
1015 else expander
= XCDR (def
);
1019 expander
= XCDR (tem
);
1020 if (NILP (expander
))
1023 form
= apply1 (expander
, XCDR (form
));
1028 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1029 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1030 TAG is evalled to get the tag to use; it must not be nil.
1032 Then the BODY is executed.
1033 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1034 If no throw happens, `catch' returns the value of the last BODY form.
1035 If a throw happens, it specifies the value to return from `catch'.
1036 usage: (catch TAG BODY...) */)
1040 register Lisp_Object tag
;
1041 struct gcpro gcpro1
;
1044 tag
= Feval (Fcar (args
));
1046 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1049 /* Set up a catch, then call C function FUNC on argument ARG.
1050 FUNC should return a Lisp_Object.
1051 This is how catches are done from within C code. */
1054 internal_catch (tag
, func
, arg
)
1056 Lisp_Object (*func
) ();
1059 /* This structure is made part of the chain `catchlist'. */
1062 /* Fill in the components of c, and put it on the list. */
1066 c
.backlist
= backtrace_list
;
1067 c
.handlerlist
= handlerlist
;
1068 c
.lisp_eval_depth
= lisp_eval_depth
;
1069 c
.pdlcount
= specpdl_ptr
- specpdl
;
1070 c
.poll_suppress_count
= poll_suppress_count
;
1071 c
.gcpro
= gcprolist
;
1072 c
.byte_stack
= byte_stack_list
;
1076 if (! _setjmp (c
.jmp
))
1077 c
.val
= (*func
) (arg
);
1079 /* Throw works by a longjmp that comes right here. */
1084 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1085 jump to that CATCH, returning VALUE as the value of that catch.
1087 This is the guts Fthrow and Fsignal; they differ only in the way
1088 they choose the catch tag to throw to. A catch tag for a
1089 condition-case form has a TAG of Qnil.
1091 Before each catch is discarded, unbind all special bindings and
1092 execute all unwind-protect clauses made above that catch. Unwind
1093 the handler stack as we go, so that the proper handlers are in
1094 effect for each unwind-protect clause we run. At the end, restore
1095 some static info saved in CATCH, and longjmp to the location
1098 This is used for correct unwinding in Fthrow and Fsignal. */
1101 unwind_to_catch (catch, value
)
1102 struct catchtag
*catch;
1105 register int last_time
;
1107 /* Save the value in the tag. */
1110 /* Restore the polling-suppression count. */
1111 set_poll_suppress_count (catch->poll_suppress_count
);
1115 last_time
= catchlist
== catch;
1117 /* Unwind the specpdl stack, and then restore the proper set of
1119 unbind_to (catchlist
->pdlcount
, Qnil
);
1120 handlerlist
= catchlist
->handlerlist
;
1121 catchlist
= catchlist
->next
;
1123 while (! last_time
);
1125 byte_stack_list
= catch->byte_stack
;
1126 gcprolist
= catch->gcpro
;
1129 gcpro_level
= gcprolist
->level
+ 1;
1133 backtrace_list
= catch->backlist
;
1134 lisp_eval_depth
= catch->lisp_eval_depth
;
1136 _longjmp (catch->jmp
, 1);
1139 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1140 doc
: /* Throw to the catch for TAG and return VALUE from it.
1141 Both TAG and VALUE are evalled. */)
1143 register Lisp_Object tag
, value
;
1145 register struct catchtag
*c
;
1150 for (c
= catchlist
; c
; c
= c
->next
)
1152 if (EQ (c
->tag
, tag
))
1153 unwind_to_catch (c
, value
);
1155 tag
= Fsignal (Qno_catch
, Fcons (tag
, Fcons (value
, Qnil
)));
1160 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1161 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1162 If BODYFORM completes normally, its value is returned
1163 after executing the UNWINDFORMS.
1164 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1165 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1170 int count
= specpdl_ptr
- specpdl
;
1172 record_unwind_protect (0, Fcdr (args
));
1173 val
= Feval (Fcar (args
));
1174 return unbind_to (count
, val
);
1177 /* Chain of condition handlers currently in effect.
1178 The elements of this chain are contained in the stack frames
1179 of Fcondition_case and internal_condition_case.
1180 When an error is signaled (by calling Fsignal, below),
1181 this chain is searched for an element that applies. */
1183 struct handler
*handlerlist
;
1185 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1186 doc
: /* Regain control when an error is signaled.
1187 Executes BODYFORM and returns its value if no error happens.
1188 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1189 where the BODY is made of Lisp expressions.
1191 A handler is applicable to an error
1192 if CONDITION-NAME is one of the error's condition names.
1193 If an error happens, the first applicable handler is run.
1195 The car of a handler may be a list of condition names
1196 instead of a single condition name.
1198 When a handler handles an error,
1199 control returns to the condition-case and the handler BODY... is executed
1200 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1201 VAR may be nil; then you do not get access to the signal information.
1203 The value of the last BODY form is returned from the condition-case.
1204 See also the function `signal' for more info.
1205 usage: (condition-case VAR BODYFORM HANDLERS...) */)
1212 register Lisp_Object bodyform
, handlers
;
1213 volatile Lisp_Object var
;
1216 bodyform
= Fcar (Fcdr (args
));
1217 handlers
= Fcdr (Fcdr (args
));
1220 for (val
= handlers
; ! NILP (val
); val
= Fcdr (val
))
1226 && (SYMBOLP (XCAR (tem
))
1227 || CONSP (XCAR (tem
))))))
1228 error ("Invalid condition handler", tem
);
1233 c
.backlist
= backtrace_list
;
1234 c
.handlerlist
= handlerlist
;
1235 c
.lisp_eval_depth
= lisp_eval_depth
;
1236 c
.pdlcount
= specpdl_ptr
- specpdl
;
1237 c
.poll_suppress_count
= poll_suppress_count
;
1238 c
.gcpro
= gcprolist
;
1239 c
.byte_stack
= byte_stack_list
;
1240 if (_setjmp (c
.jmp
))
1243 specbind (h
.var
, c
.val
);
1244 val
= Fprogn (Fcdr (h
.chosen_clause
));
1246 /* Note that this just undoes the binding of h.var; whoever
1247 longjumped to us unwound the stack to c.pdlcount before
1249 unbind_to (c
.pdlcount
, Qnil
);
1256 h
.handler
= handlers
;
1257 h
.next
= handlerlist
;
1261 val
= Feval (bodyform
);
1263 handlerlist
= h
.next
;
1267 /* Call the function BFUN with no arguments, catching errors within it
1268 according to HANDLERS. If there is an error, call HFUN with
1269 one argument which is the data that describes the error:
1272 HANDLERS can be a list of conditions to catch.
1273 If HANDLERS is Qt, catch all errors.
1274 If HANDLERS is Qerror, catch all errors
1275 but allow the debugger to run if that is enabled. */
1278 internal_condition_case (bfun
, handlers
, hfun
)
1279 Lisp_Object (*bfun
) ();
1280 Lisp_Object handlers
;
1281 Lisp_Object (*hfun
) ();
1287 #if 0 /* Can't do this check anymore because realize_basic_faces has
1288 to BLOCK_INPUT, and can call Lisp. What's really needed is a
1289 flag indicating that we're currently handling a signal. */
1290 /* Since Fsignal resets this to 0, it had better be 0 now
1291 or else we have a potential bug. */
1292 if (interrupt_input_blocked
!= 0)
1298 c
.backlist
= backtrace_list
;
1299 c
.handlerlist
= handlerlist
;
1300 c
.lisp_eval_depth
= lisp_eval_depth
;
1301 c
.pdlcount
= specpdl_ptr
- specpdl
;
1302 c
.poll_suppress_count
= poll_suppress_count
;
1303 c
.gcpro
= gcprolist
;
1304 c
.byte_stack
= byte_stack_list
;
1305 if (_setjmp (c
.jmp
))
1307 return (*hfun
) (c
.val
);
1311 h
.handler
= handlers
;
1313 h
.next
= handlerlist
;
1319 handlerlist
= h
.next
;
1323 /* Like internal_condition_case but call HFUN with ARG as its argument. */
1326 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1327 Lisp_Object (*bfun
) ();
1329 Lisp_Object handlers
;
1330 Lisp_Object (*hfun
) ();
1338 c
.backlist
= backtrace_list
;
1339 c
.handlerlist
= handlerlist
;
1340 c
.lisp_eval_depth
= lisp_eval_depth
;
1341 c
.pdlcount
= specpdl_ptr
- specpdl
;
1342 c
.poll_suppress_count
= poll_suppress_count
;
1343 c
.gcpro
= gcprolist
;
1344 c
.byte_stack
= byte_stack_list
;
1345 if (_setjmp (c
.jmp
))
1347 return (*hfun
) (c
.val
);
1351 h
.handler
= handlers
;
1353 h
.next
= handlerlist
;
1357 val
= (*bfun
) (arg
);
1359 handlerlist
= h
.next
;
1364 /* Like internal_condition_case but call HFUN with NARGS as first,
1365 and ARGS as second argument. */
1368 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1369 Lisp_Object (*bfun
) ();
1372 Lisp_Object handlers
;
1373 Lisp_Object (*hfun
) ();
1381 c
.backlist
= backtrace_list
;
1382 c
.handlerlist
= handlerlist
;
1383 c
.lisp_eval_depth
= lisp_eval_depth
;
1384 c
.pdlcount
= specpdl_ptr
- specpdl
;
1385 c
.poll_suppress_count
= poll_suppress_count
;
1386 c
.gcpro
= gcprolist
;
1387 c
.byte_stack
= byte_stack_list
;
1388 if (_setjmp (c
.jmp
))
1390 return (*hfun
) (c
.val
);
1394 h
.handler
= handlers
;
1396 h
.next
= handlerlist
;
1400 val
= (*bfun
) (nargs
, args
);
1402 handlerlist
= h
.next
;
1407 static Lisp_Object
find_handler_clause ();
1409 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1410 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1411 This function does not return.
1413 An error symbol is a symbol with an `error-conditions' property
1414 that is a list of condition names.
1415 A handler for any of those names will get to handle this signal.
1416 The symbol `error' should normally be one of them.
1418 DATA should be a list. Its elements are printed as part of the error message.
1419 If the signal is handled, DATA is made available to the handler.
1420 See also the function `condition-case'. */)
1421 (error_symbol
, data
)
1422 Lisp_Object error_symbol
, data
;
1424 /* When memory is full, ERROR-SYMBOL is nil,
1425 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA). */
1426 register struct handler
*allhandlers
= handlerlist
;
1427 Lisp_Object conditions
;
1428 extern int gc_in_progress
;
1429 extern int waiting_for_input
;
1430 Lisp_Object debugger_value
;
1432 Lisp_Object real_error_symbol
;
1433 extern int display_hourglass_p
;
1434 struct backtrace
*bp
;
1436 immediate_quit
= handling_signal
= 0;
1437 if (gc_in_progress
|| waiting_for_input
)
1440 TOTALLY_UNBLOCK_INPUT
;
1442 if (NILP (error_symbol
))
1443 real_error_symbol
= Fcar (data
);
1445 real_error_symbol
= error_symbol
;
1447 #ifdef HAVE_X_WINDOWS
1448 if (display_hourglass_p
)
1449 cancel_hourglass ();
1452 /* This hook is used by edebug. */
1453 if (! NILP (Vsignal_hook_function
))
1454 call2 (Vsignal_hook_function
, error_symbol
, data
);
1456 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1458 /* Remember from where signal was called. Skip over the frame for
1459 `signal' itself. If a frame for `error' follows, skip that,
1461 Vsignaling_function
= Qnil
;
1464 bp
= backtrace_list
->next
;
1465 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1467 if (bp
&& bp
->function
)
1468 Vsignaling_function
= *bp
->function
;
1471 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1473 register Lisp_Object clause
;
1475 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1476 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1478 if (specpdl_size
+ 40 > max_specpdl_size
)
1479 max_specpdl_size
= specpdl_size
+ 40;
1481 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1482 error_symbol
, data
, &debugger_value
);
1484 #if 0 /* Most callers are not prepared to handle gc if this returns.
1485 So, since this feature is not very useful, take it out. */
1486 /* If have called debugger and user wants to continue,
1488 if (EQ (clause
, Qlambda
))
1489 return debugger_value
;
1491 if (EQ (clause
, Qlambda
))
1493 /* We can't return values to code which signaled an error, but we
1494 can continue code which has signaled a quit. */
1495 if (EQ (real_error_symbol
, Qquit
))
1498 error ("Cannot return from the debugger in an error");
1504 Lisp_Object unwind_data
;
1505 struct handler
*h
= handlerlist
;
1507 handlerlist
= allhandlers
;
1509 if (NILP (error_symbol
))
1512 unwind_data
= Fcons (error_symbol
, data
);
1513 h
->chosen_clause
= clause
;
1514 unwind_to_catch (h
->tag
, unwind_data
);
1518 handlerlist
= allhandlers
;
1519 /* If no handler is present now, try to run the debugger,
1520 and if that fails, throw to top level. */
1521 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1523 Fthrow (Qtop_level
, Qt
);
1525 if (! NILP (error_symbol
))
1526 data
= Fcons (error_symbol
, data
);
1528 string
= Ferror_message_string (data
);
1529 fatal ("%s", XSTRING (string
)->data
, 0);
1532 /* Return nonzero iff LIST is a non-nil atom or
1533 a list containing one of CONDITIONS. */
1536 wants_debugger (list
, conditions
)
1537 Lisp_Object list
, conditions
;
1544 while (CONSP (conditions
))
1546 Lisp_Object
this, tail
;
1547 this = XCAR (conditions
);
1548 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1549 if (EQ (XCAR (tail
), this))
1551 conditions
= XCDR (conditions
);
1556 /* Return 1 if an error with condition-symbols CONDITIONS,
1557 and described by SIGNAL-DATA, should skip the debugger
1558 according to debugger-ignored-errors. */
1561 skip_debugger (conditions
, data
)
1562 Lisp_Object conditions
, data
;
1565 int first_string
= 1;
1566 Lisp_Object error_message
;
1568 error_message
= Qnil
;
1569 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1571 if (STRINGP (XCAR (tail
)))
1575 error_message
= Ferror_message_string (data
);
1579 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1584 Lisp_Object contail
;
1586 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1587 if (EQ (XCAR (tail
), XCAR (contail
)))
1595 /* Value of Qlambda means we have called debugger and user has continued.
1596 There are two ways to pass SIG and DATA:
1597 = SIG is the error symbol, and DATA is the rest of the data.
1598 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1599 This is for memory-full errors only.
1601 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1604 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1605 Lisp_Object handlers
, conditions
, sig
, data
;
1606 Lisp_Object
*debugger_value_ptr
;
1608 register Lisp_Object h
;
1609 register Lisp_Object tem
;
1611 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1613 /* error is used similarly, but means print an error message
1614 and run the debugger if that is enabled. */
1615 if (EQ (handlers
, Qerror
)
1616 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1617 there is a handler. */
1619 int count
= specpdl_ptr
- specpdl
;
1620 int debugger_called
= 0;
1621 Lisp_Object sig_symbol
, combined_data
;
1622 /* This is set to 1 if we are handling a memory-full error,
1623 because these must not run the debugger.
1624 (There is no room in memory to do that!) */
1625 int no_debugger
= 0;
1629 combined_data
= data
;
1630 sig_symbol
= Fcar (data
);
1635 combined_data
= Fcons (sig
, data
);
1639 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1642 internal_with_output_to_temp_buffer ("*Backtrace*",
1643 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1646 internal_with_output_to_temp_buffer ("*Backtrace*",
1651 && (EQ (sig_symbol
, Qquit
)
1653 : wants_debugger (Vdebug_on_error
, conditions
))
1654 && ! skip_debugger (conditions
, combined_data
)
1655 && when_entered_debugger
< num_nonmacro_input_events
)
1657 specbind (Qdebug_on_error
, Qnil
);
1659 = call_debugger (Fcons (Qerror
,
1660 Fcons (combined_data
, Qnil
)));
1661 debugger_called
= 1;
1663 /* If there is no handler, return saying whether we ran the debugger. */
1664 if (EQ (handlers
, Qerror
))
1666 if (debugger_called
)
1667 return unbind_to (count
, Qlambda
);
1671 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1673 Lisp_Object handler
, condit
;
1676 if (!CONSP (handler
))
1678 condit
= Fcar (handler
);
1679 /* Handle a single condition name in handler HANDLER. */
1680 if (SYMBOLP (condit
))
1682 tem
= Fmemq (Fcar (handler
), conditions
);
1686 /* Handle a list of condition names in handler HANDLER. */
1687 else if (CONSP (condit
))
1689 while (CONSP (condit
))
1691 tem
= Fmemq (Fcar (condit
), conditions
);
1694 condit
= XCDR (condit
);
1701 /* dump an error message; called like printf */
1705 error (m
, a1
, a2
, a3
)
1725 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1730 buffer
= (char *) xrealloc (buffer
, size
);
1733 buffer
= (char *) xmalloc (size
);
1738 string
= build_string (buffer
);
1742 Fsignal (Qerror
, Fcons (string
, Qnil
));
1746 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 1, 0,
1747 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1748 This means it contains a description for how to read arguments to give it.
1749 The value is nil for an invalid function or a symbol with no function
1752 Interactively callable functions include strings and vectors (treated
1753 as keyboard macros), lambda-expressions that contain a top-level call
1754 to `interactive', autoload definitions made by `autoload' with non-nil
1755 fourth argument, and some of the built-in functions of Lisp.
1757 Also, a symbol satisfies `commandp' if its function definition does so. */)
1759 Lisp_Object function
;
1761 register Lisp_Object fun
;
1762 register Lisp_Object funcar
;
1766 fun
= indirect_function (fun
);
1767 if (EQ (fun
, Qunbound
))
1770 /* Emacs primitives are interactive if their DEFUN specifies an
1771 interactive spec. */
1774 if (XSUBR (fun
)->prompt
)
1780 /* Bytecode objects are interactive if they are long enough to
1781 have an element whose index is COMPILED_INTERACTIVE, which is
1782 where the interactive spec is stored. */
1783 else if (COMPILEDP (fun
))
1784 return ((XVECTOR (fun
)->size
& PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1787 /* Strings and vectors are keyboard macros. */
1788 if (STRINGP (fun
) || VECTORP (fun
))
1791 /* Lists may represent commands. */
1794 funcar
= Fcar (fun
);
1795 if (!SYMBOLP (funcar
))
1796 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
1797 if (EQ (funcar
, Qlambda
))
1798 return Fassq (Qinteractive
, Fcdr (Fcdr (fun
)));
1799 if (EQ (funcar
, Qmocklisp
))
1800 return Qt
; /* All mocklisp functions can be called interactively */
1801 if (EQ (funcar
, Qautoload
))
1802 return Fcar (Fcdr (Fcdr (Fcdr (fun
))));
1808 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1809 doc
: /* Define FUNCTION to autoload from FILE.
1810 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1811 Third arg DOCSTRING is documentation for the function.
1812 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1813 Fifth arg TYPE indicates the type of the object:
1814 nil or omitted says FUNCTION is a function,
1815 `keymap' says FUNCTION is really a keymap, and
1816 `macro' or t says FUNCTION is really a macro.
1817 Third through fifth args give info about the real definition.
1818 They default to nil.
1819 If FUNCTION is already defined other than as an autoload,
1820 this does nothing and returns nil. */)
1821 (function
, file
, docstring
, interactive
, type
)
1822 Lisp_Object function
, file
, docstring
, interactive
, type
;
1825 Lisp_Object args
[4];
1828 CHECK_SYMBOL (function
);
1829 CHECK_STRING (file
);
1831 /* If function is defined and not as an autoload, don't override */
1832 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
1833 && !(CONSP (XSYMBOL (function
)->function
)
1834 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
1837 if (NILP (Vpurify_flag
))
1838 /* Only add entries after dumping, because the ones before are
1839 not useful and else we get loads of them from the loaddefs.el. */
1840 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
1844 args
[1] = docstring
;
1845 args
[2] = interactive
;
1848 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
1849 #else /* NO_ARG_ARRAY */
1850 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
1851 #endif /* not NO_ARG_ARRAY */
1855 un_autoload (oldqueue
)
1856 Lisp_Object oldqueue
;
1858 register Lisp_Object queue
, first
, second
;
1860 /* Queue to unwind is current value of Vautoload_queue.
1861 oldqueue is the shadowed value to leave in Vautoload_queue. */
1862 queue
= Vautoload_queue
;
1863 Vautoload_queue
= oldqueue
;
1864 while (CONSP (queue
))
1866 first
= Fcar (queue
);
1867 second
= Fcdr (first
);
1868 first
= Fcar (first
);
1869 if (EQ (second
, Qnil
))
1872 Ffset (first
, second
);
1873 queue
= Fcdr (queue
);
1878 /* Load an autoloaded function.
1879 FUNNAME is the symbol which is the function's name.
1880 FUNDEF is the autoload definition (a list). */
1883 do_autoload (fundef
, funname
)
1884 Lisp_Object fundef
, funname
;
1886 int count
= specpdl_ptr
- specpdl
;
1887 Lisp_Object fun
, queue
, first
, second
;
1888 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1891 CHECK_SYMBOL (funname
);
1892 GCPRO3 (fun
, funname
, fundef
);
1894 /* Preserve the match data. */
1895 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1897 /* Value saved here is to be restored into Vautoload_queue. */
1898 record_unwind_protect (un_autoload
, Vautoload_queue
);
1899 Vautoload_queue
= Qt
;
1900 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
1902 /* Save the old autoloads, in case we ever do an unload. */
1903 queue
= Vautoload_queue
;
1904 while (CONSP (queue
))
1906 first
= Fcar (queue
);
1907 second
= Fcdr (first
);
1908 first
= Fcar (first
);
1910 /* Note: This test is subtle. The cdr of an autoload-queue entry
1911 may be an atom if the autoload entry was generated by a defalias
1914 Fput (first
, Qautoload
, (Fcdr (second
)));
1916 queue
= Fcdr (queue
);
1919 /* Once loading finishes, don't undo it. */
1920 Vautoload_queue
= Qt
;
1921 unbind_to (count
, Qnil
);
1923 fun
= Findirect_function (fun
);
1925 if (!NILP (Fequal (fun
, fundef
)))
1926 error ("Autoloading failed to define function %s",
1927 XSYMBOL (funname
)->name
->data
);
1932 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
1933 doc
: /* Evaluate FORM and return its value. */)
1937 Lisp_Object fun
, val
, original_fun
, original_args
;
1939 struct backtrace backtrace
;
1940 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1942 if (handling_signal
)
1947 if (EQ (Vmocklisp_arguments
, Qt
))
1948 return Fsymbol_value (form
);
1949 val
= Fsymbol_value (form
);
1951 XSETFASTINT (val
, 0);
1952 else if (EQ (val
, Qt
))
1953 XSETFASTINT (val
, 1);
1960 if (consing_since_gc
> gc_cons_threshold
)
1963 Fgarbage_collect ();
1967 if (++lisp_eval_depth
> max_lisp_eval_depth
)
1969 if (max_lisp_eval_depth
< 100)
1970 max_lisp_eval_depth
= 100;
1971 if (lisp_eval_depth
> max_lisp_eval_depth
)
1972 error ("Lisp nesting exceeds max-lisp-eval-depth");
1975 original_fun
= Fcar (form
);
1976 original_args
= Fcdr (form
);
1978 backtrace
.next
= backtrace_list
;
1979 backtrace_list
= &backtrace
;
1980 backtrace
.function
= &original_fun
; /* This also protects them from gc */
1981 backtrace
.args
= &original_args
;
1982 backtrace
.nargs
= UNEVALLED
;
1983 backtrace
.evalargs
= 1;
1984 backtrace
.debug_on_exit
= 0;
1986 if (debug_on_next_call
)
1987 do_debug_on_call (Qt
);
1989 /* At this point, only original_fun and original_args
1990 have values that will be used below */
1992 fun
= Findirect_function (original_fun
);
1996 Lisp_Object numargs
;
1997 Lisp_Object argvals
[8];
1998 Lisp_Object args_left
;
1999 register int i
, maxargs
;
2001 args_left
= original_args
;
2002 numargs
= Flength (args_left
);
2004 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2005 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2006 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (numargs
, Qnil
)));
2008 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2010 backtrace
.evalargs
= 0;
2011 val
= (*XSUBR (fun
)->function
) (args_left
);
2015 if (XSUBR (fun
)->max_args
== MANY
)
2017 /* Pass a vector of evaluated arguments */
2019 register int argnum
= 0;
2021 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2023 GCPRO3 (args_left
, fun
, fun
);
2027 while (!NILP (args_left
))
2029 vals
[argnum
++] = Feval (Fcar (args_left
));
2030 args_left
= Fcdr (args_left
);
2031 gcpro3
.nvars
= argnum
;
2034 backtrace
.args
= vals
;
2035 backtrace
.nargs
= XINT (numargs
);
2037 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2042 GCPRO3 (args_left
, fun
, fun
);
2043 gcpro3
.var
= argvals
;
2046 maxargs
= XSUBR (fun
)->max_args
;
2047 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2049 argvals
[i
] = Feval (Fcar (args_left
));
2055 backtrace
.args
= argvals
;
2056 backtrace
.nargs
= XINT (numargs
);
2061 val
= (*XSUBR (fun
)->function
) ();
2064 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2067 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2070 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2074 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2075 argvals
[2], argvals
[3]);
2078 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2079 argvals
[3], argvals
[4]);
2082 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2083 argvals
[3], argvals
[4], argvals
[5]);
2086 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2087 argvals
[3], argvals
[4], argvals
[5],
2092 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2093 argvals
[3], argvals
[4], argvals
[5],
2094 argvals
[6], argvals
[7]);
2098 /* Someone has created a subr that takes more arguments than
2099 is supported by this code. We need to either rewrite the
2100 subr to use a different argument protocol, or add more
2101 cases to this switch. */
2105 if (COMPILEDP (fun
))
2106 val
= apply_lambda (fun
, original_args
, 1);
2110 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2111 funcar
= Fcar (fun
);
2112 if (!SYMBOLP (funcar
))
2113 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2114 if (EQ (funcar
, Qautoload
))
2116 do_autoload (fun
, original_fun
);
2119 if (EQ (funcar
, Qmacro
))
2120 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2121 else if (EQ (funcar
, Qlambda
))
2122 val
= apply_lambda (fun
, original_args
, 1);
2123 else if (EQ (funcar
, Qmocklisp
))
2124 val
= ml_apply (fun
, original_args
);
2126 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2129 if (!EQ (Vmocklisp_arguments
, Qt
))
2132 XSETFASTINT (val
, 0);
2133 else if (EQ (val
, Qt
))
2134 XSETFASTINT (val
, 1);
2137 if (backtrace
.debug_on_exit
)
2138 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2139 backtrace_list
= backtrace
.next
;
2143 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2144 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2145 Then return the value FUNCTION returns.
2146 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2147 usage: (apply FUNCTION &rest ARGUMENTS) */)
2152 register int i
, numargs
;
2153 register Lisp_Object spread_arg
;
2154 register Lisp_Object
*funcall_args
;
2156 struct gcpro gcpro1
;
2160 spread_arg
= args
[nargs
- 1];
2161 CHECK_LIST (spread_arg
);
2163 numargs
= XINT (Flength (spread_arg
));
2166 return Ffuncall (nargs
- 1, args
);
2167 else if (numargs
== 1)
2169 args
[nargs
- 1] = XCAR (spread_arg
);
2170 return Ffuncall (nargs
, args
);
2173 numargs
+= nargs
- 2;
2175 fun
= indirect_function (fun
);
2176 if (EQ (fun
, Qunbound
))
2178 /* Let funcall get the error */
2185 if (numargs
< XSUBR (fun
)->min_args
2186 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2187 goto funcall
; /* Let funcall get the error */
2188 else if (XSUBR (fun
)->max_args
> numargs
)
2190 /* Avoid making funcall cons up a yet another new vector of arguments
2191 by explicitly supplying nil's for optional values */
2192 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2193 * sizeof (Lisp_Object
));
2194 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2195 funcall_args
[++i
] = Qnil
;
2196 GCPRO1 (*funcall_args
);
2197 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2201 /* We add 1 to numargs because funcall_args includes the
2202 function itself as well as its arguments. */
2205 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2206 * sizeof (Lisp_Object
));
2207 GCPRO1 (*funcall_args
);
2208 gcpro1
.nvars
= 1 + numargs
;
2211 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2212 /* Spread the last arg we got. Its first element goes in
2213 the slot that it used to occupy, hence this value of I. */
2215 while (!NILP (spread_arg
))
2217 funcall_args
[i
++] = XCAR (spread_arg
);
2218 spread_arg
= XCDR (spread_arg
);
2221 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2224 /* Run hook variables in various ways. */
2226 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2228 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2229 doc
: /* Run each hook in HOOKS. Major mode functions use this.
2230 Each argument should be a symbol, a hook variable.
2231 These symbols are processed in the order specified.
2232 If a hook symbol has a non-nil value, that value may be a function
2233 or a list of functions to be called to run the hook.
2234 If the value is a function, it is called with no arguments.
2235 If it is a list, the elements are called, in order, with no arguments.
2237 Do not use `make-local-variable' to make a hook variable buffer-local.
2238 Instead, use `add-hook' and specify t for the LOCAL argument.
2239 usage: (run-hooks &rest HOOKS) */)
2244 Lisp_Object hook
[1];
2247 for (i
= 0; i
< nargs
; i
++)
2250 run_hook_with_args (1, hook
, to_completion
);
2256 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2257 Srun_hook_with_args
, 1, MANY
, 0,
2258 doc
: /* Run HOOK with the specified arguments ARGS.
2259 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2260 value, that value may be a function or a list of functions to be
2261 called to run the hook. If the value is a function, it is called with
2262 the given arguments and its return value is returned. If it is a list
2263 of functions, those functions are called, in order,
2264 with the given arguments ARGS.
2265 It is best not to depend on the value return by `run-hook-with-args',
2268 Do not use `make-local-variable' to make a hook variable buffer-local.
2269 Instead, use `add-hook' and specify t for the LOCAL argument.
2270 usage: (run-hook-with-args HOOK &rest ARGS) */)
2275 return run_hook_with_args (nargs
, args
, to_completion
);
2278 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2279 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2280 doc
: /* Run HOOK with the specified arguments ARGS.
2281 HOOK should be a symbol, a hook variable. Its value should
2282 be a list of functions. We call those functions, one by one,
2283 passing arguments ARGS to each of them, until one of them
2284 returns a non-nil value. Then we return that value.
2285 If all the functions return nil, we return nil.
2287 Do not use `make-local-variable' to make a hook variable buffer-local.
2288 Instead, use `add-hook' and specify t for the LOCAL argument.
2289 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2294 return run_hook_with_args (nargs
, args
, until_success
);
2297 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2298 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2299 doc
: /* Run HOOK with the specified arguments ARGS.
2300 HOOK should be a symbol, a hook variable. Its value should
2301 be a list of functions. We call those functions, one by one,
2302 passing arguments ARGS to each of them, until one of them
2303 returns nil. Then we return nil.
2304 If all the functions return non-nil, we return non-nil.
2306 Do not use `make-local-variable' to make a hook variable buffer-local.
2307 Instead, use `add-hook' and specify t for the LOCAL argument.
2308 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2313 return run_hook_with_args (nargs
, args
, until_failure
);
2316 /* ARGS[0] should be a hook symbol.
2317 Call each of the functions in the hook value, passing each of them
2318 as arguments all the rest of ARGS (all NARGS - 1 elements).
2319 COND specifies a condition to test after each call
2320 to decide whether to stop.
2321 The caller (or its caller, etc) must gcpro all of ARGS,
2322 except that it isn't necessary to gcpro ARGS[0]. */
2325 run_hook_with_args (nargs
, args
, cond
)
2328 enum run_hooks_condition cond
;
2330 Lisp_Object sym
, val
, ret
;
2331 Lisp_Object globals
;
2332 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2334 /* If we are dying or still initializing,
2335 don't do anything--it would probably crash if we tried. */
2336 if (NILP (Vrun_hooks
))
2340 val
= find_symbol_value (sym
);
2341 ret
= (cond
== until_failure
? Qt
: Qnil
);
2343 if (EQ (val
, Qunbound
) || NILP (val
))
2345 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2348 return Ffuncall (nargs
, args
);
2353 GCPRO3 (sym
, val
, globals
);
2356 CONSP (val
) && ((cond
== to_completion
)
2357 || (cond
== until_success
? NILP (ret
)
2361 if (EQ (XCAR (val
), Qt
))
2363 /* t indicates this hook has a local binding;
2364 it means to run the global binding too. */
2366 for (globals
= Fdefault_value (sym
);
2367 CONSP (globals
) && ((cond
== to_completion
)
2368 || (cond
== until_success
? NILP (ret
)
2370 globals
= XCDR (globals
))
2372 args
[0] = XCAR (globals
);
2373 /* In a global value, t should not occur. If it does, we
2374 must ignore it to avoid an endless loop. */
2375 if (!EQ (args
[0], Qt
))
2376 ret
= Ffuncall (nargs
, args
);
2381 args
[0] = XCAR (val
);
2382 ret
= Ffuncall (nargs
, args
);
2391 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2392 present value of that symbol.
2393 Call each element of FUNLIST,
2394 passing each of them the rest of ARGS.
2395 The caller (or its caller, etc) must gcpro all of ARGS,
2396 except that it isn't necessary to gcpro ARGS[0]. */
2399 run_hook_list_with_args (funlist
, nargs
, args
)
2400 Lisp_Object funlist
;
2406 Lisp_Object globals
;
2407 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2411 GCPRO3 (sym
, val
, globals
);
2413 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2415 if (EQ (XCAR (val
), Qt
))
2417 /* t indicates this hook has a local binding;
2418 it means to run the global binding too. */
2420 for (globals
= Fdefault_value (sym
);
2422 globals
= XCDR (globals
))
2424 args
[0] = XCAR (globals
);
2425 /* In a global value, t should not occur. If it does, we
2426 must ignore it to avoid an endless loop. */
2427 if (!EQ (args
[0], Qt
))
2428 Ffuncall (nargs
, args
);
2433 args
[0] = XCAR (val
);
2434 Ffuncall (nargs
, args
);
2441 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2444 run_hook_with_args_2 (hook
, arg1
, arg2
)
2445 Lisp_Object hook
, arg1
, arg2
;
2447 Lisp_Object temp
[3];
2452 Frun_hook_with_args (3, temp
);
2455 /* Apply fn to arg */
2458 Lisp_Object fn
, arg
;
2460 struct gcpro gcpro1
;
2464 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2468 Lisp_Object args
[2];
2472 RETURN_UNGCPRO (Fapply (2, args
));
2474 #else /* not NO_ARG_ARRAY */
2475 RETURN_UNGCPRO (Fapply (2, &fn
));
2476 #endif /* not NO_ARG_ARRAY */
2479 /* Call function fn on no arguments */
2484 struct gcpro gcpro1
;
2487 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2490 /* Call function fn with 1 argument arg1 */
2494 Lisp_Object fn
, arg1
;
2496 struct gcpro gcpro1
;
2498 Lisp_Object args
[2];
2504 RETURN_UNGCPRO (Ffuncall (2, args
));
2505 #else /* not NO_ARG_ARRAY */
2508 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2509 #endif /* not NO_ARG_ARRAY */
2512 /* Call function fn with 2 arguments arg1, arg2 */
2515 call2 (fn
, arg1
, arg2
)
2516 Lisp_Object fn
, arg1
, arg2
;
2518 struct gcpro gcpro1
;
2520 Lisp_Object args
[3];
2526 RETURN_UNGCPRO (Ffuncall (3, args
));
2527 #else /* not NO_ARG_ARRAY */
2530 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2531 #endif /* not NO_ARG_ARRAY */
2534 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2537 call3 (fn
, arg1
, arg2
, arg3
)
2538 Lisp_Object fn
, arg1
, arg2
, arg3
;
2540 struct gcpro gcpro1
;
2542 Lisp_Object args
[4];
2549 RETURN_UNGCPRO (Ffuncall (4, args
));
2550 #else /* not NO_ARG_ARRAY */
2553 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2554 #endif /* not NO_ARG_ARRAY */
2557 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2560 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2561 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2563 struct gcpro gcpro1
;
2565 Lisp_Object args
[5];
2573 RETURN_UNGCPRO (Ffuncall (5, args
));
2574 #else /* not NO_ARG_ARRAY */
2577 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2578 #endif /* not NO_ARG_ARRAY */
2581 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2584 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2585 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2587 struct gcpro gcpro1
;
2589 Lisp_Object args
[6];
2598 RETURN_UNGCPRO (Ffuncall (6, args
));
2599 #else /* not NO_ARG_ARRAY */
2602 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2603 #endif /* not NO_ARG_ARRAY */
2606 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2609 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2610 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2612 struct gcpro gcpro1
;
2614 Lisp_Object args
[7];
2624 RETURN_UNGCPRO (Ffuncall (7, args
));
2625 #else /* not NO_ARG_ARRAY */
2628 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2629 #endif /* not NO_ARG_ARRAY */
2632 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2633 doc
: /* Call first argument as a function, passing remaining arguments to it.
2634 Return the value that function returns.
2635 Thus, (funcall 'cons 'x 'y) returns (x . y).
2636 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2643 int numargs
= nargs
- 1;
2644 Lisp_Object lisp_numargs
;
2646 struct backtrace backtrace
;
2647 register Lisp_Object
*internal_args
;
2651 if (consing_since_gc
> gc_cons_threshold
)
2652 Fgarbage_collect ();
2654 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2656 if (max_lisp_eval_depth
< 100)
2657 max_lisp_eval_depth
= 100;
2658 if (lisp_eval_depth
> max_lisp_eval_depth
)
2659 error ("Lisp nesting exceeds max-lisp-eval-depth");
2662 backtrace
.next
= backtrace_list
;
2663 backtrace_list
= &backtrace
;
2664 backtrace
.function
= &args
[0];
2665 backtrace
.args
= &args
[1];
2666 backtrace
.nargs
= nargs
- 1;
2667 backtrace
.evalargs
= 0;
2668 backtrace
.debug_on_exit
= 0;
2670 if (debug_on_next_call
)
2671 do_debug_on_call (Qlambda
);
2677 fun
= Findirect_function (fun
);
2681 if (numargs
< XSUBR (fun
)->min_args
2682 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2684 XSETFASTINT (lisp_numargs
, numargs
);
2685 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2688 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2689 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2691 if (XSUBR (fun
)->max_args
== MANY
)
2693 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2697 if (XSUBR (fun
)->max_args
> numargs
)
2699 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2700 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2701 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2702 internal_args
[i
] = Qnil
;
2705 internal_args
= args
+ 1;
2706 switch (XSUBR (fun
)->max_args
)
2709 val
= (*XSUBR (fun
)->function
) ();
2712 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2715 val
= (*XSUBR (fun
)->function
) (internal_args
[0],
2719 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2723 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2728 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2729 internal_args
[2], internal_args
[3],
2733 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2734 internal_args
[2], internal_args
[3],
2735 internal_args
[4], internal_args
[5]);
2738 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2739 internal_args
[2], internal_args
[3],
2740 internal_args
[4], internal_args
[5],
2745 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2746 internal_args
[2], internal_args
[3],
2747 internal_args
[4], internal_args
[5],
2748 internal_args
[6], internal_args
[7]);
2753 /* If a subr takes more than 8 arguments without using MANY
2754 or UNEVALLED, we need to extend this function to support it.
2755 Until this is done, there is no way to call the function. */
2759 if (COMPILEDP (fun
))
2760 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2764 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2765 funcar
= Fcar (fun
);
2766 if (!SYMBOLP (funcar
))
2767 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2768 if (EQ (funcar
, Qlambda
))
2769 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2770 else if (EQ (funcar
, Qmocklisp
))
2771 val
= ml_apply (fun
, Flist (numargs
, args
+ 1));
2772 else if (EQ (funcar
, Qautoload
))
2774 do_autoload (fun
, args
[0]);
2778 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2782 if (backtrace
.debug_on_exit
)
2783 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2784 backtrace_list
= backtrace
.next
;
2789 apply_lambda (fun
, args
, eval_flag
)
2790 Lisp_Object fun
, args
;
2793 Lisp_Object args_left
;
2794 Lisp_Object numargs
;
2795 register Lisp_Object
*arg_vector
;
2796 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2798 register Lisp_Object tem
;
2800 numargs
= Flength (args
);
2801 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2804 GCPRO3 (*arg_vector
, args_left
, fun
);
2807 for (i
= 0; i
< XINT (numargs
);)
2809 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2810 if (eval_flag
) tem
= Feval (tem
);
2811 arg_vector
[i
++] = tem
;
2819 backtrace_list
->args
= arg_vector
;
2820 backtrace_list
->nargs
= i
;
2822 backtrace_list
->evalargs
= 0;
2823 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
2825 /* Do the debug-on-exit now, while arg_vector still exists. */
2826 if (backtrace_list
->debug_on_exit
)
2827 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
2828 /* Don't do it again when we return to eval. */
2829 backtrace_list
->debug_on_exit
= 0;
2833 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2834 and return the result of evaluation.
2835 FUN must be either a lambda-expression or a compiled-code object. */
2838 funcall_lambda (fun
, nargs
, arg_vector
)
2841 register Lisp_Object
*arg_vector
;
2843 Lisp_Object val
, syms_left
, next
;
2844 int count
= specpdl_ptr
- specpdl
;
2845 int i
, optional
, rest
;
2847 if (NILP (Vmocklisp_arguments
))
2848 specbind (Qmocklisp_arguments
, Qt
); /* t means NOT mocklisp! */
2852 syms_left
= XCDR (fun
);
2853 if (CONSP (syms_left
))
2854 syms_left
= XCAR (syms_left
);
2856 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2858 else if (COMPILEDP (fun
))
2859 syms_left
= XVECTOR (fun
)->contents
[COMPILED_ARGLIST
];
2863 i
= optional
= rest
= 0;
2864 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2868 next
= XCAR (syms_left
);
2869 while (!SYMBOLP (next
))
2870 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2872 if (EQ (next
, Qand_rest
))
2874 else if (EQ (next
, Qand_optional
))
2878 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
2882 specbind (next
, arg_vector
[i
++]);
2884 return Fsignal (Qwrong_number_of_arguments
,
2885 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2887 specbind (next
, Qnil
);
2890 if (!NILP (syms_left
))
2891 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2893 return Fsignal (Qwrong_number_of_arguments
,
2894 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2897 val
= Fprogn (XCDR (XCDR (fun
)));
2900 /* If we have not actually read the bytecode string
2901 and constants vector yet, fetch them from the file. */
2902 if (CONSP (XVECTOR (fun
)->contents
[COMPILED_BYTECODE
]))
2903 Ffetch_bytecode (fun
);
2904 val
= Fbyte_code (XVECTOR (fun
)->contents
[COMPILED_BYTECODE
],
2905 XVECTOR (fun
)->contents
[COMPILED_CONSTANTS
],
2906 XVECTOR (fun
)->contents
[COMPILED_STACK_DEPTH
]);
2909 return unbind_to (count
, val
);
2912 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2914 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2920 if (COMPILEDP (object
)
2921 && CONSP (XVECTOR (object
)->contents
[COMPILED_BYTECODE
]))
2923 tem
= read_doc_string (XVECTOR (object
)->contents
[COMPILED_BYTECODE
]);
2925 error ("invalid byte code");
2926 XVECTOR (object
)->contents
[COMPILED_BYTECODE
] = XCAR (tem
);
2927 XVECTOR (object
)->contents
[COMPILED_CONSTANTS
] = XCDR (tem
);
2935 register int count
= specpdl_ptr
- specpdl
;
2936 if (specpdl_size
>= max_specpdl_size
)
2938 if (max_specpdl_size
< 400)
2939 max_specpdl_size
= 400;
2940 if (specpdl_size
>= max_specpdl_size
)
2942 if (!NILP (Vdebug_on_error
))
2943 /* Leave room for some specpdl in the debugger. */
2944 max_specpdl_size
= specpdl_size
+ 100;
2946 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
2950 if (specpdl_size
> max_specpdl_size
)
2951 specpdl_size
= max_specpdl_size
;
2952 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
2953 specpdl_ptr
= specpdl
+ count
;
2957 specbind (symbol
, value
)
2958 Lisp_Object symbol
, value
;
2961 Lisp_Object valcontents
;
2963 CHECK_SYMBOL (symbol
);
2964 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2967 /* The most common case is that of a non-constant symbol with a
2968 trivial value. Make that as fast as we can. */
2969 valcontents
= SYMBOL_VALUE (symbol
);
2970 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
2972 specpdl_ptr
->symbol
= symbol
;
2973 specpdl_ptr
->old_value
= valcontents
;
2974 specpdl_ptr
->func
= NULL
;
2976 SET_SYMBOL_VALUE (symbol
, value
);
2980 Lisp_Object valcontents
;
2982 ovalue
= find_symbol_value (symbol
);
2983 specpdl_ptr
->func
= 0;
2984 specpdl_ptr
->old_value
= ovalue
;
2986 valcontents
= XSYMBOL (symbol
)->value
;
2988 if (BUFFER_LOCAL_VALUEP (valcontents
)
2989 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
2990 || BUFFER_OBJFWDP (valcontents
))
2992 Lisp_Object where
, current_buffer
;
2994 current_buffer
= Fcurrent_buffer ();
2996 /* For a local variable, record both the symbol and which
2997 buffer's or frame's value we are saving. */
2998 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
2999 where
= current_buffer
;
3000 else if (!BUFFER_OBJFWDP (valcontents
)
3001 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3002 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3006 /* We're not using the `unused' slot in the specbinding
3007 structure because this would mean we have to do more
3008 work for simple variables. */
3009 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3011 /* If SYMBOL is a per-buffer variable which doesn't have a
3012 buffer-local value here, make the `let' change the global
3013 value by changing the value of SYMBOL in all buffers not
3014 having their own value. This is consistent with what
3015 happens with other buffer-local variables. */
3017 && BUFFER_OBJFWDP (valcontents
))
3020 Fset_default (symbol
, value
);
3025 specpdl_ptr
->symbol
= symbol
;
3028 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3029 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3031 set_internal (symbol
, value
, 0, 1);
3036 record_unwind_protect (function
, arg
)
3037 Lisp_Object (*function
) P_ ((Lisp_Object
));
3040 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3042 specpdl_ptr
->func
= function
;
3043 specpdl_ptr
->symbol
= Qnil
;
3044 specpdl_ptr
->old_value
= arg
;
3049 unbind_to (count
, value
)
3053 int quitf
= !NILP (Vquit_flag
);
3054 struct gcpro gcpro1
;
3059 while (specpdl_ptr
!= specpdl
+ count
)
3063 if (specpdl_ptr
->func
!= 0)
3064 (*specpdl_ptr
->func
) (specpdl_ptr
->old_value
);
3065 /* Note that a "binding" of nil is really an unwind protect,
3066 so in that case the "old value" is a list of forms to evaluate. */
3067 else if (NILP (specpdl_ptr
->symbol
))
3068 Fprogn (specpdl_ptr
->old_value
);
3069 /* If the symbol is a list, it is really (SYMBOL WHERE
3070 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3071 frame. If WHERE is a buffer or frame, this indicates we
3072 bound a variable that had a buffer-local or frame-local
3073 binding. WHERE nil means that the variable had the default
3074 value when it was bound. CURRENT-BUFFER is the buffer that
3075 was current when the variable was bound. */
3076 else if (CONSP (specpdl_ptr
->symbol
))
3078 Lisp_Object symbol
, where
;
3080 symbol
= XCAR (specpdl_ptr
->symbol
);
3081 where
= XCAR (XCDR (specpdl_ptr
->symbol
));
3084 Fset_default (symbol
, specpdl_ptr
->old_value
);
3085 else if (BUFFERP (where
))
3086 set_internal (symbol
, specpdl_ptr
->old_value
, XBUFFER (where
), 1);
3088 set_internal (symbol
, specpdl_ptr
->old_value
, NULL
, 1);
3092 /* If variable has a trivial value (no forwarding), we can
3093 just set it. No need to check for constant symbols here,
3094 since that was already done by specbind. */
3095 if (!MISCP (SYMBOL_VALUE (specpdl_ptr
->symbol
)))
3096 SET_SYMBOL_VALUE (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
);
3098 set_internal (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
, 0, 1);
3102 if (NILP (Vquit_flag
) && quitf
)
3111 /* Get the value of symbol's global binding, even if that binding
3112 is not now dynamically visible. */
3115 top_level_value (symbol
)
3118 register struct specbinding
*ptr
= specpdl
;
3120 CHECK_SYMBOL (symbol
);
3121 for (; ptr
!= specpdl_ptr
; ptr
++)
3123 if (EQ (ptr
->symbol
, symbol
))
3124 return ptr
->old_value
;
3126 return Fsymbol_value (symbol
);
3130 top_level_set (symbol
, newval
)
3131 Lisp_Object symbol
, newval
;
3133 register struct specbinding
*ptr
= specpdl
;
3135 CHECK_SYMBOL (symbol
);
3136 for (; ptr
!= specpdl_ptr
; ptr
++)
3138 if (EQ (ptr
->symbol
, symbol
))
3140 ptr
->old_value
= newval
;
3144 return Fset (symbol
, newval
);
3149 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3150 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3151 The debugger is entered when that frame exits, if the flag is non-nil. */)
3153 Lisp_Object level
, flag
;
3155 register struct backtrace
*backlist
= backtrace_list
;
3158 CHECK_NUMBER (level
);
3160 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3162 backlist
= backlist
->next
;
3166 backlist
->debug_on_exit
= !NILP (flag
);
3171 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3172 doc
: /* Print a trace of Lisp function calls currently active.
3173 Output stream used is value of `standard-output'. */)
3176 register struct backtrace
*backlist
= backtrace_list
;
3180 extern Lisp_Object Vprint_level
;
3181 struct gcpro gcpro1
;
3183 XSETFASTINT (Vprint_level
, 3);
3190 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3191 if (backlist
->nargs
== UNEVALLED
)
3193 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3194 write_string ("\n", -1);
3198 tem
= *backlist
->function
;
3199 Fprin1 (tem
, Qnil
); /* This can QUIT */
3200 write_string ("(", -1);
3201 if (backlist
->nargs
== MANY
)
3203 for (tail
= *backlist
->args
, i
= 0;
3205 tail
= Fcdr (tail
), i
++)
3207 if (i
) write_string (" ", -1);
3208 Fprin1 (Fcar (tail
), Qnil
);
3213 for (i
= 0; i
< backlist
->nargs
; i
++)
3215 if (i
) write_string (" ", -1);
3216 Fprin1 (backlist
->args
[i
], Qnil
);
3219 write_string (")\n", -1);
3221 backlist
= backlist
->next
;
3224 Vprint_level
= Qnil
;
3229 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3230 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3231 If that frame has not evaluated the arguments yet (or is a special form),
3232 the value is (nil FUNCTION ARG-FORMS...).
3233 If that frame has evaluated its arguments and called its function already,
3234 the value is (t FUNCTION ARG-VALUES...).
3235 A &rest arg is represented as the tail of the list ARG-VALUES.
3236 FUNCTION is whatever was supplied as car of evaluated list,
3237 or a lambda expression for macro calls.
3238 If NFRAMES is more than the number of frames, the value is nil. */)
3240 Lisp_Object nframes
;
3242 register struct backtrace
*backlist
= backtrace_list
;
3246 CHECK_NATNUM (nframes
);
3248 /* Find the frame requested. */
3249 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3250 backlist
= backlist
->next
;
3254 if (backlist
->nargs
== UNEVALLED
)
3255 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3258 if (backlist
->nargs
== MANY
)
3259 tem
= *backlist
->args
;
3261 tem
= Flist (backlist
->nargs
, backlist
->args
);
3263 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3271 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3272 doc
: /* *Limit on number of Lisp variable bindings & unwind-protects.
3273 If Lisp code tries to make more than this many at once,
3274 an error is signaled. */);
3276 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3277 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3278 This limit is to catch infinite recursions for you before they cause
3279 actual stack overflow in C, which would be fatal for Emacs.
3280 You can safely make it considerably larger than its default value,
3281 if that proves inconveniently small. */);
3283 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3284 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3285 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */);
3288 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3289 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3290 Note that `quit-flag' will still be set by typing C-g,
3291 so a quit will be signaled as soon as `inhibit-quit' is nil.
3292 To prevent this happening, set `quit-flag' to nil
3293 before making `inhibit-quit' nil. */);
3294 Vinhibit_quit
= Qnil
;
3296 Qinhibit_quit
= intern ("inhibit-quit");
3297 staticpro (&Qinhibit_quit
);
3299 Qautoload
= intern ("autoload");
3300 staticpro (&Qautoload
);
3302 Qdebug_on_error
= intern ("debug-on-error");
3303 staticpro (&Qdebug_on_error
);
3305 Qmacro
= intern ("macro");
3306 staticpro (&Qmacro
);
3308 /* Note that the process handling also uses Qexit, but we don't want
3309 to staticpro it twice, so we just do it here. */
3310 Qexit
= intern ("exit");
3313 Qinteractive
= intern ("interactive");
3314 staticpro (&Qinteractive
);
3316 Qcommandp
= intern ("commandp");
3317 staticpro (&Qcommandp
);
3319 Qdefun
= intern ("defun");
3320 staticpro (&Qdefun
);
3322 Qand_rest
= intern ("&rest");
3323 staticpro (&Qand_rest
);
3325 Qand_optional
= intern ("&optional");
3326 staticpro (&Qand_optional
);
3328 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3329 doc
: /* *Non-nil means automatically display a backtrace buffer
3330 after any error that is handled by the editor command loop.
3331 If the value is a list, an error only means to display a backtrace
3332 if one of its condition symbols appears in the list. */);
3333 Vstack_trace_on_error
= Qnil
;
3335 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3336 doc
: /* *Non-nil means enter debugger if an error is signaled.
3337 Does not apply to errors handled by `condition-case' or those
3338 matched by `debug-ignored-errors'.
3339 If the value is a list, an error only means to enter the debugger
3340 if one of its condition symbols appears in the list.
3341 When you evaluate an expression interactively, this variable
3342 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3343 See also variable `debug-on-quit'. */);
3344 Vdebug_on_error
= Qnil
;
3346 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3347 doc
: /* *List of errors for which the debugger should not be called.
3348 Each element may be a condition-name or a regexp that matches error messages.
3349 If any element applies to a given error, that error skips the debugger
3350 and just returns to top level.
3351 This overrides the variable `debug-on-error'.
3352 It does not apply to errors handled by `condition-case'. */);
3353 Vdebug_ignored_errors
= Qnil
;
3355 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3356 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3357 Does not apply if quit is handled by a `condition-case'.
3358 When you evaluate an expression interactively, this variable
3359 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3362 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3363 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3365 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3366 doc
: /* Non-nil means debugger may continue execution.
3367 This is nil when the debugger is called under circumstances where it
3368 might not be safe to continue. */);
3369 debugger_may_continue
= 1;
3371 DEFVAR_LISP ("debugger", &Vdebugger
,
3372 doc
: /* Function to call to invoke debugger.
3373 If due to frame exit, args are `exit' and the value being returned;
3374 this function's value will be returned instead of that.
3375 If due to error, args are `error' and a list of the args to `signal'.
3376 If due to `apply' or `funcall' entry, one arg, `lambda'.
3377 If due to `eval' entry, one arg, t. */);
3380 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3381 doc
: /* If non-nil, this is a function for `signal' to call.
3382 It receives the same arguments that `signal' was given.
3383 The Edebug package uses this to regain control. */);
3384 Vsignal_hook_function
= Qnil
;
3386 Qmocklisp_arguments
= intern ("mocklisp-arguments");
3387 staticpro (&Qmocklisp_arguments
);
3388 DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments
,
3389 doc
: /* While in a mocklisp function, the list of its unevaluated args. */);
3390 Vmocklisp_arguments
= Qt
;
3392 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3393 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3394 Note that `debug-on-error', `debug-on-quit' and friends
3395 still determine whether to handle the particular condition. */);
3396 Vdebug_on_signal
= Qnil
;
3398 Vrun_hooks
= intern ("run-hooks");
3399 staticpro (&Vrun_hooks
);
3401 staticpro (&Vautoload_queue
);
3402 Vautoload_queue
= Qnil
;
3403 staticpro (&Vsignaling_function
);
3404 Vsignaling_function
= Qnil
;
3415 defsubr (&Sfunction
);
3417 defsubr (&Sdefmacro
);
3419 defsubr (&Sdefvaralias
);
3420 defsubr (&Sdefconst
);
3421 defsubr (&Suser_variable_p
);
3425 defsubr (&Smacroexpand
);
3428 defsubr (&Sunwind_protect
);
3429 defsubr (&Scondition_case
);
3431 defsubr (&Sinteractive_p
);
3432 defsubr (&Scommandp
);
3433 defsubr (&Sautoload
);
3436 defsubr (&Sfuncall
);
3437 defsubr (&Srun_hooks
);
3438 defsubr (&Srun_hook_with_args
);
3439 defsubr (&Srun_hook_with_args_until_success
);
3440 defsubr (&Srun_hook_with_args_until_failure
);
3441 defsubr (&Sfetch_bytecode
);
3442 defsubr (&Sbacktrace_debug
);
3443 defsubr (&Sbacktrace
);
3444 defsubr (&Sbacktrace_frame
);