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 debuffer 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_errors 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 interupted 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 "Eval args until one of them yields non-nil, then return that value.\n\
290 The remaining args are not evalled at all.\n\
291 If all args return nil, return nil.\n\
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 "Eval args until one of them yields nil, then return nil.\n\
321 The remaining args are not evalled at all.\n\
322 If no arg yields nil, return the last arg's value.\n\
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 "If COND yields non-nil, do THEN, else do ELSE...\n\
352 Returns the value of THEN or the value of the last of the ELSE's.\n\
353 THEN must be one expression, but ELSE... can be zero or more expressions.\n\
354 If COND yields nil, and there are no ELSE's, the value is nil.\n\
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 "Try each clause until one succeeds.\n\
373 Each clause looks like (CONDITION BODY...). CONDITION is evaluated\n\
374 and, if the value is non-nil, this clause succeeds:\n\
375 then the expressions in BODY are evaluated and the last one's\n\
376 value is the value of the cond-form.\n\
377 If no clause succeeds, cond returns nil.\n\
378 If a clause has one element, as in (CONDITION),\n\
379 CONDITION's value if non-nil is returned from the cond-form.\n\
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 "Eval BODY forms sequentially and return value of last one.\n\
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 "Eval FIRST and BODY sequentially; value from FIRST.\n\
447 The value of FIRST is saved during the evaluation of the remaining args,\n\
448 whose values are discarded.\n\
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 "Eval X, Y and BODY sequentially; value from Y.\n\
481 The value of Y is saved during the evaluation of the remaining args,\n\
482 whose values are discarded.\n\
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 "Set each SYM to the value of its VAL.\n\
517 The symbols SYM are variables; they are literal (not evaluated).\n\
518 The values VAL are expressions; they are evaluated.\n\
519 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.\n\
520 The second VAL is not computed until after the first SYM is set, and so on;\n\
521 each VAL can use the new value of variables set earlier in the `setq'.\n\
522 The return value of the `setq' form is the value of the last VAL.\n\
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 "Return the argument, without evaluating it. `(quote x)' yields `x'.\n\
559 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
560 "Like `quote', but preferred for objects which are functions.\n\
561 In byte compilation, `function' causes its argument to be compiled.\n\
562 `quote' cannot do that.\n\
563 usage: (function ARG)")
571 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
572 "Return t if function in which this appears was called interactively.\n\
573 This means that the function was called with call-interactively (which\n\
574 includes being called as the binding of a key)\n\
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 "Define NAME as a function.\n\
641 The definition is (lambda ARGLIST [DOCSTRING] BODY...).\n\
642 See also the function `interactive'.\n\
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 "Define NAME as a macro.\n\
661 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).\n\
662 When the macro is called, as in (NAME ARGS...),\n\
663 the function (lambda ARGLIST BODY...) is applied to\n\
664 the list ARGS... as it appears in the expression,\n\
665 and the result should be a form to be evaluated instead of the original.\n\
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 "Make SYMBOL a variable alias for symbol ALIASED.\n\
685 Setting the value of SYMBOL will subsequently set the value of ALIASED,\n\
686 and getting the value of SYMBOL will return the value ALIASED has.\n\
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
, 0);
694 CHECK_SYMBOL (aliased
, 1);
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 "Define SYMBOL as a variable.\n\
711 You are not required to define a variable in order to use it,\n\
712 but the definition can supply documentation and an initial value\n\
713 in a way that tags can recognize.\n\n\
714 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.\n\
715 If SYMBOL is buffer-local, its default value is what is set;\n\
716 buffer-local values are not affected.\n\
717 INITVALUE and DOCSTRING are optional.\n\
718 If DOCSTRING starts with *, this variable is identified as a user option.\n\
719 This means that M-x set-variable recognizes it.\n\
720 See also `user-variable-p'.\n\
721 If INITVALUE is missing, SYMBOL's value is not set.\n\
722 usage: (defvar SYMBOL [INITVALUE DOCSTRING])")
726 register Lisp_Object sym
, tem
, tail
;
730 if (!NILP (Fcdr (Fcdr (tail
))))
731 error ("too many arguments");
733 tem
= Fdefault_boundp (sym
);
737 Fset_default (sym
, Feval (Fcar (tail
)));
739 if (!NILP (Fcar (tail
)))
742 if (!NILP (Vpurify_flag
))
743 tem
= Fpurecopy (tem
);
744 Fput (sym
, Qvariable_documentation
, tem
);
746 LOADHIST_ATTACH (sym
);
749 /* A (defvar <var>) should not take precedence in the load-history over
750 an earlier (defvar <var> <val>), so only add to history if the default
751 value is still unbound. */
753 LOADHIST_ATTACH (sym
);
758 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
759 "Define SYMBOL as a constant variable.\n\
760 The intent is that neither programs nor users should ever change this value.\n\
761 Always sets the value of SYMBOL to the result of evalling INITVALUE.\n\
762 If SYMBOL is buffer-local, its default value is what is set;\n\
763 buffer-local values are not affected.\n\
764 DOCSTRING is optional.\n\
765 usage: (defconst SYMBOL INITVALUE [DOCSTRING])")
769 register Lisp_Object sym
, tem
;
772 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
773 error ("too many arguments");
775 tem
= Feval (Fcar (Fcdr (args
)));
776 if (!NILP (Vpurify_flag
))
777 tem
= Fpurecopy (tem
);
778 Fset_default (sym
, tem
);
779 tem
= Fcar (Fcdr (Fcdr (args
)));
782 if (!NILP (Vpurify_flag
))
783 tem
= Fpurecopy (tem
);
784 Fput (sym
, Qvariable_documentation
, tem
);
786 LOADHIST_ATTACH (sym
);
790 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
791 "Returns t if VARIABLE is intended to be set and modified by users.\n\
792 \(The alternative is a variable used internally in a Lisp program.)\n\
793 Determined by whether the first character of the documentation\n\
794 for the variable is `*' or if the variable is customizable (has a non-nil\n\
795 value of any of `custom-type', `custom-loads' or `standard-value'\n\
796 on its property list).")
798 Lisp_Object variable
;
800 Lisp_Object documentation
;
802 if (!SYMBOLP (variable
))
805 documentation
= Fget (variable
, Qvariable_documentation
);
806 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
808 if (STRINGP (documentation
)
809 && ((unsigned char) XSTRING (documentation
)->data
[0] == '*'))
811 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
812 if (CONSP (documentation
)
813 && STRINGP (XCAR (documentation
))
814 && INTEGERP (XCDR (documentation
))
815 && XINT (XCDR (documentation
)) < 0)
818 if ((!NILP (Fget (variable
, intern ("custom-type"))))
819 || (!NILP (Fget (variable
, intern ("custom-loads"))))
820 || (!NILP (Fget (variable
, intern ("standard-value")))))
825 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
826 "Bind variables according to VARLIST then eval BODY.\n\
827 The value of the last form in BODY is returned.\n\
828 Each element of VARLIST is a symbol (which is bound to nil)\n\
829 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\
830 Each VALUEFORM can refer to the symbols already bound by this VARLIST.\n\
831 usage: (let* VARLIST BODY...)")
835 Lisp_Object varlist
, val
, elt
;
836 int count
= specpdl_ptr
- specpdl
;
837 struct gcpro gcpro1
, gcpro2
, gcpro3
;
839 GCPRO3 (args
, elt
, varlist
);
841 varlist
= Fcar (args
);
842 while (!NILP (varlist
))
845 elt
= Fcar (varlist
);
847 specbind (elt
, Qnil
);
848 else if (! NILP (Fcdr (Fcdr (elt
))))
850 Fcons (build_string ("`let' bindings can have only one value-form"),
854 val
= Feval (Fcar (Fcdr (elt
)));
855 specbind (Fcar (elt
), val
);
857 varlist
= Fcdr (varlist
);
860 val
= Fprogn (Fcdr (args
));
861 return unbind_to (count
, val
);
864 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
865 "Bind variables according to VARLIST then eval BODY.\n\
866 The value of the last form in BODY is returned.\n\
867 Each element of VARLIST is a symbol (which is bound to nil)\n\
868 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\
869 All the VALUEFORMs are evalled before any symbols are bound.\n\
870 usage: (let VARLIST BODY...)")
874 Lisp_Object
*temps
, tem
;
875 register Lisp_Object elt
, varlist
;
876 int count
= specpdl_ptr
- specpdl
;
878 struct gcpro gcpro1
, gcpro2
;
880 varlist
= Fcar (args
);
882 /* Make space to hold the values to give the bound variables */
883 elt
= Flength (varlist
);
884 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
886 /* Compute the values and store them in `temps' */
888 GCPRO2 (args
, *temps
);
891 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
894 elt
= Fcar (varlist
);
896 temps
[argnum
++] = Qnil
;
897 else if (! NILP (Fcdr (Fcdr (elt
))))
899 Fcons (build_string ("`let' bindings can have only one value-form"),
902 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
903 gcpro2
.nvars
= argnum
;
907 varlist
= Fcar (args
);
908 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
910 elt
= Fcar (varlist
);
911 tem
= temps
[argnum
++];
915 specbind (Fcar (elt
), tem
);
918 elt
= Fprogn (Fcdr (args
));
919 return unbind_to (count
, elt
);
922 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
923 "If TEST yields non-nil, eval BODY... and repeat.\n\
924 The order of execution is thus TEST, BODY, TEST, BODY and so on\n\
925 until TEST returns nil.\n\
926 usage: (while TEST BODY...)")
930 Lisp_Object test
, body
, tem
;
931 struct gcpro gcpro1
, gcpro2
;
937 while (tem
= Feval (test
),
938 (!EQ (Vmocklisp_arguments
, Qt
) ? XINT (tem
) : !NILP (tem
)))
948 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
949 "Return result of expanding macros at top level of FORM.\n\
950 If FORM is not a macro call, it is returned unchanged.\n\
951 Otherwise, the macro is expanded and the expansion is considered\n\
952 in place of FORM. When a non-macro-call results, it is returned.\n\n\
953 The second optional arg ENVIRONMENT specifies an environment of macro\n\
954 definitions to shadow the loaded ones for use in file byte-compilation.")
957 Lisp_Object environment
;
959 /* With cleanups from Hallvard Furuseth. */
960 register Lisp_Object expander
, sym
, def
, tem
;
964 /* Come back here each time we expand a macro call,
965 in case it expands into another macro call. */
968 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
969 def
= sym
= XCAR (form
);
971 /* Trace symbols aliases to other symbols
972 until we get a symbol that is not an alias. */
973 while (SYMBOLP (def
))
977 tem
= Fassq (sym
, environment
);
980 def
= XSYMBOL (sym
)->function
;
981 if (!EQ (def
, Qunbound
))
986 /* Right now TEM is the result from SYM in ENVIRONMENT,
987 and if TEM is nil then DEF is SYM's function definition. */
990 /* SYM is not mentioned in ENVIRONMENT.
991 Look at its function definition. */
992 if (EQ (def
, Qunbound
) || !CONSP (def
))
993 /* Not defined or definition not suitable */
995 if (EQ (XCAR (def
), Qautoload
))
997 /* Autoloading function: will it be a macro when loaded? */
998 tem
= Fnth (make_number (4), def
);
999 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1000 /* Yes, load it and try again. */
1002 struct gcpro gcpro1
;
1004 do_autoload (def
, sym
);
1011 else if (!EQ (XCAR (def
), Qmacro
))
1013 else expander
= XCDR (def
);
1017 expander
= XCDR (tem
);
1018 if (NILP (expander
))
1021 form
= apply1 (expander
, XCDR (form
));
1026 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1027 "Eval BODY allowing nonlocal exits using `throw'.\n\
1028 TAG is evalled to get the tag to use; it must not be nil.\n\
1030 Then the BODY is executed.\n\
1031 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.\n\
1032 If no throw happens, `catch' returns the value of the last BODY form.\n\
1033 If a throw happens, it specifies the value to return from `catch'.\n\
1034 usage: (catch TAG BODY...)")
1038 register Lisp_Object tag
;
1039 struct gcpro gcpro1
;
1042 tag
= Feval (Fcar (args
));
1044 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1047 /* Set up a catch, then call C function FUNC on argument ARG.
1048 FUNC should return a Lisp_Object.
1049 This is how catches are done from within C code. */
1052 internal_catch (tag
, func
, arg
)
1054 Lisp_Object (*func
) ();
1057 /* This structure is made part of the chain `catchlist'. */
1060 /* Fill in the components of c, and put it on the list. */
1064 c
.backlist
= backtrace_list
;
1065 c
.handlerlist
= handlerlist
;
1066 c
.lisp_eval_depth
= lisp_eval_depth
;
1067 c
.pdlcount
= specpdl_ptr
- specpdl
;
1068 c
.poll_suppress_count
= poll_suppress_count
;
1069 c
.gcpro
= gcprolist
;
1070 c
.byte_stack
= byte_stack_list
;
1074 if (! _setjmp (c
.jmp
))
1075 c
.val
= (*func
) (arg
);
1077 /* Throw works by a longjmp that comes right here. */
1082 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1083 jump to that CATCH, returning VALUE as the value of that catch.
1085 This is the guts Fthrow and Fsignal; they differ only in the way
1086 they choose the catch tag to throw to. A catch tag for a
1087 condition-case form has a TAG of Qnil.
1089 Before each catch is discarded, unbind all special bindings and
1090 execute all unwind-protect clauses made above that catch. Unwind
1091 the handler stack as we go, so that the proper handlers are in
1092 effect for each unwind-protect clause we run. At the end, restore
1093 some static info saved in CATCH, and longjmp to the location
1096 This is used for correct unwinding in Fthrow and Fsignal. */
1099 unwind_to_catch (catch, value
)
1100 struct catchtag
*catch;
1103 register int last_time
;
1105 /* Save the value in the tag. */
1108 /* Restore the polling-suppression count. */
1109 set_poll_suppress_count (catch->poll_suppress_count
);
1113 last_time
= catchlist
== catch;
1115 /* Unwind the specpdl stack, and then restore the proper set of
1117 unbind_to (catchlist
->pdlcount
, Qnil
);
1118 handlerlist
= catchlist
->handlerlist
;
1119 catchlist
= catchlist
->next
;
1121 while (! last_time
);
1123 byte_stack_list
= catch->byte_stack
;
1124 gcprolist
= catch->gcpro
;
1127 gcpro_level
= gcprolist
->level
+ 1;
1131 backtrace_list
= catch->backlist
;
1132 lisp_eval_depth
= catch->lisp_eval_depth
;
1134 _longjmp (catch->jmp
, 1);
1137 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1138 "Throw to the catch for TAG and return VALUE from it.\n\
1139 Both TAG and VALUE are evalled.")
1141 register Lisp_Object tag
, value
;
1143 register struct catchtag
*c
;
1148 for (c
= catchlist
; c
; c
= c
->next
)
1150 if (EQ (c
->tag
, tag
))
1151 unwind_to_catch (c
, value
);
1153 tag
= Fsignal (Qno_catch
, Fcons (tag
, Fcons (value
, Qnil
)));
1158 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1159 "Do BODYFORM, protecting with UNWINDFORMS.\n\
1160 If BODYFORM completes normally, its value is returned\n\
1161 after executing the UNWINDFORMS.\n\
1162 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.\n\
1163 usage: (unwind-protect BODYFORM UNWINDFORMS...)")
1168 int count
= specpdl_ptr
- specpdl
;
1170 record_unwind_protect (0, Fcdr (args
));
1171 val
= Feval (Fcar (args
));
1172 return unbind_to (count
, val
);
1175 /* Chain of condition handlers currently in effect.
1176 The elements of this chain are contained in the stack frames
1177 of Fcondition_case and internal_condition_case.
1178 When an error is signaled (by calling Fsignal, below),
1179 this chain is searched for an element that applies. */
1181 struct handler
*handlerlist
;
1183 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1184 "Regain control when an error is signaled.\n\
1185 executes BODYFORM and returns its value if no error happens.\n\
1186 Each element of HANDLERS looks like (CONDITION-NAME BODY...)\n\
1187 where the BODY is made of Lisp expressions.\n\n\
1188 A handler is applicable to an error\n\
1189 if CONDITION-NAME is one of the error's condition names.\n\
1190 If an error happens, the first applicable handler is run.\n\
1192 The car of a handler may be a list of condition names\n\
1193 instead of a single condition name.\n\
1195 When a handler handles an error,\n\
1196 control returns to the condition-case and the handler BODY... is executed\n\
1197 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).\n\
1198 VAR may be nil; then you do not get access to the signal information.\n\
1200 The value of the last BODY form is returned from the condition-case.\n\
1201 See also the function `signal' for more info.\n\
1202 usage: (condition-case VAR BODYFORM HANDLERS...)")
1209 register Lisp_Object bodyform
, handlers
;
1210 volatile Lisp_Object var
;
1213 bodyform
= Fcar (Fcdr (args
));
1214 handlers
= Fcdr (Fcdr (args
));
1215 CHECK_SYMBOL (var
, 0);
1217 for (val
= handlers
; ! NILP (val
); val
= Fcdr (val
))
1223 && (SYMBOLP (XCAR (tem
))
1224 || CONSP (XCAR (tem
))))))
1225 error ("Invalid condition handler", tem
);
1230 c
.backlist
= backtrace_list
;
1231 c
.handlerlist
= handlerlist
;
1232 c
.lisp_eval_depth
= lisp_eval_depth
;
1233 c
.pdlcount
= specpdl_ptr
- specpdl
;
1234 c
.poll_suppress_count
= poll_suppress_count
;
1235 c
.gcpro
= gcprolist
;
1236 c
.byte_stack
= byte_stack_list
;
1237 if (_setjmp (c
.jmp
))
1240 specbind (h
.var
, c
.val
);
1241 val
= Fprogn (Fcdr (h
.chosen_clause
));
1243 /* Note that this just undoes the binding of h.var; whoever
1244 longjumped to us unwound the stack to c.pdlcount before
1246 unbind_to (c
.pdlcount
, Qnil
);
1253 h
.handler
= handlers
;
1254 h
.next
= handlerlist
;
1258 val
= Feval (bodyform
);
1260 handlerlist
= h
.next
;
1264 /* Call the function BFUN with no arguments, catching errors within it
1265 according to HANDLERS. If there is an error, call HFUN with
1266 one argument which is the data that describes the error:
1269 HANDLERS can be a list of conditions to catch.
1270 If HANDLERS is Qt, catch all errors.
1271 If HANDLERS is Qerror, catch all errors
1272 but allow the debugger to run if that is enabled. */
1275 internal_condition_case (bfun
, handlers
, hfun
)
1276 Lisp_Object (*bfun
) ();
1277 Lisp_Object handlers
;
1278 Lisp_Object (*hfun
) ();
1284 #if 0 /* Can't do this check anymore because realize_basic_faces has
1285 to BLOCK_INPUT, and can call Lisp. What's really needed is a
1286 flag indicating that we're currently handling a signal. */
1287 /* Since Fsignal resets this to 0, it had better be 0 now
1288 or else we have a potential bug. */
1289 if (interrupt_input_blocked
!= 0)
1295 c
.backlist
= backtrace_list
;
1296 c
.handlerlist
= handlerlist
;
1297 c
.lisp_eval_depth
= lisp_eval_depth
;
1298 c
.pdlcount
= specpdl_ptr
- specpdl
;
1299 c
.poll_suppress_count
= poll_suppress_count
;
1300 c
.gcpro
= gcprolist
;
1301 c
.byte_stack
= byte_stack_list
;
1302 if (_setjmp (c
.jmp
))
1304 return (*hfun
) (c
.val
);
1308 h
.handler
= handlers
;
1310 h
.next
= handlerlist
;
1316 handlerlist
= h
.next
;
1320 /* Like internal_condition_case but call HFUN with ARG as its argument. */
1323 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1324 Lisp_Object (*bfun
) ();
1326 Lisp_Object handlers
;
1327 Lisp_Object (*hfun
) ();
1335 c
.backlist
= backtrace_list
;
1336 c
.handlerlist
= handlerlist
;
1337 c
.lisp_eval_depth
= lisp_eval_depth
;
1338 c
.pdlcount
= specpdl_ptr
- specpdl
;
1339 c
.poll_suppress_count
= poll_suppress_count
;
1340 c
.gcpro
= gcprolist
;
1341 c
.byte_stack
= byte_stack_list
;
1342 if (_setjmp (c
.jmp
))
1344 return (*hfun
) (c
.val
);
1348 h
.handler
= handlers
;
1350 h
.next
= handlerlist
;
1354 val
= (*bfun
) (arg
);
1356 handlerlist
= h
.next
;
1361 /* Like internal_condition_case but call HFUN with NARGS as first,
1362 and ARGS as second argument. */
1365 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1366 Lisp_Object (*bfun
) ();
1369 Lisp_Object handlers
;
1370 Lisp_Object (*hfun
) ();
1378 c
.backlist
= backtrace_list
;
1379 c
.handlerlist
= handlerlist
;
1380 c
.lisp_eval_depth
= lisp_eval_depth
;
1381 c
.pdlcount
= specpdl_ptr
- specpdl
;
1382 c
.poll_suppress_count
= poll_suppress_count
;
1383 c
.gcpro
= gcprolist
;
1384 c
.byte_stack
= byte_stack_list
;
1385 if (_setjmp (c
.jmp
))
1387 return (*hfun
) (c
.val
);
1391 h
.handler
= handlers
;
1393 h
.next
= handlerlist
;
1397 val
= (*bfun
) (nargs
, args
);
1399 handlerlist
= h
.next
;
1404 static Lisp_Object
find_handler_clause ();
1406 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1407 "Signal an error. Args are ERROR-SYMBOL and associated DATA.\n\
1408 This function does not return.\n\n\
1409 An error symbol is a symbol with an `error-conditions' property\n\
1410 that is a list of condition names.\n\
1411 A handler for any of those names will get to handle this signal.\n\
1412 The symbol `error' should normally be one of them.\n\
1414 DATA should be a list. Its elements are printed as part of the error message.\n\
1415 If the signal is handled, DATA is made available to the handler.\n\
1416 See also the function `condition-case'.")
1417 (error_symbol
, data
)
1418 Lisp_Object error_symbol
, data
;
1420 /* When memory is full, ERROR-SYMBOL is nil,
1421 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA). */
1422 register struct handler
*allhandlers
= handlerlist
;
1423 Lisp_Object conditions
;
1424 extern int gc_in_progress
;
1425 extern int waiting_for_input
;
1426 Lisp_Object debugger_value
;
1428 Lisp_Object real_error_symbol
;
1429 extern int display_hourglass_p
;
1430 struct backtrace
*bp
;
1432 immediate_quit
= handling_signal
= 0;
1433 if (gc_in_progress
|| waiting_for_input
)
1436 TOTALLY_UNBLOCK_INPUT
;
1438 if (NILP (error_symbol
))
1439 real_error_symbol
= Fcar (data
);
1441 real_error_symbol
= error_symbol
;
1443 #ifdef HAVE_X_WINDOWS
1444 if (display_hourglass_p
)
1445 cancel_hourglass ();
1448 /* This hook is used by edebug. */
1449 if (! NILP (Vsignal_hook_function
))
1450 call2 (Vsignal_hook_function
, error_symbol
, data
);
1452 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1454 /* Remember from where signal was called. Skip over the frame for
1455 `signal' itself. If a frame for `error' follows, skip that,
1457 Vsignaling_function
= Qnil
;
1460 bp
= backtrace_list
->next
;
1461 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1463 if (bp
&& bp
->function
)
1464 Vsignaling_function
= *bp
->function
;
1467 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1469 register Lisp_Object clause
;
1471 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1472 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1474 if (specpdl_size
+ 40 > max_specpdl_size
)
1475 max_specpdl_size
= specpdl_size
+ 40;
1477 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1478 error_symbol
, data
, &debugger_value
);
1480 #if 0 /* Most callers are not prepared to handle gc if this returns.
1481 So, since this feature is not very useful, take it out. */
1482 /* If have called debugger and user wants to continue,
1484 if (EQ (clause
, Qlambda
))
1485 return debugger_value
;
1487 if (EQ (clause
, Qlambda
))
1489 /* We can't return values to code which signaled an error, but we
1490 can continue code which has signaled a quit. */
1491 if (EQ (real_error_symbol
, Qquit
))
1494 error ("Cannot return from the debugger in an error");
1500 Lisp_Object unwind_data
;
1501 struct handler
*h
= handlerlist
;
1503 handlerlist
= allhandlers
;
1505 if (NILP (error_symbol
))
1508 unwind_data
= Fcons (error_symbol
, data
);
1509 h
->chosen_clause
= clause
;
1510 unwind_to_catch (h
->tag
, unwind_data
);
1514 handlerlist
= allhandlers
;
1515 /* If no handler is present now, try to run the debugger,
1516 and if that fails, throw to top level. */
1517 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1519 Fthrow (Qtop_level
, Qt
);
1521 if (! NILP (error_symbol
))
1522 data
= Fcons (error_symbol
, data
);
1524 string
= Ferror_message_string (data
);
1525 fatal ("%s", XSTRING (string
)->data
, 0);
1528 /* Return nonzero iff LIST is a non-nil atom or
1529 a list containing one of CONDITIONS. */
1532 wants_debugger (list
, conditions
)
1533 Lisp_Object list
, conditions
;
1540 while (CONSP (conditions
))
1542 Lisp_Object
this, tail
;
1543 this = XCAR (conditions
);
1544 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1545 if (EQ (XCAR (tail
), this))
1547 conditions
= XCDR (conditions
);
1552 /* Return 1 if an error with condition-symbols CONDITIONS,
1553 and described by SIGNAL-DATA, should skip the debugger
1554 according to debugger-ignore-errors. */
1557 skip_debugger (conditions
, data
)
1558 Lisp_Object conditions
, data
;
1561 int first_string
= 1;
1562 Lisp_Object error_message
;
1564 error_message
= Qnil
;
1565 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1567 if (STRINGP (XCAR (tail
)))
1571 error_message
= Ferror_message_string (data
);
1575 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1580 Lisp_Object contail
;
1582 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1583 if (EQ (XCAR (tail
), XCAR (contail
)))
1591 /* Value of Qlambda means we have called debugger and user has continued.
1592 There are two ways to pass SIG and DATA:
1593 = SIG is the error symbol, and DATA is the rest of the data.
1594 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1595 This is for memory-full errors only.
1597 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1600 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1601 Lisp_Object handlers
, conditions
, sig
, data
;
1602 Lisp_Object
*debugger_value_ptr
;
1604 register Lisp_Object h
;
1605 register Lisp_Object tem
;
1607 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1609 /* error is used similarly, but means print an error message
1610 and run the debugger if that is enabled. */
1611 if (EQ (handlers
, Qerror
)
1612 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1613 there is a handler. */
1615 int count
= specpdl_ptr
- specpdl
;
1616 int debugger_called
= 0;
1617 Lisp_Object sig_symbol
, combined_data
;
1618 /* This is set to 1 if we are handling a memory-full error,
1619 because these must not run the debugger.
1620 (There is no room in memory to do that!) */
1621 int no_debugger
= 0;
1625 combined_data
= data
;
1626 sig_symbol
= Fcar (data
);
1631 combined_data
= Fcons (sig
, data
);
1635 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1638 internal_with_output_to_temp_buffer ("*Backtrace*",
1639 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1642 internal_with_output_to_temp_buffer ("*Backtrace*",
1647 && (EQ (sig_symbol
, Qquit
)
1649 : wants_debugger (Vdebug_on_error
, conditions
))
1650 && ! skip_debugger (conditions
, combined_data
)
1651 && when_entered_debugger
< num_nonmacro_input_events
)
1653 specbind (Qdebug_on_error
, Qnil
);
1655 = call_debugger (Fcons (Qerror
,
1656 Fcons (combined_data
, Qnil
)));
1657 debugger_called
= 1;
1659 /* If there is no handler, return saying whether we ran the debugger. */
1660 if (EQ (handlers
, Qerror
))
1662 if (debugger_called
)
1663 return unbind_to (count
, Qlambda
);
1667 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1669 Lisp_Object handler
, condit
;
1672 if (!CONSP (handler
))
1674 condit
= Fcar (handler
);
1675 /* Handle a single condition name in handler HANDLER. */
1676 if (SYMBOLP (condit
))
1678 tem
= Fmemq (Fcar (handler
), conditions
);
1682 /* Handle a list of condition names in handler HANDLER. */
1683 else if (CONSP (condit
))
1685 while (CONSP (condit
))
1687 tem
= Fmemq (Fcar (condit
), conditions
);
1690 condit
= XCDR (condit
);
1697 /* dump an error message; called like printf */
1701 error (m
, a1
, a2
, a3
)
1721 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1726 buffer
= (char *) xrealloc (buffer
, size
);
1729 buffer
= (char *) xmalloc (size
);
1734 string
= build_string (buffer
);
1738 Fsignal (Qerror
, Fcons (string
, Qnil
));
1742 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 1, 0,
1743 "T if FUNCTION makes provisions for interactive calling.\n\
1744 This means it contains a description for how to read arguments to give it.\n\
1745 The value is nil for an invalid function or a symbol with no function\n\
1748 Interactively callable functions include strings and vectors (treated\n\
1749 as keyboard macros), lambda-expressions that contain a top-level call\n\
1750 to `interactive', autoload definitions made by `autoload' with non-nil\n\
1751 fourth argument, and some of the built-in functions of Lisp.\n\
1753 Also, a symbol satisfies `commandp' if its function definition does so.")
1755 Lisp_Object function
;
1757 register Lisp_Object fun
;
1758 register Lisp_Object funcar
;
1762 fun
= indirect_function (fun
);
1763 if (EQ (fun
, Qunbound
))
1766 /* Emacs primitives are interactive if their DEFUN specifies an
1767 interactive spec. */
1770 if (XSUBR (fun
)->prompt
)
1776 /* Bytecode objects are interactive if they are long enough to
1777 have an element whose index is COMPILED_INTERACTIVE, which is
1778 where the interactive spec is stored. */
1779 else if (COMPILEDP (fun
))
1780 return ((XVECTOR (fun
)->size
& PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1783 /* Strings and vectors are keyboard macros. */
1784 if (STRINGP (fun
) || VECTORP (fun
))
1787 /* Lists may represent commands. */
1790 funcar
= Fcar (fun
);
1791 if (!SYMBOLP (funcar
))
1792 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
1793 if (EQ (funcar
, Qlambda
))
1794 return Fassq (Qinteractive
, Fcdr (Fcdr (fun
)));
1795 if (EQ (funcar
, Qmocklisp
))
1796 return Qt
; /* All mocklisp functions can be called interactively */
1797 if (EQ (funcar
, Qautoload
))
1798 return Fcar (Fcdr (Fcdr (Fcdr (fun
))));
1804 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1805 "Define FUNCTION to autoload from FILE.\n\
1806 FUNCTION is a symbol; FILE is a file name string to pass to `load'.\n\
1807 Third arg DOCSTRING is documentation for the function.\n\
1808 Fourth arg INTERACTIVE if non-nil says function can be called interactively.\n\
1809 Fifth arg TYPE indicates the type of the object:\n\
1810 nil or omitted says FUNCTION is a function,\n\
1811 `keymap' says FUNCTION is really a keymap, and\n\
1812 `macro' or t says FUNCTION is really a macro.\n\
1813 Third through fifth args give info about the real definition.\n\
1814 They default to nil.\n\
1815 If FUNCTION is already defined other than as an autoload,\n\
1816 this does nothing and returns nil.")
1817 (function
, file
, docstring
, interactive
, type
)
1818 Lisp_Object function
, file
, docstring
, interactive
, type
;
1821 Lisp_Object args
[4];
1824 CHECK_SYMBOL (function
, 0);
1825 CHECK_STRING (file
, 1);
1827 /* If function is defined and not as an autoload, don't override */
1828 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
1829 && !(CONSP (XSYMBOL (function
)->function
)
1830 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
1833 if (NILP (Vpurify_flag
))
1834 /* Only add entries after dumping, because the ones before are
1835 not useful and else we get loads of them from the loaddefs.el. */
1836 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
1840 args
[1] = docstring
;
1841 args
[2] = interactive
;
1844 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
1845 #else /* NO_ARG_ARRAY */
1846 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
1847 #endif /* not NO_ARG_ARRAY */
1851 un_autoload (oldqueue
)
1852 Lisp_Object oldqueue
;
1854 register Lisp_Object queue
, first
, second
;
1856 /* Queue to unwind is current value of Vautoload_queue.
1857 oldqueue is the shadowed value to leave in Vautoload_queue. */
1858 queue
= Vautoload_queue
;
1859 Vautoload_queue
= oldqueue
;
1860 while (CONSP (queue
))
1862 first
= Fcar (queue
);
1863 second
= Fcdr (first
);
1864 first
= Fcar (first
);
1865 if (EQ (second
, Qnil
))
1868 Ffset (first
, second
);
1869 queue
= Fcdr (queue
);
1874 /* Load an autoloaded function.
1875 FUNNAME is the symbol which is the function's name.
1876 FUNDEF is the autoload definition (a list). */
1879 do_autoload (fundef
, funname
)
1880 Lisp_Object fundef
, funname
;
1882 int count
= specpdl_ptr
- specpdl
;
1883 Lisp_Object fun
, queue
, first
, second
;
1884 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1887 CHECK_SYMBOL (funname
, 0);
1888 GCPRO3 (fun
, funname
, fundef
);
1890 /* Preserve the match data. */
1891 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1893 /* Value saved here is to be restored into Vautoload_queue. */
1894 record_unwind_protect (un_autoload
, Vautoload_queue
);
1895 Vautoload_queue
= Qt
;
1896 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
1898 /* Save the old autoloads, in case we ever do an unload. */
1899 queue
= Vautoload_queue
;
1900 while (CONSP (queue
))
1902 first
= Fcar (queue
);
1903 second
= Fcdr (first
);
1904 first
= Fcar (first
);
1906 /* Note: This test is subtle. The cdr of an autoload-queue entry
1907 may be an atom if the autoload entry was generated by a defalias
1910 Fput (first
, Qautoload
, (Fcdr (second
)));
1912 queue
= Fcdr (queue
);
1915 /* Once loading finishes, don't undo it. */
1916 Vautoload_queue
= Qt
;
1917 unbind_to (count
, Qnil
);
1919 fun
= Findirect_function (fun
);
1921 if (!NILP (Fequal (fun
, fundef
)))
1922 error ("Autoloading failed to define function %s",
1923 XSYMBOL (funname
)->name
->data
);
1928 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
1929 "Evaluate FORM and return its value.")
1933 Lisp_Object fun
, val
, original_fun
, original_args
;
1935 struct backtrace backtrace
;
1936 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1938 if (handling_signal
)
1943 if (EQ (Vmocklisp_arguments
, Qt
))
1944 return Fsymbol_value (form
);
1945 val
= Fsymbol_value (form
);
1947 XSETFASTINT (val
, 0);
1948 else if (EQ (val
, Qt
))
1949 XSETFASTINT (val
, 1);
1956 if (consing_since_gc
> gc_cons_threshold
)
1959 Fgarbage_collect ();
1963 if (++lisp_eval_depth
> max_lisp_eval_depth
)
1965 if (max_lisp_eval_depth
< 100)
1966 max_lisp_eval_depth
= 100;
1967 if (lisp_eval_depth
> max_lisp_eval_depth
)
1968 error ("Lisp nesting exceeds max-lisp-eval-depth");
1971 original_fun
= Fcar (form
);
1972 original_args
= Fcdr (form
);
1974 backtrace
.next
= backtrace_list
;
1975 backtrace_list
= &backtrace
;
1976 backtrace
.function
= &original_fun
; /* This also protects them from gc */
1977 backtrace
.args
= &original_args
;
1978 backtrace
.nargs
= UNEVALLED
;
1979 backtrace
.evalargs
= 1;
1980 backtrace
.debug_on_exit
= 0;
1982 if (debug_on_next_call
)
1983 do_debug_on_call (Qt
);
1985 /* At this point, only original_fun and original_args
1986 have values that will be used below */
1988 fun
= Findirect_function (original_fun
);
1992 Lisp_Object numargs
;
1993 Lisp_Object argvals
[8];
1994 Lisp_Object args_left
;
1995 register int i
, maxargs
;
1997 args_left
= original_args
;
1998 numargs
= Flength (args_left
);
2000 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2001 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2002 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (numargs
, Qnil
)));
2004 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2006 backtrace
.evalargs
= 0;
2007 val
= (*XSUBR (fun
)->function
) (args_left
);
2011 if (XSUBR (fun
)->max_args
== MANY
)
2013 /* Pass a vector of evaluated arguments */
2015 register int argnum
= 0;
2017 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2019 GCPRO3 (args_left
, fun
, fun
);
2023 while (!NILP (args_left
))
2025 vals
[argnum
++] = Feval (Fcar (args_left
));
2026 args_left
= Fcdr (args_left
);
2027 gcpro3
.nvars
= argnum
;
2030 backtrace
.args
= vals
;
2031 backtrace
.nargs
= XINT (numargs
);
2033 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2038 GCPRO3 (args_left
, fun
, fun
);
2039 gcpro3
.var
= argvals
;
2042 maxargs
= XSUBR (fun
)->max_args
;
2043 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2045 argvals
[i
] = Feval (Fcar (args_left
));
2051 backtrace
.args
= argvals
;
2052 backtrace
.nargs
= XINT (numargs
);
2057 val
= (*XSUBR (fun
)->function
) ();
2060 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2063 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2066 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2070 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2071 argvals
[2], argvals
[3]);
2074 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2075 argvals
[3], argvals
[4]);
2078 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2079 argvals
[3], argvals
[4], argvals
[5]);
2082 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2083 argvals
[3], argvals
[4], argvals
[5],
2088 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2089 argvals
[3], argvals
[4], argvals
[5],
2090 argvals
[6], argvals
[7]);
2094 /* Someone has created a subr that takes more arguments than
2095 is supported by this code. We need to either rewrite the
2096 subr to use a different argument protocol, or add more
2097 cases to this switch. */
2101 if (COMPILEDP (fun
))
2102 val
= apply_lambda (fun
, original_args
, 1);
2106 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2107 funcar
= Fcar (fun
);
2108 if (!SYMBOLP (funcar
))
2109 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2110 if (EQ (funcar
, Qautoload
))
2112 do_autoload (fun
, original_fun
);
2115 if (EQ (funcar
, Qmacro
))
2116 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2117 else if (EQ (funcar
, Qlambda
))
2118 val
= apply_lambda (fun
, original_args
, 1);
2119 else if (EQ (funcar
, Qmocklisp
))
2120 val
= ml_apply (fun
, original_args
);
2122 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2125 if (!EQ (Vmocklisp_arguments
, Qt
))
2128 XSETFASTINT (val
, 0);
2129 else if (EQ (val
, Qt
))
2130 XSETFASTINT (val
, 1);
2133 if (backtrace
.debug_on_exit
)
2134 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2135 backtrace_list
= backtrace
.next
;
2139 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2140 "Call FUNCTION with our remaining args, using our last arg as list of args.\n\
2141 Then return the value FUNCTION returns.\n\
2142 Thus, (apply '+ 1 2 '(3 4)) returns 10.\n\
2143 usage: (apply FUNCTION &rest ARGUMENTS)")
2148 register int i
, numargs
;
2149 register Lisp_Object spread_arg
;
2150 register Lisp_Object
*funcall_args
;
2152 struct gcpro gcpro1
;
2156 spread_arg
= args
[nargs
- 1];
2157 CHECK_LIST (spread_arg
, nargs
);
2159 numargs
= XINT (Flength (spread_arg
));
2162 return Ffuncall (nargs
- 1, args
);
2163 else if (numargs
== 1)
2165 args
[nargs
- 1] = XCAR (spread_arg
);
2166 return Ffuncall (nargs
, args
);
2169 numargs
+= nargs
- 2;
2171 fun
= indirect_function (fun
);
2172 if (EQ (fun
, Qunbound
))
2174 /* Let funcall get the error */
2181 if (numargs
< XSUBR (fun
)->min_args
2182 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2183 goto funcall
; /* Let funcall get the error */
2184 else if (XSUBR (fun
)->max_args
> numargs
)
2186 /* Avoid making funcall cons up a yet another new vector of arguments
2187 by explicitly supplying nil's for optional values */
2188 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2189 * sizeof (Lisp_Object
));
2190 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2191 funcall_args
[++i
] = Qnil
;
2192 GCPRO1 (*funcall_args
);
2193 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2197 /* We add 1 to numargs because funcall_args includes the
2198 function itself as well as its arguments. */
2201 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2202 * sizeof (Lisp_Object
));
2203 GCPRO1 (*funcall_args
);
2204 gcpro1
.nvars
= 1 + numargs
;
2207 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2208 /* Spread the last arg we got. Its first element goes in
2209 the slot that it used to occupy, hence this value of I. */
2211 while (!NILP (spread_arg
))
2213 funcall_args
[i
++] = XCAR (spread_arg
);
2214 spread_arg
= XCDR (spread_arg
);
2217 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2220 /* Run hook variables in various ways. */
2222 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2224 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2225 "Run each hook in HOOKS. Major mode functions use this.\n\
2226 Each argument should be a symbol, a hook variable.\n\
2227 These symbols are processed in the order specified.\n\
2228 If a hook symbol has a non-nil value, that value may be a function\n\
2229 or a list of functions to be called to run the hook.\n\
2230 If the value is a function, it is called with no arguments.\n\
2231 If it is a list, the elements are called, in order, with no arguments.\n\
2233 To make a hook variable buffer-local, use `make-local-hook',\n\
2234 not `make-local-variable'.\n\
2235 usage: (run-hooks &rest HOOKS)")
2240 Lisp_Object hook
[1];
2243 for (i
= 0; i
< nargs
; i
++)
2246 run_hook_with_args (1, hook
, to_completion
);
2252 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2253 Srun_hook_with_args
, 1, MANY
, 0,
2254 "Run HOOK with the specified arguments ARGS.\n\
2255 HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\
2256 value, that value may be a function or a list of functions to be\n\
2257 called to run the hook. If the value is a function, it is called with\n\
2258 the given arguments and its return value is returned. If it is a list\n\
2259 of functions, those functions are called, in order,\n\
2260 with the given arguments ARGS.\n\
2261 It is best not to depend on the value return by `run-hook-with-args',\n\
2262 as that may change.\n\
2264 To make a hook variable buffer-local, use `make-local-hook',\n\
2265 not `make-local-variable'.\n\
2266 usage: (run-hook-with-args HOOK &rest ARGS)")
2271 return run_hook_with_args (nargs
, args
, to_completion
);
2274 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2275 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2276 "Run HOOK with the specified arguments ARGS.\n\
2277 HOOK should be a symbol, a hook variable. Its value should\n\
2278 be a list of functions. We call those functions, one by one,\n\
2279 passing arguments ARGS to each of them, until one of them\n\
2280 returns a non-nil value. Then we return that value.\n\
2281 If all the functions return nil, we return nil.\n\
2283 To make a hook variable buffer-local, use `make-local-hook',\n\
2284 not `make-local-variable'.\n\
2285 usage: (run-hook-with-args-until-success HOOK &rest ARGS)")
2290 return run_hook_with_args (nargs
, args
, until_success
);
2293 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2294 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2295 "Run HOOK with the specified arguments ARGS.\n\
2296 HOOK should be a symbol, a hook variable. Its value should\n\
2297 be a list of functions. We call those functions, one by one,\n\
2298 passing arguments ARGS to each of them, until one of them\n\
2299 returns nil. Then we return nil.\n\
2300 If all the functions return non-nil, we return non-nil.\n\
2302 To make a hook variable buffer-local, use `make-local-hook',\n\
2303 not `make-local-variable'.\n\
2304 usage: (run-hook-with-args-until-failure HOOK &rest ARGS)")
2309 return run_hook_with_args (nargs
, args
, until_failure
);
2312 /* ARGS[0] should be a hook symbol.
2313 Call each of the functions in the hook value, passing each of them
2314 as arguments all the rest of ARGS (all NARGS - 1 elements).
2315 COND specifies a condition to test after each call
2316 to decide whether to stop.
2317 The caller (or its caller, etc) must gcpro all of ARGS,
2318 except that it isn't necessary to gcpro ARGS[0]. */
2321 run_hook_with_args (nargs
, args
, cond
)
2324 enum run_hooks_condition cond
;
2326 Lisp_Object sym
, val
, ret
;
2327 Lisp_Object globals
;
2328 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2330 /* If we are dying or still initializing,
2331 don't do anything--it would probably crash if we tried. */
2332 if (NILP (Vrun_hooks
))
2336 val
= find_symbol_value (sym
);
2337 ret
= (cond
== until_failure
? Qt
: Qnil
);
2339 if (EQ (val
, Qunbound
) || NILP (val
))
2341 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2344 return Ffuncall (nargs
, args
);
2349 GCPRO3 (sym
, val
, globals
);
2352 CONSP (val
) && ((cond
== to_completion
)
2353 || (cond
== until_success
? NILP (ret
)
2357 if (EQ (XCAR (val
), Qt
))
2359 /* t indicates this hook has a local binding;
2360 it means to run the global binding too. */
2362 for (globals
= Fdefault_value (sym
);
2363 CONSP (globals
) && ((cond
== to_completion
)
2364 || (cond
== until_success
? NILP (ret
)
2366 globals
= XCDR (globals
))
2368 args
[0] = XCAR (globals
);
2369 /* In a global value, t should not occur. If it does, we
2370 must ignore it to avoid an endless loop. */
2371 if (!EQ (args
[0], Qt
))
2372 ret
= Ffuncall (nargs
, args
);
2377 args
[0] = XCAR (val
);
2378 ret
= Ffuncall (nargs
, args
);
2387 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2388 present value of that symbol.
2389 Call each element of FUNLIST,
2390 passing each of them the rest of ARGS.
2391 The caller (or its caller, etc) must gcpro all of ARGS,
2392 except that it isn't necessary to gcpro ARGS[0]. */
2395 run_hook_list_with_args (funlist
, nargs
, args
)
2396 Lisp_Object funlist
;
2402 Lisp_Object globals
;
2403 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2407 GCPRO3 (sym
, val
, globals
);
2409 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2411 if (EQ (XCAR (val
), Qt
))
2413 /* t indicates this hook has a local binding;
2414 it means to run the global binding too. */
2416 for (globals
= Fdefault_value (sym
);
2418 globals
= XCDR (globals
))
2420 args
[0] = XCAR (globals
);
2421 /* In a global value, t should not occur. If it does, we
2422 must ignore it to avoid an endless loop. */
2423 if (!EQ (args
[0], Qt
))
2424 Ffuncall (nargs
, args
);
2429 args
[0] = XCAR (val
);
2430 Ffuncall (nargs
, args
);
2437 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2440 run_hook_with_args_2 (hook
, arg1
, arg2
)
2441 Lisp_Object hook
, arg1
, arg2
;
2443 Lisp_Object temp
[3];
2448 Frun_hook_with_args (3, temp
);
2451 /* Apply fn to arg */
2454 Lisp_Object fn
, arg
;
2456 struct gcpro gcpro1
;
2460 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2464 Lisp_Object args
[2];
2468 RETURN_UNGCPRO (Fapply (2, args
));
2470 #else /* not NO_ARG_ARRAY */
2471 RETURN_UNGCPRO (Fapply (2, &fn
));
2472 #endif /* not NO_ARG_ARRAY */
2475 /* Call function fn on no arguments */
2480 struct gcpro gcpro1
;
2483 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2486 /* Call function fn with 1 argument arg1 */
2490 Lisp_Object fn
, arg1
;
2492 struct gcpro gcpro1
;
2494 Lisp_Object args
[2];
2500 RETURN_UNGCPRO (Ffuncall (2, args
));
2501 #else /* not NO_ARG_ARRAY */
2504 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2505 #endif /* not NO_ARG_ARRAY */
2508 /* Call function fn with 2 arguments arg1, arg2 */
2511 call2 (fn
, arg1
, arg2
)
2512 Lisp_Object fn
, arg1
, arg2
;
2514 struct gcpro gcpro1
;
2516 Lisp_Object args
[3];
2522 RETURN_UNGCPRO (Ffuncall (3, args
));
2523 #else /* not NO_ARG_ARRAY */
2526 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2527 #endif /* not NO_ARG_ARRAY */
2530 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2533 call3 (fn
, arg1
, arg2
, arg3
)
2534 Lisp_Object fn
, arg1
, arg2
, arg3
;
2536 struct gcpro gcpro1
;
2538 Lisp_Object args
[4];
2545 RETURN_UNGCPRO (Ffuncall (4, args
));
2546 #else /* not NO_ARG_ARRAY */
2549 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2550 #endif /* not NO_ARG_ARRAY */
2553 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2556 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2557 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2559 struct gcpro gcpro1
;
2561 Lisp_Object args
[5];
2569 RETURN_UNGCPRO (Ffuncall (5, args
));
2570 #else /* not NO_ARG_ARRAY */
2573 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2574 #endif /* not NO_ARG_ARRAY */
2577 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2580 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2581 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2583 struct gcpro gcpro1
;
2585 Lisp_Object args
[6];
2594 RETURN_UNGCPRO (Ffuncall (6, args
));
2595 #else /* not NO_ARG_ARRAY */
2598 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2599 #endif /* not NO_ARG_ARRAY */
2602 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2605 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2606 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2608 struct gcpro gcpro1
;
2610 Lisp_Object args
[7];
2620 RETURN_UNGCPRO (Ffuncall (7, args
));
2621 #else /* not NO_ARG_ARRAY */
2624 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2625 #endif /* not NO_ARG_ARRAY */
2628 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2629 "Call first argument as a function, passing remaining arguments to it.\n\
2630 Return the value that function returns.\n\
2631 Thus, (funcall 'cons 'x 'y) returns (x . y).\n\
2632 usage: (funcall FUNCTION &rest ARGUMENTS)")
2639 int numargs
= nargs
- 1;
2640 Lisp_Object lisp_numargs
;
2642 struct backtrace backtrace
;
2643 register Lisp_Object
*internal_args
;
2647 if (consing_since_gc
> gc_cons_threshold
)
2648 Fgarbage_collect ();
2650 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2652 if (max_lisp_eval_depth
< 100)
2653 max_lisp_eval_depth
= 100;
2654 if (lisp_eval_depth
> max_lisp_eval_depth
)
2655 error ("Lisp nesting exceeds max-lisp-eval-depth");
2658 backtrace
.next
= backtrace_list
;
2659 backtrace_list
= &backtrace
;
2660 backtrace
.function
= &args
[0];
2661 backtrace
.args
= &args
[1];
2662 backtrace
.nargs
= nargs
- 1;
2663 backtrace
.evalargs
= 0;
2664 backtrace
.debug_on_exit
= 0;
2666 if (debug_on_next_call
)
2667 do_debug_on_call (Qlambda
);
2673 fun
= Findirect_function (fun
);
2677 if (numargs
< XSUBR (fun
)->min_args
2678 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2680 XSETFASTINT (lisp_numargs
, numargs
);
2681 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2684 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2685 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2687 if (XSUBR (fun
)->max_args
== MANY
)
2689 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2693 if (XSUBR (fun
)->max_args
> numargs
)
2695 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2696 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2697 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2698 internal_args
[i
] = Qnil
;
2701 internal_args
= args
+ 1;
2702 switch (XSUBR (fun
)->max_args
)
2705 val
= (*XSUBR (fun
)->function
) ();
2708 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2711 val
= (*XSUBR (fun
)->function
) (internal_args
[0],
2715 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2719 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2724 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2725 internal_args
[2], internal_args
[3],
2729 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2730 internal_args
[2], internal_args
[3],
2731 internal_args
[4], internal_args
[5]);
2734 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2735 internal_args
[2], internal_args
[3],
2736 internal_args
[4], internal_args
[5],
2741 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2742 internal_args
[2], internal_args
[3],
2743 internal_args
[4], internal_args
[5],
2744 internal_args
[6], internal_args
[7]);
2749 /* If a subr takes more than 8 arguments without using MANY
2750 or UNEVALLED, we need to extend this function to support it.
2751 Until this is done, there is no way to call the function. */
2755 if (COMPILEDP (fun
))
2756 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2760 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2761 funcar
= Fcar (fun
);
2762 if (!SYMBOLP (funcar
))
2763 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2764 if (EQ (funcar
, Qlambda
))
2765 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2766 else if (EQ (funcar
, Qmocklisp
))
2767 val
= ml_apply (fun
, Flist (numargs
, args
+ 1));
2768 else if (EQ (funcar
, Qautoload
))
2770 do_autoload (fun
, args
[0]);
2774 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2778 if (backtrace
.debug_on_exit
)
2779 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2780 backtrace_list
= backtrace
.next
;
2785 apply_lambda (fun
, args
, eval_flag
)
2786 Lisp_Object fun
, args
;
2789 Lisp_Object args_left
;
2790 Lisp_Object numargs
;
2791 register Lisp_Object
*arg_vector
;
2792 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2794 register Lisp_Object tem
;
2796 numargs
= Flength (args
);
2797 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2800 GCPRO3 (*arg_vector
, args_left
, fun
);
2803 for (i
= 0; i
< XINT (numargs
);)
2805 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2806 if (eval_flag
) tem
= Feval (tem
);
2807 arg_vector
[i
++] = tem
;
2815 backtrace_list
->args
= arg_vector
;
2816 backtrace_list
->nargs
= i
;
2818 backtrace_list
->evalargs
= 0;
2819 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
2821 /* Do the debug-on-exit now, while arg_vector still exists. */
2822 if (backtrace_list
->debug_on_exit
)
2823 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
2824 /* Don't do it again when we return to eval. */
2825 backtrace_list
->debug_on_exit
= 0;
2829 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2830 and return the result of evaluation.
2831 FUN must be either a lambda-expression or a compiled-code object. */
2834 funcall_lambda (fun
, nargs
, arg_vector
)
2837 register Lisp_Object
*arg_vector
;
2839 Lisp_Object val
, syms_left
, next
;
2840 int count
= specpdl_ptr
- specpdl
;
2841 int i
, optional
, rest
;
2843 if (NILP (Vmocklisp_arguments
))
2844 specbind (Qmocklisp_arguments
, Qt
); /* t means NOT mocklisp! */
2848 syms_left
= XCDR (fun
);
2849 if (CONSP (syms_left
))
2850 syms_left
= XCAR (syms_left
);
2852 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2854 else if (COMPILEDP (fun
))
2855 syms_left
= XVECTOR (fun
)->contents
[COMPILED_ARGLIST
];
2859 i
= optional
= rest
= 0;
2860 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2864 next
= XCAR (syms_left
);
2865 while (!SYMBOLP (next
))
2866 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2868 if (EQ (next
, Qand_rest
))
2870 else if (EQ (next
, Qand_optional
))
2874 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
2878 specbind (next
, arg_vector
[i
++]);
2880 return Fsignal (Qwrong_number_of_arguments
,
2881 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2883 specbind (next
, Qnil
);
2886 if (!NILP (syms_left
))
2887 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2889 return Fsignal (Qwrong_number_of_arguments
,
2890 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2893 val
= Fprogn (XCDR (XCDR (fun
)));
2896 /* If we have not actually read the bytecode string
2897 and constants vector yet, fetch them from the file. */
2898 if (CONSP (XVECTOR (fun
)->contents
[COMPILED_BYTECODE
]))
2899 Ffetch_bytecode (fun
);
2900 val
= Fbyte_code (XVECTOR (fun
)->contents
[COMPILED_BYTECODE
],
2901 XVECTOR (fun
)->contents
[COMPILED_CONSTANTS
],
2902 XVECTOR (fun
)->contents
[COMPILED_STACK_DEPTH
]);
2905 return unbind_to (count
, val
);
2908 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2910 "If byte-compiled OBJECT is lazy-loaded, fetch it now.")
2916 if (COMPILEDP (object
)
2917 && CONSP (XVECTOR (object
)->contents
[COMPILED_BYTECODE
]))
2919 tem
= read_doc_string (XVECTOR (object
)->contents
[COMPILED_BYTECODE
]);
2921 error ("invalid byte code");
2922 XVECTOR (object
)->contents
[COMPILED_BYTECODE
] = XCAR (tem
);
2923 XVECTOR (object
)->contents
[COMPILED_CONSTANTS
] = XCDR (tem
);
2931 register int count
= specpdl_ptr
- specpdl
;
2932 if (specpdl_size
>= max_specpdl_size
)
2934 if (max_specpdl_size
< 400)
2935 max_specpdl_size
= 400;
2936 if (specpdl_size
>= max_specpdl_size
)
2938 if (!NILP (Vdebug_on_error
))
2939 /* Leave room for some specpdl in the debugger. */
2940 max_specpdl_size
= specpdl_size
+ 100;
2942 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
2946 if (specpdl_size
> max_specpdl_size
)
2947 specpdl_size
= max_specpdl_size
;
2948 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
2949 specpdl_ptr
= specpdl
+ count
;
2953 specbind (symbol
, value
)
2954 Lisp_Object symbol
, value
;
2957 Lisp_Object valcontents
;
2959 CHECK_SYMBOL (symbol
, 0);
2960 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2963 /* The most common case is that of a non-constant symbol with a
2964 trivial value. Make that as fast as we can. */
2965 valcontents
= SYMBOL_VALUE (symbol
);
2966 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
2968 specpdl_ptr
->symbol
= symbol
;
2969 specpdl_ptr
->old_value
= valcontents
;
2970 specpdl_ptr
->func
= NULL
;
2972 SET_SYMBOL_VALUE (symbol
, value
);
2976 Lisp_Object valcontents
;
2978 ovalue
= find_symbol_value (symbol
);
2979 specpdl_ptr
->func
= 0;
2980 specpdl_ptr
->old_value
= ovalue
;
2982 valcontents
= XSYMBOL (symbol
)->value
;
2984 if (BUFFER_LOCAL_VALUEP (valcontents
)
2985 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
2986 || BUFFER_OBJFWDP (valcontents
))
2988 Lisp_Object where
, current_buffer
;
2990 current_buffer
= Fcurrent_buffer ();
2992 /* For a local variable, record both the symbol and which
2993 buffer's or frame's value we are saving. */
2994 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
2995 where
= current_buffer
;
2996 else if (!BUFFER_OBJFWDP (valcontents
)
2997 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
2998 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3002 /* We're not using the `unused' slot in the specbinding
3003 structure because this would mean we have to do more
3004 work for simple variables. */
3005 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3007 /* If SYMBOL is a per-buffer variable which doesn't have a
3008 buffer-local value here, make the `let' change the global
3009 value by changing the value of SYMBOL in all buffers not
3010 having their own value. This is consistent with what
3011 happens with other buffer-local variables. */
3013 && BUFFER_OBJFWDP (valcontents
))
3016 Fset_default (symbol
, value
);
3021 specpdl_ptr
->symbol
= symbol
;
3024 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3025 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3027 set_internal (symbol
, value
, 0, 1);
3032 record_unwind_protect (function
, arg
)
3033 Lisp_Object (*function
) P_ ((Lisp_Object
));
3036 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3038 specpdl_ptr
->func
= function
;
3039 specpdl_ptr
->symbol
= Qnil
;
3040 specpdl_ptr
->old_value
= arg
;
3045 unbind_to (count
, value
)
3049 int quitf
= !NILP (Vquit_flag
);
3050 struct gcpro gcpro1
;
3055 while (specpdl_ptr
!= specpdl
+ count
)
3059 if (specpdl_ptr
->func
!= 0)
3060 (*specpdl_ptr
->func
) (specpdl_ptr
->old_value
);
3061 /* Note that a "binding" of nil is really an unwind protect,
3062 so in that case the "old value" is a list of forms to evaluate. */
3063 else if (NILP (specpdl_ptr
->symbol
))
3064 Fprogn (specpdl_ptr
->old_value
);
3065 /* If the symbol is a list, it is really (SYMBOL WHERE
3066 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3067 frame. If WHERE is a buffer or frame, this indicates we
3068 bound a variable that had a buffer-local or frmae-local
3069 binding.. WHERE nil means that the variable had the default
3070 value when it was bound. CURRENT-BUFFER is the buffer that
3071 was current when the variable was bound. */
3072 else if (CONSP (specpdl_ptr
->symbol
))
3074 Lisp_Object symbol
, where
;
3076 symbol
= XCAR (specpdl_ptr
->symbol
);
3077 where
= XCAR (XCDR (specpdl_ptr
->symbol
));
3080 Fset_default (symbol
, specpdl_ptr
->old_value
);
3081 else if (BUFFERP (where
))
3082 set_internal (symbol
, specpdl_ptr
->old_value
, XBUFFER (where
), 1);
3084 set_internal (symbol
, specpdl_ptr
->old_value
, NULL
, 1);
3088 /* If variable has a trivial value (no forwarding), we can
3089 just set it. No need to check for constant symbols here,
3090 since that was already done by specbind. */
3091 if (!MISCP (SYMBOL_VALUE (specpdl_ptr
->symbol
)))
3092 SET_SYMBOL_VALUE (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
);
3094 set_internal (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
, 0, 1);
3098 if (NILP (Vquit_flag
) && quitf
)
3107 /* Get the value of symbol's global binding, even if that binding
3108 is not now dynamically visible. */
3111 top_level_value (symbol
)
3114 register struct specbinding
*ptr
= specpdl
;
3116 CHECK_SYMBOL (symbol
, 0);
3117 for (; ptr
!= specpdl_ptr
; ptr
++)
3119 if (EQ (ptr
->symbol
, symbol
))
3120 return ptr
->old_value
;
3122 return Fsymbol_value (symbol
);
3126 top_level_set (symbol
, newval
)
3127 Lisp_Object symbol
, newval
;
3129 register struct specbinding
*ptr
= specpdl
;
3131 CHECK_SYMBOL (symbol
, 0);
3132 for (; ptr
!= specpdl_ptr
; ptr
++)
3134 if (EQ (ptr
->symbol
, symbol
))
3136 ptr
->old_value
= newval
;
3140 return Fset (symbol
, newval
);
3145 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3146 "Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.\n\
3147 The debugger is entered when that frame exits, if the flag is non-nil.")
3149 Lisp_Object level
, flag
;
3151 register struct backtrace
*backlist
= backtrace_list
;
3154 CHECK_NUMBER (level
, 0);
3156 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3158 backlist
= backlist
->next
;
3162 backlist
->debug_on_exit
= !NILP (flag
);
3167 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3168 "Print a trace of Lisp function calls currently active.\n\
3169 Output stream used is value of `standard-output'.")
3172 register struct backtrace
*backlist
= backtrace_list
;
3176 extern Lisp_Object Vprint_level
;
3177 struct gcpro gcpro1
;
3179 XSETFASTINT (Vprint_level
, 3);
3186 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3187 if (backlist
->nargs
== UNEVALLED
)
3189 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3190 write_string ("\n", -1);
3194 tem
= *backlist
->function
;
3195 Fprin1 (tem
, Qnil
); /* This can QUIT */
3196 write_string ("(", -1);
3197 if (backlist
->nargs
== MANY
)
3199 for (tail
= *backlist
->args
, i
= 0;
3201 tail
= Fcdr (tail
), i
++)
3203 if (i
) write_string (" ", -1);
3204 Fprin1 (Fcar (tail
), Qnil
);
3209 for (i
= 0; i
< backlist
->nargs
; i
++)
3211 if (i
) write_string (" ", -1);
3212 Fprin1 (backlist
->args
[i
], Qnil
);
3215 write_string (")\n", -1);
3217 backlist
= backlist
->next
;
3220 Vprint_level
= Qnil
;
3225 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3226 "Return the function and arguments NFRAMES up from current execution point.\n\
3227 If that frame has not evaluated the arguments yet (or is a special form),\n\
3228 the value is (nil FUNCTION ARG-FORMS...).\n\
3229 If that frame has evaluated its arguments and called its function already,\n\
3230 the value is (t FUNCTION ARG-VALUES...).\n\
3231 A &rest arg is represented as the tail of the list ARG-VALUES.\n\
3232 FUNCTION is whatever was supplied as car of evaluated list,\n\
3233 or a lambda expression for macro calls.\n\
3234 If NFRAMES is more than the number of frames, the value is nil.")
3236 Lisp_Object nframes
;
3238 register struct backtrace
*backlist
= backtrace_list
;
3242 CHECK_NATNUM (nframes
, 0);
3244 /* Find the frame requested. */
3245 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3246 backlist
= backlist
->next
;
3250 if (backlist
->nargs
== UNEVALLED
)
3251 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3254 if (backlist
->nargs
== MANY
)
3255 tem
= *backlist
->args
;
3257 tem
= Flist (backlist
->nargs
, backlist
->args
);
3259 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3267 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3268 "*Limit on number of Lisp variable bindings & unwind-protects.\n\
3269 If Lisp code tries to make more than this many at once,\n\
3270 an error is signaled.");
3272 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3273 "*Limit on depth in `eval', `apply' and `funcall' before error.\n\
3274 This limit is to catch infinite recursions for you before they cause\n\
3275 actual stack overflow in C, which would be fatal for Emacs.\n\
3276 You can safely make it considerably larger than its default value,\n\
3277 if that proves inconveniently small.");
3279 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3280 "Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.\n\
3281 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'.");
3284 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3285 "Non-nil inhibits C-g quitting from happening immediately.\n\
3286 Note that `quit-flag' will still be set by typing C-g,\n\
3287 so a quit will be signaled as soon as `inhibit-quit' is nil.\n\
3288 To prevent this happening, set `quit-flag' to nil\n\
3289 before making `inhibit-quit' nil.");
3290 Vinhibit_quit
= Qnil
;
3292 Qinhibit_quit
= intern ("inhibit-quit");
3293 staticpro (&Qinhibit_quit
);
3295 Qautoload
= intern ("autoload");
3296 staticpro (&Qautoload
);
3298 Qdebug_on_error
= intern ("debug-on-error");
3299 staticpro (&Qdebug_on_error
);
3301 Qmacro
= intern ("macro");
3302 staticpro (&Qmacro
);
3304 /* Note that the process handling also uses Qexit, but we don't want
3305 to staticpro it twice, so we just do it here. */
3306 Qexit
= intern ("exit");
3309 Qinteractive
= intern ("interactive");
3310 staticpro (&Qinteractive
);
3312 Qcommandp
= intern ("commandp");
3313 staticpro (&Qcommandp
);
3315 Qdefun
= intern ("defun");
3316 staticpro (&Qdefun
);
3318 Qand_rest
= intern ("&rest");
3319 staticpro (&Qand_rest
);
3321 Qand_optional
= intern ("&optional");
3322 staticpro (&Qand_optional
);
3324 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3325 "*Non-nil means automatically display a backtrace buffer\n\
3326 after any error that is handled by the editor command loop.\n\
3327 If the value is a list, an error only means to display a backtrace\n\
3328 if one of its condition symbols appears in the list.");
3329 Vstack_trace_on_error
= Qnil
;
3331 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3332 "*Non-nil means enter debugger if an error is signaled.\n\
3333 Does not apply to errors handled by `condition-case' or those\n\
3334 matched by `debug-ignored-errors'.\n\
3335 If the value is a list, an error only means to enter the debugger\n\
3336 if one of its condition symbols appears in the list.\n\
3337 When you evaluate an expression interactively, this variable\n\
3338 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.\n\
3339 See also variable `debug-on-quit'.");
3340 Vdebug_on_error
= Qnil
;
3342 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3343 "*List of errors for which the debugger should not be called.\n\
3344 Each element may be a condition-name or a regexp that matches error messages.\n\
3345 If any element applies to a given error, that error skips the debugger\n\
3346 and just returns to top level.\n\
3347 This overrides the variable `debug-on-error'.\n\
3348 It does not apply to errors handled by `condition-case'.");
3349 Vdebug_ignored_errors
= Qnil
;
3351 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3352 "*Non-nil means enter debugger if quit is signaled (C-g, for example).\n\
3353 Does not apply if quit is handled by a `condition-case'.\n\
3354 When you evaluate an expression interactively, this variable\n\
3355 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil.");
3358 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3359 "Non-nil means enter debugger before next `eval', `apply' or `funcall'.");
3361 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3362 "Non-nil means debugger may continue execution.\n\
3363 This is nil when the debugger is called under circumstances where it\n\
3364 might not be safe to continue.");
3365 debugger_may_continue
= 1;
3367 DEFVAR_LISP ("debugger", &Vdebugger
,
3368 "Function to call to invoke debugger.\n\
3369 If due to frame exit, args are `exit' and the value being returned;\n\
3370 this function's value will be returned instead of that.\n\
3371 If due to error, args are `error' and a list of the args to `signal'.\n\
3372 If due to `apply' or `funcall' entry, one arg, `lambda'.\n\
3373 If due to `eval' entry, one arg, t.");
3376 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3377 "If non-nil, this is a function for `signal' to call.\n\
3378 It receives the same arguments that `signal' was given.\n\
3379 The Edebug package uses this to regain control.");
3380 Vsignal_hook_function
= Qnil
;
3382 Qmocklisp_arguments
= intern ("mocklisp-arguments");
3383 staticpro (&Qmocklisp_arguments
);
3384 DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments
,
3385 "While in a mocklisp function, the list of its unevaluated args.");
3386 Vmocklisp_arguments
= Qt
;
3388 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3389 "*Non-nil means call the debugger regardless of condition handlers.\n\
3390 Note that `debug-on-error', `debug-on-quit' and friends\n\
3391 still determine whether to handle the particular condition.");
3392 Vdebug_on_signal
= Qnil
;
3394 Vrun_hooks
= intern ("run-hooks");
3395 staticpro (&Vrun_hooks
);
3397 staticpro (&Vautoload_queue
);
3398 Vautoload_queue
= Qnil
;
3399 staticpro (&Vsignaling_function
);
3400 Vsignaling_function
= Qnil
;
3411 defsubr (&Sfunction
);
3413 defsubr (&Sdefmacro
);
3415 defsubr (&Sdefvaralias
);
3416 defsubr (&Sdefconst
);
3417 defsubr (&Suser_variable_p
);
3421 defsubr (&Smacroexpand
);
3424 defsubr (&Sunwind_protect
);
3425 defsubr (&Scondition_case
);
3427 defsubr (&Sinteractive_p
);
3428 defsubr (&Scommandp
);
3429 defsubr (&Sautoload
);
3432 defsubr (&Sfuncall
);
3433 defsubr (&Srun_hooks
);
3434 defsubr (&Srun_hook_with_args
);
3435 defsubr (&Srun_hook_with_args_until_success
);
3436 defsubr (&Srun_hook_with_args_until_failure
);
3437 defsubr (&Sfetch_bytecode
);
3438 defsubr (&Sbacktrace_debug
);
3439 defsubr (&Sbacktrace
);
3440 defsubr (&Sbacktrace_frame
);