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 int interrupt_input_blocked
;
81 struct byte_stack
*byte_stack
;
84 struct catchtag
*catchlist
;
87 /* Count levels of GCPRO to detect failure to UNGCPRO. */
91 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
, Qdefun
, Qdefvar
;
92 Lisp_Object Qinhibit_quit
, Vinhibit_quit
, Vquit_flag
;
93 Lisp_Object Qand_rest
, Qand_optional
;
94 Lisp_Object Qdebug_on_error
;
97 /* This holds either the symbol `run-hooks' or nil.
98 It is nil at an early stage of startup, and when Emacs
101 Lisp_Object Vrun_hooks
;
103 /* Non-nil means record all fset's and provide's, to be undone
104 if the file being autoloaded is not fully loaded.
105 They are recorded by being consed onto the front of Vautoload_queue:
106 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
108 Lisp_Object Vautoload_queue
;
110 /* Current number of specbindings allocated in specpdl. */
114 /* Pointer to beginning of specpdl. */
116 struct specbinding
*specpdl
;
118 /* Pointer to first unused element in specpdl. */
120 struct specbinding
*specpdl_ptr
;
122 /* Maximum size allowed for specpdl allocation */
124 EMACS_INT max_specpdl_size
;
126 /* Depth in Lisp evaluations and function calls. */
130 /* Maximum allowed depth in Lisp evaluations and function calls. */
132 EMACS_INT max_lisp_eval_depth
;
134 /* Nonzero means enter debugger before next function call */
136 int debug_on_next_call
;
138 /* Non-zero means debugger may continue. This is zero when the
139 debugger is called during redisplay, where it might not be safe to
140 continue the interrupted redisplay. */
142 int debugger_may_continue
;
144 /* List of conditions (non-nil atom means all) which cause a backtrace
145 if an error is handled by the command loop's error handler. */
147 Lisp_Object Vstack_trace_on_error
;
149 /* List of conditions (non-nil atom means all) which enter the debugger
150 if an error is handled by the command loop's error handler. */
152 Lisp_Object Vdebug_on_error
;
154 /* List of conditions and regexps specifying error messages which
155 do not enter the debugger even if Vdebug_on_error says they should. */
157 Lisp_Object Vdebug_ignored_errors
;
159 /* Non-nil means call the debugger even if the error will be handled. */
161 Lisp_Object Vdebug_on_signal
;
163 /* Hook for edebug to use. */
165 Lisp_Object Vsignal_hook_function
;
167 /* Nonzero means enter debugger if a quit signal
168 is handled by the command loop's error handler. */
172 /* The value of num_nonmacro_input_events as of the last time we
173 started to enter the debugger. If we decide to enter the debugger
174 again when this is still equal to num_nonmacro_input_events, then we
175 know that the debugger itself has an error, and we should just
176 signal the error instead of entering an infinite loop of debugger
179 int when_entered_debugger
;
181 Lisp_Object Vdebugger
;
183 /* The function from which the last `signal' was called. Set in
186 Lisp_Object Vsignaling_function
;
188 /* Set to non-zero while processing X events. Checked in Feval to
189 make sure the Lisp interpreter isn't called from a signal handler,
190 which is unsafe because the interpreter isn't reentrant. */
194 /* Function to process declarations in defmacro forms. */
196 Lisp_Object Vmacro_declaration_function
;
199 static Lisp_Object funcall_lambda
P_ ((Lisp_Object
, int, Lisp_Object
*));
205 specpdl
= (struct specbinding
*) xmalloc (specpdl_size
* sizeof (struct specbinding
));
206 specpdl_ptr
= specpdl
;
207 max_specpdl_size
= 600;
208 max_lisp_eval_depth
= 300;
216 specpdl_ptr
= specpdl
;
221 debug_on_next_call
= 0;
226 /* This is less than the initial value of num_nonmacro_input_events. */
227 when_entered_debugger
= -1;
234 int debug_while_redisplaying
;
235 int count
= SPECPDL_INDEX ();
238 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
239 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
241 if (specpdl_size
+ 40 > max_specpdl_size
)
242 max_specpdl_size
= specpdl_size
+ 40;
244 #ifdef HAVE_X_WINDOWS
245 if (display_hourglass_p
)
249 debug_on_next_call
= 0;
250 when_entered_debugger
= num_nonmacro_input_events
;
252 /* Resetting redisplaying_p to 0 makes sure that debug output is
253 displayed if the debugger is invoked during redisplay. */
254 debug_while_redisplaying
= redisplaying_p
;
256 specbind (intern ("debugger-may-continue"),
257 debug_while_redisplaying
? Qnil
: Qt
);
258 specbind (Qinhibit_redisplay
, Qnil
);
260 #if 0 /* Binding this prevents execution of Lisp code during
261 redisplay, which necessarily leads to display problems. */
262 specbind (Qinhibit_eval_during_redisplay
, Qt
);
265 val
= apply1 (Vdebugger
, arg
);
267 /* Interrupting redisplay and resuming it later is not safe under
268 all circumstances. So, when the debugger returns, abort the
269 interrupted redisplay by going back to the top-level. */
270 if (debug_while_redisplaying
)
273 return unbind_to (count
, val
);
277 do_debug_on_call (code
)
280 debug_on_next_call
= 0;
281 backtrace_list
->debug_on_exit
= 1;
282 call_debugger (Fcons (code
, Qnil
));
285 /* NOTE!!! Every function that can call EVAL must protect its args
286 and temporaries from garbage collection while it needs them.
287 The definition of `For' shows what you have to do. */
289 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
290 doc
: /* Eval args until one of them yields non-nil, then return that value.
291 The remaining args are not evalled at all.
292 If all args return nil, return nil.
293 usage: (or CONDITIONS ...) */)
297 register Lisp_Object val
;
298 Lisp_Object args_left
;
309 val
= Feval (Fcar (args_left
));
312 args_left
= Fcdr (args_left
);
314 while (!NILP(args_left
));
320 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
321 doc
: /* Eval args until one of them yields nil, then return nil.
322 The remaining args are not evalled at all.
323 If no arg yields nil, return the last arg's value.
324 usage: (and CONDITIONS ...) */)
328 register Lisp_Object val
;
329 Lisp_Object args_left
;
340 val
= Feval (Fcar (args_left
));
343 args_left
= Fcdr (args_left
);
345 while (!NILP(args_left
));
351 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
352 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
353 Returns the value of THEN or the value of the last of the ELSE's.
354 THEN must be one expression, but ELSE... can be zero or more expressions.
355 If COND yields nil, and there are no ELSE's, the value is nil.
356 usage: (if COND THEN ELSE...) */)
360 register Lisp_Object cond
;
364 cond
= Feval (Fcar (args
));
368 return Feval (Fcar (Fcdr (args
)));
369 return Fprogn (Fcdr (Fcdr (args
)));
372 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
373 doc
: /* Try each clause until one succeeds.
374 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
375 and, if the value is non-nil, this clause succeeds:
376 then the expressions in BODY are evaluated and the last one's
377 value is the value of the cond-form.
378 If no clause succeeds, cond returns nil.
379 If a clause has one element, as in (CONDITION),
380 CONDITION's value if non-nil is returned from the cond-form.
381 usage: (cond CLAUSES...) */)
385 register Lisp_Object clause
, val
;
392 clause
= Fcar (args
);
393 val
= Feval (Fcar (clause
));
396 if (!EQ (XCDR (clause
), Qnil
))
397 val
= Fprogn (XCDR (clause
));
407 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
408 doc
: /* Eval BODY forms sequentially and return value of last one.
409 usage: (progn BODY ...) */)
413 register Lisp_Object val
;
414 Lisp_Object args_left
;
425 val
= Feval (Fcar (args_left
));
426 args_left
= Fcdr (args_left
);
428 while (!NILP(args_left
));
434 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
435 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
436 The value of FIRST is saved during the evaluation of the remaining args,
437 whose values are discarded.
438 usage: (prog1 FIRST BODY...) */)
443 register Lisp_Object args_left
;
444 struct gcpro gcpro1
, gcpro2
;
445 register int argnum
= 0;
457 val
= Feval (Fcar (args_left
));
459 Feval (Fcar (args_left
));
460 args_left
= Fcdr (args_left
);
462 while (!NILP(args_left
));
468 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
469 doc
: /* Eval X, Y and BODY sequentially; value from Y.
470 The value of Y is saved during the evaluation of the remaining args,
471 whose values are discarded.
472 usage: (prog2 X Y BODY...) */)
477 register Lisp_Object args_left
;
478 struct gcpro gcpro1
, gcpro2
;
479 register int argnum
= -1;
493 val
= Feval (Fcar (args_left
));
495 Feval (Fcar (args_left
));
496 args_left
= Fcdr (args_left
);
498 while (!NILP (args_left
));
504 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
505 doc
: /* Set each SYM to the value of its VAL.
506 The symbols SYM are variables; they are literal (not evaluated).
507 The values VAL are expressions; they are evaluated.
508 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
509 The second VAL is not computed until after the first SYM is set, and so on;
510 each VAL can use the new value of variables set earlier in the `setq'.
511 The return value of the `setq' form is the value of the last VAL.
512 usage: (setq SYM VAL SYM VAL ...) */)
516 register Lisp_Object args_left
;
517 register Lisp_Object val
, sym
;
528 val
= Feval (Fcar (Fcdr (args_left
)));
529 sym
= Fcar (args_left
);
531 args_left
= Fcdr (Fcdr (args_left
));
533 while (!NILP(args_left
));
539 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
540 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
541 usage: (quote ARG) */)
548 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
549 doc
: /* Like `quote', but preferred for objects which are functions.
550 In byte compilation, `function' causes its argument to be compiled.
551 `quote' cannot do that.
552 usage: (function ARG) */)
560 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
561 doc
: /* Return t if function in which this appears was called interactively.
562 This means that the function was called with call-interactively (which
563 includes being called as the binding of a key)
564 and input is currently coming from the keyboard (not in keyboard macro). */)
567 return interactive_p (1) ? Qt
: Qnil
;
571 /* Return 1 if function in which this appears was called
572 interactively. This means that the function was called with
573 call-interactively (which includes being called as the binding of
574 a key) and input is currently coming from the keyboard (not in
577 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
578 called is a built-in. */
581 interactive_p (exclude_subrs_p
)
584 struct backtrace
*btp
;
590 btp
= backtrace_list
;
592 /* If this isn't a byte-compiled function, there may be a frame at
593 the top for Finteractive_p. If so, skip it. */
594 fun
= Findirect_function (*btp
->function
);
595 if (SUBRP (fun
) && XSUBR (fun
) == &Sinteractive_p
)
598 /* If we're running an Emacs 18-style byte-compiled function, there
599 may be a frame for Fbytecode at the top level. In any version of
600 Emacs there can be Fbytecode frames for subexpressions evaluated
601 inside catch and condition-case. Skip past them.
603 If this isn't a byte-compiled function, then we may now be
604 looking at several frames for special forms. Skip past them. */
606 && (EQ (*btp
->function
, Qbytecode
)
607 || btp
->nargs
== UNEVALLED
))
610 /* btp now points at the frame of the innermost function that isn't
611 a special form, ignoring frames for Finteractive_p and/or
612 Fbytecode at the top. If this frame is for a built-in function
613 (such as load or eval-region) return nil. */
614 fun
= Findirect_function (*btp
->function
);
615 if (exclude_subrs_p
&& SUBRP (fun
))
618 /* btp points to the frame of a Lisp function that called interactive-p.
619 Return t if that function was called interactively. */
620 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
626 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
627 doc
: /* Define NAME as a function.
628 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
629 See also the function `interactive'.
630 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
634 register Lisp_Object fn_name
;
635 register Lisp_Object defn
;
637 fn_name
= Fcar (args
);
638 defn
= Fcons (Qlambda
, Fcdr (args
));
639 if (!NILP (Vpurify_flag
))
640 defn
= Fpurecopy (defn
);
641 if (CONSP (XSYMBOL (fn_name
)->function
)
642 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
643 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
644 Ffset (fn_name
, defn
);
645 LOADHIST_ATTACH (fn_name
);
649 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
650 doc
: /* Define NAME as a macro.
651 The actual definition looks like
652 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
653 When the macro is called, as in (NAME ARGS...),
654 the function (lambda ARGLIST BODY...) is applied to
655 the list ARGS... as it appears in the expression,
656 and the result should be a form to be evaluated instead of the original.
658 DECL is a declaration, optional, which can specify how to indent
659 calls to this macro and how Edebug should handle it. It looks like this:
661 The elements can look like this:
663 Set NAME's `lisp-indent-function' property to INDENT.
666 Set NAME's `edebug-form-spec' property to DEBUG. (This is
667 equivalent to writing a `def-edebug-spec' for the macro.
668 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
672 register Lisp_Object fn_name
;
673 register Lisp_Object defn
;
674 Lisp_Object lambda_list
, doc
, tail
;
676 fn_name
= Fcar (args
);
677 lambda_list
= Fcar (Fcdr (args
));
678 tail
= Fcdr (Fcdr (args
));
681 if (STRINGP (Fcar (tail
)))
687 while (CONSP (Fcar (tail
))
688 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
690 if (!NILP (Vmacro_declaration_function
))
694 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
702 tail
= Fcons (lambda_list
, tail
);
704 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
705 defn
= Fcons (Qmacro
, Fcons (Qlambda
, tail
));
707 if (!NILP (Vpurify_flag
))
708 defn
= Fpurecopy (defn
);
709 if (CONSP (XSYMBOL (fn_name
)->function
)
710 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
711 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
712 Ffset (fn_name
, defn
);
713 LOADHIST_ATTACH (fn_name
);
718 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
719 doc
: /* Make SYMBOL a variable alias for symbol ALIASED.
720 Setting the value of SYMBOL will subsequently set the value of ALIASED,
721 and getting the value of SYMBOL will return the value ALIASED has.
722 ALIASED nil means remove the alias; SYMBOL is unbound after that.
723 Third arg DOCSTRING, if non-nil, is documentation for SYMBOL. */)
724 (symbol
, aliased
, docstring
)
725 Lisp_Object symbol
, aliased
, docstring
;
727 struct Lisp_Symbol
*sym
;
729 CHECK_SYMBOL (symbol
);
730 CHECK_SYMBOL (aliased
);
732 if (SYMBOL_CONSTANT_P (symbol
))
733 error ("Cannot make a constant an alias");
735 sym
= XSYMBOL (symbol
);
736 sym
->indirect_variable
= 1;
737 sym
->value
= aliased
;
738 sym
->constant
= SYMBOL_CONSTANT_P (aliased
);
739 LOADHIST_ATTACH (Fcons (Qdefvar
, symbol
));
740 if (!NILP (docstring
))
741 Fput (symbol
, Qvariable_documentation
, docstring
);
747 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
748 doc
: /* Define SYMBOL as a variable.
749 You are not required to define a variable in order to use it,
750 but the definition can supply documentation and an initial value
751 in a way that tags can recognize.
753 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
754 If SYMBOL is buffer-local, its default value is what is set;
755 buffer-local values are not affected.
756 INITVALUE and DOCSTRING are optional.
757 If DOCSTRING starts with *, this variable is identified as a user option.
758 This means that M-x set-variable recognizes it.
759 See also `user-variable-p'.
760 If INITVALUE is missing, SYMBOL's value is not set.
761 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
765 register Lisp_Object sym
, tem
, tail
;
769 if (!NILP (Fcdr (Fcdr (tail
))))
770 error ("too many arguments");
772 tem
= Fdefault_boundp (sym
);
776 Fset_default (sym
, Feval (Fcar (tail
)));
778 if (!NILP (Fcar (tail
)))
781 if (!NILP (Vpurify_flag
))
782 tem
= Fpurecopy (tem
);
783 Fput (sym
, Qvariable_documentation
, tem
);
785 LOADHIST_ATTACH (Fcons (Qdefvar
, sym
));
788 /* Simple (defvar <var>) should not count as a definition at all.
789 It could get in the way of other definitions, and unloading this
790 package could try to make the variable unbound. */
796 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
797 doc
: /* Define SYMBOL as a constant variable.
798 The intent is that neither programs nor users should ever change this value.
799 Always sets the value of SYMBOL to the result of evalling INITVALUE.
800 If SYMBOL is buffer-local, its default value is what is set;
801 buffer-local values are not affected.
802 DOCSTRING is optional.
803 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
807 register Lisp_Object sym
, tem
;
810 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
811 error ("too many arguments");
813 tem
= Feval (Fcar (Fcdr (args
)));
814 if (!NILP (Vpurify_flag
))
815 tem
= Fpurecopy (tem
);
816 Fset_default (sym
, tem
);
817 tem
= Fcar (Fcdr (Fcdr (args
)));
820 if (!NILP (Vpurify_flag
))
821 tem
= Fpurecopy (tem
);
822 Fput (sym
, Qvariable_documentation
, tem
);
824 LOADHIST_ATTACH (Fcons (Qdefvar
, sym
));
828 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
829 doc
: /* Returns t if VARIABLE is intended to be set and modified by users.
830 \(The alternative is a variable used internally in a Lisp program.)
831 Determined by whether the first character of the documentation
832 for the variable is `*' or if the variable is customizable (has a non-nil
833 value of any of `custom-type', `custom-loads' or `standard-value'
834 on its property list). */)
836 Lisp_Object variable
;
838 Lisp_Object documentation
;
840 if (!SYMBOLP (variable
))
843 documentation
= Fget (variable
, Qvariable_documentation
);
844 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
846 if (STRINGP (documentation
)
847 && ((unsigned char) SREF (documentation
, 0) == '*'))
849 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
850 if (CONSP (documentation
)
851 && STRINGP (XCAR (documentation
))
852 && INTEGERP (XCDR (documentation
))
853 && XINT (XCDR (documentation
)) < 0)
856 if ((!NILP (Fget (variable
, intern ("custom-type"))))
857 || (!NILP (Fget (variable
, intern ("custom-loads"))))
858 || (!NILP (Fget (variable
, intern ("standard-value")))))
863 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
864 doc
: /* Bind variables according to VARLIST then eval BODY.
865 The value of the last form in BODY is returned.
866 Each element of VARLIST is a symbol (which is bound to nil)
867 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
868 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
869 usage: (let* VARLIST BODY...) */)
873 Lisp_Object varlist
, val
, elt
;
874 int count
= SPECPDL_INDEX ();
875 struct gcpro gcpro1
, gcpro2
, gcpro3
;
877 GCPRO3 (args
, elt
, varlist
);
879 varlist
= Fcar (args
);
880 while (!NILP (varlist
))
883 elt
= Fcar (varlist
);
885 specbind (elt
, Qnil
);
886 else if (! NILP (Fcdr (Fcdr (elt
))))
888 Fcons (build_string ("`let' bindings can have only one value-form"),
892 val
= Feval (Fcar (Fcdr (elt
)));
893 specbind (Fcar (elt
), val
);
895 varlist
= Fcdr (varlist
);
898 val
= Fprogn (Fcdr (args
));
899 return unbind_to (count
, val
);
902 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
903 doc
: /* Bind variables according to VARLIST then eval BODY.
904 The value of the last form in BODY is returned.
905 Each element of VARLIST is a symbol (which is bound to nil)
906 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
907 All the VALUEFORMs are evalled before any symbols are bound.
908 usage: (let VARLIST BODY...) */)
912 Lisp_Object
*temps
, tem
;
913 register Lisp_Object elt
, varlist
;
914 int count
= SPECPDL_INDEX ();
916 struct gcpro gcpro1
, gcpro2
;
918 varlist
= Fcar (args
);
920 /* Make space to hold the values to give the bound variables */
921 elt
= Flength (varlist
);
922 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
924 /* Compute the values and store them in `temps' */
926 GCPRO2 (args
, *temps
);
929 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
932 elt
= Fcar (varlist
);
934 temps
[argnum
++] = Qnil
;
935 else if (! NILP (Fcdr (Fcdr (elt
))))
937 Fcons (build_string ("`let' bindings can have only one value-form"),
940 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
941 gcpro2
.nvars
= argnum
;
945 varlist
= Fcar (args
);
946 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
948 elt
= Fcar (varlist
);
949 tem
= temps
[argnum
++];
953 specbind (Fcar (elt
), tem
);
956 elt
= Fprogn (Fcdr (args
));
957 return unbind_to (count
, elt
);
960 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
961 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
962 The order of execution is thus TEST, BODY, TEST, BODY and so on
963 until TEST returns nil.
964 usage: (while TEST BODY...) */)
968 Lisp_Object test
, body
;
969 struct gcpro gcpro1
, gcpro2
;
975 while (!NILP (Feval (test
)))
985 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
986 doc
: /* Return result of expanding macros at top level of FORM.
987 If FORM is not a macro call, it is returned unchanged.
988 Otherwise, the macro is expanded and the expansion is considered
989 in place of FORM. When a non-macro-call results, it is returned.
991 The second optional arg ENVIRONMENT specifies an environment of macro
992 definitions to shadow the loaded ones for use in file byte-compilation. */)
995 Lisp_Object environment
;
997 /* With cleanups from Hallvard Furuseth. */
998 register Lisp_Object expander
, sym
, def
, tem
;
1002 /* Come back here each time we expand a macro call,
1003 in case it expands into another macro call. */
1006 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1007 def
= sym
= XCAR (form
);
1009 /* Trace symbols aliases to other symbols
1010 until we get a symbol that is not an alias. */
1011 while (SYMBOLP (def
))
1015 tem
= Fassq (sym
, environment
);
1018 def
= XSYMBOL (sym
)->function
;
1019 if (!EQ (def
, Qunbound
))
1024 /* Right now TEM is the result from SYM in ENVIRONMENT,
1025 and if TEM is nil then DEF is SYM's function definition. */
1028 /* SYM is not mentioned in ENVIRONMENT.
1029 Look at its function definition. */
1030 if (EQ (def
, Qunbound
) || !CONSP (def
))
1031 /* Not defined or definition not suitable */
1033 if (EQ (XCAR (def
), Qautoload
))
1035 /* Autoloading function: will it be a macro when loaded? */
1036 tem
= Fnth (make_number (4), def
);
1037 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1038 /* Yes, load it and try again. */
1040 struct gcpro gcpro1
;
1042 do_autoload (def
, sym
);
1049 else if (!EQ (XCAR (def
), Qmacro
))
1051 else expander
= XCDR (def
);
1055 expander
= XCDR (tem
);
1056 if (NILP (expander
))
1059 form
= apply1 (expander
, XCDR (form
));
1064 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1065 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1066 TAG is evalled to get the tag to use; it must not be nil.
1068 Then the BODY is executed.
1069 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1070 If no throw happens, `catch' returns the value of the last BODY form.
1071 If a throw happens, it specifies the value to return from `catch'.
1072 usage: (catch TAG BODY...) */)
1076 register Lisp_Object tag
;
1077 struct gcpro gcpro1
;
1080 tag
= Feval (Fcar (args
));
1082 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1085 /* Set up a catch, then call C function FUNC on argument ARG.
1086 FUNC should return a Lisp_Object.
1087 This is how catches are done from within C code. */
1090 internal_catch (tag
, func
, arg
)
1092 Lisp_Object (*func
) ();
1095 /* This structure is made part of the chain `catchlist'. */
1098 /* Fill in the components of c, and put it on the list. */
1102 c
.backlist
= backtrace_list
;
1103 c
.handlerlist
= handlerlist
;
1104 c
.lisp_eval_depth
= lisp_eval_depth
;
1105 c
.pdlcount
= SPECPDL_INDEX ();
1106 c
.poll_suppress_count
= poll_suppress_count
;
1107 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1108 c
.gcpro
= gcprolist
;
1109 c
.byte_stack
= byte_stack_list
;
1113 if (! _setjmp (c
.jmp
))
1114 c
.val
= (*func
) (arg
);
1116 /* Throw works by a longjmp that comes right here. */
1121 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1122 jump to that CATCH, returning VALUE as the value of that catch.
1124 This is the guts Fthrow and Fsignal; they differ only in the way
1125 they choose the catch tag to throw to. A catch tag for a
1126 condition-case form has a TAG of Qnil.
1128 Before each catch is discarded, unbind all special bindings and
1129 execute all unwind-protect clauses made above that catch. Unwind
1130 the handler stack as we go, so that the proper handlers are in
1131 effect for each unwind-protect clause we run. At the end, restore
1132 some static info saved in CATCH, and longjmp to the location
1135 This is used for correct unwinding in Fthrow and Fsignal. */
1138 unwind_to_catch (catch, value
)
1139 struct catchtag
*catch;
1142 register int last_time
;
1144 /* Save the value in the tag. */
1147 /* Restore the polling-suppression count. */
1148 set_poll_suppress_count (catch->poll_suppress_count
);
1149 interrupt_input_blocked
= catch->interrupt_input_blocked
;
1153 last_time
= catchlist
== catch;
1155 /* Unwind the specpdl stack, and then restore the proper set of
1157 unbind_to (catchlist
->pdlcount
, Qnil
);
1158 handlerlist
= catchlist
->handlerlist
;
1159 catchlist
= catchlist
->next
;
1161 while (! last_time
);
1163 byte_stack_list
= catch->byte_stack
;
1164 gcprolist
= catch->gcpro
;
1167 gcpro_level
= gcprolist
->level
+ 1;
1171 backtrace_list
= catch->backlist
;
1172 lisp_eval_depth
= catch->lisp_eval_depth
;
1174 _longjmp (catch->jmp
, 1);
1177 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1178 doc
: /* Throw to the catch for TAG and return VALUE from it.
1179 Both TAG and VALUE are evalled. */)
1181 register Lisp_Object tag
, value
;
1183 register struct catchtag
*c
;
1188 for (c
= catchlist
; c
; c
= c
->next
)
1190 if (EQ (c
->tag
, tag
))
1191 unwind_to_catch (c
, value
);
1193 tag
= Fsignal (Qno_catch
, Fcons (tag
, Fcons (value
, Qnil
)));
1198 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1199 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1200 If BODYFORM completes normally, its value is returned
1201 after executing the UNWINDFORMS.
1202 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1203 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1208 int count
= SPECPDL_INDEX ();
1210 record_unwind_protect (0, Fcdr (args
));
1211 val
= Feval (Fcar (args
));
1212 return unbind_to (count
, val
);
1215 /* Chain of condition handlers currently in effect.
1216 The elements of this chain are contained in the stack frames
1217 of Fcondition_case and internal_condition_case.
1218 When an error is signaled (by calling Fsignal, below),
1219 this chain is searched for an element that applies. */
1221 struct handler
*handlerlist
;
1223 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1224 doc
: /* Regain control when an error is signaled.
1225 Executes BODYFORM and returns its value if no error happens.
1226 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1227 where the BODY is made of Lisp expressions.
1229 A handler is applicable to an error
1230 if CONDITION-NAME is one of the error's condition names.
1231 If an error happens, the first applicable handler is run.
1233 The car of a handler may be a list of condition names
1234 instead of a single condition name.
1236 When a handler handles an error,
1237 control returns to the condition-case and the handler BODY... is executed
1238 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1239 VAR may be nil; then you do not get access to the signal information.
1241 The value of the last BODY form is returned from the condition-case.
1242 See also the function `signal' for more info.
1243 usage: (condition-case VAR BODYFORM HANDLERS...) */)
1250 register Lisp_Object bodyform
, handlers
;
1251 volatile Lisp_Object var
;
1254 bodyform
= Fcar (Fcdr (args
));
1255 handlers
= Fcdr (Fcdr (args
));
1258 for (val
= handlers
; ! NILP (val
); val
= Fcdr (val
))
1264 && (SYMBOLP (XCAR (tem
))
1265 || CONSP (XCAR (tem
))))))
1266 error ("Invalid condition handler", tem
);
1271 c
.backlist
= backtrace_list
;
1272 c
.handlerlist
= handlerlist
;
1273 c
.lisp_eval_depth
= lisp_eval_depth
;
1274 c
.pdlcount
= SPECPDL_INDEX ();
1275 c
.poll_suppress_count
= poll_suppress_count
;
1276 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1277 c
.gcpro
= gcprolist
;
1278 c
.byte_stack
= byte_stack_list
;
1279 if (_setjmp (c
.jmp
))
1282 specbind (h
.var
, c
.val
);
1283 val
= Fprogn (Fcdr (h
.chosen_clause
));
1285 /* Note that this just undoes the binding of h.var; whoever
1286 longjumped to us unwound the stack to c.pdlcount before
1288 unbind_to (c
.pdlcount
, Qnil
);
1295 h
.handler
= handlers
;
1296 h
.next
= handlerlist
;
1300 val
= Feval (bodyform
);
1302 handlerlist
= h
.next
;
1306 /* Call the function BFUN with no arguments, catching errors within it
1307 according to HANDLERS. If there is an error, call HFUN with
1308 one argument which is the data that describes the error:
1311 HANDLERS can be a list of conditions to catch.
1312 If HANDLERS is Qt, catch all errors.
1313 If HANDLERS is Qerror, catch all errors
1314 but allow the debugger to run if that is enabled. */
1317 internal_condition_case (bfun
, handlers
, hfun
)
1318 Lisp_Object (*bfun
) ();
1319 Lisp_Object handlers
;
1320 Lisp_Object (*hfun
) ();
1326 #if 0 /* We now handle interrupt_input_blocked properly.
1327 What we still do not handle is exiting a signal handler. */
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
.interrupt_input_blocked
= interrupt_input_blocked
;
1339 c
.gcpro
= gcprolist
;
1340 c
.byte_stack
= byte_stack_list
;
1341 if (_setjmp (c
.jmp
))
1343 return (*hfun
) (c
.val
);
1347 h
.handler
= handlers
;
1349 h
.next
= handlerlist
;
1355 handlerlist
= h
.next
;
1359 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1362 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1363 Lisp_Object (*bfun
) ();
1365 Lisp_Object handlers
;
1366 Lisp_Object (*hfun
) ();
1374 c
.backlist
= backtrace_list
;
1375 c
.handlerlist
= handlerlist
;
1376 c
.lisp_eval_depth
= lisp_eval_depth
;
1377 c
.pdlcount
= SPECPDL_INDEX ();
1378 c
.poll_suppress_count
= poll_suppress_count
;
1379 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1380 c
.gcpro
= gcprolist
;
1381 c
.byte_stack
= byte_stack_list
;
1382 if (_setjmp (c
.jmp
))
1384 return (*hfun
) (c
.val
);
1388 h
.handler
= handlers
;
1390 h
.next
= handlerlist
;
1394 val
= (*bfun
) (arg
);
1396 handlerlist
= h
.next
;
1401 /* Like internal_condition_case but call BFUN with NARGS as first,
1402 and ARGS as second argument. */
1405 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1406 Lisp_Object (*bfun
) ();
1409 Lisp_Object handlers
;
1410 Lisp_Object (*hfun
) ();
1418 c
.backlist
= backtrace_list
;
1419 c
.handlerlist
= handlerlist
;
1420 c
.lisp_eval_depth
= lisp_eval_depth
;
1421 c
.pdlcount
= SPECPDL_INDEX ();
1422 c
.poll_suppress_count
= poll_suppress_count
;
1423 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1424 c
.gcpro
= gcprolist
;
1425 c
.byte_stack
= byte_stack_list
;
1426 if (_setjmp (c
.jmp
))
1428 return (*hfun
) (c
.val
);
1432 h
.handler
= handlers
;
1434 h
.next
= handlerlist
;
1438 val
= (*bfun
) (nargs
, args
);
1440 handlerlist
= h
.next
;
1445 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1446 Lisp_Object
, Lisp_Object
,
1449 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1450 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1451 This function does not return.
1453 An error symbol is a symbol with an `error-conditions' property
1454 that is a list of condition names.
1455 A handler for any of those names will get to handle this signal.
1456 The symbol `error' should normally be one of them.
1458 DATA should be a list. Its elements are printed as part of the error message.
1459 If the signal is handled, DATA is made available to the handler.
1460 See also the function `condition-case'. */)
1461 (error_symbol
, data
)
1462 Lisp_Object error_symbol
, data
;
1464 /* When memory is full, ERROR-SYMBOL is nil,
1465 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1466 That is a special case--don't do this in other situations. */
1467 register struct handler
*allhandlers
= handlerlist
;
1468 Lisp_Object conditions
;
1469 extern int gc_in_progress
;
1470 extern int waiting_for_input
;
1471 Lisp_Object debugger_value
;
1473 Lisp_Object real_error_symbol
;
1474 struct backtrace
*bp
;
1476 immediate_quit
= handling_signal
= 0;
1477 if (gc_in_progress
|| waiting_for_input
)
1480 if (NILP (error_symbol
))
1481 real_error_symbol
= Fcar (data
);
1483 real_error_symbol
= error_symbol
;
1485 #if 0 /* rms: I don't know why this was here,
1486 but it is surely wrong for an error that is handled. */
1487 #ifdef HAVE_X_WINDOWS
1488 if (display_hourglass_p
)
1489 cancel_hourglass ();
1493 /* This hook is used by edebug. */
1494 if (! NILP (Vsignal_hook_function
)
1495 && ! NILP (error_symbol
))
1496 call2 (Vsignal_hook_function
, error_symbol
, data
);
1498 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1500 /* Remember from where signal was called. Skip over the frame for
1501 `signal' itself. If a frame for `error' follows, skip that,
1502 too. Don't do this when ERROR_SYMBOL is nil, because that
1503 is a memory-full error. */
1504 Vsignaling_function
= Qnil
;
1505 if (backtrace_list
&& !NILP (error_symbol
))
1507 bp
= backtrace_list
->next
;
1508 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1510 if (bp
&& bp
->function
)
1511 Vsignaling_function
= *bp
->function
;
1514 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1516 register Lisp_Object clause
;
1518 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1519 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1521 if (specpdl_size
+ 40 > max_specpdl_size
)
1522 max_specpdl_size
= specpdl_size
+ 40;
1524 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1525 error_symbol
, data
, &debugger_value
);
1527 if (EQ (clause
, Qlambda
))
1529 /* We can't return values to code which signaled an error, but we
1530 can continue code which has signaled a quit. */
1531 if (EQ (real_error_symbol
, Qquit
))
1534 error ("Cannot return from the debugger in an error");
1539 Lisp_Object unwind_data
;
1540 struct handler
*h
= handlerlist
;
1542 handlerlist
= allhandlers
;
1544 if (NILP (error_symbol
))
1547 unwind_data
= Fcons (error_symbol
, data
);
1548 h
->chosen_clause
= clause
;
1549 unwind_to_catch (h
->tag
, unwind_data
);
1553 handlerlist
= allhandlers
;
1554 /* If no handler is present now, try to run the debugger,
1555 and if that fails, throw to top level. */
1556 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1558 Fthrow (Qtop_level
, Qt
);
1560 if (! NILP (error_symbol
))
1561 data
= Fcons (error_symbol
, data
);
1563 string
= Ferror_message_string (data
);
1564 fatal ("%s", SDATA (string
), 0);
1567 /* Return nonzero iff LIST is a non-nil atom or
1568 a list containing one of CONDITIONS. */
1571 wants_debugger (list
, conditions
)
1572 Lisp_Object list
, conditions
;
1579 while (CONSP (conditions
))
1581 Lisp_Object
this, tail
;
1582 this = XCAR (conditions
);
1583 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1584 if (EQ (XCAR (tail
), this))
1586 conditions
= XCDR (conditions
);
1591 /* Return 1 if an error with condition-symbols CONDITIONS,
1592 and described by SIGNAL-DATA, should skip the debugger
1593 according to debugger-ignored-errors. */
1596 skip_debugger (conditions
, data
)
1597 Lisp_Object conditions
, data
;
1600 int first_string
= 1;
1601 Lisp_Object error_message
;
1603 error_message
= Qnil
;
1604 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1606 if (STRINGP (XCAR (tail
)))
1610 error_message
= Ferror_message_string (data
);
1614 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1619 Lisp_Object contail
;
1621 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1622 if (EQ (XCAR (tail
), XCAR (contail
)))
1630 /* Value of Qlambda means we have called debugger and user has continued.
1631 There are two ways to pass SIG and DATA:
1632 = SIG is the error symbol, and DATA is the rest of the data.
1633 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1634 This is for memory-full errors only.
1636 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1639 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1640 Lisp_Object handlers
, conditions
, sig
, data
;
1641 Lisp_Object
*debugger_value_ptr
;
1643 register Lisp_Object h
;
1644 register Lisp_Object tem
;
1646 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1648 /* error is used similarly, but means print an error message
1649 and run the debugger if that is enabled. */
1650 if (EQ (handlers
, Qerror
)
1651 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1652 there is a handler. */
1654 int count
= SPECPDL_INDEX ();
1655 int debugger_called
= 0;
1656 Lisp_Object sig_symbol
, combined_data
;
1657 /* This is set to 1 if we are handling a memory-full error,
1658 because these must not run the debugger.
1659 (There is no room in memory to do that!) */
1660 int no_debugger
= 0;
1664 combined_data
= data
;
1665 sig_symbol
= Fcar (data
);
1670 combined_data
= Fcons (sig
, data
);
1674 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1677 internal_with_output_to_temp_buffer ("*Backtrace*",
1678 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1681 internal_with_output_to_temp_buffer ("*Backtrace*",
1686 && (EQ (sig_symbol
, Qquit
)
1688 : wants_debugger (Vdebug_on_error
, conditions
))
1689 && ! skip_debugger (conditions
, combined_data
)
1690 && when_entered_debugger
< num_nonmacro_input_events
)
1692 specbind (Qdebug_on_error
, Qnil
);
1694 = call_debugger (Fcons (Qerror
,
1695 Fcons (combined_data
, Qnil
)));
1696 debugger_called
= 1;
1698 /* If there is no handler, return saying whether we ran the debugger. */
1699 if (EQ (handlers
, Qerror
))
1701 if (debugger_called
)
1702 return unbind_to (count
, Qlambda
);
1706 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1708 Lisp_Object handler
, condit
;
1711 if (!CONSP (handler
))
1713 condit
= Fcar (handler
);
1714 /* Handle a single condition name in handler HANDLER. */
1715 if (SYMBOLP (condit
))
1717 tem
= Fmemq (Fcar (handler
), conditions
);
1721 /* Handle a list of condition names in handler HANDLER. */
1722 else if (CONSP (condit
))
1724 while (CONSP (condit
))
1726 tem
= Fmemq (Fcar (condit
), conditions
);
1729 condit
= XCDR (condit
);
1736 /* dump an error message; called like printf */
1740 error (m
, a1
, a2
, a3
)
1760 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1765 buffer
= (char *) xrealloc (buffer
, size
);
1768 buffer
= (char *) xmalloc (size
);
1773 string
= build_string (buffer
);
1777 Fsignal (Qerror
, Fcons (string
, Qnil
));
1781 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1782 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1783 This means it contains a description for how to read arguments to give it.
1784 The value is nil for an invalid function or a symbol with no function
1787 Interactively callable functions include strings and vectors (treated
1788 as keyboard macros), lambda-expressions that contain a top-level call
1789 to `interactive', autoload definitions made by `autoload' with non-nil
1790 fourth argument, and some of the built-in functions of Lisp.
1792 Also, a symbol satisfies `commandp' if its function definition does so.
1794 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1795 then strings and vectors are not accepted. */)
1796 (function
, for_call_interactively
)
1797 Lisp_Object function
, for_call_interactively
;
1799 register Lisp_Object fun
;
1800 register Lisp_Object funcar
;
1804 fun
= indirect_function (fun
);
1805 if (EQ (fun
, Qunbound
))
1808 /* Emacs primitives are interactive if their DEFUN specifies an
1809 interactive spec. */
1812 if (XSUBR (fun
)->prompt
)
1818 /* Bytecode objects are interactive if they are long enough to
1819 have an element whose index is COMPILED_INTERACTIVE, which is
1820 where the interactive spec is stored. */
1821 else if (COMPILEDP (fun
))
1822 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1825 /* Strings and vectors are keyboard macros. */
1826 if (NILP (for_call_interactively
) && (STRINGP (fun
) || VECTORP (fun
)))
1829 /* Lists may represent commands. */
1832 funcar
= Fcar (fun
);
1833 if (!SYMBOLP (funcar
))
1834 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
1835 if (EQ (funcar
, Qlambda
))
1836 return Fassq (Qinteractive
, Fcdr (Fcdr (fun
)));
1837 if (EQ (funcar
, Qautoload
))
1838 return Fcar (Fcdr (Fcdr (Fcdr (fun
))));
1844 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1845 doc
: /* Define FUNCTION to autoload from FILE.
1846 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1847 Third arg DOCSTRING is documentation for the function.
1848 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1849 Fifth arg TYPE indicates the type of the object:
1850 nil or omitted says FUNCTION is a function,
1851 `keymap' says FUNCTION is really a keymap, and
1852 `macro' or t says FUNCTION is really a macro.
1853 Third through fifth args give info about the real definition.
1854 They default to nil.
1855 If FUNCTION is already defined other than as an autoload,
1856 this does nothing and returns nil. */)
1857 (function
, file
, docstring
, interactive
, type
)
1858 Lisp_Object function
, file
, docstring
, interactive
, type
;
1861 Lisp_Object args
[4];
1864 CHECK_SYMBOL (function
);
1865 CHECK_STRING (file
);
1867 /* If function is defined and not as an autoload, don't override */
1868 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
1869 && !(CONSP (XSYMBOL (function
)->function
)
1870 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
1873 if (NILP (Vpurify_flag
))
1874 /* Only add entries after dumping, because the ones before are
1875 not useful and else we get loads of them from the loaddefs.el. */
1876 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
1880 args
[1] = docstring
;
1881 args
[2] = interactive
;
1884 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
1885 #else /* NO_ARG_ARRAY */
1886 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
1887 #endif /* not NO_ARG_ARRAY */
1891 un_autoload (oldqueue
)
1892 Lisp_Object oldqueue
;
1894 register Lisp_Object queue
, first
, second
;
1896 /* Queue to unwind is current value of Vautoload_queue.
1897 oldqueue is the shadowed value to leave in Vautoload_queue. */
1898 queue
= Vautoload_queue
;
1899 Vautoload_queue
= oldqueue
;
1900 while (CONSP (queue
))
1902 first
= Fcar (queue
);
1903 second
= Fcdr (first
);
1904 first
= Fcar (first
);
1905 if (EQ (second
, Qnil
))
1908 Ffset (first
, second
);
1909 queue
= Fcdr (queue
);
1914 /* Load an autoloaded function.
1915 FUNNAME is the symbol which is the function's name.
1916 FUNDEF is the autoload definition (a list). */
1919 do_autoload (fundef
, funname
)
1920 Lisp_Object fundef
, funname
;
1922 int count
= SPECPDL_INDEX ();
1923 Lisp_Object fun
, queue
, first
, second
;
1924 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1926 /* This is to make sure that loadup.el gives a clear picture
1927 of what files are preloaded and when. */
1928 if (! NILP (Vpurify_flag
))
1929 error ("Attempt to autoload %s while preparing to dump",
1930 SDATA (SYMBOL_NAME (funname
)));
1933 CHECK_SYMBOL (funname
);
1934 GCPRO3 (fun
, funname
, fundef
);
1936 /* Preserve the match data. */
1937 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1939 /* Value saved here is to be restored into Vautoload_queue. */
1940 record_unwind_protect (un_autoload
, Vautoload_queue
);
1941 Vautoload_queue
= Qt
;
1942 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
1944 /* Save the old autoloads, in case we ever do an unload. */
1945 queue
= Vautoload_queue
;
1946 while (CONSP (queue
))
1948 first
= Fcar (queue
);
1949 second
= Fcdr (first
);
1950 first
= Fcar (first
);
1952 /* Note: This test is subtle. The cdr of an autoload-queue entry
1953 may be an atom if the autoload entry was generated by a defalias
1956 Fput (first
, Qautoload
, (Fcdr (second
)));
1958 queue
= Fcdr (queue
);
1961 /* Once loading finishes, don't undo it. */
1962 Vautoload_queue
= Qt
;
1963 unbind_to (count
, Qnil
);
1965 fun
= Findirect_function (fun
);
1967 if (!NILP (Fequal (fun
, fundef
)))
1968 error ("Autoloading failed to define function %s",
1969 SDATA (SYMBOL_NAME (funname
)));
1974 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
1975 doc
: /* Evaluate FORM and return its value. */)
1979 Lisp_Object fun
, val
, original_fun
, original_args
;
1981 struct backtrace backtrace
;
1982 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1984 if (handling_signal
)
1988 return Fsymbol_value (form
);
1993 if (consing_since_gc
> gc_cons_threshold
)
1996 Fgarbage_collect ();
2000 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2002 if (max_lisp_eval_depth
< 100)
2003 max_lisp_eval_depth
= 100;
2004 if (lisp_eval_depth
> max_lisp_eval_depth
)
2005 error ("Lisp nesting exceeds max-lisp-eval-depth");
2008 original_fun
= Fcar (form
);
2009 original_args
= Fcdr (form
);
2011 backtrace
.next
= backtrace_list
;
2012 backtrace_list
= &backtrace
;
2013 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2014 backtrace
.args
= &original_args
;
2015 backtrace
.nargs
= UNEVALLED
;
2016 backtrace
.evalargs
= 1;
2017 backtrace
.debug_on_exit
= 0;
2019 if (debug_on_next_call
)
2020 do_debug_on_call (Qt
);
2022 /* At this point, only original_fun and original_args
2023 have values that will be used below */
2025 fun
= Findirect_function (original_fun
);
2029 Lisp_Object numargs
;
2030 Lisp_Object argvals
[8];
2031 Lisp_Object args_left
;
2032 register int i
, maxargs
;
2034 args_left
= original_args
;
2035 numargs
= Flength (args_left
);
2037 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2038 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2039 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (numargs
, Qnil
)));
2041 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2043 backtrace
.evalargs
= 0;
2044 val
= (*XSUBR (fun
)->function
) (args_left
);
2048 if (XSUBR (fun
)->max_args
== MANY
)
2050 /* Pass a vector of evaluated arguments */
2052 register int argnum
= 0;
2054 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2056 GCPRO3 (args_left
, fun
, fun
);
2060 while (!NILP (args_left
))
2062 vals
[argnum
++] = Feval (Fcar (args_left
));
2063 args_left
= Fcdr (args_left
);
2064 gcpro3
.nvars
= argnum
;
2067 backtrace
.args
= vals
;
2068 backtrace
.nargs
= XINT (numargs
);
2070 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2075 GCPRO3 (args_left
, fun
, fun
);
2076 gcpro3
.var
= argvals
;
2079 maxargs
= XSUBR (fun
)->max_args
;
2080 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2082 argvals
[i
] = Feval (Fcar (args_left
));
2088 backtrace
.args
= argvals
;
2089 backtrace
.nargs
= XINT (numargs
);
2094 val
= (*XSUBR (fun
)->function
) ();
2097 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2100 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2103 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2107 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2108 argvals
[2], argvals
[3]);
2111 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2112 argvals
[3], argvals
[4]);
2115 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2116 argvals
[3], argvals
[4], argvals
[5]);
2119 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2120 argvals
[3], argvals
[4], argvals
[5],
2125 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2126 argvals
[3], argvals
[4], argvals
[5],
2127 argvals
[6], argvals
[7]);
2131 /* Someone has created a subr that takes more arguments than
2132 is supported by this code. We need to either rewrite the
2133 subr to use a different argument protocol, or add more
2134 cases to this switch. */
2138 if (COMPILEDP (fun
))
2139 val
= apply_lambda (fun
, original_args
, 1);
2143 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2144 funcar
= Fcar (fun
);
2145 if (!SYMBOLP (funcar
))
2146 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2147 if (EQ (funcar
, Qautoload
))
2149 do_autoload (fun
, original_fun
);
2152 if (EQ (funcar
, Qmacro
))
2153 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2154 else if (EQ (funcar
, Qlambda
))
2155 val
= apply_lambda (fun
, original_args
, 1);
2157 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2161 if (backtrace
.debug_on_exit
)
2162 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2163 backtrace_list
= backtrace
.next
;
2166 mac_check_for_quit_char();
2171 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2172 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2173 Then return the value FUNCTION returns.
2174 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2175 usage: (apply FUNCTION &rest ARGUMENTS) */)
2180 register int i
, numargs
;
2181 register Lisp_Object spread_arg
;
2182 register Lisp_Object
*funcall_args
;
2184 struct gcpro gcpro1
;
2188 spread_arg
= args
[nargs
- 1];
2189 CHECK_LIST (spread_arg
);
2191 numargs
= XINT (Flength (spread_arg
));
2194 return Ffuncall (nargs
- 1, args
);
2195 else if (numargs
== 1)
2197 args
[nargs
- 1] = XCAR (spread_arg
);
2198 return Ffuncall (nargs
, args
);
2201 numargs
+= nargs
- 2;
2203 fun
= indirect_function (fun
);
2204 if (EQ (fun
, Qunbound
))
2206 /* Let funcall get the error */
2213 if (numargs
< XSUBR (fun
)->min_args
2214 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2215 goto funcall
; /* Let funcall get the error */
2216 else if (XSUBR (fun
)->max_args
> numargs
)
2218 /* Avoid making funcall cons up a yet another new vector of arguments
2219 by explicitly supplying nil's for optional values */
2220 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2221 * sizeof (Lisp_Object
));
2222 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2223 funcall_args
[++i
] = Qnil
;
2224 GCPRO1 (*funcall_args
);
2225 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2229 /* We add 1 to numargs because funcall_args includes the
2230 function itself as well as its arguments. */
2233 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2234 * sizeof (Lisp_Object
));
2235 GCPRO1 (*funcall_args
);
2236 gcpro1
.nvars
= 1 + numargs
;
2239 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2240 /* Spread the last arg we got. Its first element goes in
2241 the slot that it used to occupy, hence this value of I. */
2243 while (!NILP (spread_arg
))
2245 funcall_args
[i
++] = XCAR (spread_arg
);
2246 spread_arg
= XCDR (spread_arg
);
2249 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2252 /* Run hook variables in various ways. */
2254 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2255 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2256 enum run_hooks_condition
));
2258 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2259 doc
: /* Run each hook in HOOKS. Major mode functions use this.
2260 Each argument should be a symbol, a hook variable.
2261 These symbols are processed in the order specified.
2262 If a hook symbol has a non-nil value, that value may be a function
2263 or a list of functions to be called to run the hook.
2264 If the value is a function, it is called with no arguments.
2265 If it is a list, the elements are called, in order, with no arguments.
2267 Do not use `make-local-variable' to make a hook variable buffer-local.
2268 Instead, use `add-hook' and specify t for the LOCAL argument.
2269 usage: (run-hooks &rest HOOKS) */)
2274 Lisp_Object hook
[1];
2277 for (i
= 0; i
< nargs
; i
++)
2280 run_hook_with_args (1, hook
, to_completion
);
2286 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2287 Srun_hook_with_args
, 1, MANY
, 0,
2288 doc
: /* Run HOOK with the specified arguments ARGS.
2289 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2290 value, that value may be a function or a list of functions to be
2291 called to run the hook. If the value is a function, it is called with
2292 the given arguments and its return value is returned. If it is a list
2293 of functions, those functions are called, in order,
2294 with the given arguments ARGS.
2295 It is best not to depend on the value return by `run-hook-with-args',
2298 Do not use `make-local-variable' to make a hook variable buffer-local.
2299 Instead, use `add-hook' and specify t for the LOCAL argument.
2300 usage: (run-hook-with-args HOOK &rest ARGS) */)
2305 return run_hook_with_args (nargs
, args
, to_completion
);
2308 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2309 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2310 doc
: /* Run HOOK with the specified arguments ARGS.
2311 HOOK should be a symbol, a hook variable. Its value should
2312 be a list of functions. We call those functions, one by one,
2313 passing arguments ARGS to each of them, until one of them
2314 returns a non-nil value. Then we return that value.
2315 If all the functions return nil, we return nil.
2317 Do not use `make-local-variable' to make a hook variable buffer-local.
2318 Instead, use `add-hook' and specify t for the LOCAL argument.
2319 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2324 return run_hook_with_args (nargs
, args
, until_success
);
2327 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2328 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2329 doc
: /* Run HOOK with the specified arguments ARGS.
2330 HOOK should be a symbol, a hook variable. Its value should
2331 be a list of functions. We call those functions, one by one,
2332 passing arguments ARGS to each of them, until one of them
2333 returns nil. Then we return nil.
2334 If all the functions return non-nil, we return non-nil.
2336 Do not use `make-local-variable' to make a hook variable buffer-local.
2337 Instead, use `add-hook' and specify t for the LOCAL argument.
2338 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2343 return run_hook_with_args (nargs
, args
, until_failure
);
2346 /* ARGS[0] should be a hook symbol.
2347 Call each of the functions in the hook value, passing each of them
2348 as arguments all the rest of ARGS (all NARGS - 1 elements).
2349 COND specifies a condition to test after each call
2350 to decide whether to stop.
2351 The caller (or its caller, etc) must gcpro all of ARGS,
2352 except that it isn't necessary to gcpro ARGS[0]. */
2355 run_hook_with_args (nargs
, args
, cond
)
2358 enum run_hooks_condition cond
;
2360 Lisp_Object sym
, val
, ret
;
2361 Lisp_Object globals
;
2362 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2364 /* If we are dying or still initializing,
2365 don't do anything--it would probably crash if we tried. */
2366 if (NILP (Vrun_hooks
))
2370 val
= find_symbol_value (sym
);
2371 ret
= (cond
== until_failure
? Qt
: Qnil
);
2373 if (EQ (val
, Qunbound
) || NILP (val
))
2375 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2378 return Ffuncall (nargs
, args
);
2383 GCPRO3 (sym
, val
, globals
);
2386 CONSP (val
) && ((cond
== to_completion
)
2387 || (cond
== until_success
? NILP (ret
)
2391 if (EQ (XCAR (val
), Qt
))
2393 /* t indicates this hook has a local binding;
2394 it means to run the global binding too. */
2396 for (globals
= Fdefault_value (sym
);
2397 CONSP (globals
) && ((cond
== to_completion
)
2398 || (cond
== until_success
? NILP (ret
)
2400 globals
= XCDR (globals
))
2402 args
[0] = XCAR (globals
);
2403 /* In a global value, t should not occur. If it does, we
2404 must ignore it to avoid an endless loop. */
2405 if (!EQ (args
[0], Qt
))
2406 ret
= Ffuncall (nargs
, args
);
2411 args
[0] = XCAR (val
);
2412 ret
= Ffuncall (nargs
, args
);
2421 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2422 present value of that symbol.
2423 Call each element of FUNLIST,
2424 passing each of them the rest of ARGS.
2425 The caller (or its caller, etc) must gcpro all of ARGS,
2426 except that it isn't necessary to gcpro ARGS[0]. */
2429 run_hook_list_with_args (funlist
, nargs
, args
)
2430 Lisp_Object funlist
;
2436 Lisp_Object globals
;
2437 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2441 GCPRO3 (sym
, val
, globals
);
2443 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2445 if (EQ (XCAR (val
), Qt
))
2447 /* t indicates this hook has a local binding;
2448 it means to run the global binding too. */
2450 for (globals
= Fdefault_value (sym
);
2452 globals
= XCDR (globals
))
2454 args
[0] = XCAR (globals
);
2455 /* In a global value, t should not occur. If it does, we
2456 must ignore it to avoid an endless loop. */
2457 if (!EQ (args
[0], Qt
))
2458 Ffuncall (nargs
, args
);
2463 args
[0] = XCAR (val
);
2464 Ffuncall (nargs
, args
);
2471 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2474 run_hook_with_args_2 (hook
, arg1
, arg2
)
2475 Lisp_Object hook
, arg1
, arg2
;
2477 Lisp_Object temp
[3];
2482 Frun_hook_with_args (3, temp
);
2485 /* Apply fn to arg */
2488 Lisp_Object fn
, arg
;
2490 struct gcpro gcpro1
;
2494 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2498 Lisp_Object args
[2];
2502 RETURN_UNGCPRO (Fapply (2, args
));
2504 #else /* not NO_ARG_ARRAY */
2505 RETURN_UNGCPRO (Fapply (2, &fn
));
2506 #endif /* not NO_ARG_ARRAY */
2509 /* Call function fn on no arguments */
2514 struct gcpro gcpro1
;
2517 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2520 /* Call function fn with 1 argument arg1 */
2524 Lisp_Object fn
, arg1
;
2526 struct gcpro gcpro1
;
2528 Lisp_Object args
[2];
2534 RETURN_UNGCPRO (Ffuncall (2, args
));
2535 #else /* not NO_ARG_ARRAY */
2538 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2539 #endif /* not NO_ARG_ARRAY */
2542 /* Call function fn with 2 arguments arg1, arg2 */
2545 call2 (fn
, arg1
, arg2
)
2546 Lisp_Object fn
, arg1
, arg2
;
2548 struct gcpro gcpro1
;
2550 Lisp_Object args
[3];
2556 RETURN_UNGCPRO (Ffuncall (3, args
));
2557 #else /* not NO_ARG_ARRAY */
2560 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2561 #endif /* not NO_ARG_ARRAY */
2564 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2567 call3 (fn
, arg1
, arg2
, arg3
)
2568 Lisp_Object fn
, arg1
, arg2
, arg3
;
2570 struct gcpro gcpro1
;
2572 Lisp_Object args
[4];
2579 RETURN_UNGCPRO (Ffuncall (4, args
));
2580 #else /* not NO_ARG_ARRAY */
2583 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2584 #endif /* not NO_ARG_ARRAY */
2587 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2590 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2591 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2593 struct gcpro gcpro1
;
2595 Lisp_Object args
[5];
2603 RETURN_UNGCPRO (Ffuncall (5, args
));
2604 #else /* not NO_ARG_ARRAY */
2607 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2608 #endif /* not NO_ARG_ARRAY */
2611 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2614 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2615 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2617 struct gcpro gcpro1
;
2619 Lisp_Object args
[6];
2628 RETURN_UNGCPRO (Ffuncall (6, args
));
2629 #else /* not NO_ARG_ARRAY */
2632 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2633 #endif /* not NO_ARG_ARRAY */
2636 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2639 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2640 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2642 struct gcpro gcpro1
;
2644 Lisp_Object args
[7];
2654 RETURN_UNGCPRO (Ffuncall (7, args
));
2655 #else /* not NO_ARG_ARRAY */
2658 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2659 #endif /* not NO_ARG_ARRAY */
2662 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2663 doc
: /* Call first argument as a function, passing remaining arguments to it.
2664 Return the value that function returns.
2665 Thus, (funcall 'cons 'x 'y) returns (x . y).
2666 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2673 int numargs
= nargs
- 1;
2674 Lisp_Object lisp_numargs
;
2676 struct backtrace backtrace
;
2677 register Lisp_Object
*internal_args
;
2681 if (consing_since_gc
> gc_cons_threshold
)
2682 Fgarbage_collect ();
2684 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2686 if (max_lisp_eval_depth
< 100)
2687 max_lisp_eval_depth
= 100;
2688 if (lisp_eval_depth
> max_lisp_eval_depth
)
2689 error ("Lisp nesting exceeds max-lisp-eval-depth");
2692 backtrace
.next
= backtrace_list
;
2693 backtrace_list
= &backtrace
;
2694 backtrace
.function
= &args
[0];
2695 backtrace
.args
= &args
[1];
2696 backtrace
.nargs
= nargs
- 1;
2697 backtrace
.evalargs
= 0;
2698 backtrace
.debug_on_exit
= 0;
2700 if (debug_on_next_call
)
2701 do_debug_on_call (Qlambda
);
2707 fun
= Findirect_function (fun
);
2711 if (numargs
< XSUBR (fun
)->min_args
2712 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2714 XSETFASTINT (lisp_numargs
, numargs
);
2715 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2718 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2719 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2721 if (XSUBR (fun
)->max_args
== MANY
)
2723 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2727 if (XSUBR (fun
)->max_args
> numargs
)
2729 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2730 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2731 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2732 internal_args
[i
] = Qnil
;
2735 internal_args
= args
+ 1;
2736 switch (XSUBR (fun
)->max_args
)
2739 val
= (*XSUBR (fun
)->function
) ();
2742 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2745 val
= (*XSUBR (fun
)->function
) (internal_args
[0],
2749 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2753 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2758 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2759 internal_args
[2], internal_args
[3],
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]);
2768 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2769 internal_args
[2], internal_args
[3],
2770 internal_args
[4], internal_args
[5],
2775 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2776 internal_args
[2], internal_args
[3],
2777 internal_args
[4], internal_args
[5],
2778 internal_args
[6], internal_args
[7]);
2783 /* If a subr takes more than 8 arguments without using MANY
2784 or UNEVALLED, we need to extend this function to support it.
2785 Until this is done, there is no way to call the function. */
2789 if (COMPILEDP (fun
))
2790 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2794 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2795 funcar
= Fcar (fun
);
2796 if (!SYMBOLP (funcar
))
2797 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2798 if (EQ (funcar
, Qlambda
))
2799 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2800 else if (EQ (funcar
, Qautoload
))
2802 do_autoload (fun
, args
[0]);
2806 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2810 if (backtrace
.debug_on_exit
)
2811 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2812 backtrace_list
= backtrace
.next
;
2817 apply_lambda (fun
, args
, eval_flag
)
2818 Lisp_Object fun
, args
;
2821 Lisp_Object args_left
;
2822 Lisp_Object numargs
;
2823 register Lisp_Object
*arg_vector
;
2824 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2826 register Lisp_Object tem
;
2828 numargs
= Flength (args
);
2829 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2832 GCPRO3 (*arg_vector
, args_left
, fun
);
2835 for (i
= 0; i
< XINT (numargs
);)
2837 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2838 if (eval_flag
) tem
= Feval (tem
);
2839 arg_vector
[i
++] = tem
;
2847 backtrace_list
->args
= arg_vector
;
2848 backtrace_list
->nargs
= i
;
2850 backtrace_list
->evalargs
= 0;
2851 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
2853 /* Do the debug-on-exit now, while arg_vector still exists. */
2854 if (backtrace_list
->debug_on_exit
)
2855 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
2856 /* Don't do it again when we return to eval. */
2857 backtrace_list
->debug_on_exit
= 0;
2861 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2862 and return the result of evaluation.
2863 FUN must be either a lambda-expression or a compiled-code object. */
2866 funcall_lambda (fun
, nargs
, arg_vector
)
2869 register Lisp_Object
*arg_vector
;
2871 Lisp_Object val
, syms_left
, next
;
2872 int count
= SPECPDL_INDEX ();
2873 int i
, optional
, rest
;
2877 syms_left
= XCDR (fun
);
2878 if (CONSP (syms_left
))
2879 syms_left
= XCAR (syms_left
);
2881 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2883 else if (COMPILEDP (fun
))
2884 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2888 i
= optional
= rest
= 0;
2889 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2893 next
= XCAR (syms_left
);
2894 while (!SYMBOLP (next
))
2895 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2897 if (EQ (next
, Qand_rest
))
2899 else if (EQ (next
, Qand_optional
))
2903 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
2907 specbind (next
, arg_vector
[i
++]);
2909 return Fsignal (Qwrong_number_of_arguments
,
2910 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2912 specbind (next
, Qnil
);
2915 if (!NILP (syms_left
))
2916 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2918 return Fsignal (Qwrong_number_of_arguments
,
2919 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2922 val
= Fprogn (XCDR (XCDR (fun
)));
2925 /* If we have not actually read the bytecode string
2926 and constants vector yet, fetch them from the file. */
2927 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2928 Ffetch_bytecode (fun
);
2929 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
2930 AREF (fun
, COMPILED_CONSTANTS
),
2931 AREF (fun
, COMPILED_STACK_DEPTH
));
2934 return unbind_to (count
, val
);
2937 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2939 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2945 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
2947 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2950 tem
= AREF (object
, COMPILED_BYTECODE
);
2951 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2952 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2954 error ("Invalid byte code");
2956 AREF (object
, COMPILED_BYTECODE
) = XCAR (tem
);
2957 AREF (object
, COMPILED_CONSTANTS
) = XCDR (tem
);
2965 register int count
= SPECPDL_INDEX ();
2966 if (specpdl_size
>= max_specpdl_size
)
2968 if (max_specpdl_size
< 400)
2969 max_specpdl_size
= 400;
2970 if (specpdl_size
>= max_specpdl_size
)
2972 if (!NILP (Vdebug_on_error
))
2973 /* Leave room for some specpdl in the debugger. */
2974 max_specpdl_size
= specpdl_size
+ 100;
2976 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
2980 if (specpdl_size
> max_specpdl_size
)
2981 specpdl_size
= max_specpdl_size
;
2982 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
2983 specpdl_ptr
= specpdl
+ count
;
2987 specbind (symbol
, value
)
2988 Lisp_Object symbol
, value
;
2991 Lisp_Object valcontents
;
2993 CHECK_SYMBOL (symbol
);
2994 if (specpdl_ptr
== specpdl
+ specpdl_size
)
2997 /* The most common case is that of a non-constant symbol with a
2998 trivial value. Make that as fast as we can. */
2999 valcontents
= SYMBOL_VALUE (symbol
);
3000 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3002 specpdl_ptr
->symbol
= symbol
;
3003 specpdl_ptr
->old_value
= valcontents
;
3004 specpdl_ptr
->func
= NULL
;
3006 SET_SYMBOL_VALUE (symbol
, value
);
3010 Lisp_Object valcontents
;
3012 ovalue
= find_symbol_value (symbol
);
3013 specpdl_ptr
->func
= 0;
3014 specpdl_ptr
->old_value
= ovalue
;
3016 valcontents
= XSYMBOL (symbol
)->value
;
3018 if (BUFFER_LOCAL_VALUEP (valcontents
)
3019 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
3020 || BUFFER_OBJFWDP (valcontents
))
3022 Lisp_Object where
, current_buffer
;
3024 current_buffer
= Fcurrent_buffer ();
3026 /* For a local variable, record both the symbol and which
3027 buffer's or frame's value we are saving. */
3028 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3029 where
= current_buffer
;
3030 else if (!BUFFER_OBJFWDP (valcontents
)
3031 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3032 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3036 /* We're not using the `unused' slot in the specbinding
3037 structure because this would mean we have to do more
3038 work for simple variables. */
3039 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3041 /* If SYMBOL is a per-buffer variable which doesn't have a
3042 buffer-local value here, make the `let' change the global
3043 value by changing the value of SYMBOL in all buffers not
3044 having their own value. This is consistent with what
3045 happens with other buffer-local variables. */
3047 && BUFFER_OBJFWDP (valcontents
))
3050 Fset_default (symbol
, value
);
3055 specpdl_ptr
->symbol
= symbol
;
3058 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3059 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3061 set_internal (symbol
, value
, 0, 1);
3066 record_unwind_protect (function
, arg
)
3067 Lisp_Object (*function
) P_ ((Lisp_Object
));
3070 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3072 specpdl_ptr
->func
= function
;
3073 specpdl_ptr
->symbol
= Qnil
;
3074 specpdl_ptr
->old_value
= arg
;
3079 unbind_to (count
, value
)
3083 int quitf
= !NILP (Vquit_flag
);
3084 struct gcpro gcpro1
;
3089 while (specpdl_ptr
!= specpdl
+ count
)
3093 if (specpdl_ptr
->func
!= 0)
3094 (*specpdl_ptr
->func
) (specpdl_ptr
->old_value
);
3095 /* Note that a "binding" of nil is really an unwind protect,
3096 so in that case the "old value" is a list of forms to evaluate. */
3097 else if (NILP (specpdl_ptr
->symbol
))
3098 Fprogn (specpdl_ptr
->old_value
);
3099 /* If the symbol is a list, it is really (SYMBOL WHERE
3100 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3101 frame. If WHERE is a buffer or frame, this indicates we
3102 bound a variable that had a buffer-local or frame-local
3103 binding. WHERE nil means that the variable had the default
3104 value when it was bound. CURRENT-BUFFER is the buffer that
3105 was current when the variable was bound. */
3106 else if (CONSP (specpdl_ptr
->symbol
))
3108 Lisp_Object symbol
, where
;
3110 symbol
= XCAR (specpdl_ptr
->symbol
);
3111 where
= XCAR (XCDR (specpdl_ptr
->symbol
));
3114 Fset_default (symbol
, specpdl_ptr
->old_value
);
3115 else if (BUFFERP (where
))
3116 set_internal (symbol
, specpdl_ptr
->old_value
, XBUFFER (where
), 1);
3118 set_internal (symbol
, specpdl_ptr
->old_value
, NULL
, 1);
3122 /* If variable has a trivial value (no forwarding), we can
3123 just set it. No need to check for constant symbols here,
3124 since that was already done by specbind. */
3125 if (!MISCP (SYMBOL_VALUE (specpdl_ptr
->symbol
)))
3126 SET_SYMBOL_VALUE (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
);
3128 set_internal (specpdl_ptr
->symbol
, specpdl_ptr
->old_value
, 0, 1);
3132 if (NILP (Vquit_flag
) && quitf
)
3139 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3140 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3141 The debugger is entered when that frame exits, if the flag is non-nil. */)
3143 Lisp_Object level
, flag
;
3145 register struct backtrace
*backlist
= backtrace_list
;
3148 CHECK_NUMBER (level
);
3150 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3152 backlist
= backlist
->next
;
3156 backlist
->debug_on_exit
= !NILP (flag
);
3161 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3162 doc
: /* Print a trace of Lisp function calls currently active.
3163 Output stream used is value of `standard-output'. */)
3166 register struct backtrace
*backlist
= backtrace_list
;
3170 extern Lisp_Object Vprint_level
;
3171 struct gcpro gcpro1
;
3173 XSETFASTINT (Vprint_level
, 3);
3180 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3181 if (backlist
->nargs
== UNEVALLED
)
3183 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3184 write_string ("\n", -1);
3188 tem
= *backlist
->function
;
3189 Fprin1 (tem
, Qnil
); /* This can QUIT */
3190 write_string ("(", -1);
3191 if (backlist
->nargs
== MANY
)
3193 for (tail
= *backlist
->args
, i
= 0;
3195 tail
= Fcdr (tail
), i
++)
3197 if (i
) write_string (" ", -1);
3198 Fprin1 (Fcar (tail
), Qnil
);
3203 for (i
= 0; i
< backlist
->nargs
; i
++)
3205 if (i
) write_string (" ", -1);
3206 Fprin1 (backlist
->args
[i
], Qnil
);
3209 write_string (")\n", -1);
3211 backlist
= backlist
->next
;
3214 Vprint_level
= Qnil
;
3219 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3220 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3221 If that frame has not evaluated the arguments yet (or is a special form),
3222 the value is (nil FUNCTION ARG-FORMS...).
3223 If that frame has evaluated its arguments and called its function already,
3224 the value is (t FUNCTION ARG-VALUES...).
3225 A &rest arg is represented as the tail of the list ARG-VALUES.
3226 FUNCTION is whatever was supplied as car of evaluated list,
3227 or a lambda expression for macro calls.
3228 If NFRAMES is more than the number of frames, the value is nil. */)
3230 Lisp_Object nframes
;
3232 register struct backtrace
*backlist
= backtrace_list
;
3236 CHECK_NATNUM (nframes
);
3238 /* Find the frame requested. */
3239 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3240 backlist
= backlist
->next
;
3244 if (backlist
->nargs
== UNEVALLED
)
3245 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3248 if (backlist
->nargs
== MANY
)
3249 tem
= *backlist
->args
;
3251 tem
= Flist (backlist
->nargs
, backlist
->args
);
3253 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3261 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3262 doc
: /* *Limit on number of Lisp variable bindings & unwind-protects.
3263 If Lisp code tries to make more than this many at once,
3264 an error is signaled.
3265 You can safely use a value considerably larger than the default value,
3266 if that proves inconveniently small. However, if you increase it too far,
3267 Emacs could run out of memory trying to make the stack bigger. */);
3269 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3270 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3272 This limit serves to catch infinite recursions for you before they cause
3273 actual stack overflow in C, which would be fatal for Emacs.
3274 You can safely make it considerably larger than its default value,
3275 if that proves inconveniently small. However, if you increase it too far,
3276 Emacs could overflow the real C stack, and crash. */);
3278 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3279 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3280 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */);
3283 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3284 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3285 Note that `quit-flag' will still be set by typing C-g,
3286 so a quit will be signaled as soon as `inhibit-quit' is nil.
3287 To prevent this happening, set `quit-flag' to nil
3288 before making `inhibit-quit' nil. */);
3289 Vinhibit_quit
= Qnil
;
3291 Qinhibit_quit
= intern ("inhibit-quit");
3292 staticpro (&Qinhibit_quit
);
3294 Qautoload
= intern ("autoload");
3295 staticpro (&Qautoload
);
3297 Qdebug_on_error
= intern ("debug-on-error");
3298 staticpro (&Qdebug_on_error
);
3300 Qmacro
= intern ("macro");
3301 staticpro (&Qmacro
);
3303 Qdeclare
= intern ("declare");
3304 staticpro (&Qdeclare
);
3306 /* Note that the process handling also uses Qexit, but we don't want
3307 to staticpro it twice, so we just do it here. */
3308 Qexit
= intern ("exit");
3311 Qinteractive
= intern ("interactive");
3312 staticpro (&Qinteractive
);
3314 Qcommandp
= intern ("commandp");
3315 staticpro (&Qcommandp
);
3317 Qdefun
= intern ("defun");
3318 staticpro (&Qdefun
);
3320 Qdefvar
= intern ("defvar");
3321 staticpro (&Qdefvar
);
3323 Qand_rest
= intern ("&rest");
3324 staticpro (&Qand_rest
);
3326 Qand_optional
= intern ("&optional");
3327 staticpro (&Qand_optional
);
3329 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3330 doc
: /* *Non-nil means errors display a backtrace buffer.
3331 More precisely, this happens for any error that is handled
3332 by the editor command loop.
3333 If the value is a list, an error only means to display a backtrace
3334 if one of its condition symbols appears in the list. */);
3335 Vstack_trace_on_error
= Qnil
;
3337 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3338 doc
: /* *Non-nil means enter debugger if an error is signaled.
3339 Does not apply to errors handled by `condition-case' or those
3340 matched by `debug-ignored-errors'.
3341 If the value is a list, an error only means to enter the debugger
3342 if one of its condition symbols appears in the list.
3343 When you evaluate an expression interactively, this variable
3344 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3345 See also variable `debug-on-quit'. */);
3346 Vdebug_on_error
= Qnil
;
3348 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3349 doc
: /* *List of errors for which the debugger should not be called.
3350 Each element may be a condition-name or a regexp that matches error messages.
3351 If any element applies to a given error, that error skips the debugger
3352 and just returns to top level.
3353 This overrides the variable `debug-on-error'.
3354 It does not apply to errors handled by `condition-case'. */);
3355 Vdebug_ignored_errors
= Qnil
;
3357 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3358 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3359 Does not apply if quit is handled by a `condition-case'.
3360 When you evaluate an expression interactively, this variable
3361 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3364 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3365 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3367 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3368 doc
: /* Non-nil means debugger may continue execution.
3369 This is nil when the debugger is called under circumstances where it
3370 might not be safe to continue. */);
3371 debugger_may_continue
= 1;
3373 DEFVAR_LISP ("debugger", &Vdebugger
,
3374 doc
: /* Function to call to invoke debugger.
3375 If due to frame exit, args are `exit' and the value being returned;
3376 this function's value will be returned instead of that.
3377 If due to error, args are `error' and a list of the args to `signal'.
3378 If due to `apply' or `funcall' entry, one arg, `lambda'.
3379 If due to `eval' entry, one arg, t. */);
3382 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3383 doc
: /* If non-nil, this is a function for `signal' to call.
3384 It receives the same arguments that `signal' was given.
3385 The Edebug package uses this to regain control. */);
3386 Vsignal_hook_function
= Qnil
;
3388 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3389 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3390 Note that `debug-on-error', `debug-on-quit' and friends
3391 still determine whether to handle the particular condition. */);
3392 Vdebug_on_signal
= Qnil
;
3394 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3395 doc
: /* Function to process declarations in a macro definition.
3396 The function will be called with two args MACRO and DECL.
3397 MACRO is the name of the macro being defined.
3398 DECL is a list `(declare ...)' containing the declarations.
3399 The value the function returns is not used. */);
3400 Vmacro_declaration_function
= Qnil
;
3402 Vrun_hooks
= intern ("run-hooks");
3403 staticpro (&Vrun_hooks
);
3405 staticpro (&Vautoload_queue
);
3406 Vautoload_queue
= Qnil
;
3407 staticpro (&Vsignaling_function
);
3408 Vsignaling_function
= Qnil
;
3419 defsubr (&Sfunction
);
3421 defsubr (&Sdefmacro
);
3423 defsubr (&Sdefvaralias
);
3424 defsubr (&Sdefconst
);
3425 defsubr (&Suser_variable_p
);
3429 defsubr (&Smacroexpand
);
3432 defsubr (&Sunwind_protect
);
3433 defsubr (&Scondition_case
);
3435 defsubr (&Sinteractive_p
);
3436 defsubr (&Scommandp
);
3437 defsubr (&Sautoload
);
3440 defsubr (&Sfuncall
);
3441 defsubr (&Srun_hooks
);
3442 defsubr (&Srun_hook_with_args
);
3443 defsubr (&Srun_hook_with_args_until_success
);
3444 defsubr (&Srun_hook_with_args_until_failure
);
3445 defsubr (&Sfetch_bytecode
);
3446 defsubr (&Sbacktrace_debug
);
3447 defsubr (&Sbacktrace
);
3448 defsubr (&Sbacktrace_frame
);