1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006 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., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, 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
;
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, (0 . OFEATURES) 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 /* Don't forget to update docs (lispref node "Local Variables"). */
208 max_specpdl_size
= 1000;
209 max_lisp_eval_depth
= 300;
217 specpdl_ptr
= specpdl
;
222 debug_on_next_call
= 0;
227 /* This is less than the initial value of num_nonmacro_input_events. */
228 when_entered_debugger
= -1;
231 /* unwind-protect function used by call_debugger. */
234 restore_stack_limits (data
)
237 max_specpdl_size
= XINT (XCAR (data
));
238 max_lisp_eval_depth
= XINT (XCDR (data
));
242 /* Call the Lisp debugger, giving it argument ARG. */
248 int debug_while_redisplaying
;
249 int count
= SPECPDL_INDEX ();
251 int old_max
= max_specpdl_size
;
253 /* Temporarily bump up the stack limits,
254 so the debugger won't run out of stack. */
256 max_specpdl_size
+= 1;
257 record_unwind_protect (restore_stack_limits
,
258 Fcons (make_number (old_max
),
259 make_number (max_lisp_eval_depth
)));
260 max_specpdl_size
= old_max
;
262 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
263 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
265 if (SPECPDL_INDEX () + 100 > max_specpdl_size
)
266 max_specpdl_size
= SPECPDL_INDEX () + 100;
268 #ifdef HAVE_X_WINDOWS
269 if (display_hourglass_p
)
273 debug_on_next_call
= 0;
274 when_entered_debugger
= num_nonmacro_input_events
;
276 /* Resetting redisplaying_p to 0 makes sure that debug output is
277 displayed if the debugger is invoked during redisplay. */
278 debug_while_redisplaying
= redisplaying_p
;
280 specbind (intern ("debugger-may-continue"),
281 debug_while_redisplaying
? Qnil
: Qt
);
282 specbind (Qinhibit_redisplay
, Qnil
);
283 specbind (Qdebug_on_error
, Qnil
);
285 #if 0 /* Binding this prevents execution of Lisp code during
286 redisplay, which necessarily leads to display problems. */
287 specbind (Qinhibit_eval_during_redisplay
, Qt
);
290 val
= apply1 (Vdebugger
, arg
);
292 /* Interrupting redisplay and resuming it later is not safe under
293 all circumstances. So, when the debugger returns, abort the
294 interrupted redisplay by going back to the top-level. */
295 if (debug_while_redisplaying
)
298 return unbind_to (count
, val
);
302 do_debug_on_call (code
)
305 debug_on_next_call
= 0;
306 backtrace_list
->debug_on_exit
= 1;
307 call_debugger (Fcons (code
, Qnil
));
310 /* NOTE!!! Every function that can call EVAL must protect its args
311 and temporaries from garbage collection while it needs them.
312 The definition of `For' shows what you have to do. */
314 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
315 doc
: /* Eval args until one of them yields non-nil, then return that value.
316 The remaining args are not evalled at all.
317 If all args return nil, return nil.
318 usage: (or CONDITIONS ...) */)
322 register Lisp_Object val
= Qnil
;
329 val
= Feval (XCAR (args
));
339 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
340 doc
: /* Eval args until one of them yields nil, then return nil.
341 The remaining args are not evalled at all.
342 If no arg yields nil, return the last arg's value.
343 usage: (and CONDITIONS ...) */)
347 register Lisp_Object val
= Qt
;
354 val
= Feval (XCAR (args
));
364 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
365 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
366 Returns the value of THEN or the value of the last of the ELSE's.
367 THEN must be one expression, but ELSE... can be zero or more expressions.
368 If COND yields nil, and there are no ELSE's, the value is nil.
369 usage: (if COND THEN ELSE...) */)
373 register Lisp_Object cond
;
377 cond
= Feval (Fcar (args
));
381 return Feval (Fcar (Fcdr (args
)));
382 return Fprogn (Fcdr (Fcdr (args
)));
385 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
386 doc
: /* Try each clause until one succeeds.
387 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
388 and, if the value is non-nil, this clause succeeds:
389 then the expressions in BODY are evaluated and the last one's
390 value is the value of the cond-form.
391 If no clause succeeds, cond returns nil.
392 If a clause has one element, as in (CONDITION),
393 CONDITION's value if non-nil is returned from the cond-form.
394 usage: (cond CLAUSES...) */)
398 register Lisp_Object clause
, val
;
405 clause
= Fcar (args
);
406 val
= Feval (Fcar (clause
));
409 if (!EQ (XCDR (clause
), Qnil
))
410 val
= Fprogn (XCDR (clause
));
420 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
421 doc
: /* Eval BODY forms sequentially and return value of last one.
422 usage: (progn BODY ...) */)
426 register Lisp_Object val
= Qnil
;
433 val
= Feval (XCAR (args
));
441 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
442 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
443 The value of FIRST is saved during the evaluation of the remaining args,
444 whose values are discarded.
445 usage: (prog1 FIRST BODY...) */)
450 register Lisp_Object args_left
;
451 struct gcpro gcpro1
, gcpro2
;
452 register int argnum
= 0;
464 val
= Feval (Fcar (args_left
));
466 Feval (Fcar (args_left
));
467 args_left
= Fcdr (args_left
);
469 while (!NILP(args_left
));
475 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
476 doc
: /* Eval FORM1, FORM2 and BODY sequentially; value from FORM2.
477 The value of FORM2 is saved during the evaluation of the
478 remaining args, whose values are discarded.
479 usage: (prog2 FORM1 FORM2 BODY...) */)
484 register Lisp_Object args_left
;
485 struct gcpro gcpro1
, gcpro2
;
486 register int argnum
= -1;
500 val
= Feval (Fcar (args_left
));
502 Feval (Fcar (args_left
));
503 args_left
= Fcdr (args_left
);
505 while (!NILP (args_left
));
511 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
512 doc
: /* Set each SYM to the value of its VAL.
513 The symbols SYM are variables; they are literal (not evaluated).
514 The values VAL are expressions; they are evaluated.
515 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
516 The second VAL is not computed until after the first SYM is set, and so on;
517 each VAL can use the new value of variables set earlier in the `setq'.
518 The return value of the `setq' form is the value of the last VAL.
519 usage: (setq SYM VAL SYM VAL ...) */)
523 register Lisp_Object args_left
;
524 register Lisp_Object val
, sym
;
535 val
= Feval (Fcar (Fcdr (args_left
)));
536 sym
= Fcar (args_left
);
538 args_left
= Fcdr (Fcdr (args_left
));
540 while (!NILP(args_left
));
546 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
547 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
548 usage: (quote ARG) */)
555 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
556 doc
: /* Like `quote', but preferred for objects which are functions.
557 In byte compilation, `function' causes its argument to be compiled.
558 `quote' cannot do that.
559 usage: (function ARG) */)
567 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
568 doc
: /* Return t if the function was run directly by user input.
569 This means that the function was called with `call-interactively'
570 \(which includes being called as the binding of a key)
571 and input is currently coming from the keyboard (not in keyboard macro),
572 and Emacs is not running in batch mode (`noninteractive' is nil).
574 The only known proper use of `interactive-p' is in deciding whether to
575 display a helpful message, or how to display it. If you're thinking
576 of using it for any other purpose, it is quite likely that you're
577 making a mistake. Think: what do you want to do when the command is
578 called from a keyboard macro?
580 If you want to test whether your function was called with
581 `call-interactively', the way to do that is by adding an extra
582 optional argument, and making the `interactive' spec specify non-nil
583 unconditionally for that argument. (`p' is a good way to do this.) */)
586 return (INTERACTIVE
&& interactive_p (1)) ? Qt
: Qnil
;
590 DEFUN ("called-interactively-p", Fcalled_interactively_p
, Scalled_interactively_p
, 0, 0, 0,
591 doc
: /* Return t if the function using this was called with `call-interactively'.
592 This is used for implementing advice and other function-modifying
595 The cleanest way to test whether your function was called with
596 `call-interactively' is by adding an extra optional argument,
597 and making the `interactive' spec specify non-nil unconditionally
598 for that argument. (`p' is a good way to do this.) */)
601 return interactive_p (1) ? Qt
: Qnil
;
605 /* Return 1 if function in which this appears was called using
608 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
609 called is a built-in. */
612 interactive_p (exclude_subrs_p
)
615 struct backtrace
*btp
;
618 btp
= backtrace_list
;
620 /* If this isn't a byte-compiled function, there may be a frame at
621 the top for Finteractive_p. If so, skip it. */
622 fun
= Findirect_function (*btp
->function
, Qnil
);
623 if (SUBRP (fun
) && (XSUBR (fun
) == &Sinteractive_p
624 || XSUBR (fun
) == &Scalled_interactively_p
))
627 /* If we're running an Emacs 18-style byte-compiled function, there
628 may be a frame for Fbytecode at the top level. In any version of
629 Emacs there can be Fbytecode frames for subexpressions evaluated
630 inside catch and condition-case. Skip past them.
632 If this isn't a byte-compiled function, then we may now be
633 looking at several frames for special forms. Skip past them. */
635 && (EQ (*btp
->function
, Qbytecode
)
636 || btp
->nargs
== UNEVALLED
))
639 /* btp now points at the frame of the innermost function that isn't
640 a special form, ignoring frames for Finteractive_p and/or
641 Fbytecode at the top. If this frame is for a built-in function
642 (such as load or eval-region) return nil. */
643 fun
= Findirect_function (*btp
->function
, Qnil
);
644 if (exclude_subrs_p
&& SUBRP (fun
))
647 /* btp points to the frame of a Lisp function that called interactive-p.
648 Return t if that function was called interactively. */
649 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
655 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
656 doc
: /* Define NAME as a function.
657 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
658 See also the function `interactive'.
659 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
663 register Lisp_Object fn_name
;
664 register Lisp_Object defn
;
666 fn_name
= Fcar (args
);
667 CHECK_SYMBOL (fn_name
);
668 defn
= Fcons (Qlambda
, Fcdr (args
));
669 if (!NILP (Vpurify_flag
))
670 defn
= Fpurecopy (defn
);
671 if (CONSP (XSYMBOL (fn_name
)->function
)
672 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
673 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
674 Ffset (fn_name
, defn
);
675 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
679 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
680 doc
: /* Define NAME as a macro.
681 The actual definition looks like
682 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
683 When the macro is called, as in (NAME ARGS...),
684 the function (lambda ARGLIST BODY...) is applied to
685 the list ARGS... as it appears in the expression,
686 and the result should be a form to be evaluated instead of the original.
688 DECL is a declaration, optional, which can specify how to indent
689 calls to this macro and how Edebug should handle it. It looks like this:
691 The elements can look like this:
693 Set NAME's `lisp-indent-function' property to INDENT.
696 Set NAME's `edebug-form-spec' property to DEBUG. (This is
697 equivalent to writing a `def-edebug-spec' for the macro.)
698 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
702 register Lisp_Object fn_name
;
703 register Lisp_Object defn
;
704 Lisp_Object lambda_list
, doc
, tail
;
706 fn_name
= Fcar (args
);
707 CHECK_SYMBOL (fn_name
);
708 lambda_list
= Fcar (Fcdr (args
));
709 tail
= Fcdr (Fcdr (args
));
712 if (STRINGP (Fcar (tail
)))
718 while (CONSP (Fcar (tail
))
719 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
721 if (!NILP (Vmacro_declaration_function
))
725 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
733 tail
= Fcons (lambda_list
, tail
);
735 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
736 defn
= Fcons (Qmacro
, Fcons (Qlambda
, tail
));
738 if (!NILP (Vpurify_flag
))
739 defn
= Fpurecopy (defn
);
740 if (CONSP (XSYMBOL (fn_name
)->function
)
741 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
742 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
743 Ffset (fn_name
, defn
);
744 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
749 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
750 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
751 Setting the value of NEW-ALIAS will subsequently set the value of BASE-VARIABLE,
752 and getting the value of NEW-ALIAS will return the value BASE-VARIABLE has.
753 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
754 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
755 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
757 The return value is BASE-VARIABLE. */)
758 (new_alias
, base_variable
, docstring
)
759 Lisp_Object new_alias
, base_variable
, docstring
;
761 struct Lisp_Symbol
*sym
;
763 CHECK_SYMBOL (new_alias
);
764 CHECK_SYMBOL (base_variable
);
766 if (SYMBOL_CONSTANT_P (new_alias
))
767 error ("Cannot make a constant an alias");
769 sym
= XSYMBOL (new_alias
);
770 sym
->indirect_variable
= 1;
771 sym
->value
= base_variable
;
772 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
773 LOADHIST_ATTACH (new_alias
);
774 if (!NILP (docstring
))
775 Fput (new_alias
, Qvariable_documentation
, docstring
);
777 Fput (new_alias
, Qvariable_documentation
, Qnil
);
779 return base_variable
;
783 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
784 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
785 You are not required to define a variable in order to use it,
786 but the definition can supply documentation and an initial value
787 in a way that tags can recognize.
789 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
790 If SYMBOL is buffer-local, its default value is what is set;
791 buffer-local values are not affected.
792 INITVALUE and DOCSTRING are optional.
793 If DOCSTRING starts with *, this variable is identified as a user option.
794 This means that M-x set-variable recognizes it.
795 See also `user-variable-p'.
796 If INITVALUE is missing, SYMBOL's value is not set.
798 If SYMBOL has a local binding, then this form affects the local
799 binding. This is usually not what you want. Thus, if you need to
800 load a file defining variables, with this form or with `defconst' or
801 `defcustom', you should always load that file _outside_ any bindings
802 for these variables. \(`defconst' and `defcustom' behave similarly in
804 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
808 register Lisp_Object sym
, tem
, tail
;
812 if (!NILP (Fcdr (Fcdr (tail
))))
813 error ("Too many arguments");
815 tem
= Fdefault_boundp (sym
);
818 if (SYMBOL_CONSTANT_P (sym
))
820 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
821 Lisp_Object tem
= Fcar (tail
);
823 && EQ (XCAR (tem
), Qquote
)
824 && CONSP (XCDR (tem
))
825 && EQ (XCAR (XCDR (tem
)), sym
)))
826 error ("Constant symbol `%s' specified in defvar",
827 SDATA (SYMBOL_NAME (sym
)));
831 Fset_default (sym
, Feval (Fcar (tail
)));
833 { /* Check if there is really a global binding rather than just a let
834 binding that shadows the global unboundness of the var. */
835 volatile struct specbinding
*pdl
= specpdl_ptr
;
836 while (--pdl
>= specpdl
)
838 if (EQ (pdl
->symbol
, sym
) && !pdl
->func
839 && EQ (pdl
->old_value
, Qunbound
))
841 message_with_string ("Warning: defvar ignored because %s is let-bound",
842 SYMBOL_NAME (sym
), 1);
851 if (!NILP (Vpurify_flag
))
852 tem
= Fpurecopy (tem
);
853 Fput (sym
, Qvariable_documentation
, tem
);
855 LOADHIST_ATTACH (sym
);
858 /* Simple (defvar <var>) should not count as a definition at all.
859 It could get in the way of other definitions, and unloading this
860 package could try to make the variable unbound. */
866 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
867 doc
: /* Define SYMBOL as a constant variable.
868 The intent is that neither programs nor users should ever change this value.
869 Always sets the value of SYMBOL to the result of evalling INITVALUE.
870 If SYMBOL is buffer-local, its default value is what is set;
871 buffer-local values are not affected.
872 DOCSTRING is optional.
874 If SYMBOL has a local binding, then this form sets the local binding's
875 value. However, you should normally not make local bindings for
876 variables defined with this form.
877 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
881 register Lisp_Object sym
, tem
;
884 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
885 error ("Too many arguments");
887 tem
= Feval (Fcar (Fcdr (args
)));
888 if (!NILP (Vpurify_flag
))
889 tem
= Fpurecopy (tem
);
890 Fset_default (sym
, tem
);
891 tem
= Fcar (Fcdr (Fcdr (args
)));
894 if (!NILP (Vpurify_flag
))
895 tem
= Fpurecopy (tem
);
896 Fput (sym
, Qvariable_documentation
, tem
);
898 LOADHIST_ATTACH (sym
);
902 /* Error handler used in Fuser_variable_p. */
904 user_variable_p_eh (ignore
)
910 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
911 doc
: /* Return t if VARIABLE is intended to be set and modified by users.
912 \(The alternative is a variable used internally in a Lisp program.)
913 A variable is a user variable if
914 \(1) the first character of its documentation is `*', or
915 \(2) it is customizable (its property list contains a non-nil value
916 of `standard-value' or `custom-autoload'), or
917 \(3) it is an alias for another user variable.
918 Return nil if VARIABLE is an alias and there is a loop in the
919 chain of symbols. */)
921 Lisp_Object variable
;
923 Lisp_Object documentation
;
925 if (!SYMBOLP (variable
))
928 /* If indirect and there's an alias loop, don't check anything else. */
929 if (XSYMBOL (variable
)->indirect_variable
930 && NILP (internal_condition_case_1 (indirect_variable
, variable
,
931 Qt
, user_variable_p_eh
)))
936 documentation
= Fget (variable
, Qvariable_documentation
);
937 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
939 if (STRINGP (documentation
)
940 && ((unsigned char) SREF (documentation
, 0) == '*'))
942 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
943 if (CONSP (documentation
)
944 && STRINGP (XCAR (documentation
))
945 && INTEGERP (XCDR (documentation
))
946 && XINT (XCDR (documentation
)) < 0)
948 /* Customizable? See `custom-variable-p'. */
949 if ((!NILP (Fget (variable
, intern ("standard-value"))))
950 || (!NILP (Fget (variable
, intern ("custom-autoload")))))
953 if (!XSYMBOL (variable
)->indirect_variable
)
956 /* An indirect variable? Let's follow the chain. */
957 variable
= XSYMBOL (variable
)->value
;
961 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
962 doc
: /* Bind variables according to VARLIST then eval BODY.
963 The value of the last form in BODY is returned.
964 Each element of VARLIST is a symbol (which is bound to nil)
965 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
966 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
967 usage: (let* VARLIST BODY...) */)
971 Lisp_Object varlist
, val
, elt
;
972 int count
= SPECPDL_INDEX ();
973 struct gcpro gcpro1
, gcpro2
, gcpro3
;
975 GCPRO3 (args
, elt
, varlist
);
977 varlist
= Fcar (args
);
978 while (!NILP (varlist
))
981 elt
= Fcar (varlist
);
983 specbind (elt
, Qnil
);
984 else if (! NILP (Fcdr (Fcdr (elt
))))
986 Fcons (build_string ("`let' bindings can have only one value-form"),
990 val
= Feval (Fcar (Fcdr (elt
)));
991 specbind (Fcar (elt
), val
);
993 varlist
= Fcdr (varlist
);
996 val
= Fprogn (Fcdr (args
));
997 return unbind_to (count
, val
);
1000 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
1001 doc
: /* Bind variables according to VARLIST then eval BODY.
1002 The value of the last form in BODY is returned.
1003 Each element of VARLIST is a symbol (which is bound to nil)
1004 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1005 All the VALUEFORMs are evalled before any symbols are bound.
1006 usage: (let VARLIST BODY...) */)
1010 Lisp_Object
*temps
, tem
;
1011 register Lisp_Object elt
, varlist
;
1012 int count
= SPECPDL_INDEX ();
1013 register int argnum
;
1014 struct gcpro gcpro1
, gcpro2
;
1016 varlist
= Fcar (args
);
1018 /* Make space to hold the values to give the bound variables */
1019 elt
= Flength (varlist
);
1020 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
1022 /* Compute the values and store them in `temps' */
1024 GCPRO2 (args
, *temps
);
1027 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
1030 elt
= Fcar (varlist
);
1032 temps
[argnum
++] = Qnil
;
1033 else if (! NILP (Fcdr (Fcdr (elt
))))
1035 Fcons (build_string ("`let' bindings can have only one value-form"),
1038 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
1039 gcpro2
.nvars
= argnum
;
1043 varlist
= Fcar (args
);
1044 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
1046 elt
= Fcar (varlist
);
1047 tem
= temps
[argnum
++];
1049 specbind (elt
, tem
);
1051 specbind (Fcar (elt
), tem
);
1054 elt
= Fprogn (Fcdr (args
));
1055 return unbind_to (count
, elt
);
1058 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
1059 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
1060 The order of execution is thus TEST, BODY, TEST, BODY and so on
1061 until TEST returns nil.
1062 usage: (while TEST BODY...) */)
1066 Lisp_Object test
, body
;
1067 struct gcpro gcpro1
, gcpro2
;
1069 GCPRO2 (test
, body
);
1073 while (!NILP (Feval (test
)))
1083 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1084 doc
: /* Return result of expanding macros at top level of FORM.
1085 If FORM is not a macro call, it is returned unchanged.
1086 Otherwise, the macro is expanded and the expansion is considered
1087 in place of FORM. When a non-macro-call results, it is returned.
1089 The second optional arg ENVIRONMENT specifies an environment of macro
1090 definitions to shadow the loaded ones for use in file byte-compilation. */)
1093 Lisp_Object environment
;
1095 /* With cleanups from Hallvard Furuseth. */
1096 register Lisp_Object expander
, sym
, def
, tem
;
1100 /* Come back here each time we expand a macro call,
1101 in case it expands into another macro call. */
1104 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1105 def
= sym
= XCAR (form
);
1107 /* Trace symbols aliases to other symbols
1108 until we get a symbol that is not an alias. */
1109 while (SYMBOLP (def
))
1113 tem
= Fassq (sym
, environment
);
1116 def
= XSYMBOL (sym
)->function
;
1117 if (!EQ (def
, Qunbound
))
1122 /* Right now TEM is the result from SYM in ENVIRONMENT,
1123 and if TEM is nil then DEF is SYM's function definition. */
1126 /* SYM is not mentioned in ENVIRONMENT.
1127 Look at its function definition. */
1128 if (EQ (def
, Qunbound
) || !CONSP (def
))
1129 /* Not defined or definition not suitable */
1131 if (EQ (XCAR (def
), Qautoload
))
1133 /* Autoloading function: will it be a macro when loaded? */
1134 tem
= Fnth (make_number (4), def
);
1135 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1136 /* Yes, load it and try again. */
1138 struct gcpro gcpro1
;
1140 do_autoload (def
, sym
);
1147 else if (!EQ (XCAR (def
), Qmacro
))
1149 else expander
= XCDR (def
);
1153 expander
= XCDR (tem
);
1154 if (NILP (expander
))
1157 form
= apply1 (expander
, XCDR (form
));
1162 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1163 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1164 TAG is evalled to get the tag to use; it must not be nil.
1166 Then the BODY is executed.
1167 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1168 If no throw happens, `catch' returns the value of the last BODY form.
1169 If a throw happens, it specifies the value to return from `catch'.
1170 usage: (catch TAG BODY...) */)
1174 register Lisp_Object tag
;
1175 struct gcpro gcpro1
;
1178 tag
= Feval (Fcar (args
));
1180 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1183 /* Set up a catch, then call C function FUNC on argument ARG.
1184 FUNC should return a Lisp_Object.
1185 This is how catches are done from within C code. */
1188 internal_catch (tag
, func
, arg
)
1190 Lisp_Object (*func
) ();
1193 /* This structure is made part of the chain `catchlist'. */
1196 /* Fill in the components of c, and put it on the list. */
1200 c
.backlist
= backtrace_list
;
1201 c
.handlerlist
= handlerlist
;
1202 c
.lisp_eval_depth
= lisp_eval_depth
;
1203 c
.pdlcount
= SPECPDL_INDEX ();
1204 c
.poll_suppress_count
= poll_suppress_count
;
1205 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1206 c
.gcpro
= gcprolist
;
1207 c
.byte_stack
= byte_stack_list
;
1211 if (! _setjmp (c
.jmp
))
1212 c
.val
= (*func
) (arg
);
1214 /* Throw works by a longjmp that comes right here. */
1219 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1220 jump to that CATCH, returning VALUE as the value of that catch.
1222 This is the guts Fthrow and Fsignal; they differ only in the way
1223 they choose the catch tag to throw to. A catch tag for a
1224 condition-case form has a TAG of Qnil.
1226 Before each catch is discarded, unbind all special bindings and
1227 execute all unwind-protect clauses made above that catch. Unwind
1228 the handler stack as we go, so that the proper handlers are in
1229 effect for each unwind-protect clause we run. At the end, restore
1230 some static info saved in CATCH, and longjmp to the location
1233 This is used for correct unwinding in Fthrow and Fsignal. */
1236 unwind_to_catch (catch, value
)
1237 struct catchtag
*catch;
1240 register int last_time
;
1242 /* Save the value in the tag. */
1245 /* Restore certain special C variables. */
1246 set_poll_suppress_count (catch->poll_suppress_count
);
1247 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked
);
1248 handling_signal
= 0;
1253 last_time
= catchlist
== catch;
1255 /* Unwind the specpdl stack, and then restore the proper set of
1257 unbind_to (catchlist
->pdlcount
, Qnil
);
1258 handlerlist
= catchlist
->handlerlist
;
1259 catchlist
= catchlist
->next
;
1261 while (! last_time
);
1264 /* If x_catch_errors was done, turn it off now.
1265 (First we give unbind_to a chance to do that.) */
1266 x_fully_uncatch_errors ();
1269 byte_stack_list
= catch->byte_stack
;
1270 gcprolist
= catch->gcpro
;
1273 gcpro_level
= gcprolist
->level
+ 1;
1277 backtrace_list
= catch->backlist
;
1278 lisp_eval_depth
= catch->lisp_eval_depth
;
1280 _longjmp (catch->jmp
, 1);
1283 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1284 doc
: /* Throw to the catch for TAG and return VALUE from it.
1285 Both TAG and VALUE are evalled. */)
1287 register Lisp_Object tag
, value
;
1289 register struct catchtag
*c
;
1294 for (c
= catchlist
; c
; c
= c
->next
)
1296 if (EQ (c
->tag
, tag
))
1297 unwind_to_catch (c
, value
);
1299 tag
= Fsignal (Qno_catch
, Fcons (tag
, Fcons (value
, Qnil
)));
1304 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1305 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1306 If BODYFORM completes normally, its value is returned
1307 after executing the UNWINDFORMS.
1308 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1309 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1314 int count
= SPECPDL_INDEX ();
1316 record_unwind_protect (Fprogn
, Fcdr (args
));
1317 val
= Feval (Fcar (args
));
1318 return unbind_to (count
, val
);
1321 /* Chain of condition handlers currently in effect.
1322 The elements of this chain are contained in the stack frames
1323 of Fcondition_case and internal_condition_case.
1324 When an error is signaled (by calling Fsignal, below),
1325 this chain is searched for an element that applies. */
1327 struct handler
*handlerlist
;
1329 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1330 doc
: /* Regain control when an error is signaled.
1331 Executes BODYFORM and returns its value if no error happens.
1332 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1333 where the BODY is made of Lisp expressions.
1335 A handler is applicable to an error
1336 if CONDITION-NAME is one of the error's condition names.
1337 If an error happens, the first applicable handler is run.
1339 The car of a handler may be a list of condition names
1340 instead of a single condition name.
1342 When a handler handles an error,
1343 control returns to the condition-case and the handler BODY... is executed
1344 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1345 VAR may be nil; then you do not get access to the signal information.
1347 The value of the last BODY form is returned from the condition-case.
1348 See also the function `signal' for more info.
1349 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1353 register Lisp_Object bodyform
, handlers
;
1354 volatile Lisp_Object var
;
1357 bodyform
= Fcar (Fcdr (args
));
1358 handlers
= Fcdr (Fcdr (args
));
1360 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1363 /* Like Fcondition_case, but the args are separate
1364 rather than passed in a list. Used by Fbyte_code. */
1367 internal_lisp_condition_case (var
, bodyform
, handlers
)
1368 volatile Lisp_Object var
;
1369 Lisp_Object bodyform
, handlers
;
1377 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1383 && (SYMBOLP (XCAR (tem
))
1384 || CONSP (XCAR (tem
))))))
1385 error ("Invalid condition handler", tem
);
1390 c
.backlist
= backtrace_list
;
1391 c
.handlerlist
= handlerlist
;
1392 c
.lisp_eval_depth
= lisp_eval_depth
;
1393 c
.pdlcount
= SPECPDL_INDEX ();
1394 c
.poll_suppress_count
= poll_suppress_count
;
1395 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1396 c
.gcpro
= gcprolist
;
1397 c
.byte_stack
= byte_stack_list
;
1398 if (_setjmp (c
.jmp
))
1401 specbind (h
.var
, c
.val
);
1402 val
= Fprogn (Fcdr (h
.chosen_clause
));
1404 /* Note that this just undoes the binding of h.var; whoever
1405 longjumped to us unwound the stack to c.pdlcount before
1407 unbind_to (c
.pdlcount
, Qnil
);
1414 h
.handler
= handlers
;
1415 h
.next
= handlerlist
;
1419 val
= Feval (bodyform
);
1421 handlerlist
= h
.next
;
1425 /* Call the function BFUN with no arguments, catching errors within it
1426 according to HANDLERS. If there is an error, call HFUN with
1427 one argument which is the data that describes the error:
1430 HANDLERS can be a list of conditions to catch.
1431 If HANDLERS is Qt, catch all errors.
1432 If HANDLERS is Qerror, catch all errors
1433 but allow the debugger to run if that is enabled. */
1436 internal_condition_case (bfun
, handlers
, hfun
)
1437 Lisp_Object (*bfun
) ();
1438 Lisp_Object handlers
;
1439 Lisp_Object (*hfun
) ();
1445 /* Since Fsignal will close off all calls to x_catch_errors,
1446 we will get the wrong results if some are not closed now. */
1448 if (x_catching_errors ())
1454 c
.backlist
= backtrace_list
;
1455 c
.handlerlist
= handlerlist
;
1456 c
.lisp_eval_depth
= lisp_eval_depth
;
1457 c
.pdlcount
= SPECPDL_INDEX ();
1458 c
.poll_suppress_count
= poll_suppress_count
;
1459 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1460 c
.gcpro
= gcprolist
;
1461 c
.byte_stack
= byte_stack_list
;
1462 if (_setjmp (c
.jmp
))
1464 return (*hfun
) (c
.val
);
1468 h
.handler
= handlers
;
1470 h
.next
= handlerlist
;
1476 handlerlist
= h
.next
;
1480 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1483 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1484 Lisp_Object (*bfun
) ();
1486 Lisp_Object handlers
;
1487 Lisp_Object (*hfun
) ();
1493 /* Since Fsignal will close off all calls to x_catch_errors,
1494 we will get the wrong results if some are not closed now. */
1496 if (x_catching_errors ())
1502 c
.backlist
= backtrace_list
;
1503 c
.handlerlist
= handlerlist
;
1504 c
.lisp_eval_depth
= lisp_eval_depth
;
1505 c
.pdlcount
= SPECPDL_INDEX ();
1506 c
.poll_suppress_count
= poll_suppress_count
;
1507 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1508 c
.gcpro
= gcprolist
;
1509 c
.byte_stack
= byte_stack_list
;
1510 if (_setjmp (c
.jmp
))
1512 return (*hfun
) (c
.val
);
1516 h
.handler
= handlers
;
1518 h
.next
= handlerlist
;
1522 val
= (*bfun
) (arg
);
1524 handlerlist
= h
.next
;
1529 /* Like internal_condition_case but call BFUN with NARGS as first,
1530 and ARGS as second argument. */
1533 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1534 Lisp_Object (*bfun
) ();
1537 Lisp_Object handlers
;
1538 Lisp_Object (*hfun
) ();
1544 /* Since Fsignal will close off all calls to x_catch_errors,
1545 we will get the wrong results if some are not closed now. */
1547 if (x_catching_errors ())
1553 c
.backlist
= backtrace_list
;
1554 c
.handlerlist
= handlerlist
;
1555 c
.lisp_eval_depth
= lisp_eval_depth
;
1556 c
.pdlcount
= SPECPDL_INDEX ();
1557 c
.poll_suppress_count
= poll_suppress_count
;
1558 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1559 c
.gcpro
= gcprolist
;
1560 c
.byte_stack
= byte_stack_list
;
1561 if (_setjmp (c
.jmp
))
1563 return (*hfun
) (c
.val
);
1567 h
.handler
= handlers
;
1569 h
.next
= handlerlist
;
1573 val
= (*bfun
) (nargs
, args
);
1575 handlerlist
= h
.next
;
1580 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1581 Lisp_Object
, Lisp_Object
,
1584 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1585 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1586 This function does not return.
1588 An error symbol is a symbol with an `error-conditions' property
1589 that is a list of condition names.
1590 A handler for any of those names will get to handle this signal.
1591 The symbol `error' should normally be one of them.
1593 DATA should be a list. Its elements are printed as part of the error message.
1594 See Info anchor `(elisp)Definition of signal' for some details on how this
1595 error message is constructed.
1596 If the signal is handled, DATA is made available to the handler.
1597 See also the function `condition-case'. */)
1598 (error_symbol
, data
)
1599 Lisp_Object error_symbol
, data
;
1601 /* When memory is full, ERROR-SYMBOL is nil,
1602 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1603 That is a special case--don't do this in other situations. */
1604 register struct handler
*allhandlers
= handlerlist
;
1605 Lisp_Object conditions
;
1606 extern int gc_in_progress
;
1607 extern int waiting_for_input
;
1608 Lisp_Object debugger_value
;
1610 Lisp_Object real_error_symbol
;
1611 struct backtrace
*bp
;
1613 immediate_quit
= handling_signal
= 0;
1615 if (gc_in_progress
|| waiting_for_input
)
1618 if (NILP (error_symbol
))
1619 real_error_symbol
= Fcar (data
);
1621 real_error_symbol
= error_symbol
;
1623 #if 0 /* rms: I don't know why this was here,
1624 but it is surely wrong for an error that is handled. */
1625 #ifdef HAVE_X_WINDOWS
1626 if (display_hourglass_p
)
1627 cancel_hourglass ();
1631 /* This hook is used by edebug. */
1632 if (! NILP (Vsignal_hook_function
)
1633 && ! NILP (error_symbol
))
1635 /* Edebug takes care of restoring these variables when it exits. */
1636 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1637 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1639 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1640 max_specpdl_size
= SPECPDL_INDEX () + 40;
1642 call2 (Vsignal_hook_function
, error_symbol
, data
);
1645 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1647 /* Remember from where signal was called. Skip over the frame for
1648 `signal' itself. If a frame for `error' follows, skip that,
1649 too. Don't do this when ERROR_SYMBOL is nil, because that
1650 is a memory-full error. */
1651 Vsignaling_function
= Qnil
;
1652 if (backtrace_list
&& !NILP (error_symbol
))
1654 bp
= backtrace_list
->next
;
1655 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1657 if (bp
&& bp
->function
)
1658 Vsignaling_function
= *bp
->function
;
1661 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1663 register Lisp_Object clause
;
1665 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1666 error_symbol
, data
, &debugger_value
);
1668 if (EQ (clause
, Qlambda
))
1670 /* We can't return values to code which signaled an error, but we
1671 can continue code which has signaled a quit. */
1672 if (EQ (real_error_symbol
, Qquit
))
1675 error ("Cannot return from the debugger in an error");
1680 Lisp_Object unwind_data
;
1681 struct handler
*h
= handlerlist
;
1683 handlerlist
= allhandlers
;
1685 if (NILP (error_symbol
))
1688 unwind_data
= Fcons (error_symbol
, data
);
1689 h
->chosen_clause
= clause
;
1690 unwind_to_catch (h
->tag
, unwind_data
);
1694 handlerlist
= allhandlers
;
1695 /* If no handler is present now, try to run the debugger,
1696 and if that fails, throw to top level. */
1697 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1699 Fthrow (Qtop_level
, Qt
);
1701 if (! NILP (error_symbol
))
1702 data
= Fcons (error_symbol
, data
);
1704 string
= Ferror_message_string (data
);
1705 fatal ("%s", SDATA (string
), 0);
1708 /* Return nonzero iff LIST is a non-nil atom or
1709 a list containing one of CONDITIONS. */
1712 wants_debugger (list
, conditions
)
1713 Lisp_Object list
, conditions
;
1720 while (CONSP (conditions
))
1722 Lisp_Object
this, tail
;
1723 this = XCAR (conditions
);
1724 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1725 if (EQ (XCAR (tail
), this))
1727 conditions
= XCDR (conditions
);
1732 /* Return 1 if an error with condition-symbols CONDITIONS,
1733 and described by SIGNAL-DATA, should skip the debugger
1734 according to debugger-ignored-errors. */
1737 skip_debugger (conditions
, data
)
1738 Lisp_Object conditions
, data
;
1741 int first_string
= 1;
1742 Lisp_Object error_message
;
1744 error_message
= Qnil
;
1745 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1747 if (STRINGP (XCAR (tail
)))
1751 error_message
= Ferror_message_string (data
);
1755 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1760 Lisp_Object contail
;
1762 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1763 if (EQ (XCAR (tail
), XCAR (contail
)))
1771 /* Value of Qlambda means we have called debugger and user has continued.
1772 There are two ways to pass SIG and DATA:
1773 = SIG is the error symbol, and DATA is the rest of the data.
1774 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1775 This is for memory-full errors only.
1777 Store value returned from debugger into *DEBUGGER_VALUE_PTR.
1779 We need to increase max_specpdl_size temporarily around
1780 anything we do that can push on the specpdl, so as not to get
1781 a second error here in case we're handling specpdl overflow. */
1784 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1785 Lisp_Object handlers
, conditions
, sig
, data
;
1786 Lisp_Object
*debugger_value_ptr
;
1788 register Lisp_Object h
;
1789 register Lisp_Object tem
;
1791 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1793 /* error is used similarly, but means print an error message
1794 and run the debugger if that is enabled. */
1795 if (EQ (handlers
, Qerror
)
1796 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1797 there is a handler. */
1799 int debugger_called
= 0;
1800 Lisp_Object sig_symbol
, combined_data
;
1801 /* This is set to 1 if we are handling a memory-full error,
1802 because these must not run the debugger.
1803 (There is no room in memory to do that!) */
1804 int no_debugger
= 0;
1808 combined_data
= data
;
1809 sig_symbol
= Fcar (data
);
1814 combined_data
= Fcons (sig
, data
);
1818 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1822 internal_with_output_to_temp_buffer ("*Backtrace*",
1823 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1826 internal_with_output_to_temp_buffer ("*Backtrace*",
1832 && (EQ (sig_symbol
, Qquit
)
1834 : wants_debugger (Vdebug_on_error
, conditions
))
1835 && ! skip_debugger (conditions
, combined_data
)
1836 && when_entered_debugger
< num_nonmacro_input_events
)
1839 = call_debugger (Fcons (Qerror
,
1840 Fcons (combined_data
, Qnil
)));
1841 debugger_called
= 1;
1843 /* If there is no handler, return saying whether we ran the debugger. */
1844 if (EQ (handlers
, Qerror
))
1846 if (debugger_called
)
1851 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1853 Lisp_Object handler
, condit
;
1856 if (!CONSP (handler
))
1858 condit
= Fcar (handler
);
1859 /* Handle a single condition name in handler HANDLER. */
1860 if (SYMBOLP (condit
))
1862 tem
= Fmemq (Fcar (handler
), conditions
);
1866 /* Handle a list of condition names in handler HANDLER. */
1867 else if (CONSP (condit
))
1869 while (CONSP (condit
))
1871 tem
= Fmemq (Fcar (condit
), conditions
);
1874 condit
= XCDR (condit
);
1881 /* dump an error message; called like printf */
1885 error (m
, a1
, a2
, a3
)
1905 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1910 buffer
= (char *) xrealloc (buffer
, size
);
1913 buffer
= (char *) xmalloc (size
);
1918 string
= build_string (buffer
);
1922 Fsignal (Qerror
, Fcons (string
, Qnil
));
1926 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1927 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1928 This means it contains a description for how to read arguments to give it.
1929 The value is nil for an invalid function or a symbol with no function
1932 Interactively callable functions include strings and vectors (treated
1933 as keyboard macros), lambda-expressions that contain a top-level call
1934 to `interactive', autoload definitions made by `autoload' with non-nil
1935 fourth argument, and some of the built-in functions of Lisp.
1937 Also, a symbol satisfies `commandp' if its function definition does so.
1939 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1940 then strings and vectors are not accepted. */)
1941 (function
, for_call_interactively
)
1942 Lisp_Object function
, for_call_interactively
;
1944 register Lisp_Object fun
;
1945 register Lisp_Object funcar
;
1949 fun
= indirect_function (fun
);
1950 if (EQ (fun
, Qunbound
))
1953 /* Emacs primitives are interactive if their DEFUN specifies an
1954 interactive spec. */
1957 if (XSUBR (fun
)->prompt
)
1963 /* Bytecode objects are interactive if they are long enough to
1964 have an element whose index is COMPILED_INTERACTIVE, which is
1965 where the interactive spec is stored. */
1966 else if (COMPILEDP (fun
))
1967 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1970 /* Strings and vectors are keyboard macros. */
1971 if (NILP (for_call_interactively
) && (STRINGP (fun
) || VECTORP (fun
)))
1974 /* Lists may represent commands. */
1977 funcar
= XCAR (fun
);
1978 if (EQ (funcar
, Qlambda
))
1979 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
1980 if (EQ (funcar
, Qautoload
))
1981 return Fcar (Fcdr (Fcdr (XCDR (fun
))));
1987 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1988 doc
: /* Define FUNCTION to autoload from FILE.
1989 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1990 Third arg DOCSTRING is documentation for the function.
1991 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1992 Fifth arg TYPE indicates the type of the object:
1993 nil or omitted says FUNCTION is a function,
1994 `keymap' says FUNCTION is really a keymap, and
1995 `macro' or t says FUNCTION is really a macro.
1996 Third through fifth args give info about the real definition.
1997 They default to nil.
1998 If FUNCTION is already defined other than as an autoload,
1999 this does nothing and returns nil. */)
2000 (function
, file
, docstring
, interactive
, type
)
2001 Lisp_Object function
, file
, docstring
, interactive
, type
;
2004 Lisp_Object args
[4];
2007 CHECK_SYMBOL (function
);
2008 CHECK_STRING (file
);
2010 /* If function is defined and not as an autoload, don't override */
2011 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
2012 && !(CONSP (XSYMBOL (function
)->function
)
2013 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
2016 if (NILP (Vpurify_flag
))
2017 /* Only add entries after dumping, because the ones before are
2018 not useful and else we get loads of them from the loaddefs.el. */
2019 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
2023 args
[1] = docstring
;
2024 args
[2] = interactive
;
2027 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
2028 #else /* NO_ARG_ARRAY */
2029 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
2030 #endif /* not NO_ARG_ARRAY */
2034 un_autoload (oldqueue
)
2035 Lisp_Object oldqueue
;
2037 register Lisp_Object queue
, first
, second
;
2039 /* Queue to unwind is current value of Vautoload_queue.
2040 oldqueue is the shadowed value to leave in Vautoload_queue. */
2041 queue
= Vautoload_queue
;
2042 Vautoload_queue
= oldqueue
;
2043 while (CONSP (queue
))
2045 first
= XCAR (queue
);
2046 second
= Fcdr (first
);
2047 first
= Fcar (first
);
2048 if (EQ (first
, make_number (0)))
2051 Ffset (first
, second
);
2052 queue
= XCDR (queue
);
2057 /* Load an autoloaded function.
2058 FUNNAME is the symbol which is the function's name.
2059 FUNDEF is the autoload definition (a list). */
2062 do_autoload (fundef
, funname
)
2063 Lisp_Object fundef
, funname
;
2065 int count
= SPECPDL_INDEX ();
2066 Lisp_Object fun
, queue
, first
, second
;
2067 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2069 /* This is to make sure that loadup.el gives a clear picture
2070 of what files are preloaded and when. */
2071 if (! NILP (Vpurify_flag
))
2072 error ("Attempt to autoload %s while preparing to dump",
2073 SDATA (SYMBOL_NAME (funname
)));
2076 CHECK_SYMBOL (funname
);
2077 GCPRO3 (fun
, funname
, fundef
);
2079 /* Preserve the match data. */
2080 record_unwind_save_match_data ();
2082 /* Value saved here is to be restored into Vautoload_queue. */
2083 record_unwind_protect (un_autoload
, Vautoload_queue
);
2084 Vautoload_queue
= Qt
;
2085 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
2087 /* Save the old autoloads, in case we ever do an unload. */
2088 queue
= Vautoload_queue
;
2089 while (CONSP (queue
))
2091 first
= XCAR (queue
);
2092 second
= Fcdr (first
);
2093 first
= Fcar (first
);
2095 if (SYMBOLP (first
) && CONSP (second
) && EQ (XCAR (second
), Qautoload
))
2096 Fput (first
, Qautoload
, (XCDR (second
)));
2098 queue
= XCDR (queue
);
2101 /* Once loading finishes, don't undo it. */
2102 Vautoload_queue
= Qt
;
2103 unbind_to (count
, Qnil
);
2105 fun
= Findirect_function (fun
, Qnil
);
2107 if (!NILP (Fequal (fun
, fundef
)))
2108 error ("Autoloading failed to define function %s",
2109 SDATA (SYMBOL_NAME (funname
)));
2114 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
2115 doc
: /* Evaluate FORM and return its value. */)
2119 Lisp_Object fun
, val
, original_fun
, original_args
;
2121 struct backtrace backtrace
;
2122 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2124 if (handling_signal
)
2128 return Fsymbol_value (form
);
2133 if ((consing_since_gc
> gc_cons_threshold
2134 && consing_since_gc
> gc_relative_threshold
)
2136 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2139 Fgarbage_collect ();
2143 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2145 if (max_lisp_eval_depth
< 100)
2146 max_lisp_eval_depth
= 100;
2147 if (lisp_eval_depth
> max_lisp_eval_depth
)
2148 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2151 original_fun
= Fcar (form
);
2152 original_args
= Fcdr (form
);
2154 backtrace
.next
= backtrace_list
;
2155 backtrace_list
= &backtrace
;
2156 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2157 backtrace
.args
= &original_args
;
2158 backtrace
.nargs
= UNEVALLED
;
2159 backtrace
.evalargs
= 1;
2160 backtrace
.debug_on_exit
= 0;
2162 if (debug_on_next_call
)
2163 do_debug_on_call (Qt
);
2165 /* At this point, only original_fun and original_args
2166 have values that will be used below */
2168 fun
= Findirect_function (original_fun
, Qnil
);
2172 Lisp_Object numargs
;
2173 Lisp_Object argvals
[8];
2174 Lisp_Object args_left
;
2175 register int i
, maxargs
;
2177 args_left
= original_args
;
2178 numargs
= Flength (args_left
);
2182 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2183 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2184 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (numargs
, Qnil
)));
2186 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2188 backtrace
.evalargs
= 0;
2189 val
= (*XSUBR (fun
)->function
) (args_left
);
2193 if (XSUBR (fun
)->max_args
== MANY
)
2195 /* Pass a vector of evaluated arguments */
2197 register int argnum
= 0;
2199 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2201 GCPRO3 (args_left
, fun
, fun
);
2205 while (!NILP (args_left
))
2207 vals
[argnum
++] = Feval (Fcar (args_left
));
2208 args_left
= Fcdr (args_left
);
2209 gcpro3
.nvars
= argnum
;
2212 backtrace
.args
= vals
;
2213 backtrace
.nargs
= XINT (numargs
);
2215 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2220 GCPRO3 (args_left
, fun
, fun
);
2221 gcpro3
.var
= argvals
;
2224 maxargs
= XSUBR (fun
)->max_args
;
2225 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2227 argvals
[i
] = Feval (Fcar (args_left
));
2233 backtrace
.args
= argvals
;
2234 backtrace
.nargs
= XINT (numargs
);
2239 val
= (*XSUBR (fun
)->function
) ();
2242 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2245 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2248 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2252 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2253 argvals
[2], argvals
[3]);
2256 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2257 argvals
[3], argvals
[4]);
2260 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2261 argvals
[3], argvals
[4], argvals
[5]);
2264 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2265 argvals
[3], argvals
[4], argvals
[5],
2270 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2271 argvals
[3], argvals
[4], argvals
[5],
2272 argvals
[6], argvals
[7]);
2276 /* Someone has created a subr that takes more arguments than
2277 is supported by this code. We need to either rewrite the
2278 subr to use a different argument protocol, or add more
2279 cases to this switch. */
2283 if (COMPILEDP (fun
))
2284 val
= apply_lambda (fun
, original_args
, 1);
2288 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2289 funcar
= Fcar (fun
);
2290 if (!SYMBOLP (funcar
))
2291 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2292 if (EQ (funcar
, Qautoload
))
2294 do_autoload (fun
, original_fun
);
2297 if (EQ (funcar
, Qmacro
))
2298 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2299 else if (EQ (funcar
, Qlambda
))
2300 val
= apply_lambda (fun
, original_args
, 1);
2302 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2308 if (backtrace
.debug_on_exit
)
2309 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2310 backtrace_list
= backtrace
.next
;
2315 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2316 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2317 Then return the value FUNCTION returns.
2318 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2319 usage: (apply FUNCTION &rest ARGUMENTS) */)
2324 register int i
, numargs
;
2325 register Lisp_Object spread_arg
;
2326 register Lisp_Object
*funcall_args
;
2328 struct gcpro gcpro1
;
2332 spread_arg
= args
[nargs
- 1];
2333 CHECK_LIST (spread_arg
);
2335 numargs
= XINT (Flength (spread_arg
));
2338 return Ffuncall (nargs
- 1, args
);
2339 else if (numargs
== 1)
2341 args
[nargs
- 1] = XCAR (spread_arg
);
2342 return Ffuncall (nargs
, args
);
2345 numargs
+= nargs
- 2;
2347 fun
= indirect_function (fun
);
2348 if (EQ (fun
, Qunbound
))
2350 /* Let funcall get the error */
2357 if (numargs
< XSUBR (fun
)->min_args
2358 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2359 goto funcall
; /* Let funcall get the error */
2360 else if (XSUBR (fun
)->max_args
> numargs
)
2362 /* Avoid making funcall cons up a yet another new vector of arguments
2363 by explicitly supplying nil's for optional values */
2364 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2365 * sizeof (Lisp_Object
));
2366 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2367 funcall_args
[++i
] = Qnil
;
2368 GCPRO1 (*funcall_args
);
2369 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2373 /* We add 1 to numargs because funcall_args includes the
2374 function itself as well as its arguments. */
2377 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2378 * sizeof (Lisp_Object
));
2379 GCPRO1 (*funcall_args
);
2380 gcpro1
.nvars
= 1 + numargs
;
2383 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2384 /* Spread the last arg we got. Its first element goes in
2385 the slot that it used to occupy, hence this value of I. */
2387 while (!NILP (spread_arg
))
2389 funcall_args
[i
++] = XCAR (spread_arg
);
2390 spread_arg
= XCDR (spread_arg
);
2393 /* By convention, the caller needs to gcpro Ffuncall's args. */
2394 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2397 /* Run hook variables in various ways. */
2399 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2400 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2401 enum run_hooks_condition
));
2403 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2404 doc
: /* Run each hook in HOOKS.
2405 Each argument should be a symbol, a hook variable.
2406 These symbols are processed in the order specified.
2407 If a hook symbol has a non-nil value, that value may be a function
2408 or a list of functions to be called to run the hook.
2409 If the value is a function, it is called with no arguments.
2410 If it is a list, the elements are called, in order, with no arguments.
2412 Major modes should not use this function directly to run their mode
2413 hook; they should use `run-mode-hooks' instead.
2415 Do not use `make-local-variable' to make a hook variable buffer-local.
2416 Instead, use `add-hook' and specify t for the LOCAL argument.
2417 usage: (run-hooks &rest HOOKS) */)
2422 Lisp_Object hook
[1];
2425 for (i
= 0; i
< nargs
; i
++)
2428 run_hook_with_args (1, hook
, to_completion
);
2434 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2435 Srun_hook_with_args
, 1, MANY
, 0,
2436 doc
: /* Run HOOK with the specified arguments ARGS.
2437 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2438 value, that value may be a function or a list of functions to be
2439 called to run the hook. If the value is a function, it is called with
2440 the given arguments and its return value is returned. If it is a list
2441 of functions, those functions are called, in order,
2442 with the given arguments ARGS.
2443 It is best not to depend on the value returned by `run-hook-with-args',
2446 Do not use `make-local-variable' to make a hook variable buffer-local.
2447 Instead, use `add-hook' and specify t for the LOCAL argument.
2448 usage: (run-hook-with-args HOOK &rest ARGS) */)
2453 return run_hook_with_args (nargs
, args
, to_completion
);
2456 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2457 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2458 doc
: /* Run HOOK with the specified arguments ARGS.
2459 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2460 value, that value may be a function or a list of functions to be
2461 called to run the hook. If the value is a function, it is called with
2462 the given arguments and its return value is returned.
2463 If it is a list of functions, those functions are called, in order,
2464 with the given arguments ARGS, until one of them
2465 returns a non-nil value. Then we return that value.
2466 However, if they all return nil, we return nil.
2468 Do not use `make-local-variable' to make a hook variable buffer-local.
2469 Instead, use `add-hook' and specify t for the LOCAL argument.
2470 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2475 return run_hook_with_args (nargs
, args
, until_success
);
2478 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2479 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2480 doc
: /* Run HOOK with the specified arguments ARGS.
2481 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2482 value, that value may be a function or a list of functions to be
2483 called to run the hook. If the value is a function, it is called with
2484 the given arguments and its return value is returned.
2485 If it is a list of functions, those functions are called, in order,
2486 with the given arguments ARGS, until one of them returns nil.
2487 Then we return nil. However, if they all return non-nil, we return non-nil.
2489 Do not use `make-local-variable' to make a hook variable buffer-local.
2490 Instead, use `add-hook' and specify t for the LOCAL argument.
2491 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2496 return run_hook_with_args (nargs
, args
, until_failure
);
2499 /* ARGS[0] should be a hook symbol.
2500 Call each of the functions in the hook value, passing each of them
2501 as arguments all the rest of ARGS (all NARGS - 1 elements).
2502 COND specifies a condition to test after each call
2503 to decide whether to stop.
2504 The caller (or its caller, etc) must gcpro all of ARGS,
2505 except that it isn't necessary to gcpro ARGS[0]. */
2508 run_hook_with_args (nargs
, args
, cond
)
2511 enum run_hooks_condition cond
;
2513 Lisp_Object sym
, val
, ret
;
2514 Lisp_Object globals
;
2515 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2517 /* If we are dying or still initializing,
2518 don't do anything--it would probably crash if we tried. */
2519 if (NILP (Vrun_hooks
))
2523 val
= find_symbol_value (sym
);
2524 ret
= (cond
== until_failure
? Qt
: Qnil
);
2526 if (EQ (val
, Qunbound
) || NILP (val
))
2528 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2531 return Ffuncall (nargs
, args
);
2536 GCPRO3 (sym
, val
, globals
);
2539 CONSP (val
) && ((cond
== to_completion
)
2540 || (cond
== until_success
? NILP (ret
)
2544 if (EQ (XCAR (val
), Qt
))
2546 /* t indicates this hook has a local binding;
2547 it means to run the global binding too. */
2549 for (globals
= Fdefault_value (sym
);
2550 CONSP (globals
) && ((cond
== to_completion
)
2551 || (cond
== until_success
? NILP (ret
)
2553 globals
= XCDR (globals
))
2555 args
[0] = XCAR (globals
);
2556 /* In a global value, t should not occur. If it does, we
2557 must ignore it to avoid an endless loop. */
2558 if (!EQ (args
[0], Qt
))
2559 ret
= Ffuncall (nargs
, args
);
2564 args
[0] = XCAR (val
);
2565 ret
= Ffuncall (nargs
, args
);
2574 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2575 present value of that symbol.
2576 Call each element of FUNLIST,
2577 passing each of them the rest of ARGS.
2578 The caller (or its caller, etc) must gcpro all of ARGS,
2579 except that it isn't necessary to gcpro ARGS[0]. */
2582 run_hook_list_with_args (funlist
, nargs
, args
)
2583 Lisp_Object funlist
;
2589 Lisp_Object globals
;
2590 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2594 GCPRO3 (sym
, val
, globals
);
2596 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2598 if (EQ (XCAR (val
), Qt
))
2600 /* t indicates this hook has a local binding;
2601 it means to run the global binding too. */
2603 for (globals
= Fdefault_value (sym
);
2605 globals
= XCDR (globals
))
2607 args
[0] = XCAR (globals
);
2608 /* In a global value, t should not occur. If it does, we
2609 must ignore it to avoid an endless loop. */
2610 if (!EQ (args
[0], Qt
))
2611 Ffuncall (nargs
, args
);
2616 args
[0] = XCAR (val
);
2617 Ffuncall (nargs
, args
);
2624 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2627 run_hook_with_args_2 (hook
, arg1
, arg2
)
2628 Lisp_Object hook
, arg1
, arg2
;
2630 Lisp_Object temp
[3];
2635 Frun_hook_with_args (3, temp
);
2638 /* Apply fn to arg */
2641 Lisp_Object fn
, arg
;
2643 struct gcpro gcpro1
;
2647 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2651 Lisp_Object args
[2];
2655 RETURN_UNGCPRO (Fapply (2, args
));
2657 #else /* not NO_ARG_ARRAY */
2658 RETURN_UNGCPRO (Fapply (2, &fn
));
2659 #endif /* not NO_ARG_ARRAY */
2662 /* Call function fn on no arguments */
2667 struct gcpro gcpro1
;
2670 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2673 /* Call function fn with 1 argument arg1 */
2677 Lisp_Object fn
, arg1
;
2679 struct gcpro gcpro1
;
2681 Lisp_Object args
[2];
2687 RETURN_UNGCPRO (Ffuncall (2, args
));
2688 #else /* not NO_ARG_ARRAY */
2691 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2692 #endif /* not NO_ARG_ARRAY */
2695 /* Call function fn with 2 arguments arg1, arg2 */
2698 call2 (fn
, arg1
, arg2
)
2699 Lisp_Object fn
, arg1
, arg2
;
2701 struct gcpro gcpro1
;
2703 Lisp_Object args
[3];
2709 RETURN_UNGCPRO (Ffuncall (3, args
));
2710 #else /* not NO_ARG_ARRAY */
2713 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2714 #endif /* not NO_ARG_ARRAY */
2717 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2720 call3 (fn
, arg1
, arg2
, arg3
)
2721 Lisp_Object fn
, arg1
, arg2
, arg3
;
2723 struct gcpro gcpro1
;
2725 Lisp_Object args
[4];
2732 RETURN_UNGCPRO (Ffuncall (4, args
));
2733 #else /* not NO_ARG_ARRAY */
2736 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2737 #endif /* not NO_ARG_ARRAY */
2740 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2743 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2744 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2746 struct gcpro gcpro1
;
2748 Lisp_Object args
[5];
2756 RETURN_UNGCPRO (Ffuncall (5, args
));
2757 #else /* not NO_ARG_ARRAY */
2760 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2761 #endif /* not NO_ARG_ARRAY */
2764 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2767 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2768 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2770 struct gcpro gcpro1
;
2772 Lisp_Object args
[6];
2781 RETURN_UNGCPRO (Ffuncall (6, args
));
2782 #else /* not NO_ARG_ARRAY */
2785 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2786 #endif /* not NO_ARG_ARRAY */
2789 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2792 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2793 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2795 struct gcpro gcpro1
;
2797 Lisp_Object args
[7];
2807 RETURN_UNGCPRO (Ffuncall (7, args
));
2808 #else /* not NO_ARG_ARRAY */
2811 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2812 #endif /* not NO_ARG_ARRAY */
2815 /* The caller should GCPRO all the elements of ARGS. */
2817 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2818 doc
: /* Call first argument as a function, passing remaining arguments to it.
2819 Return the value that function returns.
2820 Thus, (funcall 'cons 'x 'y) returns (x . y).
2821 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2828 int numargs
= nargs
- 1;
2829 Lisp_Object lisp_numargs
;
2831 struct backtrace backtrace
;
2832 register Lisp_Object
*internal_args
;
2836 if ((consing_since_gc
> gc_cons_threshold
2837 && consing_since_gc
> gc_relative_threshold
)
2839 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2840 Fgarbage_collect ();
2842 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2844 if (max_lisp_eval_depth
< 100)
2845 max_lisp_eval_depth
= 100;
2846 if (lisp_eval_depth
> max_lisp_eval_depth
)
2847 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2850 backtrace
.next
= backtrace_list
;
2851 backtrace_list
= &backtrace
;
2852 backtrace
.function
= &args
[0];
2853 backtrace
.args
= &args
[1];
2854 backtrace
.nargs
= nargs
- 1;
2855 backtrace
.evalargs
= 0;
2856 backtrace
.debug_on_exit
= 0;
2858 if (debug_on_next_call
)
2859 do_debug_on_call (Qlambda
);
2867 fun
= Findirect_function (fun
, Qnil
);
2871 if (numargs
< XSUBR (fun
)->min_args
2872 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2874 XSETFASTINT (lisp_numargs
, numargs
);
2875 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2878 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2879 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2881 if (XSUBR (fun
)->max_args
== MANY
)
2883 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2887 if (XSUBR (fun
)->max_args
> numargs
)
2889 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2890 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2891 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2892 internal_args
[i
] = Qnil
;
2895 internal_args
= args
+ 1;
2896 switch (XSUBR (fun
)->max_args
)
2899 val
= (*XSUBR (fun
)->function
) ();
2902 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2905 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1]);
2908 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2912 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2913 internal_args
[2], internal_args
[3]);
2916 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2917 internal_args
[2], internal_args
[3],
2921 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2922 internal_args
[2], internal_args
[3],
2923 internal_args
[4], internal_args
[5]);
2926 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2927 internal_args
[2], internal_args
[3],
2928 internal_args
[4], internal_args
[5],
2933 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2934 internal_args
[2], internal_args
[3],
2935 internal_args
[4], internal_args
[5],
2936 internal_args
[6], internal_args
[7]);
2941 /* If a subr takes more than 8 arguments without using MANY
2942 or UNEVALLED, we need to extend this function to support it.
2943 Until this is done, there is no way to call the function. */
2947 if (COMPILEDP (fun
))
2948 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2952 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2953 funcar
= Fcar (fun
);
2954 if (!SYMBOLP (funcar
))
2955 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2956 if (EQ (funcar
, Qlambda
))
2957 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2958 else if (EQ (funcar
, Qautoload
))
2960 do_autoload (fun
, args
[0]);
2965 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2970 if (backtrace
.debug_on_exit
)
2971 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2972 backtrace_list
= backtrace
.next
;
2977 apply_lambda (fun
, args
, eval_flag
)
2978 Lisp_Object fun
, args
;
2981 Lisp_Object args_left
;
2982 Lisp_Object numargs
;
2983 register Lisp_Object
*arg_vector
;
2984 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2986 register Lisp_Object tem
;
2988 numargs
= Flength (args
);
2989 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2992 GCPRO3 (*arg_vector
, args_left
, fun
);
2995 for (i
= 0; i
< XINT (numargs
);)
2997 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2998 if (eval_flag
) tem
= Feval (tem
);
2999 arg_vector
[i
++] = tem
;
3007 backtrace_list
->args
= arg_vector
;
3008 backtrace_list
->nargs
= i
;
3010 backtrace_list
->evalargs
= 0;
3011 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
3013 /* Do the debug-on-exit now, while arg_vector still exists. */
3014 if (backtrace_list
->debug_on_exit
)
3015 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
3016 /* Don't do it again when we return to eval. */
3017 backtrace_list
->debug_on_exit
= 0;
3021 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3022 and return the result of evaluation.
3023 FUN must be either a lambda-expression or a compiled-code object. */
3026 funcall_lambda (fun
, nargs
, arg_vector
)
3029 register Lisp_Object
*arg_vector
;
3031 Lisp_Object val
, syms_left
, next
;
3032 int count
= SPECPDL_INDEX ();
3033 int i
, optional
, rest
;
3037 syms_left
= XCDR (fun
);
3038 if (CONSP (syms_left
))
3039 syms_left
= XCAR (syms_left
);
3041 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
3043 else if (COMPILEDP (fun
))
3044 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
3048 i
= optional
= rest
= 0;
3049 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
3053 next
= XCAR (syms_left
);
3054 while (!SYMBOLP (next
))
3055 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
3057 if (EQ (next
, Qand_rest
))
3059 else if (EQ (next
, Qand_optional
))
3063 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
3067 specbind (next
, arg_vector
[i
++]);
3069 return Fsignal (Qwrong_number_of_arguments
,
3070 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
3072 specbind (next
, Qnil
);
3075 if (!NILP (syms_left
))
3076 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
3078 return Fsignal (Qwrong_number_of_arguments
,
3079 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
3082 val
= Fprogn (XCDR (XCDR (fun
)));
3085 /* If we have not actually read the bytecode string
3086 and constants vector yet, fetch them from the file. */
3087 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3088 Ffetch_bytecode (fun
);
3089 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
3090 AREF (fun
, COMPILED_CONSTANTS
),
3091 AREF (fun
, COMPILED_STACK_DEPTH
));
3094 return unbind_to (count
, val
);
3097 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3099 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3105 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3107 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3110 tem
= AREF (object
, COMPILED_BYTECODE
);
3111 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3112 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3114 error ("Invalid byte code");
3116 AREF (object
, COMPILED_BYTECODE
) = XCAR (tem
);
3117 AREF (object
, COMPILED_CONSTANTS
) = XCDR (tem
);
3125 register int count
= SPECPDL_INDEX ();
3126 if (specpdl_size
>= max_specpdl_size
)
3128 if (max_specpdl_size
< 400)
3129 max_specpdl_size
= 400;
3130 if (specpdl_size
>= max_specpdl_size
)
3132 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
3135 if (specpdl_size
> max_specpdl_size
)
3136 specpdl_size
= max_specpdl_size
;
3137 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
3138 specpdl_ptr
= specpdl
+ count
;
3142 specbind (symbol
, value
)
3143 Lisp_Object symbol
, value
;
3146 Lisp_Object valcontents
;
3148 CHECK_SYMBOL (symbol
);
3149 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3152 /* The most common case is that of a non-constant symbol with a
3153 trivial value. Make that as fast as we can. */
3154 valcontents
= SYMBOL_VALUE (symbol
);
3155 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3157 specpdl_ptr
->symbol
= symbol
;
3158 specpdl_ptr
->old_value
= valcontents
;
3159 specpdl_ptr
->func
= NULL
;
3161 SET_SYMBOL_VALUE (symbol
, value
);
3165 Lisp_Object valcontents
;
3167 ovalue
= find_symbol_value (symbol
);
3168 specpdl_ptr
->func
= 0;
3169 specpdl_ptr
->old_value
= ovalue
;
3171 valcontents
= XSYMBOL (symbol
)->value
;
3173 if (BUFFER_LOCAL_VALUEP (valcontents
)
3174 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
3175 || BUFFER_OBJFWDP (valcontents
))
3177 Lisp_Object where
, current_buffer
;
3179 current_buffer
= Fcurrent_buffer ();
3181 /* For a local variable, record both the symbol and which
3182 buffer's or frame's value we are saving. */
3183 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3184 where
= current_buffer
;
3185 else if (!BUFFER_OBJFWDP (valcontents
)
3186 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3187 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3191 /* We're not using the `unused' slot in the specbinding
3192 structure because this would mean we have to do more
3193 work for simple variables. */
3194 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3196 /* If SYMBOL is a per-buffer variable which doesn't have a
3197 buffer-local value here, make the `let' change the global
3198 value by changing the value of SYMBOL in all buffers not
3199 having their own value. This is consistent with what
3200 happens with other buffer-local variables. */
3202 && BUFFER_OBJFWDP (valcontents
))
3205 Fset_default (symbol
, value
);
3210 specpdl_ptr
->symbol
= symbol
;
3213 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3214 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3216 set_internal (symbol
, value
, 0, 1);
3221 record_unwind_protect (function
, arg
)
3222 Lisp_Object (*function
) P_ ((Lisp_Object
));
3225 eassert (!handling_signal
);
3227 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3229 specpdl_ptr
->func
= function
;
3230 specpdl_ptr
->symbol
= Qnil
;
3231 specpdl_ptr
->old_value
= arg
;
3236 unbind_to (count
, value
)
3240 Lisp_Object quitf
= Vquit_flag
;
3241 struct gcpro gcpro1
, gcpro2
;
3243 GCPRO2 (value
, quitf
);
3246 while (specpdl_ptr
!= specpdl
+ count
)
3248 /* Copy the binding, and decrement specpdl_ptr, before we do
3249 the work to unbind it. We decrement first
3250 so that an error in unbinding won't try to unbind
3251 the same entry again, and we copy the binding first
3252 in case more bindings are made during some of the code we run. */
3254 struct specbinding this_binding
;
3255 this_binding
= *--specpdl_ptr
;
3257 if (this_binding
.func
!= 0)
3258 (*this_binding
.func
) (this_binding
.old_value
);
3259 /* If the symbol is a list, it is really (SYMBOL WHERE
3260 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3261 frame. If WHERE is a buffer or frame, this indicates we
3262 bound a variable that had a buffer-local or frame-local
3263 binding. WHERE nil means that the variable had the default
3264 value when it was bound. CURRENT-BUFFER is the buffer that
3265 was current when the variable was bound. */
3266 else if (CONSP (this_binding
.symbol
))
3268 Lisp_Object symbol
, where
;
3270 symbol
= XCAR (this_binding
.symbol
);
3271 where
= XCAR (XCDR (this_binding
.symbol
));
3274 Fset_default (symbol
, this_binding
.old_value
);
3275 else if (BUFFERP (where
))
3276 set_internal (symbol
, this_binding
.old_value
, XBUFFER (where
), 1);
3278 set_internal (symbol
, this_binding
.old_value
, NULL
, 1);
3282 /* If variable has a trivial value (no forwarding), we can
3283 just set it. No need to check for constant symbols here,
3284 since that was already done by specbind. */
3285 if (!MISCP (SYMBOL_VALUE (this_binding
.symbol
)))
3286 SET_SYMBOL_VALUE (this_binding
.symbol
, this_binding
.old_value
);
3288 set_internal (this_binding
.symbol
, this_binding
.old_value
, 0, 1);
3292 if (NILP (Vquit_flag
) && !NILP (quitf
))
3299 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3300 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3301 The debugger is entered when that frame exits, if the flag is non-nil. */)
3303 Lisp_Object level
, flag
;
3305 register struct backtrace
*backlist
= backtrace_list
;
3308 CHECK_NUMBER (level
);
3310 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3312 backlist
= backlist
->next
;
3316 backlist
->debug_on_exit
= !NILP (flag
);
3321 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3322 doc
: /* Print a trace of Lisp function calls currently active.
3323 Output stream used is value of `standard-output'. */)
3326 register struct backtrace
*backlist
= backtrace_list
;
3330 extern Lisp_Object Vprint_level
;
3331 struct gcpro gcpro1
;
3333 XSETFASTINT (Vprint_level
, 3);
3340 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3341 if (backlist
->nargs
== UNEVALLED
)
3343 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3344 write_string ("\n", -1);
3348 tem
= *backlist
->function
;
3349 Fprin1 (tem
, Qnil
); /* This can QUIT */
3350 write_string ("(", -1);
3351 if (backlist
->nargs
== MANY
)
3353 for (tail
= *backlist
->args
, i
= 0;
3355 tail
= Fcdr (tail
), i
++)
3357 if (i
) write_string (" ", -1);
3358 Fprin1 (Fcar (tail
), Qnil
);
3363 for (i
= 0; i
< backlist
->nargs
; i
++)
3365 if (i
) write_string (" ", -1);
3366 Fprin1 (backlist
->args
[i
], Qnil
);
3369 write_string (")\n", -1);
3371 backlist
= backlist
->next
;
3374 Vprint_level
= Qnil
;
3379 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3380 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3381 If that frame has not evaluated the arguments yet (or is a special form),
3382 the value is (nil FUNCTION ARG-FORMS...).
3383 If that frame has evaluated its arguments and called its function already,
3384 the value is (t FUNCTION ARG-VALUES...).
3385 A &rest arg is represented as the tail of the list ARG-VALUES.
3386 FUNCTION is whatever was supplied as car of evaluated list,
3387 or a lambda expression for macro calls.
3388 If NFRAMES is more than the number of frames, the value is nil. */)
3390 Lisp_Object nframes
;
3392 register struct backtrace
*backlist
= backtrace_list
;
3396 CHECK_NATNUM (nframes
);
3398 /* Find the frame requested. */
3399 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3400 backlist
= backlist
->next
;
3404 if (backlist
->nargs
== UNEVALLED
)
3405 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3408 if (backlist
->nargs
== MANY
)
3409 tem
= *backlist
->args
;
3411 tem
= Flist (backlist
->nargs
, backlist
->args
);
3413 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3421 register struct backtrace
*backlist
;
3424 for (backlist
= backtrace_list
; backlist
; backlist
= backlist
->next
)
3426 mark_object (*backlist
->function
);
3428 if (backlist
->nargs
== UNEVALLED
|| backlist
->nargs
== MANY
)
3431 i
= backlist
->nargs
- 1;
3433 mark_object (backlist
->args
[i
]);
3440 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3441 doc
: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3442 If Lisp code tries to increase the total number past this amount,
3443 an error is signaled.
3444 You can safely use a value considerably larger than the default value,
3445 if that proves inconveniently small. However, if you increase it too far,
3446 Emacs could run out of memory trying to make the stack bigger. */);
3448 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3449 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3451 This limit serves to catch infinite recursions for you before they cause
3452 actual stack overflow in C, which would be fatal for Emacs.
3453 You can safely make it considerably larger than its default value,
3454 if that proves inconveniently small. However, if you increase it too far,
3455 Emacs could overflow the real C stack, and crash. */);
3457 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3458 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3459 If the value is t, that means do an ordinary quit.
3460 If the value equals `throw-on-input', that means quit by throwing
3461 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3462 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3463 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3466 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3467 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3468 Note that `quit-flag' will still be set by typing C-g,
3469 so a quit will be signaled as soon as `inhibit-quit' is nil.
3470 To prevent this happening, set `quit-flag' to nil
3471 before making `inhibit-quit' nil. */);
3472 Vinhibit_quit
= Qnil
;
3474 Qinhibit_quit
= intern ("inhibit-quit");
3475 staticpro (&Qinhibit_quit
);
3477 Qautoload
= intern ("autoload");
3478 staticpro (&Qautoload
);
3480 Qdebug_on_error
= intern ("debug-on-error");
3481 staticpro (&Qdebug_on_error
);
3483 Qmacro
= intern ("macro");
3484 staticpro (&Qmacro
);
3486 Qdeclare
= intern ("declare");
3487 staticpro (&Qdeclare
);
3489 /* Note that the process handling also uses Qexit, but we don't want
3490 to staticpro it twice, so we just do it here. */
3491 Qexit
= intern ("exit");
3494 Qinteractive
= intern ("interactive");
3495 staticpro (&Qinteractive
);
3497 Qcommandp
= intern ("commandp");
3498 staticpro (&Qcommandp
);
3500 Qdefun
= intern ("defun");
3501 staticpro (&Qdefun
);
3503 Qand_rest
= intern ("&rest");
3504 staticpro (&Qand_rest
);
3506 Qand_optional
= intern ("&optional");
3507 staticpro (&Qand_optional
);
3509 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3510 doc
: /* *Non-nil means errors display a backtrace buffer.
3511 More precisely, this happens for any error that is handled
3512 by the editor command loop.
3513 If the value is a list, an error only means to display a backtrace
3514 if one of its condition symbols appears in the list. */);
3515 Vstack_trace_on_error
= Qnil
;
3517 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3518 doc
: /* *Non-nil means enter debugger if an error is signaled.
3519 Does not apply to errors handled by `condition-case' or those
3520 matched by `debug-ignored-errors'.
3521 If the value is a list, an error only means to enter the debugger
3522 if one of its condition symbols appears in the list.
3523 When you evaluate an expression interactively, this variable
3524 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3525 See also variable `debug-on-quit'. */);
3526 Vdebug_on_error
= Qnil
;
3528 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3529 doc
: /* *List of errors for which the debugger should not be called.
3530 Each element may be a condition-name or a regexp that matches error messages.
3531 If any element applies to a given error, that error skips the debugger
3532 and just returns to top level.
3533 This overrides the variable `debug-on-error'.
3534 It does not apply to errors handled by `condition-case'. */);
3535 Vdebug_ignored_errors
= Qnil
;
3537 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3538 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3539 Does not apply if quit is handled by a `condition-case'. */);
3542 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3543 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3545 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3546 doc
: /* Non-nil means debugger may continue execution.
3547 This is nil when the debugger is called under circumstances where it
3548 might not be safe to continue. */);
3549 debugger_may_continue
= 1;
3551 DEFVAR_LISP ("debugger", &Vdebugger
,
3552 doc
: /* Function to call to invoke debugger.
3553 If due to frame exit, args are `exit' and the value being returned;
3554 this function's value will be returned instead of that.
3555 If due to error, args are `error' and a list of the args to `signal'.
3556 If due to `apply' or `funcall' entry, one arg, `lambda'.
3557 If due to `eval' entry, one arg, t. */);
3560 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3561 doc
: /* If non-nil, this is a function for `signal' to call.
3562 It receives the same arguments that `signal' was given.
3563 The Edebug package uses this to regain control. */);
3564 Vsignal_hook_function
= Qnil
;
3566 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3567 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3568 Note that `debug-on-error', `debug-on-quit' and friends
3569 still determine whether to handle the particular condition. */);
3570 Vdebug_on_signal
= Qnil
;
3572 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3573 doc
: /* Function to process declarations in a macro definition.
3574 The function will be called with two args MACRO and DECL.
3575 MACRO is the name of the macro being defined.
3576 DECL is a list `(declare ...)' containing the declarations.
3577 The value the function returns is not used. */);
3578 Vmacro_declaration_function
= Qnil
;
3580 Vrun_hooks
= intern ("run-hooks");
3581 staticpro (&Vrun_hooks
);
3583 staticpro (&Vautoload_queue
);
3584 Vautoload_queue
= Qnil
;
3585 staticpro (&Vsignaling_function
);
3586 Vsignaling_function
= Qnil
;
3597 defsubr (&Sfunction
);
3599 defsubr (&Sdefmacro
);
3601 defsubr (&Sdefvaralias
);
3602 defsubr (&Sdefconst
);
3603 defsubr (&Suser_variable_p
);
3607 defsubr (&Smacroexpand
);
3610 defsubr (&Sunwind_protect
);
3611 defsubr (&Scondition_case
);
3613 defsubr (&Sinteractive_p
);
3614 defsubr (&Scalled_interactively_p
);
3615 defsubr (&Scommandp
);
3616 defsubr (&Sautoload
);
3619 defsubr (&Sfuncall
);
3620 defsubr (&Srun_hooks
);
3621 defsubr (&Srun_hook_with_args
);
3622 defsubr (&Srun_hook_with_args_until_success
);
3623 defsubr (&Srun_hook_with_args_until_failure
);
3624 defsubr (&Sfetch_bytecode
);
3625 defsubr (&Sbacktrace_debug
);
3626 defsubr (&Sbacktrace
);
3627 defsubr (&Sbacktrace_frame
);
3630 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3631 (do not change this comment) */