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
;
2166 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2167 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2168 Then return the value FUNCTION returns.
2169 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2170 usage: (apply FUNCTION &rest ARGUMENTS) */)
2175 register int i
, numargs
;
2176 register Lisp_Object spread_arg
;
2177 register Lisp_Object
*funcall_args
;
2179 struct gcpro gcpro1
;
2183 spread_arg
= args
[nargs
- 1];
2184 CHECK_LIST (spread_arg
);
2186 numargs
= XINT (Flength (spread_arg
));
2189 return Ffuncall (nargs
- 1, args
);
2190 else if (numargs
== 1)
2192 args
[nargs
- 1] = XCAR (spread_arg
);
2193 return Ffuncall (nargs
, args
);
2196 numargs
+= nargs
- 2;
2198 fun
= indirect_function (fun
);
2199 if (EQ (fun
, Qunbound
))
2201 /* Let funcall get the error */
2208 if (numargs
< XSUBR (fun
)->min_args
2209 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2210 goto funcall
; /* Let funcall get the error */
2211 else if (XSUBR (fun
)->max_args
> numargs
)
2213 /* Avoid making funcall cons up a yet another new vector of arguments
2214 by explicitly supplying nil's for optional values */
2215 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2216 * sizeof (Lisp_Object
));
2217 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2218 funcall_args
[++i
] = Qnil
;
2219 GCPRO1 (*funcall_args
);
2220 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2224 /* We add 1 to numargs because funcall_args includes the
2225 function itself as well as its arguments. */
2228 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2229 * sizeof (Lisp_Object
));
2230 GCPRO1 (*funcall_args
);
2231 gcpro1
.nvars
= 1 + numargs
;
2234 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2235 /* Spread the last arg we got. Its first element goes in
2236 the slot that it used to occupy, hence this value of I. */
2238 while (!NILP (spread_arg
))
2240 funcall_args
[i
++] = XCAR (spread_arg
);
2241 spread_arg
= XCDR (spread_arg
);
2244 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2247 /* Run hook variables in various ways. */
2249 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2250 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2251 enum run_hooks_condition
));
2253 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2254 doc
: /* Run each hook in HOOKS. Major mode functions use this.
2255 Each argument should be a symbol, a hook variable.
2256 These symbols are processed in the order specified.
2257 If a hook symbol has a non-nil value, that value may be a function
2258 or a list of functions to be called to run the hook.
2259 If the value is a function, it is called with no arguments.
2260 If it is a list, the elements are called, in order, with no arguments.
2262 Do not use `make-local-variable' to make a hook variable buffer-local.
2263 Instead, use `add-hook' and specify t for the LOCAL argument.
2264 usage: (run-hooks &rest HOOKS) */)
2269 Lisp_Object hook
[1];
2272 for (i
= 0; i
< nargs
; i
++)
2275 run_hook_with_args (1, hook
, to_completion
);
2281 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2282 Srun_hook_with_args
, 1, MANY
, 0,
2283 doc
: /* Run HOOK with the specified arguments ARGS.
2284 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2285 value, that value may be a function or a list of functions to be
2286 called to run the hook. If the value is a function, it is called with
2287 the given arguments and its return value is returned. If it is a list
2288 of functions, those functions are called, in order,
2289 with the given arguments ARGS.
2290 It is best not to depend on the value return by `run-hook-with-args',
2293 Do not use `make-local-variable' to make a hook variable buffer-local.
2294 Instead, use `add-hook' and specify t for the LOCAL argument.
2295 usage: (run-hook-with-args HOOK &rest ARGS) */)
2300 return run_hook_with_args (nargs
, args
, to_completion
);
2303 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2304 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2305 doc
: /* Run HOOK with the specified arguments ARGS.
2306 HOOK should be a symbol, a hook variable. Its value should
2307 be a list of functions. We call those functions, one by one,
2308 passing arguments ARGS to each of them, until one of them
2309 returns a non-nil value. Then we return that value.
2310 If all the functions return nil, we return nil.
2312 Do not use `make-local-variable' to make a hook variable buffer-local.
2313 Instead, use `add-hook' and specify t for the LOCAL argument.
2314 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2319 return run_hook_with_args (nargs
, args
, until_success
);
2322 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2323 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2324 doc
: /* Run HOOK with the specified arguments ARGS.
2325 HOOK should be a symbol, a hook variable. Its value should
2326 be a list of functions. We call those functions, one by one,
2327 passing arguments ARGS to each of them, until one of them
2328 returns nil. Then we return nil.
2329 If all the functions return non-nil, we return non-nil.
2331 Do not use `make-local-variable' to make a hook variable buffer-local.
2332 Instead, use `add-hook' and specify t for the LOCAL argument.
2333 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2338 return run_hook_with_args (nargs
, args
, until_failure
);
2341 /* ARGS[0] should be a hook symbol.
2342 Call each of the functions in the hook value, passing each of them
2343 as arguments all the rest of ARGS (all NARGS - 1 elements).
2344 COND specifies a condition to test after each call
2345 to decide whether to stop.
2346 The caller (or its caller, etc) must gcpro all of ARGS,
2347 except that it isn't necessary to gcpro ARGS[0]. */
2350 run_hook_with_args (nargs
, args
, cond
)
2353 enum run_hooks_condition cond
;
2355 Lisp_Object sym
, val
, ret
;
2356 Lisp_Object globals
;
2357 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2359 /* If we are dying or still initializing,
2360 don't do anything--it would probably crash if we tried. */
2361 if (NILP (Vrun_hooks
))
2365 val
= find_symbol_value (sym
);
2366 ret
= (cond
== until_failure
? Qt
: Qnil
);
2368 if (EQ (val
, Qunbound
) || NILP (val
))
2370 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2373 return Ffuncall (nargs
, args
);
2378 GCPRO3 (sym
, val
, globals
);
2381 CONSP (val
) && ((cond
== to_completion
)
2382 || (cond
== until_success
? NILP (ret
)
2386 if (EQ (XCAR (val
), Qt
))
2388 /* t indicates this hook has a local binding;
2389 it means to run the global binding too. */
2391 for (globals
= Fdefault_value (sym
);
2392 CONSP (globals
) && ((cond
== to_completion
)
2393 || (cond
== until_success
? NILP (ret
)
2395 globals
= XCDR (globals
))
2397 args
[0] = XCAR (globals
);
2398 /* In a global value, t should not occur. If it does, we
2399 must ignore it to avoid an endless loop. */
2400 if (!EQ (args
[0], Qt
))
2401 ret
= Ffuncall (nargs
, args
);
2406 args
[0] = XCAR (val
);
2407 ret
= Ffuncall (nargs
, args
);
2416 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2417 present value of that symbol.
2418 Call each element of FUNLIST,
2419 passing each of them the rest of ARGS.
2420 The caller (or its caller, etc) must gcpro all of ARGS,
2421 except that it isn't necessary to gcpro ARGS[0]. */
2424 run_hook_list_with_args (funlist
, nargs
, args
)
2425 Lisp_Object funlist
;
2431 Lisp_Object globals
;
2432 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2436 GCPRO3 (sym
, val
, globals
);
2438 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2440 if (EQ (XCAR (val
), Qt
))
2442 /* t indicates this hook has a local binding;
2443 it means to run the global binding too. */
2445 for (globals
= Fdefault_value (sym
);
2447 globals
= XCDR (globals
))
2449 args
[0] = XCAR (globals
);
2450 /* In a global value, t should not occur. If it does, we
2451 must ignore it to avoid an endless loop. */
2452 if (!EQ (args
[0], Qt
))
2453 Ffuncall (nargs
, args
);
2458 args
[0] = XCAR (val
);
2459 Ffuncall (nargs
, args
);
2466 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2469 run_hook_with_args_2 (hook
, arg1
, arg2
)
2470 Lisp_Object hook
, arg1
, arg2
;
2472 Lisp_Object temp
[3];
2477 Frun_hook_with_args (3, temp
);
2480 /* Apply fn to arg */
2483 Lisp_Object fn
, arg
;
2485 struct gcpro gcpro1
;
2489 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2493 Lisp_Object args
[2];
2497 RETURN_UNGCPRO (Fapply (2, args
));
2499 #else /* not NO_ARG_ARRAY */
2500 RETURN_UNGCPRO (Fapply (2, &fn
));
2501 #endif /* not NO_ARG_ARRAY */
2504 /* Call function fn on no arguments */
2509 struct gcpro gcpro1
;
2512 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2515 /* Call function fn with 1 argument arg1 */
2519 Lisp_Object fn
, arg1
;
2521 struct gcpro gcpro1
;
2523 Lisp_Object args
[2];
2529 RETURN_UNGCPRO (Ffuncall (2, args
));
2530 #else /* not NO_ARG_ARRAY */
2533 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2534 #endif /* not NO_ARG_ARRAY */
2537 /* Call function fn with 2 arguments arg1, arg2 */
2540 call2 (fn
, arg1
, arg2
)
2541 Lisp_Object fn
, arg1
, arg2
;
2543 struct gcpro gcpro1
;
2545 Lisp_Object args
[3];
2551 RETURN_UNGCPRO (Ffuncall (3, args
));
2552 #else /* not NO_ARG_ARRAY */
2555 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2556 #endif /* not NO_ARG_ARRAY */
2559 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2562 call3 (fn
, arg1
, arg2
, arg3
)
2563 Lisp_Object fn
, arg1
, arg2
, arg3
;
2565 struct gcpro gcpro1
;
2567 Lisp_Object args
[4];
2574 RETURN_UNGCPRO (Ffuncall (4, args
));
2575 #else /* not NO_ARG_ARRAY */
2578 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2579 #endif /* not NO_ARG_ARRAY */
2582 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2585 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2586 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2588 struct gcpro gcpro1
;
2590 Lisp_Object args
[5];
2598 RETURN_UNGCPRO (Ffuncall (5, args
));
2599 #else /* not NO_ARG_ARRAY */
2602 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2603 #endif /* not NO_ARG_ARRAY */
2606 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2609 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2610 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2612 struct gcpro gcpro1
;
2614 Lisp_Object args
[6];
2623 RETURN_UNGCPRO (Ffuncall (6, args
));
2624 #else /* not NO_ARG_ARRAY */
2627 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2628 #endif /* not NO_ARG_ARRAY */
2631 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2634 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2635 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2637 struct gcpro gcpro1
;
2639 Lisp_Object args
[7];
2649 RETURN_UNGCPRO (Ffuncall (7, args
));
2650 #else /* not NO_ARG_ARRAY */
2653 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2654 #endif /* not NO_ARG_ARRAY */
2657 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2658 doc
: /* Call first argument as a function, passing remaining arguments to it.
2659 Return the value that function returns.
2660 Thus, (funcall 'cons 'x 'y) returns (x . y).
2661 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2668 int numargs
= nargs
- 1;
2669 Lisp_Object lisp_numargs
;
2671 struct backtrace backtrace
;
2672 register Lisp_Object
*internal_args
;
2676 if (consing_since_gc
> gc_cons_threshold
)
2677 Fgarbage_collect ();
2679 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2681 if (max_lisp_eval_depth
< 100)
2682 max_lisp_eval_depth
= 100;
2683 if (lisp_eval_depth
> max_lisp_eval_depth
)
2684 error ("Lisp nesting exceeds max-lisp-eval-depth");
2687 backtrace
.next
= backtrace_list
;
2688 backtrace_list
= &backtrace
;
2689 backtrace
.function
= &args
[0];
2690 backtrace
.args
= &args
[1];
2691 backtrace
.nargs
= nargs
- 1;
2692 backtrace
.evalargs
= 0;
2693 backtrace
.debug_on_exit
= 0;
2695 if (debug_on_next_call
)
2696 do_debug_on_call (Qlambda
);
2702 fun
= Findirect_function (fun
);
2706 if (numargs
< XSUBR (fun
)->min_args
2707 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2709 XSETFASTINT (lisp_numargs
, numargs
);
2710 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2713 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2714 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2716 if (XSUBR (fun
)->max_args
== MANY
)
2718 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2722 if (XSUBR (fun
)->max_args
> numargs
)
2724 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2725 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2726 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2727 internal_args
[i
] = Qnil
;
2730 internal_args
= args
+ 1;
2731 switch (XSUBR (fun
)->max_args
)
2734 val
= (*XSUBR (fun
)->function
) ();
2737 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2740 val
= (*XSUBR (fun
)->function
) (internal_args
[0],
2744 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2748 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2753 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2754 internal_args
[2], internal_args
[3],
2758 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2759 internal_args
[2], internal_args
[3],
2760 internal_args
[4], internal_args
[5]);
2763 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2764 internal_args
[2], internal_args
[3],
2765 internal_args
[4], internal_args
[5],
2770 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2771 internal_args
[2], internal_args
[3],
2772 internal_args
[4], internal_args
[5],
2773 internal_args
[6], internal_args
[7]);
2778 /* If a subr takes more than 8 arguments without using MANY
2779 or UNEVALLED, we need to extend this function to support it.
2780 Until this is done, there is no way to call the function. */
2784 if (COMPILEDP (fun
))
2785 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2789 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2790 funcar
= Fcar (fun
);
2791 if (!SYMBOLP (funcar
))
2792 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2793 if (EQ (funcar
, Qlambda
))
2794 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2795 else if (EQ (funcar
, Qautoload
))
2797 do_autoload (fun
, args
[0]);
2801 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2805 if (backtrace
.debug_on_exit
)
2806 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2807 backtrace_list
= backtrace
.next
;
2812 apply_lambda (fun
, args
, eval_flag
)
2813 Lisp_Object fun
, args
;
2816 Lisp_Object args_left
;
2817 Lisp_Object numargs
;
2818 register Lisp_Object
*arg_vector
;
2819 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2821 register Lisp_Object tem
;
2823 numargs
= Flength (args
);
2824 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2827 GCPRO3 (*arg_vector
, args_left
, fun
);
2830 for (i
= 0; i
< XINT (numargs
);)
2832 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2833 if (eval_flag
) tem
= Feval (tem
);
2834 arg_vector
[i
++] = tem
;
2842 backtrace_list
->args
= arg_vector
;
2843 backtrace_list
->nargs
= i
;
2845 backtrace_list
->evalargs
= 0;
2846 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
2848 /* Do the debug-on-exit now, while arg_vector still exists. */
2849 if (backtrace_list
->debug_on_exit
)
2850 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
2851 /* Don't do it again when we return to eval. */
2852 backtrace_list
->debug_on_exit
= 0;
2856 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2857 and return the result of evaluation.
2858 FUN must be either a lambda-expression or a compiled-code object. */
2861 funcall_lambda (fun
, nargs
, arg_vector
)
2864 register Lisp_Object
*arg_vector
;
2866 Lisp_Object val
, syms_left
, next
;
2867 int count
= SPECPDL_INDEX ();
2868 int i
, optional
, rest
;
2872 syms_left
= XCDR (fun
);
2873 if (CONSP (syms_left
))
2874 syms_left
= XCAR (syms_left
);
2876 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2878 else if (COMPILEDP (fun
))
2879 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2883 i
= optional
= rest
= 0;
2884 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2888 next
= XCAR (syms_left
);
2889 while (!SYMBOLP (next
))
2890 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2892 if (EQ (next
, Qand_rest
))
2894 else if (EQ (next
, Qand_optional
))
2898 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
2902 specbind (next
, arg_vector
[i
++]);
2904 return Fsignal (Qwrong_number_of_arguments
,
2905 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2907 specbind (next
, Qnil
);
2910 if (!NILP (syms_left
))
2911 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2913 return Fsignal (Qwrong_number_of_arguments
,
2914 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2917 val
= Fprogn (XCDR (XCDR (fun
)));
2920 /* If we have not actually read the bytecode string
2921 and constants vector yet, fetch them from the file. */
2922 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2923 Ffetch_bytecode (fun
);
2924 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
2925 AREF (fun
, COMPILED_CONSTANTS
),
2926 AREF (fun
, COMPILED_STACK_DEPTH
));
2929 return unbind_to (count
, val
);
2932 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2934 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2940 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
2942 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2945 tem
= AREF (object
, COMPILED_BYTECODE
);
2946 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2947 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2949 error ("Invalid byte code");
2951 AREF (object
, COMPILED_BYTECODE
) = XCAR (tem
);
2952 AREF (object
, COMPILED_CONSTANTS
) = XCDR (tem
);
2960 register int count
= SPECPDL_INDEX ();
2961 if (specpdl_size
>= max_specpdl_size
)
2963 if (max_specpdl_size
< 400)
2964 max_specpdl_size
= 400;
2965 if (specpdl_size
>= max_specpdl_size
)
2967 if (!NILP (Vdebug_on_error
))
2968 /* Leave room for some specpdl in the debugger. */
2969 max_specpdl_size
= specpdl_size
+ 100;
2971 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
2975 if (specpdl_size
> max_specpdl_size
)
2976 specpdl_size
= max_specpdl_size
;
2977 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
2978 specpdl_ptr
= specpdl
+ count
;
2982 specbind (symbol
, value
)
2983 Lisp_Object symbol
, value
;
2986 Lisp_Object valcontents
;
2988 CHECK_SYMBOL (symbol
);
2989 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2992 /* The most common case is that of a non-constant symbol with a
2993 trivial value. Make that as fast as we can. */
2994 valcontents
= SYMBOL_VALUE (symbol
);
2995 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
2997 specpdl_ptr
->symbol
= symbol
;
2998 specpdl_ptr
->old_value
= valcontents
;
2999 specpdl_ptr
->func
= NULL
;
3001 SET_SYMBOL_VALUE (symbol
, value
);
3005 Lisp_Object valcontents
;
3007 ovalue
= find_symbol_value (symbol
);
3008 specpdl_ptr
->func
= 0;
3009 specpdl_ptr
->old_value
= ovalue
;
3011 valcontents
= XSYMBOL (symbol
)->value
;
3013 if (BUFFER_LOCAL_VALUEP (valcontents
)
3014 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
3015 || BUFFER_OBJFWDP (valcontents
))
3017 Lisp_Object where
, current_buffer
;
3019 current_buffer
= Fcurrent_buffer ();
3021 /* For a local variable, record both the symbol and which
3022 buffer's or frame's value we are saving. */
3023 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3024 where
= current_buffer
;
3025 else if (!BUFFER_OBJFWDP (valcontents
)
3026 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3027 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3031 /* We're not using the `unused' slot in the specbinding
3032 structure because this would mean we have to do more
3033 work for simple variables. */
3034 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3036 /* If SYMBOL is a per-buffer variable which doesn't have a
3037 buffer-local value here, make the `let' change the global
3038 value by changing the value of SYMBOL in all buffers not
3039 having their own value. This is consistent with what
3040 happens with other buffer-local variables. */
3042 && BUFFER_OBJFWDP (valcontents
))
3045 Fset_default (symbol
, value
);
3050 specpdl_ptr
->symbol
= symbol
;
3053 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3054 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3056 set_internal (symbol
, value
, 0, 1);
3061 record_unwind_protect (function
, arg
)
3062 Lisp_Object (*function
) P_ ((Lisp_Object
));
3065 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3067 specpdl_ptr
->func
= function
;
3068 specpdl_ptr
->symbol
= Qnil
;
3069 specpdl_ptr
->old_value
= arg
;
3074 unbind_to (count
, value
)
3078 int quitf
= !NILP (Vquit_flag
);
3079 struct gcpro gcpro1
;
3084 while (specpdl_ptr
!= specpdl
+ count
)
3088 if (specpdl_ptr
->func
!= 0)
3089 (*specpdl_ptr
->func
) (specpdl_ptr
->old_value
);
3090 /* Note that a "binding" of nil is really an unwind protect,
3091 so in that case the "old value" is a list of forms to evaluate. */
3092 else if (NILP (specpdl_ptr
->symbol
))
3093 Fprogn (specpdl_ptr
->old_value
);
3094 /* If the symbol is a list, it is really (SYMBOL WHERE
3095 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3096 frame. If WHERE is a buffer or frame, this indicates we
3097 bound a variable that had a buffer-local or frame-local
3098 binding. WHERE nil means that the variable had the default
3099 value when it was bound. CURRENT-BUFFER is the buffer that
3100 was current when the variable was bound. */
3101 else if (CONSP (specpdl_ptr
->symbol
))
3103 Lisp_Object symbol
, where
;
3105 symbol
= XCAR (specpdl_ptr
->symbol
);
3106 where
= XCAR (XCDR (specpdl_ptr
->symbol
));
3109 Fset_default (symbol
, specpdl_ptr
->old_value
);
3110 else if (BUFFERP (where
))
3111 set_internal (symbol
, specpdl_ptr
->old_value
, XBUFFER (where
), 1);
3113 set_internal (symbol
, specpdl_ptr
->old_value
, NULL
, 1);
3117 /* If variable has a trivial value (no forwarding), we can
3118 just set it. No need to check for constant symbols here,
3119 since that was already done by specbind. */
3120 if (!MISCP (SYMBOL_VALUE (specpdl_ptr
->symbol
)))
3121 SET_SYMBOL_VALUE (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
);
3123 set_internal (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
, 0, 1);
3127 if (NILP (Vquit_flag
) && quitf
)
3134 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3135 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3136 The debugger is entered when that frame exits, if the flag is non-nil. */)
3138 Lisp_Object level
, flag
;
3140 register struct backtrace
*backlist
= backtrace_list
;
3143 CHECK_NUMBER (level
);
3145 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3147 backlist
= backlist
->next
;
3151 backlist
->debug_on_exit
= !NILP (flag
);
3156 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3157 doc
: /* Print a trace of Lisp function calls currently active.
3158 Output stream used is value of `standard-output'. */)
3161 register struct backtrace
*backlist
= backtrace_list
;
3165 extern Lisp_Object Vprint_level
;
3166 struct gcpro gcpro1
;
3168 XSETFASTINT (Vprint_level
, 3);
3175 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3176 if (backlist
->nargs
== UNEVALLED
)
3178 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3179 write_string ("\n", -1);
3183 tem
= *backlist
->function
;
3184 Fprin1 (tem
, Qnil
); /* This can QUIT */
3185 write_string ("(", -1);
3186 if (backlist
->nargs
== MANY
)
3188 for (tail
= *backlist
->args
, i
= 0;
3190 tail
= Fcdr (tail
), i
++)
3192 if (i
) write_string (" ", -1);
3193 Fprin1 (Fcar (tail
), Qnil
);
3198 for (i
= 0; i
< backlist
->nargs
; i
++)
3200 if (i
) write_string (" ", -1);
3201 Fprin1 (backlist
->args
[i
], Qnil
);
3204 write_string (")\n", -1);
3206 backlist
= backlist
->next
;
3209 Vprint_level
= Qnil
;
3214 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3215 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3216 If that frame has not evaluated the arguments yet (or is a special form),
3217 the value is (nil FUNCTION ARG-FORMS...).
3218 If that frame has evaluated its arguments and called its function already,
3219 the value is (t FUNCTION ARG-VALUES...).
3220 A &rest arg is represented as the tail of the list ARG-VALUES.
3221 FUNCTION is whatever was supplied as car of evaluated list,
3222 or a lambda expression for macro calls.
3223 If NFRAMES is more than the number of frames, the value is nil. */)
3225 Lisp_Object nframes
;
3227 register struct backtrace
*backlist
= backtrace_list
;
3231 CHECK_NATNUM (nframes
);
3233 /* Find the frame requested. */
3234 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3235 backlist
= backlist
->next
;
3239 if (backlist
->nargs
== UNEVALLED
)
3240 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3243 if (backlist
->nargs
== MANY
)
3244 tem
= *backlist
->args
;
3246 tem
= Flist (backlist
->nargs
, backlist
->args
);
3248 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3256 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3257 doc
: /* *Limit on number of Lisp variable bindings & unwind-protects.
3258 If Lisp code tries to make more than this many at once,
3259 an error is signaled.
3260 You can safely use a value considerably larger than the default value,
3261 if that proves inconveniently small. However, if you increase it too far,
3262 Emacs could run out of memory trying to make the stack bigger. */);
3264 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3265 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3267 This limit serves to catch infinite recursions for you before they cause
3268 actual stack overflow in C, which would be fatal for Emacs.
3269 You can safely make it considerably larger than its default value,
3270 if that proves inconveniently small. However, if you increase it too far,
3271 Emacs could overflow the real C stack, and crash. */);
3273 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3274 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3275 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */);
3278 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3279 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3280 Note that `quit-flag' will still be set by typing C-g,
3281 so a quit will be signaled as soon as `inhibit-quit' is nil.
3282 To prevent this happening, set `quit-flag' to nil
3283 before making `inhibit-quit' nil. */);
3284 Vinhibit_quit
= Qnil
;
3286 Qinhibit_quit
= intern ("inhibit-quit");
3287 staticpro (&Qinhibit_quit
);
3289 Qautoload
= intern ("autoload");
3290 staticpro (&Qautoload
);
3292 Qdebug_on_error
= intern ("debug-on-error");
3293 staticpro (&Qdebug_on_error
);
3295 Qmacro
= intern ("macro");
3296 staticpro (&Qmacro
);
3298 Qdeclare
= intern ("declare");
3299 staticpro (&Qdeclare
);
3301 /* Note that the process handling also uses Qexit, but we don't want
3302 to staticpro it twice, so we just do it here. */
3303 Qexit
= intern ("exit");
3306 Qinteractive
= intern ("interactive");
3307 staticpro (&Qinteractive
);
3309 Qcommandp
= intern ("commandp");
3310 staticpro (&Qcommandp
);
3312 Qdefun
= intern ("defun");
3313 staticpro (&Qdefun
);
3315 Qdefvar
= intern ("defvar");
3316 staticpro (&Qdefvar
);
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 doc
: /* *Non-nil means errors display a backtrace buffer.
3326 More precisely, this happens for any error that is handled
3327 by the editor command loop.
3328 If the value is a list, an error only means to display a backtrace
3329 if one of its condition symbols appears in the list. */);
3330 Vstack_trace_on_error
= Qnil
;
3332 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3333 doc
: /* *Non-nil means enter debugger if an error is signaled.
3334 Does not apply to errors handled by `condition-case' or those
3335 matched by `debug-ignored-errors'.
3336 If the value is a list, an error only means to enter the debugger
3337 if one of its condition symbols appears in the list.
3338 When you evaluate an expression interactively, this variable
3339 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3340 See also variable `debug-on-quit'. */);
3341 Vdebug_on_error
= Qnil
;
3343 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3344 doc
: /* *List of errors for which the debugger should not be called.
3345 Each element may be a condition-name or a regexp that matches error messages.
3346 If any element applies to a given error, that error skips the debugger
3347 and just returns to top level.
3348 This overrides the variable `debug-on-error'.
3349 It does not apply to errors handled by `condition-case'. */);
3350 Vdebug_ignored_errors
= Qnil
;
3352 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3353 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3354 Does not apply if quit is handled by a `condition-case'.
3355 When you evaluate an expression interactively, this variable
3356 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3359 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3360 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3362 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3363 doc
: /* Non-nil means debugger may continue execution.
3364 This is nil when the debugger is called under circumstances where it
3365 might not be safe to continue. */);
3366 debugger_may_continue
= 1;
3368 DEFVAR_LISP ("debugger", &Vdebugger
,
3369 doc
: /* Function to call to invoke debugger.
3370 If due to frame exit, args are `exit' and the value being returned;
3371 this function's value will be returned instead of that.
3372 If due to error, args are `error' and a list of the args to `signal'.
3373 If due to `apply' or `funcall' entry, one arg, `lambda'.
3374 If due to `eval' entry, one arg, t. */);
3377 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3378 doc
: /* If non-nil, this is a function for `signal' to call.
3379 It receives the same arguments that `signal' was given.
3380 The Edebug package uses this to regain control. */);
3381 Vsignal_hook_function
= Qnil
;
3383 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3384 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3385 Note that `debug-on-error', `debug-on-quit' and friends
3386 still determine whether to handle the particular condition. */);
3387 Vdebug_on_signal
= Qnil
;
3389 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3390 doc
: /* Function to process declarations in a macro definition.
3391 The function will be called with two args MACRO and DECL.
3392 MACRO is the name of the macro being defined.
3393 DECL is a list `(declare ...)' containing the declarations.
3394 The value the function returns is not used. */);
3395 Vmacro_declaration_function
= Qnil
;
3397 Vrun_hooks
= intern ("run-hooks");
3398 staticpro (&Vrun_hooks
);
3400 staticpro (&Vautoload_queue
);
3401 Vautoload_queue
= Qnil
;
3402 staticpro (&Vsignaling_function
);
3403 Vsignaling_function
= Qnil
;
3414 defsubr (&Sfunction
);
3416 defsubr (&Sdefmacro
);
3418 defsubr (&Sdefvaralias
);
3419 defsubr (&Sdefconst
);
3420 defsubr (&Suser_variable_p
);
3424 defsubr (&Smacroexpand
);
3427 defsubr (&Sunwind_protect
);
3428 defsubr (&Scondition_case
);
3430 defsubr (&Sinteractive_p
);
3431 defsubr (&Scommandp
);
3432 defsubr (&Sautoload
);
3435 defsubr (&Sfuncall
);
3436 defsubr (&Srun_hooks
);
3437 defsubr (&Srun_hook_with_args
);
3438 defsubr (&Srun_hook_with_args_until_success
);
3439 defsubr (&Srun_hook_with_args_until_failure
);
3440 defsubr (&Sfetch_bytecode
);
3441 defsubr (&Sbacktrace_debug
);
3442 defsubr (&Sbacktrace
);
3443 defsubr (&Sbacktrace_frame
);