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, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
25 #include "blockinput.h"
28 #include "dispextern.h"
29 #include "frame.h" /* For XFRAME. */
35 /* This definition is duplicated in alloc.c and keyboard.c */
36 /* Putting it in lisp.h makes cc bomb out! */
40 struct backtrace
*next
;
41 Lisp_Object
*function
;
42 Lisp_Object
*args
; /* Points to vector of args. */
43 int nargs
; /* Length of vector.
44 If nargs is UNEVALLED, args points to slot holding
45 list of unevalled args */
47 /* Nonzero means call value of debugger when done with this operation. */
51 struct backtrace
*backtrace_list
;
53 struct catchtag
*catchlist
;
56 /* Count levels of GCPRO to detect failure to UNGCPRO. */
60 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
, Qdefun
;
61 Lisp_Object Qinhibit_quit
, Vinhibit_quit
, Vquit_flag
;
62 Lisp_Object Qand_rest
, Qand_optional
;
63 Lisp_Object Qdebug_on_error
;
66 Lisp_Object Qinternal_interpreter_environment
, Qclosure
;
70 /* This holds either the symbol `run-hooks' or nil.
71 It is nil at an early stage of startup, and when Emacs
74 Lisp_Object Vrun_hooks
;
76 /* Non-nil means record all fset's and provide's, to be undone
77 if the file being autoloaded is not fully loaded.
78 They are recorded by being consed onto the front of Vautoload_queue:
79 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
81 Lisp_Object Vautoload_queue
;
83 /* When lexical binding is being used, this is non-nil, and contains an
84 alist of lexically-bound variable, or (t), indicating an empty
85 environment. The lisp name of this variable is
86 `internal-interpreter-environment'. Every element of this list
87 can be either a cons (VAR . VAL) specifying a lexical binding,
88 or a single symbol VAR indicating that this variable should use
91 Lisp_Object Vinternal_interpreter_environment
;
93 /* Current number of specbindings allocated in specpdl. */
95 EMACS_INT specpdl_size
;
97 /* Pointer to beginning of specpdl. */
99 struct specbinding
*specpdl
;
101 /* Pointer to first unused element in specpdl. */
103 struct specbinding
*specpdl_ptr
;
105 /* Maximum size allowed for specpdl allocation */
107 EMACS_INT max_specpdl_size
;
109 /* Depth in Lisp evaluations and function calls. */
111 EMACS_INT lisp_eval_depth
;
113 /* Maximum allowed depth in Lisp evaluations and function calls. */
115 EMACS_INT max_lisp_eval_depth
;
117 /* Nonzero means enter debugger before next function call */
119 int debug_on_next_call
;
121 /* Non-zero means debugger may continue. This is zero when the
122 debugger is called during redisplay, where it might not be safe to
123 continue the interrupted redisplay. */
125 int debugger_may_continue
;
127 /* List of conditions (non-nil atom means all) which cause a backtrace
128 if an error is handled by the command loop's error handler. */
130 Lisp_Object Vstack_trace_on_error
;
132 /* List of conditions (non-nil atom means all) which enter the debugger
133 if an error is handled by the command loop's error handler. */
135 Lisp_Object Vdebug_on_error
;
137 /* List of conditions and regexps specifying error messages which
138 do not enter the debugger even if Vdebug_on_error says they should. */
140 Lisp_Object Vdebug_ignored_errors
;
142 /* Non-nil means call the debugger even if the error will be handled. */
144 Lisp_Object Vdebug_on_signal
;
146 /* Hook for edebug to use. */
148 Lisp_Object Vsignal_hook_function
;
150 /* Nonzero means enter debugger if a quit signal
151 is handled by the command loop's error handler. */
155 /* The value of num_nonmacro_input_events as of the last time we
156 started to enter the debugger. If we decide to enter the debugger
157 again when this is still equal to num_nonmacro_input_events, then we
158 know that the debugger itself has an error, and we should just
159 signal the error instead of entering an infinite loop of debugger
162 int when_entered_debugger
;
164 Lisp_Object Vdebugger
;
166 /* The function from which the last `signal' was called. Set in
169 Lisp_Object Vsignaling_function
;
171 /* Set to non-zero while processing X events. Checked in Feval to
172 make sure the Lisp interpreter isn't called from a signal handler,
173 which is unsafe because the interpreter isn't reentrant. */
177 /* Function to process declarations in defmacro forms. */
179 Lisp_Object Vmacro_declaration_function
;
181 static Lisp_Object
apply_lambda (Lisp_Object fun
, Lisp_Object args
);
182 static Lisp_Object
funcall_lambda (Lisp_Object
, int, Lisp_Object
*);
183 static void unwind_to_catch (struct catchtag
*, Lisp_Object
) NO_RETURN
;
186 init_eval_once (void)
189 specpdl
= (struct specbinding
*) xmalloc (specpdl_size
* sizeof (struct specbinding
));
190 specpdl_ptr
= specpdl
;
191 /* Don't forget to update docs (lispref node "Local Variables"). */
192 max_specpdl_size
= 1200; /* 1000 is not enough for CEDET's c-by.el. */
193 max_lisp_eval_depth
= 600;
201 specpdl_ptr
= specpdl
;
206 debug_on_next_call
= 0;
211 /* This is less than the initial value of num_nonmacro_input_events. */
212 when_entered_debugger
= -1;
215 /* unwind-protect function used by call_debugger. */
218 restore_stack_limits (Lisp_Object data
)
220 max_specpdl_size
= XINT (XCAR (data
));
221 max_lisp_eval_depth
= XINT (XCDR (data
));
225 /* Call the Lisp debugger, giving it argument ARG. */
228 call_debugger (Lisp_Object arg
)
230 int debug_while_redisplaying
;
231 int count
= SPECPDL_INDEX ();
233 EMACS_INT old_max
= max_specpdl_size
;
235 /* Temporarily bump up the stack limits,
236 so the debugger won't run out of stack. */
238 max_specpdl_size
+= 1;
239 record_unwind_protect (restore_stack_limits
,
240 Fcons (make_number (old_max
),
241 make_number (max_lisp_eval_depth
)));
242 max_specpdl_size
= old_max
;
244 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
245 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
247 if (SPECPDL_INDEX () + 100 > max_specpdl_size
)
248 max_specpdl_size
= SPECPDL_INDEX () + 100;
250 #ifdef HAVE_WINDOW_SYSTEM
251 if (display_hourglass_p
)
255 debug_on_next_call
= 0;
256 when_entered_debugger
= num_nonmacro_input_events
;
258 /* Resetting redisplaying_p to 0 makes sure that debug output is
259 displayed if the debugger is invoked during redisplay. */
260 debug_while_redisplaying
= redisplaying_p
;
262 specbind (intern ("debugger-may-continue"),
263 debug_while_redisplaying
? Qnil
: Qt
);
264 specbind (Qinhibit_redisplay
, Qnil
);
265 specbind (Qdebug_on_error
, Qnil
);
267 #if 0 /* Binding this prevents execution of Lisp code during
268 redisplay, which necessarily leads to display problems. */
269 specbind (Qinhibit_eval_during_redisplay
, Qt
);
272 val
= apply1 (Vdebugger
, arg
);
274 /* Interrupting redisplay and resuming it later is not safe under
275 all circumstances. So, when the debugger returns, abort the
276 interrupted redisplay by going back to the top-level. */
277 if (debug_while_redisplaying
)
280 return unbind_to (count
, val
);
284 do_debug_on_call (Lisp_Object code
)
286 debug_on_next_call
= 0;
287 backtrace_list
->debug_on_exit
= 1;
288 call_debugger (Fcons (code
, Qnil
));
291 /* NOTE!!! Every function that can call EVAL must protect its args
292 and temporaries from garbage collection while it needs them.
293 The definition of `For' shows what you have to do. */
295 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
296 doc
: /* Eval args until one of them yields non-nil, then return that value.
297 The remaining args are not evalled at all.
298 If all args return nil, return nil.
299 usage: (or CONDITIONS...) */)
302 register Lisp_Object val
= Qnil
;
309 val
= eval_sub (XCAR (args
));
319 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
320 doc
: /* Eval args until one of them yields nil, then return nil.
321 The remaining args are not evalled at all.
322 If no arg yields nil, return the last arg's value.
323 usage: (and CONDITIONS...) */)
326 register Lisp_Object val
= Qt
;
333 val
= eval_sub (XCAR (args
));
343 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
344 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
345 Returns the value of THEN or the value of the last of the ELSE's.
346 THEN must be one expression, but ELSE... can be zero or more expressions.
347 If COND yields nil, and there are no ELSE's, the value is nil.
348 usage: (if COND THEN ELSE...) */)
351 register Lisp_Object cond
;
355 cond
= eval_sub (Fcar (args
));
359 return eval_sub (Fcar (Fcdr (args
)));
360 return Fprogn (Fcdr (Fcdr (args
)));
363 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
364 doc
: /* Try each clause until one succeeds.
365 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
366 and, if the value is non-nil, this clause succeeds:
367 then the expressions in BODY are evaluated and the last one's
368 value is the value of the cond-form.
369 If no clause succeeds, cond returns nil.
370 If a clause has one element, as in (CONDITION),
371 CONDITION's value if non-nil is returned from the cond-form.
372 usage: (cond CLAUSES...) */)
375 register Lisp_Object clause
, val
;
382 clause
= Fcar (args
);
383 val
= eval_sub (Fcar (clause
));
386 if (!EQ (XCDR (clause
), Qnil
))
387 val
= Fprogn (XCDR (clause
));
397 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
398 doc
: /* Eval BODY forms sequentially and return value of last one.
399 usage: (progn BODY...) */)
402 register Lisp_Object val
= Qnil
;
409 val
= eval_sub (XCAR (args
));
417 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
418 doc
: /* Eval FIRST and BODY sequentially; return value from FIRST.
419 The value of FIRST is saved during the evaluation of the remaining args,
420 whose values are discarded.
421 usage: (prog1 FIRST BODY...) */)
425 register Lisp_Object args_left
;
426 struct gcpro gcpro1
, gcpro2
;
427 register int argnum
= 0;
439 val
= eval_sub (Fcar (args_left
));
441 eval_sub (Fcar (args_left
));
442 args_left
= Fcdr (args_left
);
444 while (!NILP(args_left
));
450 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
451 doc
: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
452 The value of FORM2 is saved during the evaluation of the
453 remaining args, whose values are discarded.
454 usage: (prog2 FORM1 FORM2 BODY...) */)
458 register Lisp_Object args_left
;
459 struct gcpro gcpro1
, gcpro2
;
460 register int argnum
= -1;
474 val
= eval_sub (Fcar (args_left
));
476 eval_sub (Fcar (args_left
));
477 args_left
= Fcdr (args_left
);
479 while (!NILP (args_left
));
485 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
486 doc
: /* Set each SYM to the value of its VAL.
487 The symbols SYM are variables; they are literal (not evaluated).
488 The values VAL are expressions; they are evaluated.
489 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
490 The second VAL is not computed until after the first SYM is set, and so on;
491 each VAL can use the new value of variables set earlier in the `setq'.
492 The return value of the `setq' form is the value of the last VAL.
493 usage: (setq [SYM VAL]...) */)
496 register Lisp_Object args_left
;
497 register Lisp_Object val
, sym
, lex_binding
;
508 val
= eval_sub (Fcar (Fcdr (args_left
)));
509 sym
= Fcar (args_left
);
511 /* Like for eval_sub, we do not check declared_special here since
512 it's been done when let-binding. */
513 if (!NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
515 && !NILP (lex_binding
516 = Fassq (sym
, Vinternal_interpreter_environment
)))
517 XSETCDR (lex_binding
, val
); /* SYM is lexically bound. */
519 Fset (sym
, val
); /* SYM is dynamically bound. */
521 args_left
= Fcdr (Fcdr (args_left
));
523 while (!NILP(args_left
));
529 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
530 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
531 usage: (quote ARG) */)
534 if (!NILP (Fcdr (args
)))
535 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
539 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
540 doc
: /* Like `quote', but preferred for objects which are functions.
541 In byte compilation, `function' causes its argument to be compiled.
542 `quote' cannot do that.
543 usage: (function ARG) */)
546 Lisp_Object quoted
= XCAR (args
);
548 if (!NILP (Fcdr (args
)))
549 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
551 if (!NILP (Vinternal_interpreter_environment
)
553 && EQ (XCAR (quoted
), Qlambda
))
554 /* This is a lambda expression within a lexical environment;
555 return an interpreted closure instead of a simple lambda. */
556 return Fcons (Qclosure
, Fcons (Vinternal_interpreter_environment
, quoted
));
558 /* Simply quote the argument. */
563 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
564 doc
: /* Return t if the containing function was run directly by user input.
565 This means that the function was called with `call-interactively'
566 \(which includes being called as the binding of a key)
567 and input is currently coming from the keyboard (not a keyboard macro),
568 and Emacs is not running in batch mode (`noninteractive' is nil).
570 The only known proper use of `interactive-p' is in deciding whether to
571 display a helpful message, or how to display it. If you're thinking
572 of using it for any other purpose, it is quite likely that you're
573 making a mistake. Think: what do you want to do when the command is
574 called from a keyboard macro?
576 To test whether your function was called with `call-interactively',
577 either (i) add an extra optional argument and give it an `interactive'
578 spec that specifies non-nil unconditionally (such as \"p\"); or (ii)
579 use `called-interactively-p'. */)
582 return interactive_p (1) ? Qt
: Qnil
;
586 DEFUN ("called-interactively-p", Fcalled_interactively_p
, Scalled_interactively_p
, 0, 1, 0,
587 doc
: /* Return t if the containing function was called by `call-interactively'.
588 If KIND is `interactive', then only return t if the call was made
589 interactively by the user, i.e. not in `noninteractive' mode nor
590 when `executing-kbd-macro'.
591 If KIND is `any', on the other hand, it will return t for any kind of
592 interactive call, including being called as the binding of a key, or
593 from a keyboard macro, or in `noninteractive' mode.
595 The only known proper use of `interactive' for KIND is in deciding
596 whether to display a helpful message, or how to display it. If you're
597 thinking of using it for any other purpose, it is quite likely that
598 you're making a mistake. Think: what do you want to do when the
599 command is called from a keyboard macro?
601 This function is meant for implementing advice and other
602 function-modifying features. Instead of using this, it is sometimes
603 cleaner to give your function an extra optional argument whose
604 `interactive' spec specifies non-nil unconditionally (\"p\" is a good
605 way to do this), or via (not (or executing-kbd-macro noninteractive)). */)
608 return ((INTERACTIVE
|| !EQ (kind
, intern ("interactive")))
609 && interactive_p (1)) ? Qt
: Qnil
;
613 /* Return 1 if function in which this appears was called using
616 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
617 called is a built-in. */
620 interactive_p (int exclude_subrs_p
)
622 struct backtrace
*btp
;
625 btp
= backtrace_list
;
627 /* If this isn't a byte-compiled function, there may be a frame at
628 the top for Finteractive_p. If so, skip it. */
629 fun
= Findirect_function (*btp
->function
, Qnil
);
630 if (SUBRP (fun
) && (XSUBR (fun
) == &Sinteractive_p
631 || XSUBR (fun
) == &Scalled_interactively_p
))
634 /* If we're running an Emacs 18-style byte-compiled function, there
635 may be a frame for Fbytecode at the top level. In any version of
636 Emacs there can be Fbytecode frames for subexpressions evaluated
637 inside catch and condition-case. Skip past them.
639 If this isn't a byte-compiled function, then we may now be
640 looking at several frames for special forms. Skip past them. */
642 && (EQ (*btp
->function
, Qbytecode
)
643 || btp
->nargs
== UNEVALLED
))
646 /* btp now points at the frame of the innermost function that isn't
647 a special form, ignoring frames for Finteractive_p and/or
648 Fbytecode at the top. If this frame is for a built-in function
649 (such as load or eval-region) return nil. */
650 fun
= Findirect_function (*btp
->function
, Qnil
);
651 if (exclude_subrs_p
&& SUBRP (fun
))
654 /* btp points to the frame of a Lisp function that called interactive-p.
655 Return t if that function was called interactively. */
656 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
662 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
663 doc
: /* Define NAME as a function.
664 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
665 See also the function `interactive'.
666 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
669 register Lisp_Object fn_name
;
670 register Lisp_Object defn
;
672 fn_name
= Fcar (args
);
673 CHECK_SYMBOL (fn_name
);
674 defn
= Fcons (Qlambda
, Fcdr (args
));
675 if (!NILP (Vinternal_interpreter_environment
)) /* Mere optimization! */
676 defn
= Ffunction (Fcons (defn
, Qnil
));
677 if (!NILP (Vpurify_flag
))
678 defn
= Fpurecopy (defn
);
679 if (CONSP (XSYMBOL (fn_name
)->function
)
680 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
681 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
682 Ffset (fn_name
, defn
);
683 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
687 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
688 doc
: /* Define NAME as a macro.
689 The actual definition looks like
690 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
691 When the macro is called, as in (NAME ARGS...),
692 the function (lambda ARGLIST BODY...) is applied to
693 the list ARGS... as it appears in the expression,
694 and the result should be a form to be evaluated instead of the original.
696 DECL is a declaration, optional, which can specify how to indent
697 calls to this macro, how Edebug should handle it, and which argument
698 should be treated as documentation. It looks like this:
700 The elements can look like this:
702 Set NAME's `lisp-indent-function' property to INDENT.
705 Set NAME's `edebug-form-spec' property to DEBUG. (This is
706 equivalent to writing a `def-edebug-spec' for the macro.)
709 Set NAME's `doc-string-elt' property to ELT.
711 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
714 register Lisp_Object fn_name
;
715 register Lisp_Object defn
;
716 Lisp_Object lambda_list
, doc
, tail
;
718 fn_name
= Fcar (args
);
719 CHECK_SYMBOL (fn_name
);
720 lambda_list
= Fcar (Fcdr (args
));
721 tail
= Fcdr (Fcdr (args
));
724 if (STRINGP (Fcar (tail
)))
730 if (CONSP (Fcar (tail
))
731 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
733 if (!NILP (Vmacro_declaration_function
))
737 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
745 tail
= Fcons (lambda_list
, tail
);
747 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
749 defn
= Fcons (Qlambda
, tail
);
750 if (!NILP (Vinternal_interpreter_environment
)) /* Mere optimization! */
751 defn
= Ffunction (Fcons (defn
, Qnil
));
752 defn
= Fcons (Qmacro
, defn
);
754 if (!NILP (Vpurify_flag
))
755 defn
= Fpurecopy (defn
);
756 if (CONSP (XSYMBOL (fn_name
)->function
)
757 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
758 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
759 Ffset (fn_name
, defn
);
760 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
765 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
766 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
767 Aliased variables always have the same value; setting one sets the other.
768 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
769 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
770 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
771 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
772 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
773 The return value is BASE-VARIABLE. */)
774 (Lisp_Object new_alias
, Lisp_Object base_variable
, Lisp_Object docstring
)
776 struct Lisp_Symbol
*sym
;
778 CHECK_SYMBOL (new_alias
);
779 CHECK_SYMBOL (base_variable
);
781 sym
= XSYMBOL (new_alias
);
784 /* Not sure why, but why not? */
785 error ("Cannot make a constant an alias");
787 switch (sym
->redirect
)
789 case SYMBOL_FORWARDED
:
790 error ("Cannot make an internal variable an alias");
791 case SYMBOL_LOCALIZED
:
792 error ("Don't know how to make a localized variable an alias");
795 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
796 If n_a is bound, but b_v is not, set the value of b_v to n_a,
797 so that old-code that affects n_a before the aliasing is setup
799 if (NILP (Fboundp (base_variable
)))
800 set_internal (base_variable
, find_symbol_value (new_alias
), Qnil
, 1);
803 struct specbinding
*p
;
805 for (p
= specpdl_ptr
- 1; p
>= specpdl
; p
--)
808 CONSP (p
->symbol
) ? XCAR (p
->symbol
) : p
->symbol
)))
809 error ("Don't know how to make a let-bound variable an alias");
812 sym
->declared_special
= 1;
813 sym
->redirect
= SYMBOL_VARALIAS
;
814 SET_SYMBOL_ALIAS (sym
, XSYMBOL (base_variable
));
815 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
816 LOADHIST_ATTACH (new_alias
);
817 /* Even if docstring is nil: remove old docstring. */
818 Fput (new_alias
, Qvariable_documentation
, docstring
);
820 return base_variable
;
824 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
825 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
826 You are not required to define a variable in order to use it,
827 but the definition can supply documentation and an initial value
828 in a way that tags can recognize.
830 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
831 If SYMBOL is buffer-local, its default value is what is set;
832 buffer-local values are not affected.
833 INITVALUE and DOCSTRING are optional.
834 If DOCSTRING starts with *, this variable is identified as a user option.
835 This means that M-x set-variable recognizes it.
836 See also `user-variable-p'.
837 If INITVALUE is missing, SYMBOL's value is not set.
839 If SYMBOL has a local binding, then this form affects the local
840 binding. This is usually not what you want. Thus, if you need to
841 load a file defining variables, with this form or with `defconst' or
842 `defcustom', you should always load that file _outside_ any bindings
843 for these variables. \(`defconst' and `defcustom' behave similarly in
845 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
848 register Lisp_Object sym
, tem
, tail
;
852 if (!NILP (Fcdr (Fcdr (tail
))))
853 error ("Too many arguments");
855 tem
= Fdefault_boundp (sym
);
858 if (SYMBOL_CONSTANT_P (sym
))
860 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
861 Lisp_Object tem
= Fcar (tail
);
863 && EQ (XCAR (tem
), Qquote
)
864 && CONSP (XCDR (tem
))
865 && EQ (XCAR (XCDR (tem
)), sym
)))
866 error ("Constant symbol `%s' specified in defvar",
867 SDATA (SYMBOL_NAME (sym
)));
871 Fset_default (sym
, eval_sub (Fcar (tail
)));
873 { /* Check if there is really a global binding rather than just a let
874 binding that shadows the global unboundness of the var. */
875 volatile struct specbinding
*pdl
= specpdl_ptr
;
876 while (--pdl
>= specpdl
)
878 if (EQ (pdl
->symbol
, sym
) && !pdl
->func
879 && EQ (pdl
->old_value
, Qunbound
))
881 message_with_string ("Warning: defvar ignored because %s is let-bound",
882 SYMBOL_NAME (sym
), 1);
891 if (!NILP (Vpurify_flag
))
892 tem
= Fpurecopy (tem
);
893 Fput (sym
, Qvariable_documentation
, tem
);
895 LOADHIST_ATTACH (sym
);
898 XSYMBOL (sym
)->declared_special
= 1;
900 else if (!NILP (Vinternal_interpreter_environment
)
901 && !XSYMBOL (sym
)->declared_special
)
902 /* A simple (defvar foo) with lexical scoping does "nothing" except
903 declare that var to be dynamically scoped *locally* (i.e. within
904 the current file or let-block). */
905 Vinternal_interpreter_environment
=
906 Fcons (sym
, Vinternal_interpreter_environment
);
908 /* Simple (defvar <var>) should not count as a definition at all.
909 It could get in the way of other definitions, and unloading this
910 package could try to make the variable unbound. */
916 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
917 doc
: /* Define SYMBOL as a constant variable.
918 The intent is that neither programs nor users should ever change this value.
919 Always sets the value of SYMBOL to the result of evalling INITVALUE.
920 If SYMBOL is buffer-local, its default value is what is set;
921 buffer-local values are not affected.
922 DOCSTRING is optional.
924 If SYMBOL has a local binding, then this form sets the local binding's
925 value. However, you should normally not make local bindings for
926 variables defined with this form.
927 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
930 register Lisp_Object sym
, tem
;
933 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
934 error ("Too many arguments");
936 tem
= eval_sub (Fcar (Fcdr (args
)));
937 if (!NILP (Vpurify_flag
))
938 tem
= Fpurecopy (tem
);
939 Fset_default (sym
, tem
);
940 XSYMBOL (sym
)->declared_special
= 1;
941 tem
= Fcar (Fcdr (Fcdr (args
)));
944 if (!NILP (Vpurify_flag
))
945 tem
= Fpurecopy (tem
);
946 Fput (sym
, Qvariable_documentation
, tem
);
948 Fput (sym
, Qrisky_local_variable
, Qt
);
949 LOADHIST_ATTACH (sym
);
953 /* Error handler used in Fuser_variable_p. */
955 user_variable_p_eh (Lisp_Object ignore
)
961 lisp_indirect_variable (Lisp_Object sym
)
963 XSETSYMBOL (sym
, indirect_variable (XSYMBOL (sym
)));
967 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
968 doc
: /* Return t if VARIABLE is intended to be set and modified by users.
969 \(The alternative is a variable used internally in a Lisp program.)
970 A variable is a user variable if
971 \(1) the first character of its documentation is `*', or
972 \(2) it is customizable (its property list contains a non-nil value
973 of `standard-value' or `custom-autoload'), or
974 \(3) it is an alias for another user variable.
975 Return nil if VARIABLE is an alias and there is a loop in the
976 chain of symbols. */)
977 (Lisp_Object variable
)
979 Lisp_Object documentation
;
981 if (!SYMBOLP (variable
))
984 /* If indirect and there's an alias loop, don't check anything else. */
985 if (XSYMBOL (variable
)->redirect
== SYMBOL_VARALIAS
986 && NILP (internal_condition_case_1 (lisp_indirect_variable
, variable
,
987 Qt
, user_variable_p_eh
)))
992 documentation
= Fget (variable
, Qvariable_documentation
);
993 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
995 if (STRINGP (documentation
)
996 && ((unsigned char) SREF (documentation
, 0) == '*'))
998 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
999 if (CONSP (documentation
)
1000 && STRINGP (XCAR (documentation
))
1001 && INTEGERP (XCDR (documentation
))
1002 && XINT (XCDR (documentation
)) < 0)
1004 /* Customizable? See `custom-variable-p'. */
1005 if ((!NILP (Fget (variable
, intern ("standard-value"))))
1006 || (!NILP (Fget (variable
, intern ("custom-autoload")))))
1009 if (!(XSYMBOL (variable
)->redirect
== SYMBOL_VARALIAS
))
1012 /* An indirect variable? Let's follow the chain. */
1013 XSETSYMBOL (variable
, SYMBOL_ALIAS (XSYMBOL (variable
)));
1017 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
1018 doc
: /* Bind variables according to VARLIST then eval BODY.
1019 The value of the last form in BODY is returned.
1020 Each element of VARLIST is a symbol (which is bound to nil)
1021 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1022 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
1023 usage: (let* VARLIST BODY...) */)
1026 Lisp_Object varlist
, var
, val
, elt
, lexenv
;
1027 int count
= SPECPDL_INDEX ();
1028 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1030 GCPRO3 (args
, elt
, varlist
);
1032 lexenv
= Vinternal_interpreter_environment
;
1034 varlist
= Fcar (args
);
1035 while (CONSP (varlist
))
1039 elt
= XCAR (varlist
);
1045 else if (! NILP (Fcdr (Fcdr (elt
))))
1046 signal_error ("`let' bindings can have only one value-form", elt
);
1050 val
= eval_sub (Fcar (Fcdr (elt
)));
1053 if (!NILP (lexenv
) && SYMBOLP (var
)
1054 && !XSYMBOL (var
)->declared_special
1055 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
1056 /* Lexically bind VAR by adding it to the interpreter's binding
1060 = Fcons (Fcons (var
, val
), Vinternal_interpreter_environment
);
1061 if (EQ (Vinternal_interpreter_environment
, lexenv
))
1062 /* Save the old lexical environment on the specpdl stack,
1063 but only for the first lexical binding, since we'll never
1064 need to revert to one of the intermediate ones. */
1065 specbind (Qinternal_interpreter_environment
, newenv
);
1067 Vinternal_interpreter_environment
= newenv
;
1070 specbind (var
, val
);
1072 varlist
= XCDR (varlist
);
1077 val
= Fprogn (Fcdr (args
));
1079 return unbind_to (count
, val
);
1082 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
1083 doc
: /* Bind variables according to VARLIST then eval BODY.
1084 The value of the last form in BODY is returned.
1085 Each element of VARLIST is a symbol (which is bound to nil)
1086 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1087 All the VALUEFORMs are evalled before any symbols are bound.
1088 usage: (let VARLIST BODY...) */)
1091 Lisp_Object
*temps
, tem
, lexenv
;
1092 register Lisp_Object elt
, varlist
;
1093 int count
= SPECPDL_INDEX ();
1094 register int argnum
;
1095 struct gcpro gcpro1
, gcpro2
;
1098 varlist
= Fcar (args
);
1100 /* Make space to hold the values to give the bound variables */
1101 elt
= Flength (varlist
);
1102 SAFE_ALLOCA_LISP (temps
, XFASTINT (elt
));
1104 /* Compute the values and store them in `temps' */
1106 GCPRO2 (args
, *temps
);
1109 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
1112 elt
= XCAR (varlist
);
1114 temps
[argnum
++] = Qnil
;
1115 else if (! NILP (Fcdr (Fcdr (elt
))))
1116 signal_error ("`let' bindings can have only one value-form", elt
);
1118 temps
[argnum
++] = eval_sub (Fcar (Fcdr (elt
)));
1119 gcpro2
.nvars
= argnum
;
1123 lexenv
= Vinternal_interpreter_environment
;
1125 varlist
= Fcar (args
);
1126 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
1130 elt
= XCAR (varlist
);
1131 var
= SYMBOLP (elt
) ? elt
: Fcar (elt
);
1132 tem
= temps
[argnum
++];
1134 if (!NILP (lexenv
) && SYMBOLP (var
)
1135 && !XSYMBOL (var
)->declared_special
1136 && NILP (Fmemq (var
, Vinternal_interpreter_environment
)))
1137 /* Lexically bind VAR by adding it to the lexenv alist. */
1138 lexenv
= Fcons (Fcons (var
, tem
), lexenv
);
1140 /* Dynamically bind VAR. */
1141 specbind (var
, tem
);
1144 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
1145 /* Instantiate a new lexical environment. */
1146 specbind (Qinternal_interpreter_environment
, lexenv
);
1148 elt
= Fprogn (Fcdr (args
));
1150 return unbind_to (count
, elt
);
1153 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
1154 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
1155 The order of execution is thus TEST, BODY, TEST, BODY and so on
1156 until TEST returns nil.
1157 usage: (while TEST BODY...) */)
1160 Lisp_Object test
, body
;
1161 struct gcpro gcpro1
, gcpro2
;
1163 GCPRO2 (test
, body
);
1167 while (!NILP (eval_sub (test
)))
1177 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1178 doc
: /* Return result of expanding macros at top level of FORM.
1179 If FORM is not a macro call, it is returned unchanged.
1180 Otherwise, the macro is expanded and the expansion is considered
1181 in place of FORM. When a non-macro-call results, it is returned.
1183 The second optional arg ENVIRONMENT specifies an environment of macro
1184 definitions to shadow the loaded ones for use in file byte-compilation. */)
1185 (Lisp_Object form
, Lisp_Object environment
)
1187 /* With cleanups from Hallvard Furuseth. */
1188 register Lisp_Object expander
, sym
, def
, tem
;
1192 /* Come back here each time we expand a macro call,
1193 in case it expands into another macro call. */
1196 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1197 def
= sym
= XCAR (form
);
1199 /* Trace symbols aliases to other symbols
1200 until we get a symbol that is not an alias. */
1201 while (SYMBOLP (def
))
1205 tem
= Fassq (sym
, environment
);
1208 def
= XSYMBOL (sym
)->function
;
1209 if (!EQ (def
, Qunbound
))
1214 /* Right now TEM is the result from SYM in ENVIRONMENT,
1215 and if TEM is nil then DEF is SYM's function definition. */
1218 /* SYM is not mentioned in ENVIRONMENT.
1219 Look at its function definition. */
1220 if (EQ (def
, Qunbound
) || !CONSP (def
))
1221 /* Not defined or definition not suitable */
1223 if (EQ (XCAR (def
), Qautoload
))
1225 /* Autoloading function: will it be a macro when loaded? */
1226 tem
= Fnth (make_number (4), def
);
1227 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1228 /* Yes, load it and try again. */
1230 struct gcpro gcpro1
;
1232 do_autoload (def
, sym
);
1239 else if (!EQ (XCAR (def
), Qmacro
))
1241 else expander
= XCDR (def
);
1245 expander
= XCDR (tem
);
1246 if (NILP (expander
))
1249 form
= apply1 (expander
, XCDR (form
));
1254 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1255 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1256 TAG is evalled to get the tag to use; it must not be nil.
1258 Then the BODY is executed.
1259 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1260 If no throw happens, `catch' returns the value of the last BODY form.
1261 If a throw happens, it specifies the value to return from `catch'.
1262 usage: (catch TAG BODY...) */)
1265 register Lisp_Object tag
;
1266 struct gcpro gcpro1
;
1269 tag
= eval_sub (Fcar (args
));
1271 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1274 /* Set up a catch, then call C function FUNC on argument ARG.
1275 FUNC should return a Lisp_Object.
1276 This is how catches are done from within C code. */
1279 internal_catch (Lisp_Object tag
, Lisp_Object (*func
) (Lisp_Object
), Lisp_Object arg
)
1281 /* This structure is made part of the chain `catchlist'. */
1284 /* Fill in the components of c, and put it on the list. */
1288 c
.backlist
= backtrace_list
;
1289 c
.handlerlist
= handlerlist
;
1290 c
.lisp_eval_depth
= lisp_eval_depth
;
1291 c
.pdlcount
= SPECPDL_INDEX ();
1292 c
.poll_suppress_count
= poll_suppress_count
;
1293 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1294 c
.gcpro
= gcprolist
;
1295 c
.byte_stack
= byte_stack_list
;
1299 if (! _setjmp (c
.jmp
))
1300 c
.val
= (*func
) (arg
);
1302 /* Throw works by a longjmp that comes right here. */
1307 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1308 jump to that CATCH, returning VALUE as the value of that catch.
1310 This is the guts Fthrow and Fsignal; they differ only in the way
1311 they choose the catch tag to throw to. A catch tag for a
1312 condition-case form has a TAG of Qnil.
1314 Before each catch is discarded, unbind all special bindings and
1315 execute all unwind-protect clauses made above that catch. Unwind
1316 the handler stack as we go, so that the proper handlers are in
1317 effect for each unwind-protect clause we run. At the end, restore
1318 some static info saved in CATCH, and longjmp to the location
1321 This is used for correct unwinding in Fthrow and Fsignal. */
1324 unwind_to_catch (struct catchtag
*catch, Lisp_Object value
)
1326 register int last_time
;
1328 /* Save the value in the tag. */
1331 /* Restore certain special C variables. */
1332 set_poll_suppress_count (catch->poll_suppress_count
);
1333 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked
);
1334 handling_signal
= 0;
1339 last_time
= catchlist
== catch;
1341 /* Unwind the specpdl stack, and then restore the proper set of
1343 unbind_to (catchlist
->pdlcount
, Qnil
);
1344 handlerlist
= catchlist
->handlerlist
;
1345 catchlist
= catchlist
->next
;
1347 while (! last_time
);
1350 /* If x_catch_errors was done, turn it off now.
1351 (First we give unbind_to a chance to do that.) */
1352 #if 0 /* This would disable x_catch_errors after x_connection_closed.
1353 The catch must remain in effect during that delicate
1354 state. --lorentey */
1355 x_fully_uncatch_errors ();
1359 byte_stack_list
= catch->byte_stack
;
1360 gcprolist
= catch->gcpro
;
1363 gcpro_level
= gcprolist
->level
+ 1;
1367 backtrace_list
= catch->backlist
;
1368 lisp_eval_depth
= catch->lisp_eval_depth
;
1370 _longjmp (catch->jmp
, 1);
1373 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1374 doc
: /* Throw to the catch for TAG and return VALUE from it.
1375 Both TAG and VALUE are evalled. */)
1376 (register Lisp_Object tag
, Lisp_Object value
)
1378 register struct catchtag
*c
;
1381 for (c
= catchlist
; c
; c
= c
->next
)
1383 if (EQ (c
->tag
, tag
))
1384 unwind_to_catch (c
, value
);
1386 xsignal2 (Qno_catch
, tag
, value
);
1390 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1391 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1392 If BODYFORM completes normally, its value is returned
1393 after executing the UNWINDFORMS.
1394 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1395 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1399 int count
= SPECPDL_INDEX ();
1401 record_unwind_protect (Fprogn
, Fcdr (args
));
1402 val
= eval_sub (Fcar (args
));
1403 return unbind_to (count
, val
);
1406 /* Chain of condition handlers currently in effect.
1407 The elements of this chain are contained in the stack frames
1408 of Fcondition_case and internal_condition_case.
1409 When an error is signaled (by calling Fsignal, below),
1410 this chain is searched for an element that applies. */
1412 struct handler
*handlerlist
;
1414 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1415 doc
: /* Regain control when an error is signaled.
1416 Executes BODYFORM and returns its value if no error happens.
1417 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1418 where the BODY is made of Lisp expressions.
1420 A handler is applicable to an error
1421 if CONDITION-NAME is one of the error's condition names.
1422 If an error happens, the first applicable handler is run.
1424 The car of a handler may be a list of condition names
1425 instead of a single condition name. Then it handles all of them.
1427 When a handler handles an error, control returns to the `condition-case'
1428 and it executes the handler's BODY...
1429 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
1430 \(If VAR is nil, the handler can't access that information.)
1431 Then the value of the last BODY form is returned from the `condition-case'
1434 See also the function `signal' for more info.
1435 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1438 register Lisp_Object bodyform
, handlers
;
1439 volatile Lisp_Object var
;
1442 bodyform
= Fcar (Fcdr (args
));
1443 handlers
= Fcdr (Fcdr (args
));
1445 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1448 /* Like Fcondition_case, but the args are separate
1449 rather than passed in a list. Used by Fbyte_code. */
1452 internal_lisp_condition_case (volatile Lisp_Object var
, Lisp_Object bodyform
,
1453 Lisp_Object handlers
)
1461 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1467 && (SYMBOLP (XCAR (tem
))
1468 || CONSP (XCAR (tem
))))))
1469 error ("Invalid condition handler", tem
);
1474 c
.backlist
= backtrace_list
;
1475 c
.handlerlist
= handlerlist
;
1476 c
.lisp_eval_depth
= lisp_eval_depth
;
1477 c
.pdlcount
= SPECPDL_INDEX ();
1478 c
.poll_suppress_count
= poll_suppress_count
;
1479 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1480 c
.gcpro
= gcprolist
;
1481 c
.byte_stack
= byte_stack_list
;
1482 if (_setjmp (c
.jmp
))
1485 specbind (h
.var
, c
.val
);
1486 val
= Fprogn (Fcdr (h
.chosen_clause
));
1488 /* Note that this just undoes the binding of h.var; whoever
1489 longjumped to us unwound the stack to c.pdlcount before
1491 unbind_to (c
.pdlcount
, Qnil
);
1498 h
.handler
= handlers
;
1499 h
.next
= handlerlist
;
1503 val
= eval_sub (bodyform
);
1505 handlerlist
= h
.next
;
1509 /* Call the function BFUN with no arguments, catching errors within it
1510 according to HANDLERS. If there is an error, call HFUN with
1511 one argument which is the data that describes the error:
1514 HANDLERS can be a list of conditions to catch.
1515 If HANDLERS is Qt, catch all errors.
1516 If HANDLERS is Qerror, catch all errors
1517 but allow the debugger to run if that is enabled. */
1520 internal_condition_case (Lisp_Object (*bfun
) (void), Lisp_Object handlers
,
1521 Lisp_Object (*hfun
) (Lisp_Object
))
1527 /* Since Fsignal will close off all calls to x_catch_errors,
1528 we will get the wrong results if some are not closed now. */
1530 if (x_catching_errors ())
1536 c
.backlist
= backtrace_list
;
1537 c
.handlerlist
= handlerlist
;
1538 c
.lisp_eval_depth
= lisp_eval_depth
;
1539 c
.pdlcount
= SPECPDL_INDEX ();
1540 c
.poll_suppress_count
= poll_suppress_count
;
1541 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1542 c
.gcpro
= gcprolist
;
1543 c
.byte_stack
= byte_stack_list
;
1544 if (_setjmp (c
.jmp
))
1546 return (*hfun
) (c
.val
);
1550 h
.handler
= handlers
;
1552 h
.next
= handlerlist
;
1558 handlerlist
= h
.next
;
1562 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1565 internal_condition_case_1 (Lisp_Object (*bfun
) (Lisp_Object
), Lisp_Object arg
,
1566 Lisp_Object handlers
, Lisp_Object (*hfun
) (Lisp_Object
))
1572 /* Since Fsignal will close off all calls to x_catch_errors,
1573 we will get the wrong results if some are not closed now. */
1575 if (x_catching_errors ())
1581 c
.backlist
= backtrace_list
;
1582 c
.handlerlist
= handlerlist
;
1583 c
.lisp_eval_depth
= lisp_eval_depth
;
1584 c
.pdlcount
= SPECPDL_INDEX ();
1585 c
.poll_suppress_count
= poll_suppress_count
;
1586 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1587 c
.gcpro
= gcprolist
;
1588 c
.byte_stack
= byte_stack_list
;
1589 if (_setjmp (c
.jmp
))
1591 return (*hfun
) (c
.val
);
1595 h
.handler
= handlers
;
1597 h
.next
= handlerlist
;
1601 val
= (*bfun
) (arg
);
1603 handlerlist
= h
.next
;
1607 /* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1611 internal_condition_case_2 (Lisp_Object (*bfun
) (Lisp_Object
, Lisp_Object
),
1614 Lisp_Object handlers
,
1615 Lisp_Object (*hfun
) (Lisp_Object
))
1621 /* Since Fsignal will close off all calls to x_catch_errors,
1622 we will get the wrong results if some are not closed now. */
1624 if (x_catching_errors ())
1630 c
.backlist
= backtrace_list
;
1631 c
.handlerlist
= handlerlist
;
1632 c
.lisp_eval_depth
= lisp_eval_depth
;
1633 c
.pdlcount
= SPECPDL_INDEX ();
1634 c
.poll_suppress_count
= poll_suppress_count
;
1635 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1636 c
.gcpro
= gcprolist
;
1637 c
.byte_stack
= byte_stack_list
;
1638 if (_setjmp (c
.jmp
))
1640 return (*hfun
) (c
.val
);
1644 h
.handler
= handlers
;
1646 h
.next
= handlerlist
;
1650 val
= (*bfun
) (arg1
, arg2
);
1652 handlerlist
= h
.next
;
1656 /* Like internal_condition_case but call BFUN with NARGS as first,
1657 and ARGS as second argument. */
1660 internal_condition_case_n (Lisp_Object (*bfun
) (int, Lisp_Object
*),
1663 Lisp_Object handlers
,
1664 Lisp_Object (*hfun
) (Lisp_Object
))
1670 /* Since Fsignal will close off all calls to x_catch_errors,
1671 we will get the wrong results if some are not closed now. */
1673 if (x_catching_errors ())
1679 c
.backlist
= backtrace_list
;
1680 c
.handlerlist
= handlerlist
;
1681 c
.lisp_eval_depth
= lisp_eval_depth
;
1682 c
.pdlcount
= SPECPDL_INDEX ();
1683 c
.poll_suppress_count
= poll_suppress_count
;
1684 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1685 c
.gcpro
= gcprolist
;
1686 c
.byte_stack
= byte_stack_list
;
1687 if (_setjmp (c
.jmp
))
1689 return (*hfun
) (c
.val
);
1693 h
.handler
= handlers
;
1695 h
.next
= handlerlist
;
1699 val
= (*bfun
) (nargs
, args
);
1701 handlerlist
= h
.next
;
1706 static Lisp_Object
find_handler_clause (Lisp_Object
, Lisp_Object
,
1707 Lisp_Object
, Lisp_Object
);
1709 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1710 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1711 This function does not return.
1713 An error symbol is a symbol with an `error-conditions' property
1714 that is a list of condition names.
1715 A handler for any of those names will get to handle this signal.
1716 The symbol `error' should normally be one of them.
1718 DATA should be a list. Its elements are printed as part of the error message.
1719 See Info anchor `(elisp)Definition of signal' for some details on how this
1720 error message is constructed.
1721 If the signal is handled, DATA is made available to the handler.
1722 See also the function `condition-case'. */)
1723 (Lisp_Object error_symbol
, Lisp_Object data
)
1725 /* When memory is full, ERROR-SYMBOL is nil,
1726 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1727 That is a special case--don't do this in other situations. */
1728 register struct handler
*allhandlers
= handlerlist
;
1729 Lisp_Object conditions
;
1731 Lisp_Object real_error_symbol
;
1732 struct backtrace
*bp
;
1734 immediate_quit
= handling_signal
= 0;
1736 if (gc_in_progress
|| waiting_for_input
)
1739 if (NILP (error_symbol
))
1740 real_error_symbol
= Fcar (data
);
1742 real_error_symbol
= error_symbol
;
1744 #if 0 /* rms: I don't know why this was here,
1745 but it is surely wrong for an error that is handled. */
1746 #ifdef HAVE_WINDOW_SYSTEM
1747 if (display_hourglass_p
)
1748 cancel_hourglass ();
1752 /* This hook is used by edebug. */
1753 if (! NILP (Vsignal_hook_function
)
1754 && ! NILP (error_symbol
))
1756 /* Edebug takes care of restoring these variables when it exits. */
1757 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1758 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1760 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1761 max_specpdl_size
= SPECPDL_INDEX () + 40;
1763 call2 (Vsignal_hook_function
, error_symbol
, data
);
1766 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1768 /* Remember from where signal was called. Skip over the frame for
1769 `signal' itself. If a frame for `error' follows, skip that,
1770 too. Don't do this when ERROR_SYMBOL is nil, because that
1771 is a memory-full error. */
1772 Vsignaling_function
= Qnil
;
1773 if (backtrace_list
&& !NILP (error_symbol
))
1775 bp
= backtrace_list
->next
;
1776 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1778 if (bp
&& bp
->function
)
1779 Vsignaling_function
= *bp
->function
;
1782 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1784 register Lisp_Object clause
;
1786 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1787 error_symbol
, data
);
1789 if (EQ (clause
, Qlambda
))
1791 /* We can't return values to code which signaled an error, but we
1792 can continue code which has signaled a quit. */
1793 if (EQ (real_error_symbol
, Qquit
))
1796 error ("Cannot return from the debugger in an error");
1801 Lisp_Object unwind_data
;
1802 struct handler
*h
= handlerlist
;
1804 handlerlist
= allhandlers
;
1806 if (NILP (error_symbol
))
1809 unwind_data
= Fcons (error_symbol
, data
);
1810 h
->chosen_clause
= clause
;
1811 unwind_to_catch (h
->tag
, unwind_data
);
1815 handlerlist
= allhandlers
;
1816 /* If no handler is present now, try to run the debugger,
1817 and if that fails, throw to top level. */
1818 find_handler_clause (Qerror
, conditions
, error_symbol
, data
);
1820 Fthrow (Qtop_level
, Qt
);
1822 if (! NILP (error_symbol
))
1823 data
= Fcons (error_symbol
, data
);
1825 string
= Ferror_message_string (data
);
1826 fatal ("%s", SDATA (string
), 0);
1829 /* Internal version of Fsignal that never returns.
1830 Used for anything but Qquit (which can return from Fsignal). */
1833 xsignal (Lisp_Object error_symbol
, Lisp_Object data
)
1835 Fsignal (error_symbol
, data
);
1839 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1842 xsignal0 (Lisp_Object error_symbol
)
1844 xsignal (error_symbol
, Qnil
);
1848 xsignal1 (Lisp_Object error_symbol
, Lisp_Object arg
)
1850 xsignal (error_symbol
, list1 (arg
));
1854 xsignal2 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
)
1856 xsignal (error_symbol
, list2 (arg1
, arg2
));
1860 xsignal3 (Lisp_Object error_symbol
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
1862 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1865 /* Signal `error' with message S, and additional arg ARG.
1866 If ARG is not a genuine list, make it a one-element list. */
1869 signal_error (const char *s
, Lisp_Object arg
)
1871 Lisp_Object tortoise
, hare
;
1873 hare
= tortoise
= arg
;
1874 while (CONSP (hare
))
1881 tortoise
= XCDR (tortoise
);
1883 if (EQ (hare
, tortoise
))
1888 arg
= Fcons (arg
, Qnil
); /* Make it a list. */
1890 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1894 /* Return nonzero if LIST is a non-nil atom or
1895 a list containing one of CONDITIONS. */
1898 wants_debugger (Lisp_Object list
, Lisp_Object conditions
)
1905 while (CONSP (conditions
))
1907 Lisp_Object
this, tail
;
1908 this = XCAR (conditions
);
1909 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1910 if (EQ (XCAR (tail
), this))
1912 conditions
= XCDR (conditions
);
1917 /* Return 1 if an error with condition-symbols CONDITIONS,
1918 and described by SIGNAL-DATA, should skip the debugger
1919 according to debugger-ignored-errors. */
1922 skip_debugger (Lisp_Object conditions
, Lisp_Object data
)
1925 int first_string
= 1;
1926 Lisp_Object error_message
;
1928 error_message
= Qnil
;
1929 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1931 if (STRINGP (XCAR (tail
)))
1935 error_message
= Ferror_message_string (data
);
1939 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1944 Lisp_Object contail
;
1946 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1947 if (EQ (XCAR (tail
), XCAR (contail
)))
1955 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1956 SIG and DATA describe the signal, as in find_handler_clause. */
1959 maybe_call_debugger (Lisp_Object conditions
, Lisp_Object sig
, Lisp_Object data
)
1961 Lisp_Object combined_data
;
1963 combined_data
= Fcons (sig
, data
);
1966 /* Don't try to run the debugger with interrupts blocked.
1967 The editing loop would return anyway. */
1969 /* Does user want to enter debugger for this kind of error? */
1972 : wants_debugger (Vdebug_on_error
, conditions
))
1973 && ! skip_debugger (conditions
, combined_data
)
1974 /* rms: what's this for? */
1975 && when_entered_debugger
< num_nonmacro_input_events
)
1977 call_debugger (Fcons (Qerror
, Fcons (combined_data
, Qnil
)));
1984 /* Value of Qlambda means we have called debugger and user has continued.
1985 There are two ways to pass SIG and DATA:
1986 = SIG is the error symbol, and DATA is the rest of the data.
1987 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1988 This is for memory-full errors only.
1990 We need to increase max_specpdl_size temporarily around
1991 anything we do that can push on the specpdl, so as not to get
1992 a second error here in case we're handling specpdl overflow. */
1995 find_handler_clause (Lisp_Object handlers
, Lisp_Object conditions
,
1996 Lisp_Object sig
, Lisp_Object data
)
1998 register Lisp_Object h
;
1999 register Lisp_Object tem
;
2000 int debugger_called
= 0;
2001 int debugger_considered
= 0;
2003 /* t is used by handlers for all conditions, set up by C code. */
2004 if (EQ (handlers
, Qt
))
2007 /* Don't run the debugger for a memory-full error.
2008 (There is no room in memory to do that!) */
2010 debugger_considered
= 1;
2012 /* error is used similarly, but means print an error message
2013 and run the debugger if that is enabled. */
2014 if (EQ (handlers
, Qerror
)
2015 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
2016 there is a handler. */
2018 if (!NILP (sig
) && wants_debugger (Vstack_trace_on_error
, conditions
))
2020 max_lisp_eval_depth
+= 15;
2025 internal_with_output_to_temp_buffer
2027 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
2030 max_lisp_eval_depth
-= 15;
2033 if (!debugger_considered
)
2035 debugger_considered
= 1;
2036 debugger_called
= maybe_call_debugger (conditions
, sig
, data
);
2039 /* If there is no handler, return saying whether we ran the debugger. */
2040 if (EQ (handlers
, Qerror
))
2042 if (debugger_called
)
2048 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
2050 Lisp_Object handler
, condit
;
2053 if (!CONSP (handler
))
2055 condit
= Fcar (handler
);
2056 /* Handle a single condition name in handler HANDLER. */
2057 if (SYMBOLP (condit
))
2059 tem
= Fmemq (Fcar (handler
), conditions
);
2063 /* Handle a list of condition names in handler HANDLER. */
2064 else if (CONSP (condit
))
2067 for (tail
= condit
; CONSP (tail
); tail
= XCDR (tail
))
2069 tem
= Fmemq (Fcar (tail
), conditions
);
2072 /* This handler is going to apply.
2073 Does it allow the debugger to run first? */
2074 if (! debugger_considered
&& !NILP (Fmemq (Qdebug
, condit
)))
2075 maybe_call_debugger (conditions
, sig
, data
);
2086 /* dump an error message; called like vprintf */
2088 verror (const char *m
, va_list ap
)
2091 EMACS_INT size
= 200;
2103 used
= doprnt (buffer
, size
, m
, m
+ mlen
, ap
);
2108 buffer
= (char *) xrealloc (buffer
, size
);
2111 buffer
= (char *) xmalloc (size
);
2116 string
= build_string (buffer
);
2120 xsignal1 (Qerror
, string
);
2124 /* dump an error message; called like printf */
2128 error (const char *m
, ...)
2136 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
2137 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
2138 This means it contains a description for how to read arguments to give it.
2139 The value is nil for an invalid function or a symbol with no function
2142 Interactively callable functions include strings and vectors (treated
2143 as keyboard macros), lambda-expressions that contain a top-level call
2144 to `interactive', autoload definitions made by `autoload' with non-nil
2145 fourth argument, and some of the built-in functions of Lisp.
2147 Also, a symbol satisfies `commandp' if its function definition does so.
2149 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
2150 then strings and vectors are not accepted. */)
2151 (Lisp_Object function
, Lisp_Object for_call_interactively
)
2153 register Lisp_Object fun
;
2154 register Lisp_Object funcar
;
2155 Lisp_Object if_prop
= Qnil
;
2159 fun
= indirect_function (fun
); /* Check cycles. */
2160 if (NILP (fun
) || EQ (fun
, Qunbound
))
2163 /* Check an `interactive-form' property if present, analogous to the
2164 function-documentation property. */
2166 while (SYMBOLP (fun
))
2168 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
2171 fun
= Fsymbol_function (fun
);
2174 /* Emacs primitives are interactive if their DEFUN specifies an
2175 interactive spec. */
2177 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
2179 /* Bytecode objects are interactive if they are long enough to
2180 have an element whose index is COMPILED_INTERACTIVE, which is
2181 where the interactive spec is stored. */
2182 else if (COMPILEDP (fun
))
2183 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
2186 /* Strings and vectors are keyboard macros. */
2187 if (STRINGP (fun
) || VECTORP (fun
))
2188 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
2190 /* Lists may represent commands. */
2193 funcar
= XCAR (fun
);
2194 if (EQ (funcar
, Qlambda
))
2195 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
2196 if (EQ (funcar
, Qautoload
))
2197 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
2202 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
2203 doc
: /* Define FUNCTION to autoload from FILE.
2204 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2205 Third arg DOCSTRING is documentation for the function.
2206 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2207 Fifth arg TYPE indicates the type of the object:
2208 nil or omitted says FUNCTION is a function,
2209 `keymap' says FUNCTION is really a keymap, and
2210 `macro' or t says FUNCTION is really a macro.
2211 Third through fifth args give info about the real definition.
2212 They default to nil.
2213 If FUNCTION is already defined other than as an autoload,
2214 this does nothing and returns nil. */)
2215 (Lisp_Object function
, Lisp_Object file
, Lisp_Object docstring
, Lisp_Object interactive
, Lisp_Object type
)
2217 CHECK_SYMBOL (function
);
2218 CHECK_STRING (file
);
2220 /* If function is defined and not as an autoload, don't override */
2221 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
2222 && !(CONSP (XSYMBOL (function
)->function
)
2223 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
2226 if (NILP (Vpurify_flag
))
2227 /* Only add entries after dumping, because the ones before are
2228 not useful and else we get loads of them from the loaddefs.el. */
2229 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
2231 /* We don't want the docstring in purespace (instead,
2232 Snarf-documentation should (hopefully) overwrite it).
2233 We used to use 0 here, but that leads to accidental sharing in
2234 purecopy's hash-consing, so we use a (hopefully) unique integer
2236 docstring
= make_number (XHASH (function
));
2237 return Ffset (function
,
2238 Fpurecopy (list5 (Qautoload
, file
, docstring
,
2239 interactive
, type
)));
2243 un_autoload (Lisp_Object oldqueue
)
2245 register Lisp_Object queue
, first
, second
;
2247 /* Queue to unwind is current value of Vautoload_queue.
2248 oldqueue is the shadowed value to leave in Vautoload_queue. */
2249 queue
= Vautoload_queue
;
2250 Vautoload_queue
= oldqueue
;
2251 while (CONSP (queue
))
2253 first
= XCAR (queue
);
2254 second
= Fcdr (first
);
2255 first
= Fcar (first
);
2256 if (EQ (first
, make_number (0)))
2259 Ffset (first
, second
);
2260 queue
= XCDR (queue
);
2265 /* Load an autoloaded function.
2266 FUNNAME is the symbol which is the function's name.
2267 FUNDEF is the autoload definition (a list). */
2270 do_autoload (Lisp_Object fundef
, Lisp_Object funname
)
2272 int count
= SPECPDL_INDEX ();
2274 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2276 /* This is to make sure that loadup.el gives a clear picture
2277 of what files are preloaded and when. */
2278 if (! NILP (Vpurify_flag
))
2279 error ("Attempt to autoload %s while preparing to dump",
2280 SDATA (SYMBOL_NAME (funname
)));
2283 CHECK_SYMBOL (funname
);
2284 GCPRO3 (fun
, funname
, fundef
);
2286 /* Preserve the match data. */
2287 record_unwind_save_match_data ();
2289 /* If autoloading gets an error (which includes the error of failing
2290 to define the function being called), we use Vautoload_queue
2291 to undo function definitions and `provide' calls made by
2292 the function. We do this in the specific case of autoloading
2293 because autoloading is not an explicit request "load this file",
2294 but rather a request to "call this function".
2296 The value saved here is to be restored into Vautoload_queue. */
2297 record_unwind_protect (un_autoload
, Vautoload_queue
);
2298 Vautoload_queue
= Qt
;
2299 Fload (Fcar (Fcdr (fundef
)), Qnil
, Qt
, Qnil
, Qt
);
2301 /* Once loading finishes, don't undo it. */
2302 Vautoload_queue
= Qt
;
2303 unbind_to (count
, Qnil
);
2305 fun
= Findirect_function (fun
, Qnil
);
2307 if (!NILP (Fequal (fun
, fundef
)))
2308 error ("Autoloading failed to define function %s",
2309 SDATA (SYMBOL_NAME (funname
)));
2314 DEFUN ("eval", Feval
, Seval
, 1, 2, 0,
2315 doc
: /* Evaluate FORM and return its value.
2316 If LEXICAL is t, evaluate using lexical scoping. */)
2317 (Lisp_Object form
, Lisp_Object lexical
)
2319 int count
= SPECPDL_INDEX ();
2320 specbind (Qinternal_interpreter_environment
,
2321 NILP (lexical
) ? Qnil
: Fcons (Qt
, Qnil
));
2322 return unbind_to (count
, eval_sub (form
));
2325 /* Eval a sub-expression of the current expression (i.e. in the same
2328 eval_sub (Lisp_Object form
)
2330 Lisp_Object fun
, val
, original_fun
, original_args
;
2332 struct backtrace backtrace
;
2333 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2335 if (handling_signal
)
2340 /* Look up its binding in the lexical environment.
2341 We do not pay attention to the declared_special flag here, since we
2342 already did that when let-binding the variable. */
2343 Lisp_Object lex_binding
2344 = !NILP (Vinternal_interpreter_environment
) /* Mere optimization! */
2345 ? Fassq (form
, Vinternal_interpreter_environment
)
2347 if (CONSP (lex_binding
))
2348 return XCDR (lex_binding
);
2350 return Fsymbol_value (form
);
2357 if ((consing_since_gc
> gc_cons_threshold
2358 && consing_since_gc
> gc_relative_threshold
)
2360 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2363 Fgarbage_collect ();
2367 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2369 if (max_lisp_eval_depth
< 100)
2370 max_lisp_eval_depth
= 100;
2371 if (lisp_eval_depth
> max_lisp_eval_depth
)
2372 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2375 original_fun
= Fcar (form
);
2376 original_args
= Fcdr (form
);
2378 backtrace
.next
= backtrace_list
;
2379 backtrace_list
= &backtrace
;
2380 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2381 backtrace
.args
= &original_args
;
2382 backtrace
.nargs
= UNEVALLED
;
2383 backtrace
.evalargs
= 1;
2384 backtrace
.debug_on_exit
= 0;
2386 if (debug_on_next_call
)
2387 do_debug_on_call (Qt
);
2389 /* At this point, only original_fun and original_args
2390 have values that will be used below */
2393 /* Optimize for no indirection. */
2395 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2396 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2397 fun
= indirect_function (fun
);
2401 Lisp_Object numargs
;
2402 Lisp_Object argvals
[8];
2403 Lisp_Object args_left
;
2404 register int i
, maxargs
;
2406 args_left
= original_args
;
2407 numargs
= Flength (args_left
);
2411 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2412 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2413 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2415 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2417 backtrace
.evalargs
= 0;
2418 val
= (XSUBR (fun
)->function
.aUNEVALLED
) (args_left
);
2420 else if (XSUBR (fun
)->max_args
== MANY
)
2422 /* Pass a vector of evaluated arguments */
2424 register int argnum
= 0;
2427 SAFE_ALLOCA_LISP (vals
, XINT (numargs
));
2429 GCPRO3 (args_left
, fun
, fun
);
2433 while (!NILP (args_left
))
2435 vals
[argnum
++] = eval_sub (Fcar (args_left
));
2436 args_left
= Fcdr (args_left
);
2437 gcpro3
.nvars
= argnum
;
2440 backtrace
.args
= vals
;
2441 backtrace
.nargs
= XINT (numargs
);
2443 val
= (XSUBR (fun
)->function
.aMANY
) (XINT (numargs
), vals
);
2449 GCPRO3 (args_left
, fun
, fun
);
2450 gcpro3
.var
= argvals
;
2453 maxargs
= XSUBR (fun
)->max_args
;
2454 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2456 argvals
[i
] = eval_sub (Fcar (args_left
));
2462 backtrace
.args
= argvals
;
2463 backtrace
.nargs
= XINT (numargs
);
2468 val
= (XSUBR (fun
)->function
.a0
) ();
2471 val
= (XSUBR (fun
)->function
.a1
) (argvals
[0]);
2474 val
= (XSUBR (fun
)->function
.a2
) (argvals
[0], argvals
[1]);
2477 val
= (XSUBR (fun
)->function
.a3
) (argvals
[0], argvals
[1],
2481 val
= (XSUBR (fun
)->function
.a4
) (argvals
[0], argvals
[1],
2482 argvals
[2], argvals
[3]);
2485 val
= (XSUBR (fun
)->function
.a5
) (argvals
[0], argvals
[1], argvals
[2],
2486 argvals
[3], argvals
[4]);
2489 val
= (XSUBR (fun
)->function
.a6
) (argvals
[0], argvals
[1], argvals
[2],
2490 argvals
[3], argvals
[4], argvals
[5]);
2493 val
= (XSUBR (fun
)->function
.a7
) (argvals
[0], argvals
[1], argvals
[2],
2494 argvals
[3], argvals
[4], argvals
[5],
2499 val
= (XSUBR (fun
)->function
.a8
) (argvals
[0], argvals
[1], argvals
[2],
2500 argvals
[3], argvals
[4], argvals
[5],
2501 argvals
[6], argvals
[7]);
2505 /* Someone has created a subr that takes more arguments than
2506 is supported by this code. We need to either rewrite the
2507 subr to use a different argument protocol, or add more
2508 cases to this switch. */
2513 else if (FUNVECP (fun
))
2514 val
= apply_lambda (fun
, original_args
);
2517 if (EQ (fun
, Qunbound
))
2518 xsignal1 (Qvoid_function
, original_fun
);
2520 xsignal1 (Qinvalid_function
, original_fun
);
2521 funcar
= XCAR (fun
);
2522 if (!SYMBOLP (funcar
))
2523 xsignal1 (Qinvalid_function
, original_fun
);
2524 if (EQ (funcar
, Qautoload
))
2526 do_autoload (fun
, original_fun
);
2529 if (EQ (funcar
, Qmacro
))
2530 val
= eval_sub (apply1 (Fcdr (fun
), original_args
));
2531 else if (EQ (funcar
, Qlambda
)
2532 || EQ (funcar
, Qclosure
))
2533 val
= apply_lambda (fun
, original_args
);
2535 xsignal1 (Qinvalid_function
, original_fun
);
2540 if (backtrace
.debug_on_exit
)
2541 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2542 backtrace_list
= backtrace
.next
;
2547 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2548 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2549 Then return the value FUNCTION returns.
2550 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2551 usage: (apply FUNCTION &rest ARGUMENTS) */)
2552 (int nargs
, Lisp_Object
*args
)
2554 register int i
, numargs
;
2555 register Lisp_Object spread_arg
;
2556 register Lisp_Object
*funcall_args
;
2557 Lisp_Object fun
, retval
;
2558 struct gcpro gcpro1
;
2563 spread_arg
= args
[nargs
- 1];
2564 CHECK_LIST (spread_arg
);
2566 numargs
= XINT (Flength (spread_arg
));
2569 return Ffuncall (nargs
- 1, args
);
2570 else if (numargs
== 1)
2572 args
[nargs
- 1] = XCAR (spread_arg
);
2573 return Ffuncall (nargs
, args
);
2576 numargs
+= nargs
- 2;
2578 /* Optimize for no indirection. */
2579 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2580 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2581 fun
= indirect_function (fun
);
2582 if (EQ (fun
, Qunbound
))
2584 /* Let funcall get the error */
2591 if (numargs
< XSUBR (fun
)->min_args
2592 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2593 goto funcall
; /* Let funcall get the error */
2594 else if (XSUBR (fun
)->max_args
> numargs
)
2596 /* Avoid making funcall cons up a yet another new vector of arguments
2597 by explicitly supplying nil's for optional values */
2598 SAFE_ALLOCA_LISP (funcall_args
, 1 + XSUBR (fun
)->max_args
);
2599 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2600 funcall_args
[++i
] = Qnil
;
2601 GCPRO1 (*funcall_args
);
2602 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2606 /* We add 1 to numargs because funcall_args includes the
2607 function itself as well as its arguments. */
2610 SAFE_ALLOCA_LISP (funcall_args
, 1 + numargs
);
2611 GCPRO1 (*funcall_args
);
2612 gcpro1
.nvars
= 1 + numargs
;
2615 memcpy (funcall_args
, args
, nargs
* sizeof (Lisp_Object
));
2616 /* Spread the last arg we got. Its first element goes in
2617 the slot that it used to occupy, hence this value of I. */
2619 while (!NILP (spread_arg
))
2621 funcall_args
[i
++] = XCAR (spread_arg
);
2622 spread_arg
= XCDR (spread_arg
);
2625 /* By convention, the caller needs to gcpro Ffuncall's args. */
2626 retval
= Ffuncall (gcpro1
.nvars
, funcall_args
);
2633 /* Run hook variables in various ways. */
2635 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2636 static Lisp_Object
run_hook_with_args (int, Lisp_Object
*,
2637 enum run_hooks_condition
);
2639 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2640 doc
: /* Run each hook in HOOKS.
2641 Each argument should be a symbol, a hook variable.
2642 These symbols are processed in the order specified.
2643 If a hook symbol has a non-nil value, that value may be a function
2644 or a list of functions to be called to run the hook.
2645 If the value is a function, it is called with no arguments.
2646 If it is a list, the elements are called, in order, with no arguments.
2648 Major modes should not use this function directly to run their mode
2649 hook; they should use `run-mode-hooks' instead.
2651 Do not use `make-local-variable' to make a hook variable buffer-local.
2652 Instead, use `add-hook' and specify t for the LOCAL argument.
2653 usage: (run-hooks &rest HOOKS) */)
2654 (int nargs
, Lisp_Object
*args
)
2656 Lisp_Object hook
[1];
2659 for (i
= 0; i
< nargs
; i
++)
2662 run_hook_with_args (1, hook
, to_completion
);
2668 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2669 Srun_hook_with_args
, 1, MANY
, 0,
2670 doc
: /* Run HOOK with the specified arguments ARGS.
2671 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2672 value, that value may be a function or a list of functions to be
2673 called to run the hook. If the value is a function, it is called with
2674 the given arguments and its return value is returned. If it is a list
2675 of functions, those functions are called, in order,
2676 with the given arguments ARGS.
2677 It is best not to depend on the value returned by `run-hook-with-args',
2680 Do not use `make-local-variable' to make a hook variable buffer-local.
2681 Instead, use `add-hook' and specify t for the LOCAL argument.
2682 usage: (run-hook-with-args HOOK &rest ARGS) */)
2683 (int nargs
, Lisp_Object
*args
)
2685 return run_hook_with_args (nargs
, args
, to_completion
);
2688 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2689 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2690 doc
: /* Run HOOK with the specified arguments ARGS.
2691 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2692 value, that value may be a function or a list of functions to be
2693 called to run the hook. If the value is a function, it is called with
2694 the given arguments and its return value is returned.
2695 If it is a list of functions, those functions are called, in order,
2696 with the given arguments ARGS, until one of them
2697 returns a non-nil value. Then we return that value.
2698 However, if they all return nil, we return nil.
2700 Do not use `make-local-variable' to make a hook variable buffer-local.
2701 Instead, use `add-hook' and specify t for the LOCAL argument.
2702 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2703 (int nargs
, Lisp_Object
*args
)
2705 return run_hook_with_args (nargs
, args
, until_success
);
2708 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2709 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2710 doc
: /* Run HOOK with the specified arguments ARGS.
2711 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2712 value, that value may be a function or a list of functions to be
2713 called to run the hook. If the value is a function, it is called with
2714 the given arguments and its return value is returned.
2715 If it is a list of functions, those functions are called, in order,
2716 with the given arguments ARGS, until one of them returns nil.
2717 Then we return nil. However, if they all return non-nil, we return non-nil.
2719 Do not use `make-local-variable' to make a hook variable buffer-local.
2720 Instead, use `add-hook' and specify t for the LOCAL argument.
2721 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2722 (int nargs
, Lisp_Object
*args
)
2724 return run_hook_with_args (nargs
, args
, until_failure
);
2727 /* ARGS[0] should be a hook symbol.
2728 Call each of the functions in the hook value, passing each of them
2729 as arguments all the rest of ARGS (all NARGS - 1 elements).
2730 COND specifies a condition to test after each call
2731 to decide whether to stop.
2732 The caller (or its caller, etc) must gcpro all of ARGS,
2733 except that it isn't necessary to gcpro ARGS[0]. */
2736 run_hook_with_args (int nargs
, Lisp_Object
*args
, enum run_hooks_condition cond
)
2738 Lisp_Object sym
, val
, ret
;
2739 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2741 /* If we are dying or still initializing,
2742 don't do anything--it would probably crash if we tried. */
2743 if (NILP (Vrun_hooks
))
2747 val
= find_symbol_value (sym
);
2748 ret
= (cond
== until_failure
? Qt
: Qnil
);
2750 if (EQ (val
, Qunbound
) || NILP (val
))
2752 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2755 return Ffuncall (nargs
, args
);
2759 Lisp_Object globals
= Qnil
;
2760 GCPRO3 (sym
, val
, globals
);
2763 CONSP (val
) && ((cond
== to_completion
)
2764 || (cond
== until_success
? NILP (ret
)
2768 if (EQ (XCAR (val
), Qt
))
2770 /* t indicates this hook has a local binding;
2771 it means to run the global binding too. */
2772 globals
= Fdefault_value (sym
);
2773 if (NILP (globals
)) continue;
2775 if (!CONSP (globals
) || EQ (XCAR (globals
), Qlambda
))
2778 ret
= Ffuncall (nargs
, args
);
2783 CONSP (globals
) && ((cond
== to_completion
)
2784 || (cond
== until_success
? NILP (ret
)
2786 globals
= XCDR (globals
))
2788 args
[0] = XCAR (globals
);
2789 /* In a global value, t should not occur. If it does, we
2790 must ignore it to avoid an endless loop. */
2791 if (!EQ (args
[0], Qt
))
2792 ret
= Ffuncall (nargs
, args
);
2798 args
[0] = XCAR (val
);
2799 ret
= Ffuncall (nargs
, args
);
2808 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2809 present value of that symbol.
2810 Call each element of FUNLIST,
2811 passing each of them the rest of ARGS.
2812 The caller (or its caller, etc) must gcpro all of ARGS,
2813 except that it isn't necessary to gcpro ARGS[0]. */
2816 run_hook_list_with_args (Lisp_Object funlist
, int nargs
, Lisp_Object
*args
)
2820 Lisp_Object globals
;
2821 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2825 GCPRO3 (sym
, val
, globals
);
2827 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2829 if (EQ (XCAR (val
), Qt
))
2831 /* t indicates this hook has a local binding;
2832 it means to run the global binding too. */
2834 for (globals
= Fdefault_value (sym
);
2836 globals
= XCDR (globals
))
2838 args
[0] = XCAR (globals
);
2839 /* In a global value, t should not occur. If it does, we
2840 must ignore it to avoid an endless loop. */
2841 if (!EQ (args
[0], Qt
))
2842 Ffuncall (nargs
, args
);
2847 args
[0] = XCAR (val
);
2848 Ffuncall (nargs
, args
);
2855 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2858 run_hook_with_args_2 (Lisp_Object hook
, Lisp_Object arg1
, Lisp_Object arg2
)
2860 Lisp_Object temp
[3];
2865 Frun_hook_with_args (3, temp
);
2868 /* Apply fn to arg */
2870 apply1 (Lisp_Object fn
, Lisp_Object arg
)
2872 struct gcpro gcpro1
;
2876 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2879 Lisp_Object args
[2];
2883 RETURN_UNGCPRO (Fapply (2, args
));
2887 /* Call function fn on no arguments */
2889 call0 (Lisp_Object fn
)
2891 struct gcpro gcpro1
;
2894 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2897 /* Call function fn with 1 argument arg1 */
2900 call1 (Lisp_Object fn
, Lisp_Object arg1
)
2902 struct gcpro gcpro1
;
2903 Lisp_Object args
[2];
2909 RETURN_UNGCPRO (Ffuncall (2, args
));
2912 /* Call function fn with 2 arguments arg1, arg2 */
2915 call2 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
)
2917 struct gcpro gcpro1
;
2918 Lisp_Object args
[3];
2924 RETURN_UNGCPRO (Ffuncall (3, args
));
2927 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2930 call3 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
)
2932 struct gcpro gcpro1
;
2933 Lisp_Object args
[4];
2940 RETURN_UNGCPRO (Ffuncall (4, args
));
2943 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2946 call4 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2949 struct gcpro gcpro1
;
2950 Lisp_Object args
[5];
2958 RETURN_UNGCPRO (Ffuncall (5, args
));
2961 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2964 call5 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2965 Lisp_Object arg4
, Lisp_Object arg5
)
2967 struct gcpro gcpro1
;
2968 Lisp_Object args
[6];
2977 RETURN_UNGCPRO (Ffuncall (6, args
));
2980 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2983 call6 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
2984 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
)
2986 struct gcpro gcpro1
;
2987 Lisp_Object args
[7];
2997 RETURN_UNGCPRO (Ffuncall (7, args
));
3000 /* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7 */
3003 call7 (Lisp_Object fn
, Lisp_Object arg1
, Lisp_Object arg2
, Lisp_Object arg3
,
3004 Lisp_Object arg4
, Lisp_Object arg5
, Lisp_Object arg6
, Lisp_Object arg7
)
3006 struct gcpro gcpro1
;
3007 Lisp_Object args
[8];
3018 RETURN_UNGCPRO (Ffuncall (8, args
));
3021 /* The caller should GCPRO all the elements of ARGS. */
3023 DEFUN ("functionp", Ffunctionp
, Sfunctionp
, 1, 1, 0,
3024 doc
: /* Return non-nil if OBJECT is a type of object that can be called as a function. */)
3025 (Lisp_Object object
)
3027 if (SYMBOLP (object
) && !NILP (Ffboundp (object
)))
3029 object
= Findirect_function (object
, Qnil
);
3031 if (CONSP (object
) && EQ (XCAR (object
), Qautoload
))
3033 /* Autoloaded symbols are functions, except if they load
3034 macros or keymaps. */
3036 for (i
= 0; i
< 4 && CONSP (object
); i
++)
3037 object
= XCDR (object
);
3039 return (CONSP (object
) && !NILP (XCAR (object
))) ? Qnil
: Qt
;
3044 return (XSUBR (object
)->max_args
!= UNEVALLED
) ? Qt
: Qnil
;
3045 else if (FUNVECP (object
))
3047 else if (CONSP (object
))
3049 Lisp_Object car
= XCAR (object
);
3050 return (EQ (car
, Qlambda
) || EQ (car
, Qclosure
)) ? Qt
: Qnil
;
3056 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
3057 doc
: /* Call first argument as a function, passing remaining arguments to it.
3058 Return the value that function returns.
3059 Thus, (funcall 'cons 'x 'y) returns (x . y).
3060 usage: (funcall FUNCTION &rest ARGUMENTS) */)
3061 (int nargs
, Lisp_Object
*args
)
3063 Lisp_Object fun
, original_fun
;
3065 int numargs
= nargs
- 1;
3066 Lisp_Object lisp_numargs
;
3068 struct backtrace backtrace
;
3069 register Lisp_Object
*internal_args
;
3073 if ((consing_since_gc
> gc_cons_threshold
3074 && consing_since_gc
> gc_relative_threshold
)
3076 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
3077 Fgarbage_collect ();
3079 if (++lisp_eval_depth
> max_lisp_eval_depth
)
3081 if (max_lisp_eval_depth
< 100)
3082 max_lisp_eval_depth
= 100;
3083 if (lisp_eval_depth
> max_lisp_eval_depth
)
3084 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
3087 backtrace
.next
= backtrace_list
;
3088 backtrace_list
= &backtrace
;
3089 backtrace
.function
= &args
[0];
3090 backtrace
.args
= &args
[1];
3091 backtrace
.nargs
= nargs
- 1;
3092 backtrace
.evalargs
= 0;
3093 backtrace
.debug_on_exit
= 0;
3095 if (debug_on_next_call
)
3096 do_debug_on_call (Qlambda
);
3100 original_fun
= args
[0];
3104 /* Optimize for no indirection. */
3106 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
3107 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
3108 fun
= indirect_function (fun
);
3112 if (numargs
< XSUBR (fun
)->min_args
3113 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
3115 XSETFASTINT (lisp_numargs
, numargs
);
3116 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
3119 if (XSUBR (fun
)->max_args
== UNEVALLED
)
3120 xsignal1 (Qinvalid_function
, original_fun
);
3122 else if (XSUBR (fun
)->max_args
== MANY
)
3123 val
= (XSUBR (fun
)->function
.aMANY
) (numargs
, args
+ 1);
3126 if (XSUBR (fun
)->max_args
> numargs
)
3128 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
3129 memcpy (internal_args
, args
+ 1, numargs
* sizeof (Lisp_Object
));
3130 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
3131 internal_args
[i
] = Qnil
;
3134 internal_args
= args
+ 1;
3135 switch (XSUBR (fun
)->max_args
)
3138 val
= (XSUBR (fun
)->function
.a0
) ();
3141 val
= (XSUBR (fun
)->function
.a1
) (internal_args
[0]);
3144 val
= (XSUBR (fun
)->function
.a2
) (internal_args
[0], internal_args
[1]);
3147 val
= (XSUBR (fun
)->function
.a3
) (internal_args
[0], internal_args
[1],
3151 val
= (XSUBR (fun
)->function
.a4
) (internal_args
[0], internal_args
[1],
3152 internal_args
[2], internal_args
[3]);
3155 val
= (XSUBR (fun
)->function
.a5
) (internal_args
[0], internal_args
[1],
3156 internal_args
[2], internal_args
[3],
3160 val
= (XSUBR (fun
)->function
.a6
) (internal_args
[0], internal_args
[1],
3161 internal_args
[2], internal_args
[3],
3162 internal_args
[4], internal_args
[5]);
3165 val
= (XSUBR (fun
)->function
.a7
) (internal_args
[0], internal_args
[1],
3166 internal_args
[2], internal_args
[3],
3167 internal_args
[4], internal_args
[5],
3172 val
= (XSUBR (fun
)->function
.a8
) (internal_args
[0], internal_args
[1],
3173 internal_args
[2], internal_args
[3],
3174 internal_args
[4], internal_args
[5],
3175 internal_args
[6], internal_args
[7]);
3180 /* If a subr takes more than 8 arguments without using MANY
3181 or UNEVALLED, we need to extend this function to support it.
3182 Until this is done, there is no way to call the function. */
3187 else if (FUNVECP (fun
))
3188 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3191 if (EQ (fun
, Qunbound
))
3192 xsignal1 (Qvoid_function
, original_fun
);
3194 xsignal1 (Qinvalid_function
, original_fun
);
3195 funcar
= XCAR (fun
);
3196 if (!SYMBOLP (funcar
))
3197 xsignal1 (Qinvalid_function
, original_fun
);
3198 if (EQ (funcar
, Qlambda
)
3199 || EQ (funcar
, Qclosure
))
3200 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3201 else if (EQ (funcar
, Qautoload
))
3203 do_autoload (fun
, original_fun
);
3208 xsignal1 (Qinvalid_function
, original_fun
);
3212 if (backtrace
.debug_on_exit
)
3213 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
3214 backtrace_list
= backtrace
.next
;
3219 apply_lambda (Lisp_Object fun
, Lisp_Object args
)
3221 Lisp_Object args_left
;
3222 Lisp_Object numargs
;
3223 register Lisp_Object
*arg_vector
;
3224 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3226 register Lisp_Object tem
;
3229 numargs
= Flength (args
);
3230 SAFE_ALLOCA_LISP (arg_vector
, XINT (numargs
));
3233 GCPRO3 (*arg_vector
, args_left
, fun
);
3236 for (i
= 0; i
< XINT (numargs
);)
3238 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
3239 tem
= eval_sub (tem
);
3240 arg_vector
[i
++] = tem
;
3246 backtrace_list
->args
= arg_vector
;
3247 backtrace_list
->nargs
= i
;
3248 backtrace_list
->evalargs
= 0;
3249 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
3251 /* Do the debug-on-exit now, while arg_vector still exists. */
3252 if (backtrace_list
->debug_on_exit
)
3253 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
3254 /* Don't do it again when we return to eval. */
3255 backtrace_list
->debug_on_exit
= 0;
3261 /* Call a non-bytecode funvec object FUN, on the argments in ARGS (of
3265 funcall_funvec (Lisp_Object fun
, int nargs
, Lisp_Object
*args
)
3267 int size
= FUNVEC_SIZE (fun
);
3268 Lisp_Object tag
= (size
> 0 ? AREF (fun
, 0) : Qnil
);
3270 if (EQ (tag
, Qcurry
))
3272 /* A curried function is a way to attach arguments to a another
3273 function. The first element of the vector is the identifier
3274 `curry', the second is the wrapped function, and remaining
3275 elements are the attached arguments. */
3276 int num_curried_args
= size
- 2;
3277 /* Offset of the curried and user args in the final arglist. Curried
3278 args are first in the new arg vector, after the function. User
3280 int curried_args_offs
= 1;
3281 int user_args_offs
= curried_args_offs
+ num_curried_args
;
3282 /* The curried function and arguments. */
3283 Lisp_Object
*curry_params
= XVECTOR (fun
)->contents
+ 1;
3284 /* The arguments in the curry vector. */
3285 Lisp_Object
*curried_args
= curry_params
+ 1;
3286 /* The number of arguments with which we'll call funcall, and the
3287 arguments themselves. */
3288 int num_funcall_args
= 1 + num_curried_args
+ nargs
;
3289 Lisp_Object
*funcall_args
3290 = (Lisp_Object
*) alloca (num_funcall_args
* sizeof (Lisp_Object
));
3292 /* First comes the real function. */
3293 funcall_args
[0] = curry_params
[0];
3295 /* Then the arguments in the appropriate order. */
3296 memcpy (funcall_args
+ curried_args_offs
, curried_args
,
3297 num_curried_args
* sizeof (Lisp_Object
));
3298 memcpy (funcall_args
+ user_args_offs
, args
,
3299 nargs
* sizeof (Lisp_Object
));
3301 return Ffuncall (num_funcall_args
, funcall_args
);
3304 xsignal1 (Qinvalid_function
, fun
);
3308 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3309 and return the result of evaluation.
3310 FUN must be either a lambda-expression or a compiled-code object. */
3313 funcall_lambda (Lisp_Object fun
, int nargs
,
3314 register Lisp_Object
*arg_vector
)
3316 Lisp_Object val
, syms_left
, next
, lexenv
;
3317 int count
= SPECPDL_INDEX ();
3318 int i
, optional
, rest
;
3321 && FUNVEC_SIZE (fun
) > COMPILED_PUSH_ARGS
3322 && ! NILP (XVECTOR (fun
)->contents
[COMPILED_PUSH_ARGS
]))
3323 /* A byte-code object with a non-nil `push args' slot means we
3324 shouldn't bind any arguments, instead just call the byte-code
3325 interpreter directly; it will push arguments as necessary.
3327 Byte-code objects with either a non-existant, or a nil value for
3328 the `push args' slot (the default), have dynamically-bound
3329 arguments, and use the argument-binding code below instead (as do
3330 all interpreted functions, even lexically bound ones). */
3332 /* If we have not actually read the bytecode string
3333 and constants vector yet, fetch them from the file. */
3334 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3335 Ffetch_bytecode (fun
);
3336 return exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
3337 AREF (fun
, COMPILED_CONSTANTS
),
3338 AREF (fun
, COMPILED_STACK_DEPTH
),
3339 AREF (fun
, COMPILED_ARGLIST
),
3343 if (FUNVECP (fun
) && !FUNVEC_COMPILED_P (fun
))
3344 /* Byte-compiled functions are handled directly below, but we
3345 call other funvec types via funcall_funvec. */
3346 return funcall_funvec (fun
, nargs
, arg_vector
);
3350 if (EQ (XCAR (fun
), Qclosure
))
3352 fun
= XCDR (fun
); /* Drop `closure'. */
3353 lexenv
= XCAR (fun
);
3354 fun
= XCDR (fun
); /* Drop the lexical environment. */
3358 syms_left
= XCDR (fun
);
3359 if (CONSP (syms_left
))
3360 syms_left
= XCAR (syms_left
);
3362 xsignal1 (Qinvalid_function
, fun
);
3364 else if (COMPILEDP (fun
))
3366 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
3372 i
= optional
= rest
= 0;
3373 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
3377 next
= XCAR (syms_left
);
3378 if (!SYMBOLP (next
))
3379 xsignal1 (Qinvalid_function
, fun
);
3381 if (EQ (next
, Qand_rest
))
3383 else if (EQ (next
, Qand_optional
))
3390 val
= Flist (nargs
- i
, &arg_vector
[i
]);
3394 val
= arg_vector
[i
++];
3396 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3400 /* Bind the argument. */
3401 if (!NILP (lexenv
) && SYMBOLP (next
)
3402 /* FIXME: there's no good reason to allow dynamic-scoping
3403 on function arguments, other than consistency with let. */
3404 && !XSYMBOL (next
)->declared_special
3405 && NILP (Fmemq (next
, Vinternal_interpreter_environment
)))
3406 /* Lexically bind NEXT by adding it to the lexenv alist. */
3407 lexenv
= Fcons (Fcons (next
, val
), lexenv
);
3409 /* Dynamically bind NEXT. */
3410 specbind (next
, val
);
3414 if (!NILP (syms_left
))
3415 xsignal1 (Qinvalid_function
, fun
);
3417 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3419 if (!EQ (lexenv
, Vinternal_interpreter_environment
))
3420 /* Instantiate a new lexical environment. */
3421 specbind (Qinternal_interpreter_environment
, lexenv
);
3424 val
= Fprogn (XCDR (XCDR (fun
)));
3427 /* If we have not actually read the bytecode string
3428 and constants vector yet, fetch them from the file. */
3429 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3430 Ffetch_bytecode (fun
);
3431 val
= exec_byte_code (AREF (fun
, COMPILED_BYTECODE
),
3432 AREF (fun
, COMPILED_CONSTANTS
),
3433 AREF (fun
, COMPILED_STACK_DEPTH
),
3437 return unbind_to (count
, val
);
3440 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3442 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3443 (Lisp_Object object
)
3447 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3449 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3452 tem
= AREF (object
, COMPILED_BYTECODE
);
3453 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3454 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3456 error ("Invalid byte code");
3458 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
3459 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
3467 register int count
= SPECPDL_INDEX ();
3468 if (specpdl_size
>= max_specpdl_size
)
3470 if (max_specpdl_size
< 400)
3471 max_specpdl_size
= 400;
3472 if (specpdl_size
>= max_specpdl_size
)
3473 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil
);
3476 if (specpdl_size
> max_specpdl_size
)
3477 specpdl_size
= max_specpdl_size
;
3478 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
3479 specpdl_ptr
= specpdl
+ count
;
3482 /* specpdl_ptr->symbol is a field which describes which variable is
3483 let-bound, so it can be properly undone when we unbind_to.
3484 It can have the following two shapes:
3485 - SYMBOL : if it's a plain symbol, it means that we have let-bound
3486 a symbol that is not buffer-local (at least at the time
3487 the let binding started). Note also that it should not be
3488 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3490 - (SYMBOL WHERE . BUFFER) : this means that it is a let-binding for
3491 variable SYMBOL which can be buffer-local. WHERE tells us
3492 which buffer is affected (or nil if the let-binding affects the
3493 global value of the variable) and BUFFER tells us which buffer was
3494 current (i.e. if WHERE is non-nil, then BUFFER==WHERE, otherwise
3495 BUFFER did not yet have a buffer-local value). */
3498 specbind (Lisp_Object symbol
, Lisp_Object value
)
3500 struct Lisp_Symbol
*sym
;
3502 eassert (!handling_signal
);
3504 CHECK_SYMBOL (symbol
);
3505 sym
= XSYMBOL (symbol
);
3506 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3510 switch (sym
->redirect
)
3512 case SYMBOL_VARALIAS
:
3513 sym
= indirect_variable (sym
); XSETSYMBOL (symbol
, sym
); goto start
;
3514 case SYMBOL_PLAINVAL
:
3515 /* The most common case is that of a non-constant symbol with a
3516 trivial value. Make that as fast as we can. */
3517 specpdl_ptr
->symbol
= symbol
;
3518 specpdl_ptr
->old_value
= SYMBOL_VAL (sym
);
3519 specpdl_ptr
->func
= NULL
;
3522 SET_SYMBOL_VAL (sym
, value
);
3524 set_internal (symbol
, value
, Qnil
, 1);
3526 case SYMBOL_LOCALIZED
:
3527 if (SYMBOL_BLV (sym
)->frame_local
)
3528 error ("Frame-local vars cannot be let-bound");
3529 case SYMBOL_FORWARDED
:
3531 Lisp_Object ovalue
= find_symbol_value (symbol
);
3532 specpdl_ptr
->func
= 0;
3533 specpdl_ptr
->old_value
= ovalue
;
3535 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3536 || (EQ (SYMBOL_BLV (sym
)->where
,
3537 SYMBOL_BLV (sym
)->frame_local
?
3538 Fselected_frame () : Fcurrent_buffer ())));
3540 if (sym
->redirect
== SYMBOL_LOCALIZED
3541 || BUFFER_OBJFWDP (SYMBOL_FWD (sym
)))
3543 Lisp_Object where
, cur_buf
= Fcurrent_buffer ();
3545 /* For a local variable, record both the symbol and which
3546 buffer's or frame's value we are saving. */
3547 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3549 eassert (sym
->redirect
!= SYMBOL_LOCALIZED
3550 || (BLV_FOUND (SYMBOL_BLV (sym
))
3551 && EQ (cur_buf
, SYMBOL_BLV (sym
)->where
)));
3554 else if (sym
->redirect
== SYMBOL_LOCALIZED
3555 && BLV_FOUND (SYMBOL_BLV (sym
)))
3556 where
= SYMBOL_BLV (sym
)->where
;
3560 /* We're not using the `unused' slot in the specbinding
3561 structure because this would mean we have to do more
3562 work for simple variables. */
3563 /* FIXME: The third value `current_buffer' is only used in
3564 let_shadows_buffer_binding_p which is itself only used
3565 in set_internal for local_if_set. */
3566 eassert (NILP (where
) || EQ (where
, cur_buf
));
3567 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, cur_buf
));
3569 /* If SYMBOL is a per-buffer variable which doesn't have a
3570 buffer-local value here, make the `let' change the global
3571 value by changing the value of SYMBOL in all buffers not
3572 having their own value. This is consistent with what
3573 happens with other buffer-local variables. */
3575 && sym
->redirect
== SYMBOL_FORWARDED
)
3577 eassert (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)));
3579 Fset_default (symbol
, value
);
3584 specpdl_ptr
->symbol
= symbol
;
3587 set_internal (symbol
, value
, Qnil
, 1);
3595 record_unwind_protect (Lisp_Object (*function
) (Lisp_Object
), Lisp_Object arg
)
3597 eassert (!handling_signal
);
3599 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3601 specpdl_ptr
->func
= function
;
3602 specpdl_ptr
->symbol
= Qnil
;
3603 specpdl_ptr
->old_value
= arg
;
3608 unbind_to (int count
, Lisp_Object value
)
3610 Lisp_Object quitf
= Vquit_flag
;
3611 struct gcpro gcpro1
, gcpro2
;
3613 GCPRO2 (value
, quitf
);
3616 while (specpdl_ptr
!= specpdl
+ count
)
3618 /* Copy the binding, and decrement specpdl_ptr, before we do
3619 the work to unbind it. We decrement first
3620 so that an error in unbinding won't try to unbind
3621 the same entry again, and we copy the binding first
3622 in case more bindings are made during some of the code we run. */
3624 struct specbinding this_binding
;
3625 this_binding
= *--specpdl_ptr
;
3627 if (this_binding
.func
!= 0)
3628 (*this_binding
.func
) (this_binding
.old_value
);
3629 /* If the symbol is a list, it is really (SYMBOL WHERE
3630 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3631 frame. If WHERE is a buffer or frame, this indicates we
3632 bound a variable that had a buffer-local or frame-local
3633 binding. WHERE nil means that the variable had the default
3634 value when it was bound. CURRENT-BUFFER is the buffer that
3635 was current when the variable was bound. */
3636 else if (CONSP (this_binding
.symbol
))
3638 Lisp_Object symbol
, where
;
3640 symbol
= XCAR (this_binding
.symbol
);
3641 where
= XCAR (XCDR (this_binding
.symbol
));
3644 Fset_default (symbol
, this_binding
.old_value
);
3645 /* If `where' is non-nil, reset the value in the appropriate
3646 local binding, but only if that binding still exists. */
3647 else if (BUFFERP (where
)
3648 ? !NILP (Flocal_variable_p (symbol
, where
))
3649 : !NILP (Fassq (symbol
, XFRAME (where
)->param_alist
)))
3650 set_internal (symbol
, this_binding
.old_value
, where
, 1);
3652 /* If variable has a trivial value (no forwarding), we can
3653 just set it. No need to check for constant symbols here,
3654 since that was already done by specbind. */
3655 else if (XSYMBOL (this_binding
.symbol
)->redirect
== SYMBOL_PLAINVAL
)
3656 SET_SYMBOL_VAL (XSYMBOL (this_binding
.symbol
),
3657 this_binding
.old_value
);
3659 /* NOTE: we only ever come here if make_local_foo was used for
3660 the first time on this var within this let. */
3661 Fset_default (this_binding
.symbol
, this_binding
.old_value
);
3664 if (NILP (Vquit_flag
) && !NILP (quitf
))
3673 DEFUN ("special-variable-p", Fspecial_variable_p
, Sspecial_variable_p
, 1, 1, 0,
3674 doc
: /* Return non-nil if SYMBOL's global binding has been declared special.
3675 A special variable is one that will be bound dynamically, even in a
3676 context where binding is lexical by default. */)
3677 (Lisp_Object symbol
)
3679 CHECK_SYMBOL (symbol
);
3680 return XSYMBOL (symbol
)->declared_special
? Qt
: Qnil
;
3685 DEFUN ("curry", Fcurry
, Scurry
, 1, MANY
, 0,
3686 doc
: /* Return FUN curried with ARGS.
3687 The result is a function-like object that will append any arguments it
3688 is called with to ARGS, and call FUN with the resulting list of arguments.
3691 (funcall (curry '+ 3 4 5) 2) is the same as (funcall '+ 3 4 5 2)
3693 (mapcar (curry 'concat "The ") '("a" "b" "c"))
3694 => ("The a" "The b" "The c")
3696 usage: (curry FUN &rest ARGS) */)
3697 (int nargs
, Lisp_Object
*args
)
3699 return make_funvec (Qcurry
, 0, nargs
, args
);
3703 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3704 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3705 The debugger is entered when that frame exits, if the flag is non-nil. */)
3706 (Lisp_Object level
, Lisp_Object flag
)
3708 register struct backtrace
*backlist
= backtrace_list
;
3711 CHECK_NUMBER (level
);
3713 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3715 backlist
= backlist
->next
;
3719 backlist
->debug_on_exit
= !NILP (flag
);
3724 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3725 doc
: /* Print a trace of Lisp function calls currently active.
3726 Output stream used is value of `standard-output'. */)
3729 register struct backtrace
*backlist
= backtrace_list
;
3733 struct gcpro gcpro1
;
3734 Lisp_Object old_print_level
= Vprint_level
;
3736 if (NILP (Vprint_level
))
3737 XSETFASTINT (Vprint_level
, 8);
3744 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3745 if (backlist
->nargs
== UNEVALLED
)
3747 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3748 write_string ("\n", -1);
3752 tem
= *backlist
->function
;
3753 Fprin1 (tem
, Qnil
); /* This can QUIT */
3754 write_string ("(", -1);
3755 if (backlist
->nargs
== MANY
)
3757 for (tail
= *backlist
->args
, i
= 0;
3759 tail
= Fcdr (tail
), i
++)
3761 if (i
) write_string (" ", -1);
3762 Fprin1 (Fcar (tail
), Qnil
);
3767 for (i
= 0; i
< backlist
->nargs
; i
++)
3769 if (i
) write_string (" ", -1);
3770 Fprin1 (backlist
->args
[i
], Qnil
);
3773 write_string (")\n", -1);
3775 backlist
= backlist
->next
;
3778 Vprint_level
= old_print_level
;
3783 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3784 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3785 If that frame has not evaluated the arguments yet (or is a special form),
3786 the value is (nil FUNCTION ARG-FORMS...).
3787 If that frame has evaluated its arguments and called its function already,
3788 the value is (t FUNCTION ARG-VALUES...).
3789 A &rest arg is represented as the tail of the list ARG-VALUES.
3790 FUNCTION is whatever was supplied as car of evaluated list,
3791 or a lambda expression for macro calls.
3792 If NFRAMES is more than the number of frames, the value is nil. */)
3793 (Lisp_Object nframes
)
3795 register struct backtrace
*backlist
= backtrace_list
;
3799 CHECK_NATNUM (nframes
);
3801 /* Find the frame requested. */
3802 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3803 backlist
= backlist
->next
;
3807 if (backlist
->nargs
== UNEVALLED
)
3808 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3811 if (backlist
->nargs
== MANY
)
3812 tem
= *backlist
->args
;
3814 tem
= Flist (backlist
->nargs
, backlist
->args
);
3816 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3822 mark_backtrace (void)
3824 register struct backtrace
*backlist
;
3827 for (backlist
= backtrace_list
; backlist
; backlist
= backlist
->next
)
3829 mark_object (*backlist
->function
);
3831 if (backlist
->nargs
== UNEVALLED
|| backlist
->nargs
== MANY
)
3834 i
= backlist
->nargs
- 1;
3836 mark_object (backlist
->args
[i
]);
3843 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3844 doc
: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3845 If Lisp code tries to increase the total number past this amount,
3846 an error is signaled.
3847 You can safely use a value considerably larger than the default value,
3848 if that proves inconveniently small. However, if you increase it too far,
3849 Emacs could run out of memory trying to make the stack bigger. */);
3851 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3852 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3854 This limit serves to catch infinite recursions for you before they cause
3855 actual stack overflow in C, which would be fatal for Emacs.
3856 You can safely make it considerably larger than its default value,
3857 if that proves inconveniently small. However, if you increase it too far,
3858 Emacs could overflow the real C stack, and crash. */);
3860 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3861 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3862 If the value is t, that means do an ordinary quit.
3863 If the value equals `throw-on-input', that means quit by throwing
3864 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3865 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3866 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3869 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3870 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3871 Note that `quit-flag' will still be set by typing C-g,
3872 so a quit will be signaled as soon as `inhibit-quit' is nil.
3873 To prevent this happening, set `quit-flag' to nil
3874 before making `inhibit-quit' nil. */);
3875 Vinhibit_quit
= Qnil
;
3877 Qinhibit_quit
= intern_c_string ("inhibit-quit");
3878 staticpro (&Qinhibit_quit
);
3880 Qautoload
= intern_c_string ("autoload");
3881 staticpro (&Qautoload
);
3883 Qdebug_on_error
= intern_c_string ("debug-on-error");
3884 staticpro (&Qdebug_on_error
);
3886 Qmacro
= intern_c_string ("macro");
3887 staticpro (&Qmacro
);
3889 Qdeclare
= intern_c_string ("declare");
3890 staticpro (&Qdeclare
);
3892 /* Note that the process handling also uses Qexit, but we don't want
3893 to staticpro it twice, so we just do it here. */
3894 Qexit
= intern_c_string ("exit");
3897 Qinteractive
= intern_c_string ("interactive");
3898 staticpro (&Qinteractive
);
3900 Qcommandp
= intern_c_string ("commandp");
3901 staticpro (&Qcommandp
);
3903 Qdefun
= intern_c_string ("defun");
3904 staticpro (&Qdefun
);
3906 Qand_rest
= intern_c_string ("&rest");
3907 staticpro (&Qand_rest
);
3909 Qand_optional
= intern_c_string ("&optional");
3910 staticpro (&Qand_optional
);
3912 Qclosure
= intern_c_string ("closure");
3913 staticpro (&Qclosure
);
3915 Qcurry
= intern_c_string ("curry");
3916 staticpro (&Qcurry
);
3918 Qdebug
= intern_c_string ("debug");
3919 staticpro (&Qdebug
);
3921 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3922 doc
: /* *Non-nil means errors display a backtrace buffer.
3923 More precisely, this happens for any error that is handled
3924 by the editor command loop.
3925 If the value is a list, an error only means to display a backtrace
3926 if one of its condition symbols appears in the list. */);
3927 Vstack_trace_on_error
= Qnil
;
3929 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3930 doc
: /* *Non-nil means enter debugger if an error is signaled.
3931 Does not apply to errors handled by `condition-case' or those
3932 matched by `debug-ignored-errors'.
3933 If the value is a list, an error only means to enter the debugger
3934 if one of its condition symbols appears in the list.
3935 When you evaluate an expression interactively, this variable
3936 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3937 The command `toggle-debug-on-error' toggles this.
3938 See also the variable `debug-on-quit'. */);
3939 Vdebug_on_error
= Qnil
;
3941 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3942 doc
: /* *List of errors for which the debugger should not be called.
3943 Each element may be a condition-name or a regexp that matches error messages.
3944 If any element applies to a given error, that error skips the debugger
3945 and just returns to top level.
3946 This overrides the variable `debug-on-error'.
3947 It does not apply to errors handled by `condition-case'. */);
3948 Vdebug_ignored_errors
= Qnil
;
3950 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3951 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3952 Does not apply if quit is handled by a `condition-case'. */);
3955 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3956 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3958 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3959 doc
: /* Non-nil means debugger may continue execution.
3960 This is nil when the debugger is called under circumstances where it
3961 might not be safe to continue. */);
3962 debugger_may_continue
= 1;
3964 DEFVAR_LISP ("debugger", &Vdebugger
,
3965 doc
: /* Function to call to invoke debugger.
3966 If due to frame exit, args are `exit' and the value being returned;
3967 this function's value will be returned instead of that.
3968 If due to error, args are `error' and a list of the args to `signal'.
3969 If due to `apply' or `funcall' entry, one arg, `lambda'.
3970 If due to `eval' entry, one arg, t. */);
3973 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3974 doc
: /* If non-nil, this is a function for `signal' to call.
3975 It receives the same arguments that `signal' was given.
3976 The Edebug package uses this to regain control. */);
3977 Vsignal_hook_function
= Qnil
;
3979 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3980 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3981 Note that `debug-on-error', `debug-on-quit' and friends
3982 still determine whether to handle the particular condition. */);
3983 Vdebug_on_signal
= Qnil
;
3985 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3986 doc
: /* Function to process declarations in a macro definition.
3987 The function will be called with two args MACRO and DECL.
3988 MACRO is the name of the macro being defined.
3989 DECL is a list `(declare ...)' containing the declarations.
3990 The value the function returns is not used. */);
3991 Vmacro_declaration_function
= Qnil
;
3993 Qinternal_interpreter_environment
3994 = intern_c_string ("internal-interpreter-environment");
3995 staticpro (&Qinternal_interpreter_environment
);
3996 DEFVAR_LISP ("internal-interpreter-environment",
3997 &Vinternal_interpreter_environment
,
3998 doc
: /* If non-nil, the current lexical environment of the lisp interpreter.
3999 When lexical binding is not being used, this variable is nil.
4000 A value of `(t)' indicates an empty environment, otherwise it is an
4001 alist of active lexical bindings. */);
4002 Vinternal_interpreter_environment
= Qnil
;
4004 Vrun_hooks
= intern_c_string ("run-hooks");
4005 staticpro (&Vrun_hooks
);
4007 staticpro (&Vautoload_queue
);
4008 Vautoload_queue
= Qnil
;
4009 staticpro (&Vsignaling_function
);
4010 Vsignaling_function
= Qnil
;
4021 defsubr (&Sfunction
);
4023 defsubr (&Sdefmacro
);
4025 defsubr (&Sdefvaralias
);
4026 defsubr (&Sdefconst
);
4027 defsubr (&Suser_variable_p
);
4031 defsubr (&Smacroexpand
);
4034 defsubr (&Sunwind_protect
);
4035 defsubr (&Scondition_case
);
4037 defsubr (&Sinteractive_p
);
4038 defsubr (&Scalled_interactively_p
);
4039 defsubr (&Scommandp
);
4040 defsubr (&Sautoload
);
4043 defsubr (&Sfuncall
);
4044 defsubr (&Srun_hooks
);
4045 defsubr (&Srun_hook_with_args
);
4046 defsubr (&Srun_hook_with_args_until_success
);
4047 defsubr (&Srun_hook_with_args_until_failure
);
4048 defsubr (&Sfetch_bytecode
);
4050 defsubr (&Sbacktrace_debug
);
4051 defsubr (&Sbacktrace
);
4052 defsubr (&Sbacktrace_frame
);
4054 defsubr (&Sspecial_variable_p
);
4055 defsubr (&Sfunctionp
);
4058 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
4059 (do not change this comment) */