1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001, 2002
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
, Qdefvar
;
91 Lisp_Object Qinhibit_quit
, Vinhibit_quit
, Vquit_flag
;
92 Lisp_Object Qand_rest
, Qand_optional
;
93 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 EMACS_INT max_specpdl_size
;
125 /* Depth in Lisp evaluations and function calls. */
129 /* Maximum allowed depth in Lisp evaluations and function calls. */
131 EMACS_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 /* Function to process declarations in defmacro forms. */
195 Lisp_Object Vmacro_declaration_function
;
198 static Lisp_Object funcall_lambda
P_ ((Lisp_Object
, int, Lisp_Object
*));
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_INDEX ();
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
;
413 Lisp_Object args_left
;
424 val
= Feval (Fcar (args_left
));
425 args_left
= Fcdr (args_left
);
427 while (!NILP(args_left
));
433 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
434 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
435 The value of FIRST is saved during the evaluation of the remaining args,
436 whose values are discarded.
437 usage: (prog1 FIRST BODY...) */)
442 register Lisp_Object args_left
;
443 struct gcpro gcpro1
, gcpro2
;
444 register int argnum
= 0;
456 val
= Feval (Fcar (args_left
));
458 Feval (Fcar (args_left
));
459 args_left
= Fcdr (args_left
);
461 while (!NILP(args_left
));
467 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
468 doc
: /* Eval X, Y and BODY sequentially; value from Y.
469 The value of Y is saved during the evaluation of the remaining args,
470 whose values are discarded.
471 usage: (prog2 X Y BODY...) */)
476 register Lisp_Object args_left
;
477 struct gcpro gcpro1
, gcpro2
;
478 register int argnum
= -1;
492 val
= Feval (Fcar (args_left
));
494 Feval (Fcar (args_left
));
495 args_left
= Fcdr (args_left
);
497 while (!NILP (args_left
));
503 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
504 doc
: /* Set each SYM to the value of its VAL.
505 The symbols SYM are variables; they are literal (not evaluated).
506 The values VAL are expressions; they are evaluated.
507 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
508 The second VAL is not computed until after the first SYM is set, and so on;
509 each VAL can use the new value of variables set earlier in the `setq'.
510 The return value of the `setq' form is the value of the last VAL.
511 usage: (setq SYM VAL SYM VAL ...) */)
515 register Lisp_Object args_left
;
516 register Lisp_Object val
, sym
;
527 val
= Feval (Fcar (Fcdr (args_left
)));
528 sym
= Fcar (args_left
);
530 args_left
= Fcdr (Fcdr (args_left
));
532 while (!NILP(args_left
));
538 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
539 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
540 usage: (quote ARG) */)
547 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
548 doc
: /* Like `quote', but preferred for objects which are functions.
549 In byte compilation, `function' causes its argument to be compiled.
550 `quote' cannot do that.
551 usage: (function ARG) */)
559 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
560 doc
: /* Return t if function in which this appears was called interactively.
561 This means that the function was called with call-interactively (which
562 includes being called as the binding of a key)
563 and input is currently coming from the keyboard (not in keyboard macro). */)
566 return interactive_p (1) ? Qt
: Qnil
;
570 /* Return 1 if function in which this appears was called
571 interactively. This means that the function was called with
572 call-interactively (which includes being called as the binding of
573 a key) and input is currently coming from the keyboard (not in
576 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
577 called is a built-in. */
580 interactive_p (exclude_subrs_p
)
583 struct backtrace
*btp
;
589 btp
= backtrace_list
;
591 /* If this isn't a byte-compiled function, there may be a frame at
592 the top for Finteractive_p. If so, skip it. */
593 fun
= Findirect_function (*btp
->function
);
594 if (SUBRP (fun
) && XSUBR (fun
) == &Sinteractive_p
)
597 /* If we're running an Emacs 18-style byte-compiled function, there
598 may be a frame for Fbytecode at the top level. In any version of
599 Emacs there can be Fbytecode frames for subexpressions evaluated
600 inside catch and condition-case. Skip past them.
602 If this isn't a byte-compiled function, then we may now be
603 looking at several frames for special forms. Skip past them. */
605 && (EQ (*btp
->function
, Qbytecode
)
606 || btp
->nargs
== UNEVALLED
))
609 /* btp now points at the frame of the innermost function that isn't
610 a special form, ignoring frames for Finteractive_p and/or
611 Fbytecode at the top. If this frame is for a built-in function
612 (such as load or eval-region) return nil. */
613 fun
= Findirect_function (*btp
->function
);
614 if (exclude_subrs_p
&& SUBRP (fun
))
617 /* btp points to the frame of a Lisp function that called interactive-p.
618 Return t if that function was called interactively. */
619 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
625 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
626 doc
: /* Define NAME as a function.
627 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
628 See also the function `interactive'.
629 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
633 register Lisp_Object fn_name
;
634 register Lisp_Object defn
;
636 fn_name
= Fcar (args
);
637 defn
= Fcons (Qlambda
, Fcdr (args
));
638 if (!NILP (Vpurify_flag
))
639 defn
= Fpurecopy (defn
);
640 if (CONSP (XSYMBOL (fn_name
)->function
)
641 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
642 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
643 Ffset (fn_name
, defn
);
644 LOADHIST_ATTACH (fn_name
);
648 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
649 doc
: /* Define NAME as a macro.
650 The actual definition looks like
651 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
652 When the macro is called, as in (NAME ARGS...),
653 the function (lambda ARGLIST BODY...) is applied to
654 the list ARGS... as it appears in the expression,
655 and the result should be a form to be evaluated instead of the original.
657 DECL is a declaration, optional, which can specify how to indent
658 calls to this macro and how Edebug should handle it. It looks like this:
660 The elements can look like this:
662 Set NAME's `lisp-indent-function' property to INDENT.
665 Set NAME's `edebug-form-spec' property to DEBUG. (This is
666 equivalent to writing a `def-edebug-spec' for the macro.
667 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
671 register Lisp_Object fn_name
;
672 register Lisp_Object defn
;
673 Lisp_Object lambda_list
, doc
, tail
;
675 fn_name
= Fcar (args
);
676 lambda_list
= Fcar (Fcdr (args
));
677 tail
= Fcdr (Fcdr (args
));
680 if (STRINGP (Fcar (tail
)))
686 while (CONSP (Fcar (tail
))
687 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
689 if (!NILP (Vmacro_declaration_function
))
693 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
701 tail
= Fcons (lambda_list
, tail
);
703 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
704 defn
= Fcons (Qmacro
, Fcons (Qlambda
, tail
));
706 if (!NILP (Vpurify_flag
))
707 defn
= Fpurecopy (defn
);
708 if (CONSP (XSYMBOL (fn_name
)->function
)
709 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
710 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
711 Ffset (fn_name
, defn
);
712 LOADHIST_ATTACH (fn_name
);
717 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
718 doc
: /* Make SYMBOL a variable alias for symbol ALIASED.
719 Setting the value of SYMBOL will subsequently set the value of ALIASED,
720 and getting the value of SYMBOL will return the value ALIASED has.
721 ALIASED nil means remove the alias; SYMBOL is unbound after that.
722 Third arg DOCSTRING, if non-nil, is documentation for SYMBOL. */)
723 (symbol
, aliased
, docstring
)
724 Lisp_Object symbol
, aliased
, docstring
;
726 struct Lisp_Symbol
*sym
;
728 CHECK_SYMBOL (symbol
);
729 CHECK_SYMBOL (aliased
);
731 if (SYMBOL_CONSTANT_P (symbol
))
732 error ("Cannot make a constant an alias");
734 sym
= XSYMBOL (symbol
);
735 sym
->indirect_variable
= 1;
736 sym
->value
= aliased
;
737 sym
->constant
= SYMBOL_CONSTANT_P (aliased
);
738 LOADHIST_ATTACH (Fcons (Qdefvar
, symbol
));
739 if (!NILP (docstring
))
740 Fput (symbol
, Qvariable_documentation
, docstring
);
746 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
747 doc
: /* Define SYMBOL as a variable.
748 You are not required to define a variable in order to use it,
749 but the definition can supply documentation and an initial value
750 in a way that tags can recognize.
752 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
753 If SYMBOL is buffer-local, its default value is what is set;
754 buffer-local values are not affected.
755 INITVALUE and DOCSTRING are optional.
756 If DOCSTRING starts with *, this variable is identified as a user option.
757 This means that M-x set-variable recognizes it.
758 See also `user-variable-p'.
759 If INITVALUE is missing, SYMBOL's value is not set.
760 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
764 register Lisp_Object sym
, tem
, tail
;
768 if (!NILP (Fcdr (Fcdr (tail
))))
769 error ("too many arguments");
771 tem
= Fdefault_boundp (sym
);
775 Fset_default (sym
, Feval (Fcar (tail
)));
777 if (!NILP (Fcar (tail
)))
780 if (!NILP (Vpurify_flag
))
781 tem
= Fpurecopy (tem
);
782 Fput (sym
, Qvariable_documentation
, tem
);
784 LOADHIST_ATTACH (Fcons (Qdefvar
, sym
));
787 /* Simple (defvar <var>) should not count as a definition at all.
788 It could get in the way of other definitions, and unloading this
789 package could try to make the variable unbound. */
795 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
796 doc
: /* Define SYMBOL as a constant variable.
797 The intent is that neither programs nor users should ever change this value.
798 Always sets the value of SYMBOL to the result of evalling INITVALUE.
799 If SYMBOL is buffer-local, its default value is what is set;
800 buffer-local values are not affected.
801 DOCSTRING is optional.
802 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
806 register Lisp_Object sym
, tem
;
809 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
810 error ("too many arguments");
812 tem
= Feval (Fcar (Fcdr (args
)));
813 if (!NILP (Vpurify_flag
))
814 tem
= Fpurecopy (tem
);
815 Fset_default (sym
, tem
);
816 tem
= Fcar (Fcdr (Fcdr (args
)));
819 if (!NILP (Vpurify_flag
))
820 tem
= Fpurecopy (tem
);
821 Fput (sym
, Qvariable_documentation
, tem
);
823 LOADHIST_ATTACH (Fcons (Qdefvar
, sym
));
827 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
828 doc
: /* Returns t if VARIABLE is intended to be set and modified by users.
829 \(The alternative is a variable used internally in a Lisp program.)
830 Determined by whether the first character of the documentation
831 for the variable is `*' or if the variable is customizable (has a non-nil
832 value of any of `custom-type', `custom-loads' or `standard-value'
833 on its property list). */)
835 Lisp_Object variable
;
837 Lisp_Object documentation
;
839 if (!SYMBOLP (variable
))
842 documentation
= Fget (variable
, Qvariable_documentation
);
843 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
845 if (STRINGP (documentation
)
846 && ((unsigned char) SREF (documentation
, 0) == '*'))
848 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
849 if (CONSP (documentation
)
850 && STRINGP (XCAR (documentation
))
851 && INTEGERP (XCDR (documentation
))
852 && XINT (XCDR (documentation
)) < 0)
855 if ((!NILP (Fget (variable
, intern ("custom-type"))))
856 || (!NILP (Fget (variable
, intern ("custom-loads"))))
857 || (!NILP (Fget (variable
, intern ("standard-value")))))
862 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
863 doc
: /* Bind variables according to VARLIST then eval BODY.
864 The value of the last form in BODY is returned.
865 Each element of VARLIST is a symbol (which is bound to nil)
866 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
867 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
868 usage: (let* VARLIST BODY...) */)
872 Lisp_Object varlist
, val
, elt
;
873 int count
= SPECPDL_INDEX ();
874 struct gcpro gcpro1
, gcpro2
, gcpro3
;
876 GCPRO3 (args
, elt
, varlist
);
878 varlist
= Fcar (args
);
879 while (!NILP (varlist
))
882 elt
= Fcar (varlist
);
884 specbind (elt
, Qnil
);
885 else if (! NILP (Fcdr (Fcdr (elt
))))
887 Fcons (build_string ("`let' bindings can have only one value-form"),
891 val
= Feval (Fcar (Fcdr (elt
)));
892 specbind (Fcar (elt
), val
);
894 varlist
= Fcdr (varlist
);
897 val
= Fprogn (Fcdr (args
));
898 return unbind_to (count
, val
);
901 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
902 doc
: /* Bind variables according to VARLIST then eval BODY.
903 The value of the last form in BODY is returned.
904 Each element of VARLIST is a symbol (which is bound to nil)
905 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
906 All the VALUEFORMs are evalled before any symbols are bound.
907 usage: (let VARLIST BODY...) */)
911 Lisp_Object
*temps
, tem
;
912 register Lisp_Object elt
, varlist
;
913 int count
= SPECPDL_INDEX ();
915 struct gcpro gcpro1
, gcpro2
;
917 varlist
= Fcar (args
);
919 /* Make space to hold the values to give the bound variables */
920 elt
= Flength (varlist
);
921 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
923 /* Compute the values and store them in `temps' */
925 GCPRO2 (args
, *temps
);
928 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
931 elt
= Fcar (varlist
);
933 temps
[argnum
++] = Qnil
;
934 else if (! NILP (Fcdr (Fcdr (elt
))))
936 Fcons (build_string ("`let' bindings can have only one value-form"),
939 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
940 gcpro2
.nvars
= argnum
;
944 varlist
= Fcar (args
);
945 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
947 elt
= Fcar (varlist
);
948 tem
= temps
[argnum
++];
952 specbind (Fcar (elt
), tem
);
955 elt
= Fprogn (Fcdr (args
));
956 return unbind_to (count
, elt
);
959 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
960 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
961 The order of execution is thus TEST, BODY, TEST, BODY and so on
962 until TEST returns nil.
963 usage: (while TEST BODY...) */)
967 Lisp_Object test
, body
;
968 struct gcpro gcpro1
, gcpro2
;
974 while (!NILP (Feval (test
)))
984 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
985 doc
: /* Return result of expanding macros at top level of FORM.
986 If FORM is not a macro call, it is returned unchanged.
987 Otherwise, the macro is expanded and the expansion is considered
988 in place of FORM. When a non-macro-call results, it is returned.
990 The second optional arg ENVIRONMENT specifies an environment of macro
991 definitions to shadow the loaded ones for use in file byte-compilation. */)
994 Lisp_Object environment
;
996 /* With cleanups from Hallvard Furuseth. */
997 register Lisp_Object expander
, sym
, def
, tem
;
1001 /* Come back here each time we expand a macro call,
1002 in case it expands into another macro call. */
1005 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1006 def
= sym
= XCAR (form
);
1008 /* Trace symbols aliases to other symbols
1009 until we get a symbol that is not an alias. */
1010 while (SYMBOLP (def
))
1014 tem
= Fassq (sym
, environment
);
1017 def
= XSYMBOL (sym
)->function
;
1018 if (!EQ (def
, Qunbound
))
1023 /* Right now TEM is the result from SYM in ENVIRONMENT,
1024 and if TEM is nil then DEF is SYM's function definition. */
1027 /* SYM is not mentioned in ENVIRONMENT.
1028 Look at its function definition. */
1029 if (EQ (def
, Qunbound
) || !CONSP (def
))
1030 /* Not defined or definition not suitable */
1032 if (EQ (XCAR (def
), Qautoload
))
1034 /* Autoloading function: will it be a macro when loaded? */
1035 tem
= Fnth (make_number (4), def
);
1036 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1037 /* Yes, load it and try again. */
1039 struct gcpro gcpro1
;
1041 do_autoload (def
, sym
);
1048 else if (!EQ (XCAR (def
), Qmacro
))
1050 else expander
= XCDR (def
);
1054 expander
= XCDR (tem
);
1055 if (NILP (expander
))
1058 form
= apply1 (expander
, XCDR (form
));
1063 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1064 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1065 TAG is evalled to get the tag to use; it must not be nil.
1067 Then the BODY is executed.
1068 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1069 If no throw happens, `catch' returns the value of the last BODY form.
1070 If a throw happens, it specifies the value to return from `catch'.
1071 usage: (catch TAG BODY...) */)
1075 register Lisp_Object tag
;
1076 struct gcpro gcpro1
;
1079 tag
= Feval (Fcar (args
));
1081 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1084 /* Set up a catch, then call C function FUNC on argument ARG.
1085 FUNC should return a Lisp_Object.
1086 This is how catches are done from within C code. */
1089 internal_catch (tag
, func
, arg
)
1091 Lisp_Object (*func
) ();
1094 /* This structure is made part of the chain `catchlist'. */
1097 /* Fill in the components of c, and put it on the list. */
1101 c
.backlist
= backtrace_list
;
1102 c
.handlerlist
= handlerlist
;
1103 c
.lisp_eval_depth
= lisp_eval_depth
;
1104 c
.pdlcount
= SPECPDL_INDEX ();
1105 c
.poll_suppress_count
= poll_suppress_count
;
1106 c
.gcpro
= gcprolist
;
1107 c
.byte_stack
= byte_stack_list
;
1111 if (! _setjmp (c
.jmp
))
1112 c
.val
= (*func
) (arg
);
1114 /* Throw works by a longjmp that comes right here. */
1119 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1120 jump to that CATCH, returning VALUE as the value of that catch.
1122 This is the guts Fthrow and Fsignal; they differ only in the way
1123 they choose the catch tag to throw to. A catch tag for a
1124 condition-case form has a TAG of Qnil.
1126 Before each catch is discarded, unbind all special bindings and
1127 execute all unwind-protect clauses made above that catch. Unwind
1128 the handler stack as we go, so that the proper handlers are in
1129 effect for each unwind-protect clause we run. At the end, restore
1130 some static info saved in CATCH, and longjmp to the location
1133 This is used for correct unwinding in Fthrow and Fsignal. */
1136 unwind_to_catch (catch, value
)
1137 struct catchtag
*catch;
1140 register int last_time
;
1142 /* Save the value in the tag. */
1145 /* Restore the polling-suppression count. */
1146 set_poll_suppress_count (catch->poll_suppress_count
);
1150 last_time
= catchlist
== catch;
1152 /* Unwind the specpdl stack, and then restore the proper set of
1154 unbind_to (catchlist
->pdlcount
, Qnil
);
1155 handlerlist
= catchlist
->handlerlist
;
1156 catchlist
= catchlist
->next
;
1158 while (! last_time
);
1160 byte_stack_list
= catch->byte_stack
;
1161 gcprolist
= catch->gcpro
;
1164 gcpro_level
= gcprolist
->level
+ 1;
1168 backtrace_list
= catch->backlist
;
1169 lisp_eval_depth
= catch->lisp_eval_depth
;
1171 _longjmp (catch->jmp
, 1);
1174 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1175 doc
: /* Throw to the catch for TAG and return VALUE from it.
1176 Both TAG and VALUE are evalled. */)
1178 register Lisp_Object tag
, value
;
1180 register struct catchtag
*c
;
1185 for (c
= catchlist
; c
; c
= c
->next
)
1187 if (EQ (c
->tag
, tag
))
1188 unwind_to_catch (c
, value
);
1190 tag
= Fsignal (Qno_catch
, Fcons (tag
, Fcons (value
, Qnil
)));
1195 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1196 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1197 If BODYFORM completes normally, its value is returned
1198 after executing the UNWINDFORMS.
1199 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1200 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1205 int count
= SPECPDL_INDEX ();
1207 record_unwind_protect (0, Fcdr (args
));
1208 val
= Feval (Fcar (args
));
1209 return unbind_to (count
, val
);
1212 /* Chain of condition handlers currently in effect.
1213 The elements of this chain are contained in the stack frames
1214 of Fcondition_case and internal_condition_case.
1215 When an error is signaled (by calling Fsignal, below),
1216 this chain is searched for an element that applies. */
1218 struct handler
*handlerlist
;
1220 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1221 doc
: /* Regain control when an error is signaled.
1222 Executes BODYFORM and returns its value if no error happens.
1223 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1224 where the BODY is made of Lisp expressions.
1226 A handler is applicable to an error
1227 if CONDITION-NAME is one of the error's condition names.
1228 If an error happens, the first applicable handler is run.
1230 The car of a handler may be a list of condition names
1231 instead of a single condition name.
1233 When a handler handles an error,
1234 control returns to the condition-case and the handler BODY... is executed
1235 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1236 VAR may be nil; then you do not get access to the signal information.
1238 The value of the last BODY form is returned from the condition-case.
1239 See also the function `signal' for more info.
1240 usage: (condition-case VAR BODYFORM HANDLERS...) */)
1247 register Lisp_Object bodyform
, handlers
;
1248 volatile Lisp_Object var
;
1251 bodyform
= Fcar (Fcdr (args
));
1252 handlers
= Fcdr (Fcdr (args
));
1255 for (val
= handlers
; ! NILP (val
); val
= Fcdr (val
))
1261 && (SYMBOLP (XCAR (tem
))
1262 || CONSP (XCAR (tem
))))))
1263 error ("Invalid condition handler", tem
);
1268 c
.backlist
= backtrace_list
;
1269 c
.handlerlist
= handlerlist
;
1270 c
.lisp_eval_depth
= lisp_eval_depth
;
1271 c
.pdlcount
= SPECPDL_INDEX ();
1272 c
.poll_suppress_count
= poll_suppress_count
;
1273 c
.gcpro
= gcprolist
;
1274 c
.byte_stack
= byte_stack_list
;
1275 if (_setjmp (c
.jmp
))
1278 specbind (h
.var
, c
.val
);
1279 val
= Fprogn (Fcdr (h
.chosen_clause
));
1281 /* Note that this just undoes the binding of h.var; whoever
1282 longjumped to us unwound the stack to c.pdlcount before
1284 unbind_to (c
.pdlcount
, Qnil
);
1291 h
.handler
= handlers
;
1292 h
.next
= handlerlist
;
1296 val
= Feval (bodyform
);
1298 handlerlist
= h
.next
;
1302 /* Call the function BFUN with no arguments, catching errors within it
1303 according to HANDLERS. If there is an error, call HFUN with
1304 one argument which is the data that describes the error:
1307 HANDLERS can be a list of conditions to catch.
1308 If HANDLERS is Qt, catch all errors.
1309 If HANDLERS is Qerror, catch all errors
1310 but allow the debugger to run if that is enabled. */
1313 internal_condition_case (bfun
, handlers
, hfun
)
1314 Lisp_Object (*bfun
) ();
1315 Lisp_Object handlers
;
1316 Lisp_Object (*hfun
) ();
1322 #if 0 /* Can't do this check anymore because realize_basic_faces has
1323 to BLOCK_INPUT, and can call Lisp. What's really needed is a
1324 flag indicating that we're currently handling a signal. */
1325 /* Since Fsignal resets this to 0, it had better be 0 now
1326 or else we have a potential bug. */
1327 if (interrupt_input_blocked
!= 0)
1333 c
.backlist
= backtrace_list
;
1334 c
.handlerlist
= handlerlist
;
1335 c
.lisp_eval_depth
= lisp_eval_depth
;
1336 c
.pdlcount
= SPECPDL_INDEX ();
1337 c
.poll_suppress_count
= poll_suppress_count
;
1338 c
.gcpro
= gcprolist
;
1339 c
.byte_stack
= byte_stack_list
;
1340 if (_setjmp (c
.jmp
))
1342 return (*hfun
) (c
.val
);
1346 h
.handler
= handlers
;
1348 h
.next
= handlerlist
;
1354 handlerlist
= h
.next
;
1358 /* Like internal_condition_case but call HFUN with ARG as its argument. */
1361 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1362 Lisp_Object (*bfun
) ();
1364 Lisp_Object handlers
;
1365 Lisp_Object (*hfun
) ();
1373 c
.backlist
= backtrace_list
;
1374 c
.handlerlist
= handlerlist
;
1375 c
.lisp_eval_depth
= lisp_eval_depth
;
1376 c
.pdlcount
= SPECPDL_INDEX ();
1377 c
.poll_suppress_count
= poll_suppress_count
;
1378 c
.gcpro
= gcprolist
;
1379 c
.byte_stack
= byte_stack_list
;
1380 if (_setjmp (c
.jmp
))
1382 return (*hfun
) (c
.val
);
1386 h
.handler
= handlers
;
1388 h
.next
= handlerlist
;
1392 val
= (*bfun
) (arg
);
1394 handlerlist
= h
.next
;
1399 /* Like internal_condition_case but call HFUN with NARGS as first,
1400 and ARGS as second argument. */
1403 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1404 Lisp_Object (*bfun
) ();
1407 Lisp_Object handlers
;
1408 Lisp_Object (*hfun
) ();
1416 c
.backlist
= backtrace_list
;
1417 c
.handlerlist
= handlerlist
;
1418 c
.lisp_eval_depth
= lisp_eval_depth
;
1419 c
.pdlcount
= SPECPDL_INDEX ();
1420 c
.poll_suppress_count
= poll_suppress_count
;
1421 c
.gcpro
= gcprolist
;
1422 c
.byte_stack
= byte_stack_list
;
1423 if (_setjmp (c
.jmp
))
1425 return (*hfun
) (c
.val
);
1429 h
.handler
= handlers
;
1431 h
.next
= handlerlist
;
1435 val
= (*bfun
) (nargs
, args
);
1437 handlerlist
= h
.next
;
1442 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1443 Lisp_Object
, Lisp_Object
,
1446 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1447 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1448 This function does not return.
1450 An error symbol is a symbol with an `error-conditions' property
1451 that is a list of condition names.
1452 A handler for any of those names will get to handle this signal.
1453 The symbol `error' should normally be one of them.
1455 DATA should be a list. Its elements are printed as part of the error message.
1456 If the signal is handled, DATA is made available to the handler.
1457 See also the function `condition-case'. */)
1458 (error_symbol
, data
)
1459 Lisp_Object error_symbol
, data
;
1461 /* When memory is full, ERROR-SYMBOL is nil,
1462 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1463 That is a special case--don't do this in other situations. */
1464 register struct handler
*allhandlers
= handlerlist
;
1465 Lisp_Object conditions
;
1466 extern int gc_in_progress
;
1467 extern int waiting_for_input
;
1468 Lisp_Object debugger_value
;
1470 Lisp_Object real_error_symbol
;
1471 struct backtrace
*bp
;
1473 immediate_quit
= handling_signal
= 0;
1474 if (gc_in_progress
|| waiting_for_input
)
1477 TOTALLY_UNBLOCK_INPUT
;
1479 if (NILP (error_symbol
))
1480 real_error_symbol
= Fcar (data
);
1482 real_error_symbol
= error_symbol
;
1484 #if 0 /* rms: I don't know why this was here,
1485 but it is surely wrong for an error that is handled. */
1486 #ifdef HAVE_X_WINDOWS
1487 if (display_hourglass_p
)
1488 cancel_hourglass ();
1492 /* This hook is used by edebug. */
1493 if (! NILP (Vsignal_hook_function
)
1494 && ! NILP (error_symbol
))
1495 call2 (Vsignal_hook_function
, error_symbol
, data
);
1497 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1499 /* Remember from where signal was called. Skip over the frame for
1500 `signal' itself. If a frame for `error' follows, skip that,
1501 too. Don't do this when ERROR_SYMBOL is nil, because that
1502 is a memory-full error. */
1503 Vsignaling_function
= Qnil
;
1504 if (backtrace_list
&& !NILP (error_symbol
))
1506 bp
= backtrace_list
->next
;
1507 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1509 if (bp
&& bp
->function
)
1510 Vsignaling_function
= *bp
->function
;
1513 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1515 register Lisp_Object clause
;
1517 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1518 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1520 if (specpdl_size
+ 40 > max_specpdl_size
)
1521 max_specpdl_size
= specpdl_size
+ 40;
1523 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1524 error_symbol
, data
, &debugger_value
);
1526 if (EQ (clause
, Qlambda
))
1528 /* We can't return values to code which signaled an error, but we
1529 can continue code which has signaled a quit. */
1530 if (EQ (real_error_symbol
, Qquit
))
1533 error ("Cannot return from the debugger in an error");
1538 Lisp_Object unwind_data
;
1539 struct handler
*h
= handlerlist
;
1541 handlerlist
= allhandlers
;
1543 if (NILP (error_symbol
))
1546 unwind_data
= Fcons (error_symbol
, data
);
1547 h
->chosen_clause
= clause
;
1548 unwind_to_catch (h
->tag
, unwind_data
);
1552 handlerlist
= allhandlers
;
1553 /* If no handler is present now, try to run the debugger,
1554 and if that fails, throw to top level. */
1555 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1557 Fthrow (Qtop_level
, Qt
);
1559 if (! NILP (error_symbol
))
1560 data
= Fcons (error_symbol
, data
);
1562 string
= Ferror_message_string (data
);
1563 fatal ("%s", SDATA (string
), 0);
1566 /* Return nonzero iff LIST is a non-nil atom or
1567 a list containing one of CONDITIONS. */
1570 wants_debugger (list
, conditions
)
1571 Lisp_Object list
, conditions
;
1578 while (CONSP (conditions
))
1580 Lisp_Object
this, tail
;
1581 this = XCAR (conditions
);
1582 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1583 if (EQ (XCAR (tail
), this))
1585 conditions
= XCDR (conditions
);
1590 /* Return 1 if an error with condition-symbols CONDITIONS,
1591 and described by SIGNAL-DATA, should skip the debugger
1592 according to debugger-ignored-errors. */
1595 skip_debugger (conditions
, data
)
1596 Lisp_Object conditions
, data
;
1599 int first_string
= 1;
1600 Lisp_Object error_message
;
1602 error_message
= Qnil
;
1603 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1605 if (STRINGP (XCAR (tail
)))
1609 error_message
= Ferror_message_string (data
);
1613 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1618 Lisp_Object contail
;
1620 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1621 if (EQ (XCAR (tail
), XCAR (contail
)))
1629 /* Value of Qlambda means we have called debugger and user has continued.
1630 There are two ways to pass SIG and DATA:
1631 = SIG is the error symbol, and DATA is the rest of the data.
1632 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1633 This is for memory-full errors only.
1635 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1638 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1639 Lisp_Object handlers
, conditions
, sig
, data
;
1640 Lisp_Object
*debugger_value_ptr
;
1642 register Lisp_Object h
;
1643 register Lisp_Object tem
;
1645 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1647 /* error is used similarly, but means print an error message
1648 and run the debugger if that is enabled. */
1649 if (EQ (handlers
, Qerror
)
1650 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1651 there is a handler. */
1653 int count
= SPECPDL_INDEX ();
1654 int debugger_called
= 0;
1655 Lisp_Object sig_symbol
, combined_data
;
1656 /* This is set to 1 if we are handling a memory-full error,
1657 because these must not run the debugger.
1658 (There is no room in memory to do that!) */
1659 int no_debugger
= 0;
1663 combined_data
= data
;
1664 sig_symbol
= Fcar (data
);
1669 combined_data
= Fcons (sig
, data
);
1673 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1676 internal_with_output_to_temp_buffer ("*Backtrace*",
1677 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1680 internal_with_output_to_temp_buffer ("*Backtrace*",
1685 && (EQ (sig_symbol
, Qquit
)
1687 : wants_debugger (Vdebug_on_error
, conditions
))
1688 && ! skip_debugger (conditions
, combined_data
)
1689 && when_entered_debugger
< num_nonmacro_input_events
)
1691 specbind (Qdebug_on_error
, Qnil
);
1693 = call_debugger (Fcons (Qerror
,
1694 Fcons (combined_data
, Qnil
)));
1695 debugger_called
= 1;
1697 /* If there is no handler, return saying whether we ran the debugger. */
1698 if (EQ (handlers
, Qerror
))
1700 if (debugger_called
)
1701 return unbind_to (count
, Qlambda
);
1705 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1707 Lisp_Object handler
, condit
;
1710 if (!CONSP (handler
))
1712 condit
= Fcar (handler
);
1713 /* Handle a single condition name in handler HANDLER. */
1714 if (SYMBOLP (condit
))
1716 tem
= Fmemq (Fcar (handler
), conditions
);
1720 /* Handle a list of condition names in handler HANDLER. */
1721 else if (CONSP (condit
))
1723 while (CONSP (condit
))
1725 tem
= Fmemq (Fcar (condit
), conditions
);
1728 condit
= XCDR (condit
);
1735 /* dump an error message; called like printf */
1739 error (m
, a1
, a2
, a3
)
1759 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1764 buffer
= (char *) xrealloc (buffer
, size
);
1767 buffer
= (char *) xmalloc (size
);
1772 string
= build_string (buffer
);
1776 Fsignal (Qerror
, Fcons (string
, Qnil
));
1780 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1781 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1782 This means it contains a description for how to read arguments to give it.
1783 The value is nil for an invalid function or a symbol with no function
1786 Interactively callable functions include strings and vectors (treated
1787 as keyboard macros), lambda-expressions that contain a top-level call
1788 to `interactive', autoload definitions made by `autoload' with non-nil
1789 fourth argument, and some of the built-in functions of Lisp.
1791 Also, a symbol satisfies `commandp' if its function definition does so.
1793 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1794 then strings and vectors are not accepted. */)
1795 (function
, for_call_interactively
)
1796 Lisp_Object function
, for_call_interactively
;
1798 register Lisp_Object fun
;
1799 register Lisp_Object funcar
;
1803 fun
= indirect_function (fun
);
1804 if (EQ (fun
, Qunbound
))
1807 /* Emacs primitives are interactive if their DEFUN specifies an
1808 interactive spec. */
1811 if (XSUBR (fun
)->prompt
)
1817 /* Bytecode objects are interactive if they are long enough to
1818 have an element whose index is COMPILED_INTERACTIVE, which is
1819 where the interactive spec is stored. */
1820 else if (COMPILEDP (fun
))
1821 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1824 /* Strings and vectors are keyboard macros. */
1825 if (NILP (for_call_interactively
) && (STRINGP (fun
) || VECTORP (fun
)))
1828 /* Lists may represent commands. */
1831 funcar
= Fcar (fun
);
1832 if (!SYMBOLP (funcar
))
1833 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
1834 if (EQ (funcar
, Qlambda
))
1835 return Fassq (Qinteractive
, Fcdr (Fcdr (fun
)));
1836 if (EQ (funcar
, Qautoload
))
1837 return Fcar (Fcdr (Fcdr (Fcdr (fun
))));
1843 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1844 doc
: /* Define FUNCTION to autoload from FILE.
1845 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1846 Third arg DOCSTRING is documentation for the function.
1847 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1848 Fifth arg TYPE indicates the type of the object:
1849 nil or omitted says FUNCTION is a function,
1850 `keymap' says FUNCTION is really a keymap, and
1851 `macro' or t says FUNCTION is really a macro.
1852 Third through fifth args give info about the real definition.
1853 They default to nil.
1854 If FUNCTION is already defined other than as an autoload,
1855 this does nothing and returns nil. */)
1856 (function
, file
, docstring
, interactive
, type
)
1857 Lisp_Object function
, file
, docstring
, interactive
, type
;
1860 Lisp_Object args
[4];
1863 CHECK_SYMBOL (function
);
1864 CHECK_STRING (file
);
1866 /* If function is defined and not as an autoload, don't override */
1867 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
1868 && !(CONSP (XSYMBOL (function
)->function
)
1869 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
1872 if (NILP (Vpurify_flag
))
1873 /* Only add entries after dumping, because the ones before are
1874 not useful and else we get loads of them from the loaddefs.el. */
1875 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
1879 args
[1] = docstring
;
1880 args
[2] = interactive
;
1883 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
1884 #else /* NO_ARG_ARRAY */
1885 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
1886 #endif /* not NO_ARG_ARRAY */
1890 un_autoload (oldqueue
)
1891 Lisp_Object oldqueue
;
1893 register Lisp_Object queue
, first
, second
;
1895 /* Queue to unwind is current value of Vautoload_queue.
1896 oldqueue is the shadowed value to leave in Vautoload_queue. */
1897 queue
= Vautoload_queue
;
1898 Vautoload_queue
= oldqueue
;
1899 while (CONSP (queue
))
1901 first
= Fcar (queue
);
1902 second
= Fcdr (first
);
1903 first
= Fcar (first
);
1904 if (EQ (second
, Qnil
))
1907 Ffset (first
, second
);
1908 queue
= Fcdr (queue
);
1913 /* Load an autoloaded function.
1914 FUNNAME is the symbol which is the function's name.
1915 FUNDEF is the autoload definition (a list). */
1918 do_autoload (fundef
, funname
)
1919 Lisp_Object fundef
, funname
;
1921 int count
= SPECPDL_INDEX ();
1922 Lisp_Object fun
, queue
, first
, second
;
1923 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1925 /* This is to make sure that loadup.el gives a clear picture
1926 of what files are preloaded and when. */
1927 if (! NILP (Vpurify_flag
))
1928 error ("Attempt to autoload %s while preparing to dump",
1929 SDATA (SYMBOL_NAME (funname
)));
1932 CHECK_SYMBOL (funname
);
1933 GCPRO3 (fun
, funname
, fundef
);
1935 /* Preserve the match data. */
1936 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1938 /* Value saved here is to be restored into Vautoload_queue. */
1939 record_unwind_protect (un_autoload
, Vautoload_queue
);
1940 Vautoload_queue
= Qt
;
1941 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
1943 /* Save the old autoloads, in case we ever do an unload. */
1944 queue
= Vautoload_queue
;
1945 while (CONSP (queue
))
1947 first
= Fcar (queue
);
1948 second
= Fcdr (first
);
1949 first
= Fcar (first
);
1951 /* Note: This test is subtle. The cdr of an autoload-queue entry
1952 may be an atom if the autoload entry was generated by a defalias
1955 Fput (first
, Qautoload
, (Fcdr (second
)));
1957 queue
= Fcdr (queue
);
1960 /* Once loading finishes, don't undo it. */
1961 Vautoload_queue
= Qt
;
1962 unbind_to (count
, Qnil
);
1964 fun
= Findirect_function (fun
);
1966 if (!NILP (Fequal (fun
, fundef
)))
1967 error ("Autoloading failed to define function %s",
1968 SDATA (SYMBOL_NAME (funname
)));
1973 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
1974 doc
: /* Evaluate FORM and return its value. */)
1978 Lisp_Object fun
, val
, original_fun
, original_args
;
1980 struct backtrace backtrace
;
1981 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1983 if (handling_signal
)
1987 return Fsymbol_value (form
);
1992 if (consing_since_gc
> gc_cons_threshold
)
1995 Fgarbage_collect ();
1999 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2001 if (max_lisp_eval_depth
< 100)
2002 max_lisp_eval_depth
= 100;
2003 if (lisp_eval_depth
> max_lisp_eval_depth
)
2004 error ("Lisp nesting exceeds max-lisp-eval-depth");
2007 original_fun
= Fcar (form
);
2008 original_args
= Fcdr (form
);
2010 backtrace
.next
= backtrace_list
;
2011 backtrace_list
= &backtrace
;
2012 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2013 backtrace
.args
= &original_args
;
2014 backtrace
.nargs
= UNEVALLED
;
2015 backtrace
.evalargs
= 1;
2016 backtrace
.debug_on_exit
= 0;
2018 if (debug_on_next_call
)
2019 do_debug_on_call (Qt
);
2021 /* At this point, only original_fun and original_args
2022 have values that will be used below */
2024 fun
= Findirect_function (original_fun
);
2028 Lisp_Object numargs
;
2029 Lisp_Object argvals
[8];
2030 Lisp_Object args_left
;
2031 register int i
, maxargs
;
2033 args_left
= original_args
;
2034 numargs
= Flength (args_left
);
2036 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2037 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2038 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (numargs
, Qnil
)));
2040 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2042 backtrace
.evalargs
= 0;
2043 val
= (*XSUBR (fun
)->function
) (args_left
);
2047 if (XSUBR (fun
)->max_args
== MANY
)
2049 /* Pass a vector of evaluated arguments */
2051 register int argnum
= 0;
2053 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2055 GCPRO3 (args_left
, fun
, fun
);
2059 while (!NILP (args_left
))
2061 vals
[argnum
++] = Feval (Fcar (args_left
));
2062 args_left
= Fcdr (args_left
);
2063 gcpro3
.nvars
= argnum
;
2066 backtrace
.args
= vals
;
2067 backtrace
.nargs
= XINT (numargs
);
2069 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2074 GCPRO3 (args_left
, fun
, fun
);
2075 gcpro3
.var
= argvals
;
2078 maxargs
= XSUBR (fun
)->max_args
;
2079 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2081 argvals
[i
] = Feval (Fcar (args_left
));
2087 backtrace
.args
= argvals
;
2088 backtrace
.nargs
= XINT (numargs
);
2093 val
= (*XSUBR (fun
)->function
) ();
2096 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2099 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2102 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2106 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2107 argvals
[2], argvals
[3]);
2110 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2111 argvals
[3], argvals
[4]);
2114 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2115 argvals
[3], argvals
[4], argvals
[5]);
2118 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2119 argvals
[3], argvals
[4], argvals
[5],
2124 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2125 argvals
[3], argvals
[4], argvals
[5],
2126 argvals
[6], argvals
[7]);
2130 /* Someone has created a subr that takes more arguments than
2131 is supported by this code. We need to either rewrite the
2132 subr to use a different argument protocol, or add more
2133 cases to this switch. */
2137 if (COMPILEDP (fun
))
2138 val
= apply_lambda (fun
, original_args
, 1);
2142 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2143 funcar
= Fcar (fun
);
2144 if (!SYMBOLP (funcar
))
2145 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2146 if (EQ (funcar
, Qautoload
))
2148 do_autoload (fun
, original_fun
);
2151 if (EQ (funcar
, Qmacro
))
2152 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2153 else if (EQ (funcar
, Qlambda
))
2154 val
= apply_lambda (fun
, original_args
, 1);
2156 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2160 if (backtrace
.debug_on_exit
)
2161 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2162 backtrace_list
= backtrace
.next
;
2165 mac_check_for_quit_char();
2170 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2171 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2172 Then return the value FUNCTION returns.
2173 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2174 usage: (apply FUNCTION &rest ARGUMENTS) */)
2179 register int i
, numargs
;
2180 register Lisp_Object spread_arg
;
2181 register Lisp_Object
*funcall_args
;
2183 struct gcpro gcpro1
;
2187 spread_arg
= args
[nargs
- 1];
2188 CHECK_LIST (spread_arg
);
2190 numargs
= XINT (Flength (spread_arg
));
2193 return Ffuncall (nargs
- 1, args
);
2194 else if (numargs
== 1)
2196 args
[nargs
- 1] = XCAR (spread_arg
);
2197 return Ffuncall (nargs
, args
);
2200 numargs
+= nargs
- 2;
2202 fun
= indirect_function (fun
);
2203 if (EQ (fun
, Qunbound
))
2205 /* Let funcall get the error */
2212 if (numargs
< XSUBR (fun
)->min_args
2213 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2214 goto funcall
; /* Let funcall get the error */
2215 else if (XSUBR (fun
)->max_args
> numargs
)
2217 /* Avoid making funcall cons up a yet another new vector of arguments
2218 by explicitly supplying nil's for optional values */
2219 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2220 * sizeof (Lisp_Object
));
2221 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2222 funcall_args
[++i
] = Qnil
;
2223 GCPRO1 (*funcall_args
);
2224 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2228 /* We add 1 to numargs because funcall_args includes the
2229 function itself as well as its arguments. */
2232 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2233 * sizeof (Lisp_Object
));
2234 GCPRO1 (*funcall_args
);
2235 gcpro1
.nvars
= 1 + numargs
;
2238 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2239 /* Spread the last arg we got. Its first element goes in
2240 the slot that it used to occupy, hence this value of I. */
2242 while (!NILP (spread_arg
))
2244 funcall_args
[i
++] = XCAR (spread_arg
);
2245 spread_arg
= XCDR (spread_arg
);
2248 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2251 /* Run hook variables in various ways. */
2253 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2254 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2255 enum run_hooks_condition
));
2257 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2258 doc
: /* Run each hook in HOOKS. Major mode functions use this.
2259 Each argument should be a symbol, a hook variable.
2260 These symbols are processed in the order specified.
2261 If a hook symbol has a non-nil value, that value may be a function
2262 or a list of functions to be called to run the hook.
2263 If the value is a function, it is called with no arguments.
2264 If it is a list, the elements are called, in order, with no arguments.
2266 Do not use `make-local-variable' to make a hook variable buffer-local.
2267 Instead, use `add-hook' and specify t for the LOCAL argument.
2268 usage: (run-hooks &rest HOOKS) */)
2273 Lisp_Object hook
[1];
2276 for (i
= 0; i
< nargs
; i
++)
2279 run_hook_with_args (1, hook
, to_completion
);
2285 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2286 Srun_hook_with_args
, 1, MANY
, 0,
2287 doc
: /* Run HOOK with the specified arguments ARGS.
2288 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2289 value, that value may be a function or a list of functions to be
2290 called to run the hook. If the value is a function, it is called with
2291 the given arguments and its return value is returned. If it is a list
2292 of functions, those functions are called, in order,
2293 with the given arguments ARGS.
2294 It is best not to depend on the value return by `run-hook-with-args',
2297 Do not use `make-local-variable' to make a hook variable buffer-local.
2298 Instead, use `add-hook' and specify t for the LOCAL argument.
2299 usage: (run-hook-with-args HOOK &rest ARGS) */)
2304 return run_hook_with_args (nargs
, args
, to_completion
);
2307 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2308 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2309 doc
: /* Run HOOK with the specified arguments ARGS.
2310 HOOK should be a symbol, a hook variable. Its value should
2311 be a list of functions. We call those functions, one by one,
2312 passing arguments ARGS to each of them, until one of them
2313 returns a non-nil value. Then we return that value.
2314 If all the functions return nil, we return nil.
2316 Do not use `make-local-variable' to make a hook variable buffer-local.
2317 Instead, use `add-hook' and specify t for the LOCAL argument.
2318 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2323 return run_hook_with_args (nargs
, args
, until_success
);
2326 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2327 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2328 doc
: /* Run HOOK with the specified arguments ARGS.
2329 HOOK should be a symbol, a hook variable. Its value should
2330 be a list of functions. We call those functions, one by one,
2331 passing arguments ARGS to each of them, until one of them
2332 returns nil. Then we return nil.
2333 If all the functions return non-nil, we return non-nil.
2335 Do not use `make-local-variable' to make a hook variable buffer-local.
2336 Instead, use `add-hook' and specify t for the LOCAL argument.
2337 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2342 return run_hook_with_args (nargs
, args
, until_failure
);
2345 /* ARGS[0] should be a hook symbol.
2346 Call each of the functions in the hook value, passing each of them
2347 as arguments all the rest of ARGS (all NARGS - 1 elements).
2348 COND specifies a condition to test after each call
2349 to decide whether to stop.
2350 The caller (or its caller, etc) must gcpro all of ARGS,
2351 except that it isn't necessary to gcpro ARGS[0]. */
2354 run_hook_with_args (nargs
, args
, cond
)
2357 enum run_hooks_condition cond
;
2359 Lisp_Object sym
, val
, ret
;
2360 Lisp_Object globals
;
2361 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2363 /* If we are dying or still initializing,
2364 don't do anything--it would probably crash if we tried. */
2365 if (NILP (Vrun_hooks
))
2369 val
= find_symbol_value (sym
);
2370 ret
= (cond
== until_failure
? Qt
: Qnil
);
2372 if (EQ (val
, Qunbound
) || NILP (val
))
2374 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2377 return Ffuncall (nargs
, args
);
2382 GCPRO3 (sym
, val
, globals
);
2385 CONSP (val
) && ((cond
== to_completion
)
2386 || (cond
== until_success
? NILP (ret
)
2390 if (EQ (XCAR (val
), Qt
))
2392 /* t indicates this hook has a local binding;
2393 it means to run the global binding too. */
2395 for (globals
= Fdefault_value (sym
);
2396 CONSP (globals
) && ((cond
== to_completion
)
2397 || (cond
== until_success
? NILP (ret
)
2399 globals
= XCDR (globals
))
2401 args
[0] = XCAR (globals
);
2402 /* In a global value, t should not occur. If it does, we
2403 must ignore it to avoid an endless loop. */
2404 if (!EQ (args
[0], Qt
))
2405 ret
= Ffuncall (nargs
, args
);
2410 args
[0] = XCAR (val
);
2411 ret
= Ffuncall (nargs
, args
);
2420 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2421 present value of that symbol.
2422 Call each element of FUNLIST,
2423 passing each of them the rest of ARGS.
2424 The caller (or its caller, etc) must gcpro all of ARGS,
2425 except that it isn't necessary to gcpro ARGS[0]. */
2428 run_hook_list_with_args (funlist
, nargs
, args
)
2429 Lisp_Object funlist
;
2435 Lisp_Object globals
;
2436 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2440 GCPRO3 (sym
, val
, globals
);
2442 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2444 if (EQ (XCAR (val
), Qt
))
2446 /* t indicates this hook has a local binding;
2447 it means to run the global binding too. */
2449 for (globals
= Fdefault_value (sym
);
2451 globals
= XCDR (globals
))
2453 args
[0] = XCAR (globals
);
2454 /* In a global value, t should not occur. If it does, we
2455 must ignore it to avoid an endless loop. */
2456 if (!EQ (args
[0], Qt
))
2457 Ffuncall (nargs
, args
);
2462 args
[0] = XCAR (val
);
2463 Ffuncall (nargs
, args
);
2470 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2473 run_hook_with_args_2 (hook
, arg1
, arg2
)
2474 Lisp_Object hook
, arg1
, arg2
;
2476 Lisp_Object temp
[3];
2481 Frun_hook_with_args (3, temp
);
2484 /* Apply fn to arg */
2487 Lisp_Object fn
, arg
;
2489 struct gcpro gcpro1
;
2493 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2497 Lisp_Object args
[2];
2501 RETURN_UNGCPRO (Fapply (2, args
));
2503 #else /* not NO_ARG_ARRAY */
2504 RETURN_UNGCPRO (Fapply (2, &fn
));
2505 #endif /* not NO_ARG_ARRAY */
2508 /* Call function fn on no arguments */
2513 struct gcpro gcpro1
;
2516 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2519 /* Call function fn with 1 argument arg1 */
2523 Lisp_Object fn
, arg1
;
2525 struct gcpro gcpro1
;
2527 Lisp_Object args
[2];
2533 RETURN_UNGCPRO (Ffuncall (2, args
));
2534 #else /* not NO_ARG_ARRAY */
2537 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2538 #endif /* not NO_ARG_ARRAY */
2541 /* Call function fn with 2 arguments arg1, arg2 */
2544 call2 (fn
, arg1
, arg2
)
2545 Lisp_Object fn
, arg1
, arg2
;
2547 struct gcpro gcpro1
;
2549 Lisp_Object args
[3];
2555 RETURN_UNGCPRO (Ffuncall (3, args
));
2556 #else /* not NO_ARG_ARRAY */
2559 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2560 #endif /* not NO_ARG_ARRAY */
2563 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2566 call3 (fn
, arg1
, arg2
, arg3
)
2567 Lisp_Object fn
, arg1
, arg2
, arg3
;
2569 struct gcpro gcpro1
;
2571 Lisp_Object args
[4];
2578 RETURN_UNGCPRO (Ffuncall (4, args
));
2579 #else /* not NO_ARG_ARRAY */
2582 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2583 #endif /* not NO_ARG_ARRAY */
2586 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2589 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2590 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2592 struct gcpro gcpro1
;
2594 Lisp_Object args
[5];
2602 RETURN_UNGCPRO (Ffuncall (5, args
));
2603 #else /* not NO_ARG_ARRAY */
2606 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2607 #endif /* not NO_ARG_ARRAY */
2610 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2613 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2614 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2616 struct gcpro gcpro1
;
2618 Lisp_Object args
[6];
2627 RETURN_UNGCPRO (Ffuncall (6, args
));
2628 #else /* not NO_ARG_ARRAY */
2631 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2632 #endif /* not NO_ARG_ARRAY */
2635 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2638 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2639 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2641 struct gcpro gcpro1
;
2643 Lisp_Object args
[7];
2653 RETURN_UNGCPRO (Ffuncall (7, args
));
2654 #else /* not NO_ARG_ARRAY */
2657 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2658 #endif /* not NO_ARG_ARRAY */
2661 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2662 doc
: /* Call first argument as a function, passing remaining arguments to it.
2663 Return the value that function returns.
2664 Thus, (funcall 'cons 'x 'y) returns (x . y).
2665 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2672 int numargs
= nargs
- 1;
2673 Lisp_Object lisp_numargs
;
2675 struct backtrace backtrace
;
2676 register Lisp_Object
*internal_args
;
2680 if (consing_since_gc
> gc_cons_threshold
)
2681 Fgarbage_collect ();
2683 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2685 if (max_lisp_eval_depth
< 100)
2686 max_lisp_eval_depth
= 100;
2687 if (lisp_eval_depth
> max_lisp_eval_depth
)
2688 error ("Lisp nesting exceeds max-lisp-eval-depth");
2691 backtrace
.next
= backtrace_list
;
2692 backtrace_list
= &backtrace
;
2693 backtrace
.function
= &args
[0];
2694 backtrace
.args
= &args
[1];
2695 backtrace
.nargs
= nargs
- 1;
2696 backtrace
.evalargs
= 0;
2697 backtrace
.debug_on_exit
= 0;
2699 if (debug_on_next_call
)
2700 do_debug_on_call (Qlambda
);
2706 fun
= Findirect_function (fun
);
2710 if (numargs
< XSUBR (fun
)->min_args
2711 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2713 XSETFASTINT (lisp_numargs
, numargs
);
2714 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2717 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2718 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2720 if (XSUBR (fun
)->max_args
== MANY
)
2722 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2726 if (XSUBR (fun
)->max_args
> numargs
)
2728 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2729 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2730 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2731 internal_args
[i
] = Qnil
;
2734 internal_args
= args
+ 1;
2735 switch (XSUBR (fun
)->max_args
)
2738 val
= (*XSUBR (fun
)->function
) ();
2741 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2744 val
= (*XSUBR (fun
)->function
) (internal_args
[0],
2748 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2752 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2757 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2758 internal_args
[2], internal_args
[3],
2762 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2763 internal_args
[2], internal_args
[3],
2764 internal_args
[4], internal_args
[5]);
2767 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2768 internal_args
[2], internal_args
[3],
2769 internal_args
[4], internal_args
[5],
2774 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2775 internal_args
[2], internal_args
[3],
2776 internal_args
[4], internal_args
[5],
2777 internal_args
[6], internal_args
[7]);
2782 /* If a subr takes more than 8 arguments without using MANY
2783 or UNEVALLED, we need to extend this function to support it.
2784 Until this is done, there is no way to call the function. */
2788 if (COMPILEDP (fun
))
2789 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2793 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2794 funcar
= Fcar (fun
);
2795 if (!SYMBOLP (funcar
))
2796 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2797 if (EQ (funcar
, Qlambda
))
2798 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2799 else if (EQ (funcar
, Qautoload
))
2801 do_autoload (fun
, args
[0]);
2805 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2809 if (backtrace
.debug_on_exit
)
2810 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2811 backtrace_list
= backtrace
.next
;
2816 apply_lambda (fun
, args
, eval_flag
)
2817 Lisp_Object fun
, args
;
2820 Lisp_Object args_left
;
2821 Lisp_Object numargs
;
2822 register Lisp_Object
*arg_vector
;
2823 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2825 register Lisp_Object tem
;
2827 numargs
= Flength (args
);
2828 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2831 GCPRO3 (*arg_vector
, args_left
, fun
);
2834 for (i
= 0; i
< XINT (numargs
);)
2836 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2837 if (eval_flag
) tem
= Feval (tem
);
2838 arg_vector
[i
++] = tem
;
2846 backtrace_list
->args
= arg_vector
;
2847 backtrace_list
->nargs
= i
;
2849 backtrace_list
->evalargs
= 0;
2850 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
2852 /* Do the debug-on-exit now, while arg_vector still exists. */
2853 if (backtrace_list
->debug_on_exit
)
2854 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
2855 /* Don't do it again when we return to eval. */
2856 backtrace_list
->debug_on_exit
= 0;
2860 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2861 and return the result of evaluation.
2862 FUN must be either a lambda-expression or a compiled-code object. */
2865 funcall_lambda (fun
, nargs
, arg_vector
)
2868 register Lisp_Object
*arg_vector
;
2870 Lisp_Object val
, syms_left
, next
;
2871 int count
= SPECPDL_INDEX ();
2872 int i
, optional
, rest
;
2876 syms_left
= XCDR (fun
);
2877 if (CONSP (syms_left
))
2878 syms_left
= XCAR (syms_left
);
2880 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2882 else if (COMPILEDP (fun
))
2883 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2887 i
= optional
= rest
= 0;
2888 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2892 next
= XCAR (syms_left
);
2893 while (!SYMBOLP (next
))
2894 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2896 if (EQ (next
, Qand_rest
))
2898 else if (EQ (next
, Qand_optional
))
2902 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
2906 specbind (next
, arg_vector
[i
++]);
2908 return Fsignal (Qwrong_number_of_arguments
,
2909 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2911 specbind (next
, Qnil
);
2914 if (!NILP (syms_left
))
2915 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2917 return Fsignal (Qwrong_number_of_arguments
,
2918 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2921 val
= Fprogn (XCDR (XCDR (fun
)));
2924 /* If we have not actually read the bytecode string
2925 and constants vector yet, fetch them from the file. */
2926 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2927 Ffetch_bytecode (fun
);
2928 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
2929 AREF (fun
, COMPILED_CONSTANTS
),
2930 AREF (fun
, COMPILED_STACK_DEPTH
));
2933 return unbind_to (count
, val
);
2936 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2938 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2944 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
2946 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2949 tem
= AREF (object
, COMPILED_BYTECODE
);
2950 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2951 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2953 error ("Invalid byte code");
2955 AREF (object
, COMPILED_BYTECODE
) = XCAR (tem
);
2956 AREF (object
, COMPILED_CONSTANTS
) = XCDR (tem
);
2964 register int count
= SPECPDL_INDEX ();
2965 if (specpdl_size
>= max_specpdl_size
)
2967 if (max_specpdl_size
< 400)
2968 max_specpdl_size
= 400;
2969 if (specpdl_size
>= max_specpdl_size
)
2971 if (!NILP (Vdebug_on_error
))
2972 /* Leave room for some specpdl in the debugger. */
2973 max_specpdl_size
= specpdl_size
+ 100;
2975 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
2979 if (specpdl_size
> max_specpdl_size
)
2980 specpdl_size
= max_specpdl_size
;
2981 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
2982 specpdl_ptr
= specpdl
+ count
;
2986 specbind (symbol
, value
)
2987 Lisp_Object symbol
, value
;
2990 Lisp_Object valcontents
;
2992 CHECK_SYMBOL (symbol
);
2993 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2996 /* The most common case is that of a non-constant symbol with a
2997 trivial value. Make that as fast as we can. */
2998 valcontents
= SYMBOL_VALUE (symbol
);
2999 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3001 specpdl_ptr
->symbol
= symbol
;
3002 specpdl_ptr
->old_value
= valcontents
;
3003 specpdl_ptr
->func
= NULL
;
3005 SET_SYMBOL_VALUE (symbol
, value
);
3009 Lisp_Object valcontents
;
3011 ovalue
= find_symbol_value (symbol
);
3012 specpdl_ptr
->func
= 0;
3013 specpdl_ptr
->old_value
= ovalue
;
3015 valcontents
= XSYMBOL (symbol
)->value
;
3017 if (BUFFER_LOCAL_VALUEP (valcontents
)
3018 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
3019 || BUFFER_OBJFWDP (valcontents
))
3021 Lisp_Object where
, current_buffer
;
3023 current_buffer
= Fcurrent_buffer ();
3025 /* For a local variable, record both the symbol and which
3026 buffer's or frame's value we are saving. */
3027 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3028 where
= current_buffer
;
3029 else if (!BUFFER_OBJFWDP (valcontents
)
3030 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3031 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3035 /* We're not using the `unused' slot in the specbinding
3036 structure because this would mean we have to do more
3037 work for simple variables. */
3038 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3040 /* If SYMBOL is a per-buffer variable which doesn't have a
3041 buffer-local value here, make the `let' change the global
3042 value by changing the value of SYMBOL in all buffers not
3043 having their own value. This is consistent with what
3044 happens with other buffer-local variables. */
3046 && BUFFER_OBJFWDP (valcontents
))
3049 Fset_default (symbol
, value
);
3054 specpdl_ptr
->symbol
= symbol
;
3057 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3058 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3060 set_internal (symbol
, value
, 0, 1);
3065 record_unwind_protect (function
, arg
)
3066 Lisp_Object (*function
) P_ ((Lisp_Object
));
3069 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3071 specpdl_ptr
->func
= function
;
3072 specpdl_ptr
->symbol
= Qnil
;
3073 specpdl_ptr
->old_value
= arg
;
3078 unbind_to (count
, value
)
3082 int quitf
= !NILP (Vquit_flag
);
3083 struct gcpro gcpro1
;
3088 while (specpdl_ptr
!= specpdl
+ count
)
3092 if (specpdl_ptr
->func
!= 0)
3093 (*specpdl_ptr
->func
) (specpdl_ptr
->old_value
);
3094 /* Note that a "binding" of nil is really an unwind protect,
3095 so in that case the "old value" is a list of forms to evaluate. */
3096 else if (NILP (specpdl_ptr
->symbol
))
3097 Fprogn (specpdl_ptr
->old_value
);
3098 /* If the symbol is a list, it is really (SYMBOL WHERE
3099 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3100 frame. If WHERE is a buffer or frame, this indicates we
3101 bound a variable that had a buffer-local or frame-local
3102 binding. WHERE nil means that the variable had the default
3103 value when it was bound. CURRENT-BUFFER is the buffer that
3104 was current when the variable was bound. */
3105 else if (CONSP (specpdl_ptr
->symbol
))
3107 Lisp_Object symbol
, where
;
3109 symbol
= XCAR (specpdl_ptr
->symbol
);
3110 where
= XCAR (XCDR (specpdl_ptr
->symbol
));
3113 Fset_default (symbol
, specpdl_ptr
->old_value
);
3114 else if (BUFFERP (where
))
3115 set_internal (symbol
, specpdl_ptr
->old_value
, XBUFFER (where
), 1);
3117 set_internal (symbol
, specpdl_ptr
->old_value
, NULL
, 1);
3121 /* If variable has a trivial value (no forwarding), we can
3122 just set it. No need to check for constant symbols here,
3123 since that was already done by specbind. */
3124 if (!MISCP (SYMBOL_VALUE (specpdl_ptr
->symbol
)))
3125 SET_SYMBOL_VALUE (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
);
3127 set_internal (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
, 0, 1);
3131 if (NILP (Vquit_flag
) && quitf
)
3138 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3139 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3140 The debugger is entered when that frame exits, if the flag is non-nil. */)
3142 Lisp_Object level
, flag
;
3144 register struct backtrace
*backlist
= backtrace_list
;
3147 CHECK_NUMBER (level
);
3149 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3151 backlist
= backlist
->next
;
3155 backlist
->debug_on_exit
= !NILP (flag
);
3160 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3161 doc
: /* Print a trace of Lisp function calls currently active.
3162 Output stream used is value of `standard-output'. */)
3165 register struct backtrace
*backlist
= backtrace_list
;
3169 extern Lisp_Object Vprint_level
;
3170 struct gcpro gcpro1
;
3172 XSETFASTINT (Vprint_level
, 3);
3179 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3180 if (backlist
->nargs
== UNEVALLED
)
3182 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3183 write_string ("\n", -1);
3187 tem
= *backlist
->function
;
3188 Fprin1 (tem
, Qnil
); /* This can QUIT */
3189 write_string ("(", -1);
3190 if (backlist
->nargs
== MANY
)
3192 for (tail
= *backlist
->args
, i
= 0;
3194 tail
= Fcdr (tail
), i
++)
3196 if (i
) write_string (" ", -1);
3197 Fprin1 (Fcar (tail
), Qnil
);
3202 for (i
= 0; i
< backlist
->nargs
; i
++)
3204 if (i
) write_string (" ", -1);
3205 Fprin1 (backlist
->args
[i
], Qnil
);
3208 write_string (")\n", -1);
3210 backlist
= backlist
->next
;
3213 Vprint_level
= Qnil
;
3218 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3219 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3220 If that frame has not evaluated the arguments yet (or is a special form),
3221 the value is (nil FUNCTION ARG-FORMS...).
3222 If that frame has evaluated its arguments and called its function already,
3223 the value is (t FUNCTION ARG-VALUES...).
3224 A &rest arg is represented as the tail of the list ARG-VALUES.
3225 FUNCTION is whatever was supplied as car of evaluated list,
3226 or a lambda expression for macro calls.
3227 If NFRAMES is more than the number of frames, the value is nil. */)
3229 Lisp_Object nframes
;
3231 register struct backtrace
*backlist
= backtrace_list
;
3235 CHECK_NATNUM (nframes
);
3237 /* Find the frame requested. */
3238 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3239 backlist
= backlist
->next
;
3243 if (backlist
->nargs
== UNEVALLED
)
3244 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3247 if (backlist
->nargs
== MANY
)
3248 tem
= *backlist
->args
;
3250 tem
= Flist (backlist
->nargs
, backlist
->args
);
3252 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3260 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3261 doc
: /* *Limit on number of Lisp variable bindings & unwind-protects.
3262 If Lisp code tries to make more than this many at once,
3263 an error is signaled.
3264 You can safely use a value considerably larger than the default value,
3265 if that proves inconveniently small. However, if you increase it too far,
3266 Emacs could run out of memory trying to make the stack bigger. */);
3268 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3269 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3271 This limit serves to catch infinite recursions for you before they cause
3272 actual stack overflow in C, which would be fatal for Emacs.
3273 You can safely make it considerably larger than its default value,
3274 if that proves inconveniently small. However, if you increase it too far,
3275 Emacs could overflow the real C stack, and crash. */);
3277 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3278 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3279 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */);
3282 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3283 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3284 Note that `quit-flag' will still be set by typing C-g,
3285 so a quit will be signaled as soon as `inhibit-quit' is nil.
3286 To prevent this happening, set `quit-flag' to nil
3287 before making `inhibit-quit' nil. */);
3288 Vinhibit_quit
= Qnil
;
3290 Qinhibit_quit
= intern ("inhibit-quit");
3291 staticpro (&Qinhibit_quit
);
3293 Qautoload
= intern ("autoload");
3294 staticpro (&Qautoload
);
3296 Qdebug_on_error
= intern ("debug-on-error");
3297 staticpro (&Qdebug_on_error
);
3299 Qmacro
= intern ("macro");
3300 staticpro (&Qmacro
);
3302 Qdeclare
= intern ("declare");
3303 staticpro (&Qdeclare
);
3305 /* Note that the process handling also uses Qexit, but we don't want
3306 to staticpro it twice, so we just do it here. */
3307 Qexit
= intern ("exit");
3310 Qinteractive
= intern ("interactive");
3311 staticpro (&Qinteractive
);
3313 Qcommandp
= intern ("commandp");
3314 staticpro (&Qcommandp
);
3316 Qdefun
= intern ("defun");
3317 staticpro (&Qdefun
);
3319 Qdefvar
= intern ("defvar");
3320 staticpro (&Qdefvar
);
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 errors display a backtrace buffer.
3330 More precisely, this happens for any error that is handled
3331 by the editor command loop.
3332 If the value is a list, an error only means to display a backtrace
3333 if one of its condition symbols appears in the list. */);
3334 Vstack_trace_on_error
= Qnil
;
3336 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3337 doc
: /* *Non-nil means enter debugger if an error is signaled.
3338 Does not apply to errors handled by `condition-case' or those
3339 matched by `debug-ignored-errors'.
3340 If the value is a list, an error only means to enter the debugger
3341 if one of its condition symbols appears in the list.
3342 When you evaluate an expression interactively, this variable
3343 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3344 See also variable `debug-on-quit'. */);
3345 Vdebug_on_error
= Qnil
;
3347 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3348 doc
: /* *List of errors for which the debugger should not be called.
3349 Each element may be a condition-name or a regexp that matches error messages.
3350 If any element applies to a given error, that error skips the debugger
3351 and just returns to top level.
3352 This overrides the variable `debug-on-error'.
3353 It does not apply to errors handled by `condition-case'. */);
3354 Vdebug_ignored_errors
= Qnil
;
3356 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3357 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3358 Does not apply if quit is handled by a `condition-case'.
3359 When you evaluate an expression interactively, this variable
3360 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3363 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3364 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3366 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3367 doc
: /* Non-nil means debugger may continue execution.
3368 This is nil when the debugger is called under circumstances where it
3369 might not be safe to continue. */);
3370 debugger_may_continue
= 1;
3372 DEFVAR_LISP ("debugger", &Vdebugger
,
3373 doc
: /* Function to call to invoke debugger.
3374 If due to frame exit, args are `exit' and the value being returned;
3375 this function's value will be returned instead of that.
3376 If due to error, args are `error' and a list of the args to `signal'.
3377 If due to `apply' or `funcall' entry, one arg, `lambda'.
3378 If due to `eval' entry, one arg, t. */);
3381 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3382 doc
: /* If non-nil, this is a function for `signal' to call.
3383 It receives the same arguments that `signal' was given.
3384 The Edebug package uses this to regain control. */);
3385 Vsignal_hook_function
= Qnil
;
3387 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3388 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3389 Note that `debug-on-error', `debug-on-quit' and friends
3390 still determine whether to handle the particular condition. */);
3391 Vdebug_on_signal
= Qnil
;
3393 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3394 doc
: /* Function to process declarations in a macro definition.
3395 The function will be called with two args MACRO and DECL.
3396 MACRO is the name of the macro being defined.
3397 DECL is a list `(declare ...)' containing the declarations.
3398 The value the function returns is not used. */);
3399 Vmacro_declaration_function
= Qnil
;
3401 Vrun_hooks
= intern ("run-hooks");
3402 staticpro (&Vrun_hooks
);
3404 staticpro (&Vautoload_queue
);
3405 Vautoload_queue
= Qnil
;
3406 staticpro (&Vsignaling_function
);
3407 Vsignaling_function
= Qnil
;
3418 defsubr (&Sfunction
);
3420 defsubr (&Sdefmacro
);
3422 defsubr (&Sdefvaralias
);
3423 defsubr (&Sdefconst
);
3424 defsubr (&Suser_variable_p
);
3428 defsubr (&Smacroexpand
);
3431 defsubr (&Sunwind_protect
);
3432 defsubr (&Scondition_case
);
3434 defsubr (&Sinteractive_p
);
3435 defsubr (&Scommandp
);
3436 defsubr (&Sautoload
);
3439 defsubr (&Sfuncall
);
3440 defsubr (&Srun_hooks
);
3441 defsubr (&Srun_hook_with_args
);
3442 defsubr (&Srun_hook_with_args_until_success
);
3443 defsubr (&Srun_hook_with_args_until_failure
);
3444 defsubr (&Sfetch_bytecode
);
3445 defsubr (&Sbacktrace_debug
);
3446 defsubr (&Sbacktrace
);
3447 defsubr (&Sbacktrace_frame
);