1 /* Evaluator for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001, 02, 2004
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
25 #include "blockinput.h"
28 #include "dispextern.h"
31 /* This definition is duplicated in alloc.c and keyboard.c */
32 /* Putting it in lisp.h makes cc bomb out! */
36 struct backtrace
*next
;
37 Lisp_Object
*function
;
38 Lisp_Object
*args
; /* Points to vector of args. */
39 int nargs
; /* Length of vector.
40 If nargs is UNEVALLED, args points to slot holding
41 list of unevalled args */
43 /* Nonzero means call value of debugger when done with this operation. */
47 struct backtrace
*backtrace_list
;
49 /* This structure helps implement the `catch' and `throw' control
50 structure. A struct catchtag contains all the information needed
51 to restore the state of the interpreter after a non-local jump.
53 Handlers for error conditions (represented by `struct handler'
54 structures) just point to a catch tag to do the cleanup required
57 catchtag structures are chained together in the C calling stack;
58 the `next' member points to the next outer catchtag.
60 A call like (throw TAG VAL) searches for a catchtag whose `tag'
61 member is TAG, and then unbinds to it. The `val' member is used to
62 hold VAL while the stack is unwound; `val' is returned as the value
65 All the other members are concerned with restoring the interpreter
72 struct catchtag
*next
;
75 struct backtrace
*backlist
;
76 struct handler
*handlerlist
;
79 int poll_suppress_count
;
80 int interrupt_input_blocked
;
81 struct byte_stack
*byte_stack
;
84 struct catchtag
*catchlist
;
87 /* Count levels of GCPRO to detect failure to UNGCPRO. */
91 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
, Qdefun
;
92 Lisp_Object Qinhibit_quit
, Vinhibit_quit
, Vquit_flag
;
93 Lisp_Object Qand_rest
, Qand_optional
;
94 Lisp_Object Qdebug_on_error
;
97 /* This holds either the symbol `run-hooks' or nil.
98 It is nil at an early stage of startup, and when Emacs
101 Lisp_Object Vrun_hooks
;
103 /* Non-nil means record all fset's and provide's, to be undone
104 if the file being autoloaded is not fully loaded.
105 They are recorded by being consed onto the front of Vautoload_queue:
106 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
108 Lisp_Object Vautoload_queue
;
110 /* Current number of specbindings allocated in specpdl. */
114 /* Pointer to beginning of specpdl. */
116 struct specbinding
*specpdl
;
118 /* Pointer to first unused element in specpdl. */
120 volatile struct specbinding
*specpdl_ptr
;
122 /* Maximum size allowed for specpdl allocation */
124 EMACS_INT max_specpdl_size
;
126 /* Depth in Lisp evaluations and function calls. */
130 /* Maximum allowed depth in Lisp evaluations and function calls. */
132 EMACS_INT max_lisp_eval_depth
;
134 /* Nonzero means enter debugger before next function call */
136 int debug_on_next_call
;
138 /* Non-zero means debugger may continue. This is zero when the
139 debugger is called during redisplay, where it might not be safe to
140 continue the interrupted redisplay. */
142 int debugger_may_continue
;
144 /* List of conditions (non-nil atom means all) which cause a backtrace
145 if an error is handled by the command loop's error handler. */
147 Lisp_Object Vstack_trace_on_error
;
149 /* List of conditions (non-nil atom means all) which enter the debugger
150 if an error is handled by the command loop's error handler. */
152 Lisp_Object Vdebug_on_error
;
154 /* List of conditions and regexps specifying error messages which
155 do not enter the debugger even if Vdebug_on_error says they should. */
157 Lisp_Object Vdebug_ignored_errors
;
159 /* Non-nil means call the debugger even if the error will be handled. */
161 Lisp_Object Vdebug_on_signal
;
163 /* Hook for edebug to use. */
165 Lisp_Object Vsignal_hook_function
;
167 /* Nonzero means enter debugger if a quit signal
168 is handled by the command loop's error handler. */
172 /* The value of num_nonmacro_input_events as of the last time we
173 started to enter the debugger. If we decide to enter the debugger
174 again when this is still equal to num_nonmacro_input_events, then we
175 know that the debugger itself has an error, and we should just
176 signal the error instead of entering an infinite loop of debugger
179 int when_entered_debugger
;
181 Lisp_Object Vdebugger
;
183 /* The function from which the last `signal' was called. Set in
186 Lisp_Object Vsignaling_function
;
188 /* Set to non-zero while processing X events. Checked in Feval to
189 make sure the Lisp interpreter isn't called from a signal handler,
190 which is unsafe because the interpreter isn't reentrant. */
194 /* Function to process declarations in defmacro forms. */
196 Lisp_Object Vmacro_declaration_function
;
199 static Lisp_Object funcall_lambda
P_ ((Lisp_Object
, int, Lisp_Object
*));
205 specpdl
= (struct specbinding
*) xmalloc (specpdl_size
* sizeof (struct specbinding
));
206 specpdl_ptr
= specpdl
;
207 max_specpdl_size
= 1000;
208 max_lisp_eval_depth
= 300;
216 specpdl_ptr
= specpdl
;
221 debug_on_next_call
= 0;
226 /* This is less than the initial value of num_nonmacro_input_events. */
227 when_entered_debugger
= -1;
234 int debug_while_redisplaying
;
235 int count
= SPECPDL_INDEX ();
238 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
239 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
241 if (specpdl_size
+ 40 > max_specpdl_size
)
242 max_specpdl_size
= specpdl_size
+ 40;
244 #ifdef HAVE_X_WINDOWS
245 if (display_hourglass_p
)
249 debug_on_next_call
= 0;
250 when_entered_debugger
= num_nonmacro_input_events
;
252 /* Resetting redisplaying_p to 0 makes sure that debug output is
253 displayed if the debugger is invoked during redisplay. */
254 debug_while_redisplaying
= redisplaying_p
;
256 specbind (intern ("debugger-may-continue"),
257 debug_while_redisplaying
? Qnil
: Qt
);
258 specbind (Qinhibit_redisplay
, Qnil
);
260 #if 0 /* Binding this prevents execution of Lisp code during
261 redisplay, which necessarily leads to display problems. */
262 specbind (Qinhibit_eval_during_redisplay
, Qt
);
265 val
= apply1 (Vdebugger
, arg
);
267 /* Interrupting redisplay and resuming it later is not safe under
268 all circumstances. So, when the debugger returns, abort the
269 interrupted redisplay by going back to the top-level. */
270 if (debug_while_redisplaying
)
273 return unbind_to (count
, val
);
277 do_debug_on_call (code
)
280 debug_on_next_call
= 0;
281 backtrace_list
->debug_on_exit
= 1;
282 call_debugger (Fcons (code
, Qnil
));
285 /* NOTE!!! Every function that can call EVAL must protect its args
286 and temporaries from garbage collection while it needs them.
287 The definition of `For' shows what you have to do. */
289 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
290 doc
: /* Eval args until one of them yields non-nil, then return that value.
291 The remaining args are not evalled at all.
292 If all args return nil, return nil.
293 usage: (or CONDITIONS ...) */)
297 register Lisp_Object val
= Qnil
;
304 val
= Feval (XCAR (args
));
314 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
315 doc
: /* Eval args until one of them yields nil, then return nil.
316 The remaining args are not evalled at all.
317 If no arg yields nil, return the last arg's value.
318 usage: (and CONDITIONS ...) */)
322 register Lisp_Object val
= Qt
;
329 val
= Feval (XCAR (args
));
339 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
340 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
341 Returns the value of THEN or the value of the last of the ELSE's.
342 THEN must be one expression, but ELSE... can be zero or more expressions.
343 If COND yields nil, and there are no ELSE's, the value is nil.
344 usage: (if COND THEN ELSE...) */)
348 register Lisp_Object cond
;
352 cond
= Feval (Fcar (args
));
356 return Feval (Fcar (Fcdr (args
)));
357 return Fprogn (Fcdr (Fcdr (args
)));
360 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
361 doc
: /* Try each clause until one succeeds.
362 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
363 and, if the value is non-nil, this clause succeeds:
364 then the expressions in BODY are evaluated and the last one's
365 value is the value of the cond-form.
366 If no clause succeeds, cond returns nil.
367 If a clause has one element, as in (CONDITION),
368 CONDITION's value if non-nil is returned from the cond-form.
369 usage: (cond CLAUSES...) */)
373 register Lisp_Object clause
, val
;
380 clause
= Fcar (args
);
381 val
= Feval (Fcar (clause
));
384 if (!EQ (XCDR (clause
), Qnil
))
385 val
= Fprogn (XCDR (clause
));
395 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
396 doc
: /* Eval BODY forms sequentially and return value of last one.
397 usage: (progn BODY ...) */)
401 register Lisp_Object val
= Qnil
;
408 val
= Feval (XCAR (args
));
416 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
417 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
418 The value of FIRST is saved during the evaluation of the remaining args,
419 whose values are discarded.
420 usage: (prog1 FIRST BODY...) */)
425 register Lisp_Object args_left
;
426 struct gcpro gcpro1
, gcpro2
;
427 register int argnum
= 0;
439 val
= Feval (Fcar (args_left
));
441 Feval (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 X, Y and BODY sequentially; value from Y.
452 The value of Y is saved during the evaluation of the remaining args,
453 whose values are discarded.
454 usage: (prog2 X Y BODY...) */)
459 register Lisp_Object args_left
;
460 struct gcpro gcpro1
, gcpro2
;
461 register int argnum
= -1;
475 val
= Feval (Fcar (args_left
));
477 Feval (Fcar (args_left
));
478 args_left
= Fcdr (args_left
);
480 while (!NILP (args_left
));
486 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
487 doc
: /* Set each SYM to the value of its VAL.
488 The symbols SYM are variables; they are literal (not evaluated).
489 The values VAL are expressions; they are evaluated.
490 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
491 The second VAL is not computed until after the first SYM is set, and so on;
492 each VAL can use the new value of variables set earlier in the `setq'.
493 The return value of the `setq' form is the value of the last VAL.
494 usage: (setq SYM VAL SYM VAL ...) */)
498 register Lisp_Object args_left
;
499 register Lisp_Object val
, sym
;
510 val
= Feval (Fcar (Fcdr (args_left
)));
511 sym
= Fcar (args_left
);
513 args_left
= Fcdr (Fcdr (args_left
));
515 while (!NILP(args_left
));
521 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
522 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
523 usage: (quote ARG) */)
530 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
531 doc
: /* Like `quote', but preferred for objects which are functions.
532 In byte compilation, `function' causes its argument to be compiled.
533 `quote' cannot do that.
534 usage: (function ARG) */)
542 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
543 doc
: /* Return t if the function was run directly by user input.
544 This means that the function was called with call-interactively (which
545 includes being called as the binding of a key)
546 and input is currently coming from the keyboard (not in keyboard macro),
547 and Emacs is not running in batch mode (`noninteractive' is nil).
549 The only known proper use of `interactive-p' is in deciding whether to
550 display a helpful message, or how to display it. If you're thinking
551 of using it for any other purpose, it is quite likely that you're
552 making a mistake. Think: what do you want to do when the command is
553 called from a keyboard macro?
555 If you want to test whether your function was called with
556 `call-interactively', the way to do that is by adding an extra
557 optional argument, and making the `interactive' spec specify non-nil
558 unconditionally for that argument. (`p' is a good way to do this.) */)
561 return (INTERACTIVE
&& interactive_p (1)) ? Qt
: Qnil
;
565 DEFUN ("called-interactively-p", Fcalled_interactively_p
, Scalled_interactively_p
, 0, 0, 0,
566 doc
: /* Return t if the function using this was called with call-interactively.
567 This is used for implementing advice and other function-modifying
570 The cleanest way to test whether your function was called with
571 `call-interactively', the way to do that is by adding an extra
572 optional argument, and making the `interactive' spec specify non-nil
573 unconditionally for that argument. (`p' is a good way to do this.) */)
576 return interactive_p (1) ? Qt
: Qnil
;
580 /* Return 1 if function in which this appears was called using
583 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
584 called is a built-in. */
587 interactive_p (exclude_subrs_p
)
590 struct backtrace
*btp
;
593 btp
= backtrace_list
;
595 /* If this isn't a byte-compiled function, there may be a frame at
596 the top for Finteractive_p. If so, skip it. */
597 fun
= Findirect_function (*btp
->function
);
598 if (SUBRP (fun
) && (XSUBR (fun
) == &Sinteractive_p
599 || XSUBR (fun
) == &Scalled_interactively_p
))
602 /* If we're running an Emacs 18-style byte-compiled function, there
603 may be a frame for Fbytecode at the top level. In any version of
604 Emacs there can be Fbytecode frames for subexpressions evaluated
605 inside catch and condition-case. Skip past them.
607 If this isn't a byte-compiled function, then we may now be
608 looking at several frames for special forms. Skip past them. */
610 && (EQ (*btp
->function
, Qbytecode
)
611 || btp
->nargs
== UNEVALLED
))
614 /* btp now points at the frame of the innermost function that isn't
615 a special form, ignoring frames for Finteractive_p and/or
616 Fbytecode at the top. If this frame is for a built-in function
617 (such as load or eval-region) return nil. */
618 fun
= Findirect_function (*btp
->function
);
619 if (exclude_subrs_p
&& SUBRP (fun
))
622 /* btp points to the frame of a Lisp function that called interactive-p.
623 Return t if that function was called interactively. */
624 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
630 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
631 doc
: /* Define NAME as a function.
632 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
633 See also the function `interactive'.
634 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
638 register Lisp_Object fn_name
;
639 register Lisp_Object defn
;
641 fn_name
= Fcar (args
);
642 CHECK_SYMBOL (fn_name
);
643 defn
= Fcons (Qlambda
, Fcdr (args
));
644 if (!NILP (Vpurify_flag
))
645 defn
= Fpurecopy (defn
);
646 if (CONSP (XSYMBOL (fn_name
)->function
)
647 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
648 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
649 Ffset (fn_name
, defn
);
650 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
654 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
655 doc
: /* Define NAME as a macro.
656 The actual definition looks like
657 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
658 When the macro is called, as in (NAME ARGS...),
659 the function (lambda ARGLIST BODY...) is applied to
660 the list ARGS... as it appears in the expression,
661 and the result should be a form to be evaluated instead of the original.
663 DECL is a declaration, optional, which can specify how to indent
664 calls to this macro and how Edebug should handle it. It looks like this:
666 The elements can look like this:
668 Set NAME's `lisp-indent-function' property to INDENT.
671 Set NAME's `edebug-form-spec' property to DEBUG. (This is
672 equivalent to writing a `def-edebug-spec' for the macro.)
673 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
677 register Lisp_Object fn_name
;
678 register Lisp_Object defn
;
679 Lisp_Object lambda_list
, doc
, tail
;
681 fn_name
= Fcar (args
);
682 CHECK_SYMBOL (fn_name
);
683 lambda_list
= Fcar (Fcdr (args
));
684 tail
= Fcdr (Fcdr (args
));
687 if (STRINGP (Fcar (tail
)))
693 while (CONSP (Fcar (tail
))
694 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
696 if (!NILP (Vmacro_declaration_function
))
700 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
708 tail
= Fcons (lambda_list
, tail
);
710 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
711 defn
= Fcons (Qmacro
, Fcons (Qlambda
, tail
));
713 if (!NILP (Vpurify_flag
))
714 defn
= Fpurecopy (defn
);
715 if (CONSP (XSYMBOL (fn_name
)->function
)
716 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
717 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
718 Ffset (fn_name
, defn
);
719 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
724 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
725 doc
: /* Make SYMBOL a variable alias for symbol ALIASED.
726 Setting the value of SYMBOL will subsequently set the value of ALIASED,
727 and getting the value of SYMBOL will return the value ALIASED has.
728 Third arg DOCSTRING, if non-nil, is documentation for SYMBOL.
729 The return value is ALIASED. */)
730 (symbol
, aliased
, docstring
)
731 Lisp_Object symbol
, aliased
, docstring
;
733 struct Lisp_Symbol
*sym
;
735 CHECK_SYMBOL (symbol
);
736 CHECK_SYMBOL (aliased
);
738 if (SYMBOL_CONSTANT_P (symbol
))
739 error ("Cannot make a constant an alias");
741 sym
= XSYMBOL (symbol
);
742 sym
->indirect_variable
= 1;
743 sym
->value
= aliased
;
744 sym
->constant
= SYMBOL_CONSTANT_P (aliased
);
745 LOADHIST_ATTACH (symbol
);
746 if (!NILP (docstring
))
747 Fput (symbol
, Qvariable_documentation
, docstring
);
753 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
754 doc
: /* Define SYMBOL as a variable.
755 You are not required to define a variable in order to use it,
756 but the definition can supply documentation and an initial value
757 in a way that tags can recognize.
759 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
760 If SYMBOL is buffer-local, its default value is what is set;
761 buffer-local values are not affected.
762 INITVALUE and DOCSTRING are optional.
763 If DOCSTRING starts with *, this variable is identified as a user option.
764 This means that M-x set-variable recognizes it.
765 See also `user-variable-p'.
766 If INITVALUE is missing, SYMBOL's value is not set.
768 If SYMBOL has a local binding, then this form affects the local
769 binding. This is usually not what you want. Thus, if you need to
770 load a file defining variables, with this form or with `defconst' or
771 `defcustom', you should always load that file _outside_ any bindings
772 for these variables. \(`defconst' and `defcustom' behave similarly in
774 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
778 register Lisp_Object sym
, tem
, tail
;
782 if (!NILP (Fcdr (Fcdr (tail
))))
783 error ("too many arguments");
785 tem
= Fdefault_boundp (sym
);
789 Fset_default (sym
, Feval (Fcar (tail
)));
791 { /* Check if there is really a global binding rather than just a let
792 binding that shadows the global unboundness of the var. */
793 volatile struct specbinding
*pdl
= specpdl_ptr
;
794 while (--pdl
>= specpdl
)
796 if (EQ (pdl
->symbol
, sym
) && !pdl
->func
797 && EQ (pdl
->old_value
, Qunbound
))
799 message_with_string ("Warning: defvar ignored because %s is let-bound",
800 SYMBOL_NAME (sym
), 1);
809 if (!NILP (Vpurify_flag
))
810 tem
= Fpurecopy (tem
);
811 Fput (sym
, Qvariable_documentation
, tem
);
813 LOADHIST_ATTACH (sym
);
816 /* Simple (defvar <var>) should not count as a definition at all.
817 It could get in the way of other definitions, and unloading this
818 package could try to make the variable unbound. */
824 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
825 doc
: /* Define SYMBOL as a constant variable.
826 The intent is that neither programs nor users should ever change this value.
827 Always sets the value of SYMBOL to the result of evalling INITVALUE.
828 If SYMBOL is buffer-local, its default value is what is set;
829 buffer-local values are not affected.
830 DOCSTRING is optional.
832 If SYMBOL has a local binding, then this form sets the local binding's
833 value. However, you should normally not make local bindings for
834 variables defined with this form.
835 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
839 register Lisp_Object sym
, tem
;
842 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
843 error ("too many arguments");
845 tem
= Feval (Fcar (Fcdr (args
)));
846 if (!NILP (Vpurify_flag
))
847 tem
= Fpurecopy (tem
);
848 Fset_default (sym
, tem
);
849 tem
= Fcar (Fcdr (Fcdr (args
)));
852 if (!NILP (Vpurify_flag
))
853 tem
= Fpurecopy (tem
);
854 Fput (sym
, Qvariable_documentation
, tem
);
856 LOADHIST_ATTACH (sym
);
860 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
861 doc
: /* Returns t if VARIABLE is intended to be set and modified by users.
862 \(The alternative is a variable used internally in a Lisp program.)
863 Determined by whether the first character of the documentation
864 for the variable is `*' or if the variable is customizable (has a non-nil
865 value of `standard-value' or of `custom-autoload' on its property list). */)
867 Lisp_Object variable
;
869 Lisp_Object documentation
;
871 if (!SYMBOLP (variable
))
874 documentation
= Fget (variable
, Qvariable_documentation
);
875 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
877 if (STRINGP (documentation
)
878 && ((unsigned char) SREF (documentation
, 0) == '*'))
880 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
881 if (CONSP (documentation
)
882 && STRINGP (XCAR (documentation
))
883 && INTEGERP (XCDR (documentation
))
884 && XINT (XCDR (documentation
)) < 0)
886 /* Customizable? See `custom-variable-p'. */
887 if ((!NILP (Fget (variable
, intern ("standard-value"))))
888 || (!NILP (Fget (variable
, intern ("custom-autoload")))))
893 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
894 doc
: /* Bind variables according to VARLIST then eval BODY.
895 The value of the last form in BODY is returned.
896 Each element of VARLIST is a symbol (which is bound to nil)
897 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
898 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
899 usage: (let* VARLIST BODY...) */)
903 Lisp_Object varlist
, val
, elt
;
904 int count
= SPECPDL_INDEX ();
905 struct gcpro gcpro1
, gcpro2
, gcpro3
;
907 GCPRO3 (args
, elt
, varlist
);
909 varlist
= Fcar (args
);
910 while (!NILP (varlist
))
913 elt
= Fcar (varlist
);
915 specbind (elt
, Qnil
);
916 else if (! NILP (Fcdr (Fcdr (elt
))))
918 Fcons (build_string ("`let' bindings can have only one value-form"),
922 val
= Feval (Fcar (Fcdr (elt
)));
923 specbind (Fcar (elt
), val
);
925 varlist
= Fcdr (varlist
);
928 val
= Fprogn (Fcdr (args
));
929 return unbind_to (count
, val
);
932 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
933 doc
: /* Bind variables according to VARLIST then eval BODY.
934 The value of the last form in BODY is returned.
935 Each element of VARLIST is a symbol (which is bound to nil)
936 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
937 All the VALUEFORMs are evalled before any symbols are bound.
938 usage: (let VARLIST BODY...) */)
942 Lisp_Object
*temps
, tem
;
943 register Lisp_Object elt
, varlist
;
944 int count
= SPECPDL_INDEX ();
946 struct gcpro gcpro1
, gcpro2
;
948 varlist
= Fcar (args
);
950 /* Make space to hold the values to give the bound variables */
951 elt
= Flength (varlist
);
952 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
954 /* Compute the values and store them in `temps' */
956 GCPRO2 (args
, *temps
);
959 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
962 elt
= Fcar (varlist
);
964 temps
[argnum
++] = Qnil
;
965 else if (! NILP (Fcdr (Fcdr (elt
))))
967 Fcons (build_string ("`let' bindings can have only one value-form"),
970 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
971 gcpro2
.nvars
= argnum
;
975 varlist
= Fcar (args
);
976 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
978 elt
= Fcar (varlist
);
979 tem
= temps
[argnum
++];
983 specbind (Fcar (elt
), tem
);
986 elt
= Fprogn (Fcdr (args
));
987 return unbind_to (count
, elt
);
990 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
991 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
992 The order of execution is thus TEST, BODY, TEST, BODY and so on
993 until TEST returns nil.
994 usage: (while TEST BODY...) */)
998 Lisp_Object test
, body
;
999 struct gcpro gcpro1
, gcpro2
;
1001 GCPRO2 (test
, body
);
1005 while (!NILP (Feval (test
)))
1015 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1016 doc
: /* Return result of expanding macros at top level of FORM.
1017 If FORM is not a macro call, it is returned unchanged.
1018 Otherwise, the macro is expanded and the expansion is considered
1019 in place of FORM. When a non-macro-call results, it is returned.
1021 The second optional arg ENVIRONMENT specifies an environment of macro
1022 definitions to shadow the loaded ones for use in file byte-compilation. */)
1025 Lisp_Object environment
;
1027 /* With cleanups from Hallvard Furuseth. */
1028 register Lisp_Object expander
, sym
, def
, tem
;
1032 /* Come back here each time we expand a macro call,
1033 in case it expands into another macro call. */
1036 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1037 def
= sym
= XCAR (form
);
1039 /* Trace symbols aliases to other symbols
1040 until we get a symbol that is not an alias. */
1041 while (SYMBOLP (def
))
1045 tem
= Fassq (sym
, environment
);
1048 def
= XSYMBOL (sym
)->function
;
1049 if (!EQ (def
, Qunbound
))
1054 /* Right now TEM is the result from SYM in ENVIRONMENT,
1055 and if TEM is nil then DEF is SYM's function definition. */
1058 /* SYM is not mentioned in ENVIRONMENT.
1059 Look at its function definition. */
1060 if (EQ (def
, Qunbound
) || !CONSP (def
))
1061 /* Not defined or definition not suitable */
1063 if (EQ (XCAR (def
), Qautoload
))
1065 /* Autoloading function: will it be a macro when loaded? */
1066 tem
= Fnth (make_number (4), def
);
1067 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1068 /* Yes, load it and try again. */
1070 struct gcpro gcpro1
;
1072 do_autoload (def
, sym
);
1079 else if (!EQ (XCAR (def
), Qmacro
))
1081 else expander
= XCDR (def
);
1085 expander
= XCDR (tem
);
1086 if (NILP (expander
))
1089 form
= apply1 (expander
, XCDR (form
));
1094 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1095 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1096 TAG is evalled to get the tag to use; it must not be nil.
1098 Then the BODY is executed.
1099 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1100 If no throw happens, `catch' returns the value of the last BODY form.
1101 If a throw happens, it specifies the value to return from `catch'.
1102 usage: (catch TAG BODY...) */)
1106 register Lisp_Object tag
;
1107 struct gcpro gcpro1
;
1110 tag
= Feval (Fcar (args
));
1112 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1115 /* Set up a catch, then call C function FUNC on argument ARG.
1116 FUNC should return a Lisp_Object.
1117 This is how catches are done from within C code. */
1120 internal_catch (tag
, func
, arg
)
1122 Lisp_Object (*func
) ();
1125 /* This structure is made part of the chain `catchlist'. */
1128 /* Fill in the components of c, and put it on the list. */
1132 c
.backlist
= backtrace_list
;
1133 c
.handlerlist
= handlerlist
;
1134 c
.lisp_eval_depth
= lisp_eval_depth
;
1135 c
.pdlcount
= SPECPDL_INDEX ();
1136 c
.poll_suppress_count
= poll_suppress_count
;
1137 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1138 c
.gcpro
= gcprolist
;
1139 c
.byte_stack
= byte_stack_list
;
1143 if (! _setjmp (c
.jmp
))
1144 c
.val
= (*func
) (arg
);
1146 /* Throw works by a longjmp that comes right here. */
1151 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1152 jump to that CATCH, returning VALUE as the value of that catch.
1154 This is the guts Fthrow and Fsignal; they differ only in the way
1155 they choose the catch tag to throw to. A catch tag for a
1156 condition-case form has a TAG of Qnil.
1158 Before each catch is discarded, unbind all special bindings and
1159 execute all unwind-protect clauses made above that catch. Unwind
1160 the handler stack as we go, so that the proper handlers are in
1161 effect for each unwind-protect clause we run. At the end, restore
1162 some static info saved in CATCH, and longjmp to the location
1165 This is used for correct unwinding in Fthrow and Fsignal. */
1168 unwind_to_catch (catch, value
)
1169 struct catchtag
*catch;
1172 register int last_time
;
1174 /* Save the value in the tag. */
1177 /* Restore certain special C variables. */
1178 set_poll_suppress_count (catch->poll_suppress_count
);
1179 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked
);
1180 handling_signal
= 0;
1185 last_time
= catchlist
== catch;
1187 /* Unwind the specpdl stack, and then restore the proper set of
1189 unbind_to (catchlist
->pdlcount
, Qnil
);
1190 handlerlist
= catchlist
->handlerlist
;
1191 catchlist
= catchlist
->next
;
1193 while (! last_time
);
1195 byte_stack_list
= catch->byte_stack
;
1196 gcprolist
= catch->gcpro
;
1199 gcpro_level
= gcprolist
->level
+ 1;
1203 backtrace_list
= catch->backlist
;
1204 lisp_eval_depth
= catch->lisp_eval_depth
;
1206 _longjmp (catch->jmp
, 1);
1209 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1210 doc
: /* Throw to the catch for TAG and return VALUE from it.
1211 Both TAG and VALUE are evalled. */)
1213 register Lisp_Object tag
, value
;
1215 register struct catchtag
*c
;
1220 for (c
= catchlist
; c
; c
= c
->next
)
1222 if (EQ (c
->tag
, tag
))
1223 unwind_to_catch (c
, value
);
1225 tag
= Fsignal (Qno_catch
, Fcons (tag
, Fcons (value
, Qnil
)));
1230 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1231 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1232 If BODYFORM completes normally, its value is returned
1233 after executing the UNWINDFORMS.
1234 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1235 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1240 int count
= SPECPDL_INDEX ();
1242 record_unwind_protect (Fprogn
, Fcdr (args
));
1243 val
= Feval (Fcar (args
));
1244 return unbind_to (count
, val
);
1247 /* Chain of condition handlers currently in effect.
1248 The elements of this chain are contained in the stack frames
1249 of Fcondition_case and internal_condition_case.
1250 When an error is signaled (by calling Fsignal, below),
1251 this chain is searched for an element that applies. */
1253 struct handler
*handlerlist
;
1255 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1256 doc
: /* Regain control when an error is signaled.
1257 Executes BODYFORM and returns its value if no error happens.
1258 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1259 where the BODY is made of Lisp expressions.
1261 A handler is applicable to an error
1262 if CONDITION-NAME is one of the error's condition names.
1263 If an error happens, the first applicable handler is run.
1265 The car of a handler may be a list of condition names
1266 instead of a single condition name.
1268 When a handler handles an error,
1269 control returns to the condition-case and the handler BODY... is executed
1270 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
1271 VAR may be nil; then you do not get access to the signal information.
1273 The value of the last BODY form is returned from the condition-case.
1274 See also the function `signal' for more info.
1275 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1282 register Lisp_Object bodyform
, handlers
;
1283 volatile Lisp_Object var
;
1286 bodyform
= Fcar (Fcdr (args
));
1287 handlers
= Fcdr (Fcdr (args
));
1290 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1296 && (SYMBOLP (XCAR (tem
))
1297 || CONSP (XCAR (tem
))))))
1298 error ("Invalid condition handler", tem
);
1303 c
.backlist
= backtrace_list
;
1304 c
.handlerlist
= handlerlist
;
1305 c
.lisp_eval_depth
= lisp_eval_depth
;
1306 c
.pdlcount
= SPECPDL_INDEX ();
1307 c
.poll_suppress_count
= poll_suppress_count
;
1308 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1309 c
.gcpro
= gcprolist
;
1310 c
.byte_stack
= byte_stack_list
;
1311 if (_setjmp (c
.jmp
))
1314 specbind (h
.var
, c
.val
);
1315 val
= Fprogn (Fcdr (h
.chosen_clause
));
1317 /* Note that this just undoes the binding of h.var; whoever
1318 longjumped to us unwound the stack to c.pdlcount before
1320 unbind_to (c
.pdlcount
, Qnil
);
1327 h
.handler
= handlers
;
1328 h
.next
= handlerlist
;
1332 val
= Feval (bodyform
);
1334 handlerlist
= h
.next
;
1338 /* Call the function BFUN with no arguments, catching errors within it
1339 according to HANDLERS. If there is an error, call HFUN with
1340 one argument which is the data that describes the error:
1343 HANDLERS can be a list of conditions to catch.
1344 If HANDLERS is Qt, catch all errors.
1345 If HANDLERS is Qerror, catch all errors
1346 but allow the debugger to run if that is enabled. */
1349 internal_condition_case (bfun
, handlers
, hfun
)
1350 Lisp_Object (*bfun
) ();
1351 Lisp_Object handlers
;
1352 Lisp_Object (*hfun
) ();
1358 #if 0 /* We now handle interrupt_input_blocked properly.
1359 What we still do not handle is exiting a signal handler. */
1365 c
.backlist
= backtrace_list
;
1366 c
.handlerlist
= handlerlist
;
1367 c
.lisp_eval_depth
= lisp_eval_depth
;
1368 c
.pdlcount
= SPECPDL_INDEX ();
1369 c
.poll_suppress_count
= poll_suppress_count
;
1370 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1371 c
.gcpro
= gcprolist
;
1372 c
.byte_stack
= byte_stack_list
;
1373 if (_setjmp (c
.jmp
))
1375 return (*hfun
) (c
.val
);
1379 h
.handler
= handlers
;
1381 h
.next
= handlerlist
;
1387 handlerlist
= h
.next
;
1391 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1394 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1395 Lisp_Object (*bfun
) ();
1397 Lisp_Object handlers
;
1398 Lisp_Object (*hfun
) ();
1406 c
.backlist
= backtrace_list
;
1407 c
.handlerlist
= handlerlist
;
1408 c
.lisp_eval_depth
= lisp_eval_depth
;
1409 c
.pdlcount
= SPECPDL_INDEX ();
1410 c
.poll_suppress_count
= poll_suppress_count
;
1411 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1412 c
.gcpro
= gcprolist
;
1413 c
.byte_stack
= byte_stack_list
;
1414 if (_setjmp (c
.jmp
))
1416 return (*hfun
) (c
.val
);
1420 h
.handler
= handlers
;
1422 h
.next
= handlerlist
;
1426 val
= (*bfun
) (arg
);
1428 handlerlist
= h
.next
;
1433 /* Like internal_condition_case but call BFUN with NARGS as first,
1434 and ARGS as second argument. */
1437 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1438 Lisp_Object (*bfun
) ();
1441 Lisp_Object handlers
;
1442 Lisp_Object (*hfun
) ();
1450 c
.backlist
= backtrace_list
;
1451 c
.handlerlist
= handlerlist
;
1452 c
.lisp_eval_depth
= lisp_eval_depth
;
1453 c
.pdlcount
= SPECPDL_INDEX ();
1454 c
.poll_suppress_count
= poll_suppress_count
;
1455 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1456 c
.gcpro
= gcprolist
;
1457 c
.byte_stack
= byte_stack_list
;
1458 if (_setjmp (c
.jmp
))
1460 return (*hfun
) (c
.val
);
1464 h
.handler
= handlers
;
1466 h
.next
= handlerlist
;
1470 val
= (*bfun
) (nargs
, args
);
1472 handlerlist
= h
.next
;
1477 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1478 Lisp_Object
, Lisp_Object
,
1481 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1482 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1483 This function does not return.
1485 An error symbol is a symbol with an `error-conditions' property
1486 that is a list of condition names.
1487 A handler for any of those names will get to handle this signal.
1488 The symbol `error' should normally be one of them.
1490 DATA should be a list. Its elements are printed as part of the error message.
1491 See Info anchor `(elisp)Definition of signal' for some details on how this
1492 error message is constructed.
1493 If the signal is handled, DATA is made available to the handler.
1494 See also the function `condition-case'. */)
1495 (error_symbol
, data
)
1496 Lisp_Object error_symbol
, data
;
1498 /* When memory is full, ERROR-SYMBOL is nil,
1499 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1500 That is a special case--don't do this in other situations. */
1501 register struct handler
*allhandlers
= handlerlist
;
1502 Lisp_Object conditions
;
1503 extern int gc_in_progress
;
1504 extern int waiting_for_input
;
1505 Lisp_Object debugger_value
;
1507 Lisp_Object real_error_symbol
;
1508 struct backtrace
*bp
;
1510 immediate_quit
= handling_signal
= 0;
1512 if (gc_in_progress
|| waiting_for_input
)
1515 if (NILP (error_symbol
))
1516 real_error_symbol
= Fcar (data
);
1518 real_error_symbol
= error_symbol
;
1520 #if 0 /* rms: I don't know why this was here,
1521 but it is surely wrong for an error that is handled. */
1522 #ifdef HAVE_X_WINDOWS
1523 if (display_hourglass_p
)
1524 cancel_hourglass ();
1528 /* This hook is used by edebug. */
1529 if (! NILP (Vsignal_hook_function
)
1530 && ! NILP (error_symbol
))
1531 call2 (Vsignal_hook_function
, error_symbol
, data
);
1533 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1535 /* Remember from where signal was called. Skip over the frame for
1536 `signal' itself. If a frame for `error' follows, skip that,
1537 too. Don't do this when ERROR_SYMBOL is nil, because that
1538 is a memory-full error. */
1539 Vsignaling_function
= Qnil
;
1540 if (backtrace_list
&& !NILP (error_symbol
))
1542 bp
= backtrace_list
->next
;
1543 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1545 if (bp
&& bp
->function
)
1546 Vsignaling_function
= *bp
->function
;
1549 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1551 register Lisp_Object clause
;
1553 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1554 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1556 if (specpdl_size
+ 40 > max_specpdl_size
)
1557 max_specpdl_size
= specpdl_size
+ 40;
1559 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1560 error_symbol
, data
, &debugger_value
);
1562 if (EQ (clause
, Qlambda
))
1564 /* We can't return values to code which signaled an error, but we
1565 can continue code which has signaled a quit. */
1566 if (EQ (real_error_symbol
, Qquit
))
1569 error ("Cannot return from the debugger in an error");
1574 Lisp_Object unwind_data
;
1575 struct handler
*h
= handlerlist
;
1577 handlerlist
= allhandlers
;
1579 if (NILP (error_symbol
))
1582 unwind_data
= Fcons (error_symbol
, data
);
1583 h
->chosen_clause
= clause
;
1584 unwind_to_catch (h
->tag
, unwind_data
);
1588 handlerlist
= allhandlers
;
1589 /* If no handler is present now, try to run the debugger,
1590 and if that fails, throw to top level. */
1591 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1593 Fthrow (Qtop_level
, Qt
);
1595 if (! NILP (error_symbol
))
1596 data
= Fcons (error_symbol
, data
);
1598 string
= Ferror_message_string (data
);
1599 fatal ("%s", SDATA (string
), 0);
1602 /* Return nonzero iff LIST is a non-nil atom or
1603 a list containing one of CONDITIONS. */
1606 wants_debugger (list
, conditions
)
1607 Lisp_Object list
, conditions
;
1614 while (CONSP (conditions
))
1616 Lisp_Object
this, tail
;
1617 this = XCAR (conditions
);
1618 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1619 if (EQ (XCAR (tail
), this))
1621 conditions
= XCDR (conditions
);
1626 /* Return 1 if an error with condition-symbols CONDITIONS,
1627 and described by SIGNAL-DATA, should skip the debugger
1628 according to debugger-ignored-errors. */
1631 skip_debugger (conditions
, data
)
1632 Lisp_Object conditions
, data
;
1635 int first_string
= 1;
1636 Lisp_Object error_message
;
1638 error_message
= Qnil
;
1639 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1641 if (STRINGP (XCAR (tail
)))
1645 error_message
= Ferror_message_string (data
);
1649 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1654 Lisp_Object contail
;
1656 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1657 if (EQ (XCAR (tail
), XCAR (contail
)))
1665 /* Value of Qlambda means we have called debugger and user has continued.
1666 There are two ways to pass SIG and DATA:
1667 = SIG is the error symbol, and DATA is the rest of the data.
1668 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1669 This is for memory-full errors only.
1671 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
1674 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1675 Lisp_Object handlers
, conditions
, sig
, data
;
1676 Lisp_Object
*debugger_value_ptr
;
1678 register Lisp_Object h
;
1679 register Lisp_Object tem
;
1681 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1683 /* error is used similarly, but means print an error message
1684 and run the debugger if that is enabled. */
1685 if (EQ (handlers
, Qerror
)
1686 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1687 there is a handler. */
1689 int count
= SPECPDL_INDEX ();
1690 int debugger_called
= 0;
1691 Lisp_Object sig_symbol
, combined_data
;
1692 /* This is set to 1 if we are handling a memory-full error,
1693 because these must not run the debugger.
1694 (There is no room in memory to do that!) */
1695 int no_debugger
= 0;
1699 combined_data
= data
;
1700 sig_symbol
= Fcar (data
);
1705 combined_data
= Fcons (sig
, data
);
1709 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1712 internal_with_output_to_temp_buffer ("*Backtrace*",
1713 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1716 internal_with_output_to_temp_buffer ("*Backtrace*",
1721 && (EQ (sig_symbol
, Qquit
)
1723 : wants_debugger (Vdebug_on_error
, conditions
))
1724 && ! skip_debugger (conditions
, combined_data
)
1725 && when_entered_debugger
< num_nonmacro_input_events
)
1727 specbind (Qdebug_on_error
, Qnil
);
1729 = call_debugger (Fcons (Qerror
,
1730 Fcons (combined_data
, Qnil
)));
1731 debugger_called
= 1;
1733 /* If there is no handler, return saying whether we ran the debugger. */
1734 if (EQ (handlers
, Qerror
))
1736 if (debugger_called
)
1737 return unbind_to (count
, Qlambda
);
1741 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1743 Lisp_Object handler
, condit
;
1746 if (!CONSP (handler
))
1748 condit
= Fcar (handler
);
1749 /* Handle a single condition name in handler HANDLER. */
1750 if (SYMBOLP (condit
))
1752 tem
= Fmemq (Fcar (handler
), conditions
);
1756 /* Handle a list of condition names in handler HANDLER. */
1757 else if (CONSP (condit
))
1759 while (CONSP (condit
))
1761 tem
= Fmemq (Fcar (condit
), conditions
);
1764 condit
= XCDR (condit
);
1771 /* dump an error message; called like printf */
1775 error (m
, a1
, a2
, a3
)
1795 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1800 buffer
= (char *) xrealloc (buffer
, size
);
1803 buffer
= (char *) xmalloc (size
);
1808 string
= build_string (buffer
);
1812 Fsignal (Qerror
, Fcons (string
, Qnil
));
1816 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
1817 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
1818 This means it contains a description for how to read arguments to give it.
1819 The value is nil for an invalid function or a symbol with no function
1822 Interactively callable functions include strings and vectors (treated
1823 as keyboard macros), lambda-expressions that contain a top-level call
1824 to `interactive', autoload definitions made by `autoload' with non-nil
1825 fourth argument, and some of the built-in functions of Lisp.
1827 Also, a symbol satisfies `commandp' if its function definition does so.
1829 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
1830 then strings and vectors are not accepted. */)
1831 (function
, for_call_interactively
)
1832 Lisp_Object function
, for_call_interactively
;
1834 register Lisp_Object fun
;
1835 register Lisp_Object funcar
;
1839 fun
= indirect_function (fun
);
1840 if (EQ (fun
, Qunbound
))
1843 /* Emacs primitives are interactive if their DEFUN specifies an
1844 interactive spec. */
1847 if (XSUBR (fun
)->prompt
)
1853 /* Bytecode objects are interactive if they are long enough to
1854 have an element whose index is COMPILED_INTERACTIVE, which is
1855 where the interactive spec is stored. */
1856 else if (COMPILEDP (fun
))
1857 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
1860 /* Strings and vectors are keyboard macros. */
1861 if (NILP (for_call_interactively
) && (STRINGP (fun
) || VECTORP (fun
)))
1864 /* Lists may represent commands. */
1867 funcar
= XCAR (fun
);
1868 if (EQ (funcar
, Qlambda
))
1869 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
1870 if (EQ (funcar
, Qautoload
))
1871 return Fcar (Fcdr (Fcdr (XCDR (fun
))));
1877 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
1878 doc
: /* Define FUNCTION to autoload from FILE.
1879 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
1880 Third arg DOCSTRING is documentation for the function.
1881 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
1882 Fifth arg TYPE indicates the type of the object:
1883 nil or omitted says FUNCTION is a function,
1884 `keymap' says FUNCTION is really a keymap, and
1885 `macro' or t says FUNCTION is really a macro.
1886 Third through fifth args give info about the real definition.
1887 They default to nil.
1888 If FUNCTION is already defined other than as an autoload,
1889 this does nothing and returns nil. */)
1890 (function
, file
, docstring
, interactive
, type
)
1891 Lisp_Object function
, file
, docstring
, interactive
, type
;
1894 Lisp_Object args
[4];
1897 CHECK_SYMBOL (function
);
1898 CHECK_STRING (file
);
1900 /* If function is defined and not as an autoload, don't override */
1901 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
1902 && !(CONSP (XSYMBOL (function
)->function
)
1903 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
1906 if (NILP (Vpurify_flag
))
1907 /* Only add entries after dumping, because the ones before are
1908 not useful and else we get loads of them from the loaddefs.el. */
1909 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
1913 args
[1] = docstring
;
1914 args
[2] = interactive
;
1917 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
1918 #else /* NO_ARG_ARRAY */
1919 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
1920 #endif /* not NO_ARG_ARRAY */
1924 un_autoload (oldqueue
)
1925 Lisp_Object oldqueue
;
1927 register Lisp_Object queue
, first
, second
;
1929 /* Queue to unwind is current value of Vautoload_queue.
1930 oldqueue is the shadowed value to leave in Vautoload_queue. */
1931 queue
= Vautoload_queue
;
1932 Vautoload_queue
= oldqueue
;
1933 while (CONSP (queue
))
1935 first
= XCAR (queue
);
1936 second
= Fcdr (first
);
1937 first
= Fcar (first
);
1938 if (EQ (second
, Qnil
))
1941 Ffset (first
, second
);
1942 queue
= XCDR (queue
);
1947 /* Load an autoloaded function.
1948 FUNNAME is the symbol which is the function's name.
1949 FUNDEF is the autoload definition (a list). */
1952 do_autoload (fundef
, funname
)
1953 Lisp_Object fundef
, funname
;
1955 int count
= SPECPDL_INDEX ();
1956 Lisp_Object fun
, queue
, first
, second
;
1957 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1959 /* This is to make sure that loadup.el gives a clear picture
1960 of what files are preloaded and when. */
1961 if (! NILP (Vpurify_flag
))
1962 error ("Attempt to autoload %s while preparing to dump",
1963 SDATA (SYMBOL_NAME (funname
)));
1966 CHECK_SYMBOL (funname
);
1967 GCPRO3 (fun
, funname
, fundef
);
1969 /* Preserve the match data. */
1970 record_unwind_protect (Fset_match_data
, Fmatch_data (Qnil
, Qnil
));
1972 /* Value saved here is to be restored into Vautoload_queue. */
1973 record_unwind_protect (un_autoload
, Vautoload_queue
);
1974 Vautoload_queue
= Qt
;
1975 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
1977 /* Save the old autoloads, in case we ever do an unload. */
1978 queue
= Vautoload_queue
;
1979 while (CONSP (queue
))
1981 first
= XCAR (queue
);
1982 second
= Fcdr (first
);
1983 first
= Fcar (first
);
1985 /* Note: This test is subtle. The cdr of an autoload-queue entry
1986 may be an atom if the autoload entry was generated by a defalias
1989 Fput (first
, Qautoload
, (XCDR (second
)));
1991 queue
= XCDR (queue
);
1994 /* Once loading finishes, don't undo it. */
1995 Vautoload_queue
= Qt
;
1996 unbind_to (count
, Qnil
);
1998 fun
= Findirect_function (fun
);
2000 if (!NILP (Fequal (fun
, fundef
)))
2001 error ("Autoloading failed to define function %s",
2002 SDATA (SYMBOL_NAME (funname
)));
2007 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
2008 doc
: /* Evaluate FORM and return its value. */)
2012 Lisp_Object fun
, val
, original_fun
, original_args
;
2014 struct backtrace backtrace
;
2015 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2017 if (handling_signal
)
2021 return Fsymbol_value (form
);
2026 if (consing_since_gc
> gc_cons_threshold
)
2029 Fgarbage_collect ();
2033 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2035 if (max_lisp_eval_depth
< 100)
2036 max_lisp_eval_depth
= 100;
2037 if (lisp_eval_depth
> max_lisp_eval_depth
)
2038 error ("Lisp nesting exceeds max-lisp-eval-depth");
2041 original_fun
= Fcar (form
);
2042 original_args
= Fcdr (form
);
2044 backtrace
.next
= backtrace_list
;
2045 backtrace_list
= &backtrace
;
2046 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2047 backtrace
.args
= &original_args
;
2048 backtrace
.nargs
= UNEVALLED
;
2049 backtrace
.evalargs
= 1;
2050 backtrace
.debug_on_exit
= 0;
2052 if (debug_on_next_call
)
2053 do_debug_on_call (Qt
);
2055 /* At this point, only original_fun and original_args
2056 have values that will be used below */
2058 fun
= Findirect_function (original_fun
);
2062 Lisp_Object numargs
;
2063 Lisp_Object argvals
[8];
2064 Lisp_Object args_left
;
2065 register int i
, maxargs
;
2067 args_left
= original_args
;
2068 numargs
= Flength (args_left
);
2072 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2073 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2074 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (numargs
, Qnil
)));
2076 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2078 backtrace
.evalargs
= 0;
2079 val
= (*XSUBR (fun
)->function
) (args_left
);
2083 if (XSUBR (fun
)->max_args
== MANY
)
2085 /* Pass a vector of evaluated arguments */
2087 register int argnum
= 0;
2089 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2091 GCPRO3 (args_left
, fun
, fun
);
2095 while (!NILP (args_left
))
2097 vals
[argnum
++] = Feval (Fcar (args_left
));
2098 args_left
= Fcdr (args_left
);
2099 gcpro3
.nvars
= argnum
;
2102 backtrace
.args
= vals
;
2103 backtrace
.nargs
= XINT (numargs
);
2105 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2110 GCPRO3 (args_left
, fun
, fun
);
2111 gcpro3
.var
= argvals
;
2114 maxargs
= XSUBR (fun
)->max_args
;
2115 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2117 argvals
[i
] = Feval (Fcar (args_left
));
2123 backtrace
.args
= argvals
;
2124 backtrace
.nargs
= XINT (numargs
);
2129 val
= (*XSUBR (fun
)->function
) ();
2132 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2135 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2138 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2142 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2143 argvals
[2], argvals
[3]);
2146 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2147 argvals
[3], argvals
[4]);
2150 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2151 argvals
[3], argvals
[4], argvals
[5]);
2154 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2155 argvals
[3], argvals
[4], argvals
[5],
2160 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2161 argvals
[3], argvals
[4], argvals
[5],
2162 argvals
[6], argvals
[7]);
2166 /* Someone has created a subr that takes more arguments than
2167 is supported by this code. We need to either rewrite the
2168 subr to use a different argument protocol, or add more
2169 cases to this switch. */
2173 if (COMPILEDP (fun
))
2174 val
= apply_lambda (fun
, original_args
, 1);
2178 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2179 funcar
= Fcar (fun
);
2180 if (!SYMBOLP (funcar
))
2181 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2182 if (EQ (funcar
, Qautoload
))
2184 do_autoload (fun
, original_fun
);
2187 if (EQ (funcar
, Qmacro
))
2188 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2189 else if (EQ (funcar
, Qlambda
))
2190 val
= apply_lambda (fun
, original_args
, 1);
2192 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2198 if (backtrace
.debug_on_exit
)
2199 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2200 backtrace_list
= backtrace
.next
;
2205 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2206 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2207 Then return the value FUNCTION returns.
2208 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2209 usage: (apply FUNCTION &rest ARGUMENTS) */)
2214 register int i
, numargs
;
2215 register Lisp_Object spread_arg
;
2216 register Lisp_Object
*funcall_args
;
2218 struct gcpro gcpro1
;
2222 spread_arg
= args
[nargs
- 1];
2223 CHECK_LIST (spread_arg
);
2225 numargs
= XINT (Flength (spread_arg
));
2228 return Ffuncall (nargs
- 1, args
);
2229 else if (numargs
== 1)
2231 args
[nargs
- 1] = XCAR (spread_arg
);
2232 return Ffuncall (nargs
, args
);
2235 numargs
+= nargs
- 2;
2237 fun
= indirect_function (fun
);
2238 if (EQ (fun
, Qunbound
))
2240 /* Let funcall get the error */
2247 if (numargs
< XSUBR (fun
)->min_args
2248 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2249 goto funcall
; /* Let funcall get the error */
2250 else if (XSUBR (fun
)->max_args
> numargs
)
2252 /* Avoid making funcall cons up a yet another new vector of arguments
2253 by explicitly supplying nil's for optional values */
2254 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2255 * sizeof (Lisp_Object
));
2256 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2257 funcall_args
[++i
] = Qnil
;
2258 GCPRO1 (*funcall_args
);
2259 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2263 /* We add 1 to numargs because funcall_args includes the
2264 function itself as well as its arguments. */
2267 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2268 * sizeof (Lisp_Object
));
2269 GCPRO1 (*funcall_args
);
2270 gcpro1
.nvars
= 1 + numargs
;
2273 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2274 /* Spread the last arg we got. Its first element goes in
2275 the slot that it used to occupy, hence this value of I. */
2277 while (!NILP (spread_arg
))
2279 funcall_args
[i
++] = XCAR (spread_arg
);
2280 spread_arg
= XCDR (spread_arg
);
2283 /* By convention, the caller needs to gcpro Ffuncall's args. */
2284 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2287 /* Run hook variables in various ways. */
2289 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2290 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2291 enum run_hooks_condition
));
2293 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2294 doc
: /* Run each hook in HOOKS. Major mode functions use this.
2295 Each argument should be a symbol, a hook variable.
2296 These symbols are processed in the order specified.
2297 If a hook symbol has a non-nil value, that value may be a function
2298 or a list of functions to be called to run the hook.
2299 If the value is a function, it is called with no arguments.
2300 If it is a list, the elements are called, in order, with no arguments.
2302 Do not use `make-local-variable' to make a hook variable buffer-local.
2303 Instead, use `add-hook' and specify t for the LOCAL argument.
2304 usage: (run-hooks &rest HOOKS) */)
2309 Lisp_Object hook
[1];
2312 for (i
= 0; i
< nargs
; i
++)
2315 run_hook_with_args (1, hook
, to_completion
);
2321 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2322 Srun_hook_with_args
, 1, MANY
, 0,
2323 doc
: /* Run HOOK with the specified arguments ARGS.
2324 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2325 value, that value may be a function or a list of functions to be
2326 called to run the hook. If the value is a function, it is called with
2327 the given arguments and its return value is returned. If it is a list
2328 of functions, those functions are called, in order,
2329 with the given arguments ARGS.
2330 It is best not to depend on the value returned by `run-hook-with-args',
2333 Do not use `make-local-variable' to make a hook variable buffer-local.
2334 Instead, use `add-hook' and specify t for the LOCAL argument.
2335 usage: (run-hook-with-args HOOK &rest ARGS) */)
2340 return run_hook_with_args (nargs
, args
, to_completion
);
2343 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2344 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2345 doc
: /* Run HOOK with the specified arguments ARGS.
2346 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2347 value, that value may be a function or a list of functions to be
2348 called to run the hook. If the value is a function, it is called with
2349 the given arguments and its return value is returned.
2350 If it is a list of functions, those functions are called, in order,
2351 with the given arguments ARGS, until one of them
2352 returns a non-nil value. Then we return that value.
2353 However, if they all return nil, we return nil.
2355 Do not use `make-local-variable' to make a hook variable buffer-local.
2356 Instead, use `add-hook' and specify t for the LOCAL argument.
2357 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2362 return run_hook_with_args (nargs
, args
, until_success
);
2365 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2366 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2367 doc
: /* Run HOOK with the specified arguments ARGS.
2368 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2369 value, that value may be a function or a list of functions to be
2370 called to run the hook. If the value is a function, it is called with
2371 the given arguments and its return value is returned.
2372 If it is a list of functions, those functions are called, in order,
2373 with the given arguments ARGS, until one of them returns nil.
2374 Then we return nil. However, if they all return non-nil, we return non-nil.
2376 Do not use `make-local-variable' to make a hook variable buffer-local.
2377 Instead, use `add-hook' and specify t for the LOCAL argument.
2378 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2383 return run_hook_with_args (nargs
, args
, until_failure
);
2386 /* ARGS[0] should be a hook symbol.
2387 Call each of the functions in the hook value, passing each of them
2388 as arguments all the rest of ARGS (all NARGS - 1 elements).
2389 COND specifies a condition to test after each call
2390 to decide whether to stop.
2391 The caller (or its caller, etc) must gcpro all of ARGS,
2392 except that it isn't necessary to gcpro ARGS[0]. */
2395 run_hook_with_args (nargs
, args
, cond
)
2398 enum run_hooks_condition cond
;
2400 Lisp_Object sym
, val
, ret
;
2401 Lisp_Object globals
;
2402 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2404 /* If we are dying or still initializing,
2405 don't do anything--it would probably crash if we tried. */
2406 if (NILP (Vrun_hooks
))
2410 val
= find_symbol_value (sym
);
2411 ret
= (cond
== until_failure
? Qt
: Qnil
);
2413 if (EQ (val
, Qunbound
) || NILP (val
))
2415 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2418 return Ffuncall (nargs
, args
);
2423 GCPRO3 (sym
, val
, globals
);
2426 CONSP (val
) && ((cond
== to_completion
)
2427 || (cond
== until_success
? NILP (ret
)
2431 if (EQ (XCAR (val
), Qt
))
2433 /* t indicates this hook has a local binding;
2434 it means to run the global binding too. */
2436 for (globals
= Fdefault_value (sym
);
2437 CONSP (globals
) && ((cond
== to_completion
)
2438 || (cond
== until_success
? NILP (ret
)
2440 globals
= XCDR (globals
))
2442 args
[0] = XCAR (globals
);
2443 /* In a global value, t should not occur. If it does, we
2444 must ignore it to avoid an endless loop. */
2445 if (!EQ (args
[0], Qt
))
2446 ret
= Ffuncall (nargs
, args
);
2451 args
[0] = XCAR (val
);
2452 ret
= Ffuncall (nargs
, args
);
2461 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2462 present value of that symbol.
2463 Call each element of FUNLIST,
2464 passing each of them the rest of ARGS.
2465 The caller (or its caller, etc) must gcpro all of ARGS,
2466 except that it isn't necessary to gcpro ARGS[0]. */
2469 run_hook_list_with_args (funlist
, nargs
, args
)
2470 Lisp_Object funlist
;
2476 Lisp_Object globals
;
2477 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2481 GCPRO3 (sym
, val
, globals
);
2483 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2485 if (EQ (XCAR (val
), Qt
))
2487 /* t indicates this hook has a local binding;
2488 it means to run the global binding too. */
2490 for (globals
= Fdefault_value (sym
);
2492 globals
= XCDR (globals
))
2494 args
[0] = XCAR (globals
);
2495 /* In a global value, t should not occur. If it does, we
2496 must ignore it to avoid an endless loop. */
2497 if (!EQ (args
[0], Qt
))
2498 Ffuncall (nargs
, args
);
2503 args
[0] = XCAR (val
);
2504 Ffuncall (nargs
, args
);
2511 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2514 run_hook_with_args_2 (hook
, arg1
, arg2
)
2515 Lisp_Object hook
, arg1
, arg2
;
2517 Lisp_Object temp
[3];
2522 Frun_hook_with_args (3, temp
);
2525 /* Apply fn to arg */
2528 Lisp_Object fn
, arg
;
2530 struct gcpro gcpro1
;
2534 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2538 Lisp_Object args
[2];
2542 RETURN_UNGCPRO (Fapply (2, args
));
2544 #else /* not NO_ARG_ARRAY */
2545 RETURN_UNGCPRO (Fapply (2, &fn
));
2546 #endif /* not NO_ARG_ARRAY */
2549 /* Call function fn on no arguments */
2554 struct gcpro gcpro1
;
2557 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2560 /* Call function fn with 1 argument arg1 */
2564 Lisp_Object fn
, arg1
;
2566 struct gcpro gcpro1
;
2568 Lisp_Object args
[2];
2574 RETURN_UNGCPRO (Ffuncall (2, args
));
2575 #else /* not NO_ARG_ARRAY */
2578 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2579 #endif /* not NO_ARG_ARRAY */
2582 /* Call function fn with 2 arguments arg1, arg2 */
2585 call2 (fn
, arg1
, arg2
)
2586 Lisp_Object fn
, arg1
, arg2
;
2588 struct gcpro gcpro1
;
2590 Lisp_Object args
[3];
2596 RETURN_UNGCPRO (Ffuncall (3, args
));
2597 #else /* not NO_ARG_ARRAY */
2600 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2601 #endif /* not NO_ARG_ARRAY */
2604 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2607 call3 (fn
, arg1
, arg2
, arg3
)
2608 Lisp_Object fn
, arg1
, arg2
, arg3
;
2610 struct gcpro gcpro1
;
2612 Lisp_Object args
[4];
2619 RETURN_UNGCPRO (Ffuncall (4, args
));
2620 #else /* not NO_ARG_ARRAY */
2623 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2624 #endif /* not NO_ARG_ARRAY */
2627 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2630 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2631 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2633 struct gcpro gcpro1
;
2635 Lisp_Object args
[5];
2643 RETURN_UNGCPRO (Ffuncall (5, args
));
2644 #else /* not NO_ARG_ARRAY */
2647 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2648 #endif /* not NO_ARG_ARRAY */
2651 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2654 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2655 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2657 struct gcpro gcpro1
;
2659 Lisp_Object args
[6];
2668 RETURN_UNGCPRO (Ffuncall (6, args
));
2669 #else /* not NO_ARG_ARRAY */
2672 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2673 #endif /* not NO_ARG_ARRAY */
2676 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2679 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2680 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2682 struct gcpro gcpro1
;
2684 Lisp_Object args
[7];
2694 RETURN_UNGCPRO (Ffuncall (7, args
));
2695 #else /* not NO_ARG_ARRAY */
2698 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2699 #endif /* not NO_ARG_ARRAY */
2702 /* The caller should GCPRO all the elements of ARGS. */
2704 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2705 doc
: /* Call first argument as a function, passing remaining arguments to it.
2706 Return the value that function returns.
2707 Thus, (funcall 'cons 'x 'y) returns (x . y).
2708 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2715 int numargs
= nargs
- 1;
2716 Lisp_Object lisp_numargs
;
2718 struct backtrace backtrace
;
2719 register Lisp_Object
*internal_args
;
2723 if (consing_since_gc
> gc_cons_threshold
)
2724 Fgarbage_collect ();
2726 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2728 if (max_lisp_eval_depth
< 100)
2729 max_lisp_eval_depth
= 100;
2730 if (lisp_eval_depth
> max_lisp_eval_depth
)
2731 error ("Lisp nesting exceeds max-lisp-eval-depth");
2734 backtrace
.next
= backtrace_list
;
2735 backtrace_list
= &backtrace
;
2736 backtrace
.function
= &args
[0];
2737 backtrace
.args
= &args
[1];
2738 backtrace
.nargs
= nargs
- 1;
2739 backtrace
.evalargs
= 0;
2740 backtrace
.debug_on_exit
= 0;
2742 if (debug_on_next_call
)
2743 do_debug_on_call (Qlambda
);
2749 fun
= Findirect_function (fun
);
2755 if (numargs
< XSUBR (fun
)->min_args
2756 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2758 XSETFASTINT (lisp_numargs
, numargs
);
2759 return Fsignal (Qwrong_number_of_arguments
, Fcons (fun
, Fcons (lisp_numargs
, Qnil
)));
2762 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2763 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2765 if (XSUBR (fun
)->max_args
== MANY
)
2767 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2771 if (XSUBR (fun
)->max_args
> numargs
)
2773 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2774 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2775 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2776 internal_args
[i
] = Qnil
;
2779 internal_args
= args
+ 1;
2780 switch (XSUBR (fun
)->max_args
)
2783 val
= (*XSUBR (fun
)->function
) ();
2786 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2789 val
= (*XSUBR (fun
)->function
) (internal_args
[0],
2793 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2797 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2802 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2803 internal_args
[2], internal_args
[3],
2807 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2808 internal_args
[2], internal_args
[3],
2809 internal_args
[4], internal_args
[5]);
2812 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2813 internal_args
[2], internal_args
[3],
2814 internal_args
[4], internal_args
[5],
2819 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
2820 internal_args
[2], internal_args
[3],
2821 internal_args
[4], internal_args
[5],
2822 internal_args
[6], internal_args
[7]);
2827 /* If a subr takes more than 8 arguments without using MANY
2828 or UNEVALLED, we need to extend this function to support it.
2829 Until this is done, there is no way to call the function. */
2833 if (COMPILEDP (fun
))
2834 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2838 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2839 funcar
= Fcar (fun
);
2840 if (!SYMBOLP (funcar
))
2841 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2842 if (EQ (funcar
, Qlambda
))
2843 val
= funcall_lambda (fun
, numargs
, args
+ 1);
2844 else if (EQ (funcar
, Qautoload
))
2846 do_autoload (fun
, args
[0]);
2850 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2855 if (backtrace
.debug_on_exit
)
2856 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2857 backtrace_list
= backtrace
.next
;
2862 apply_lambda (fun
, args
, eval_flag
)
2863 Lisp_Object fun
, args
;
2866 Lisp_Object args_left
;
2867 Lisp_Object numargs
;
2868 register Lisp_Object
*arg_vector
;
2869 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2871 register Lisp_Object tem
;
2873 numargs
= Flength (args
);
2874 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2877 GCPRO3 (*arg_vector
, args_left
, fun
);
2880 for (i
= 0; i
< XINT (numargs
);)
2882 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
2883 if (eval_flag
) tem
= Feval (tem
);
2884 arg_vector
[i
++] = tem
;
2892 backtrace_list
->args
= arg_vector
;
2893 backtrace_list
->nargs
= i
;
2895 backtrace_list
->evalargs
= 0;
2896 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
2898 /* Do the debug-on-exit now, while arg_vector still exists. */
2899 if (backtrace_list
->debug_on_exit
)
2900 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
2901 /* Don't do it again when we return to eval. */
2902 backtrace_list
->debug_on_exit
= 0;
2906 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
2907 and return the result of evaluation.
2908 FUN must be either a lambda-expression or a compiled-code object. */
2911 funcall_lambda (fun
, nargs
, arg_vector
)
2914 register Lisp_Object
*arg_vector
;
2916 Lisp_Object val
, syms_left
, next
;
2917 int count
= SPECPDL_INDEX ();
2918 int i
, optional
, rest
;
2922 syms_left
= XCDR (fun
);
2923 if (CONSP (syms_left
))
2924 syms_left
= XCAR (syms_left
);
2926 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2928 else if (COMPILEDP (fun
))
2929 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
2933 i
= optional
= rest
= 0;
2934 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
2938 next
= XCAR (syms_left
);
2939 while (!SYMBOLP (next
))
2940 next
= Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2942 if (EQ (next
, Qand_rest
))
2944 else if (EQ (next
, Qand_optional
))
2948 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
2952 specbind (next
, arg_vector
[i
++]);
2954 return Fsignal (Qwrong_number_of_arguments
,
2955 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2957 specbind (next
, Qnil
);
2960 if (!NILP (syms_left
))
2961 return Fsignal (Qinvalid_function
, Fcons (fun
, Qnil
));
2963 return Fsignal (Qwrong_number_of_arguments
,
2964 Fcons (fun
, Fcons (make_number (nargs
), Qnil
)));
2967 val
= Fprogn (XCDR (XCDR (fun
)));
2970 /* If we have not actually read the bytecode string
2971 and constants vector yet, fetch them from the file. */
2972 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
2973 Ffetch_bytecode (fun
);
2974 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
2975 AREF (fun
, COMPILED_CONSTANTS
),
2976 AREF (fun
, COMPILED_STACK_DEPTH
));
2979 return unbind_to (count
, val
);
2982 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
2984 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
2990 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
2992 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
2995 tem
= AREF (object
, COMPILED_BYTECODE
);
2996 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
2997 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
2999 error ("Invalid byte code");
3001 AREF (object
, COMPILED_BYTECODE
) = XCAR (tem
);
3002 AREF (object
, COMPILED_CONSTANTS
) = XCDR (tem
);
3010 register int count
= SPECPDL_INDEX ();
3011 if (specpdl_size
>= max_specpdl_size
)
3013 if (max_specpdl_size
< 400)
3014 max_specpdl_size
= 400;
3015 if (specpdl_size
>= max_specpdl_size
)
3017 if (!NILP (Vdebug_on_error
))
3018 /* Leave room for some specpdl in the debugger. */
3019 max_specpdl_size
= specpdl_size
+ 100;
3021 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil
));
3025 if (specpdl_size
> max_specpdl_size
)
3026 specpdl_size
= max_specpdl_size
;
3027 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
3028 specpdl_ptr
= specpdl
+ count
;
3032 specbind (symbol
, value
)
3033 Lisp_Object symbol
, value
;
3036 Lisp_Object valcontents
;
3038 CHECK_SYMBOL (symbol
);
3039 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3042 /* The most common case is that of a non-constant symbol with a
3043 trivial value. Make that as fast as we can. */
3044 valcontents
= SYMBOL_VALUE (symbol
);
3045 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3047 specpdl_ptr
->symbol
= symbol
;
3048 specpdl_ptr
->old_value
= valcontents
;
3049 specpdl_ptr
->func
= NULL
;
3051 SET_SYMBOL_VALUE (symbol
, value
);
3055 Lisp_Object valcontents
;
3057 ovalue
= find_symbol_value (symbol
);
3058 specpdl_ptr
->func
= 0;
3059 specpdl_ptr
->old_value
= ovalue
;
3061 valcontents
= XSYMBOL (symbol
)->value
;
3063 if (BUFFER_LOCAL_VALUEP (valcontents
)
3064 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
3065 || BUFFER_OBJFWDP (valcontents
))
3067 Lisp_Object where
, current_buffer
;
3069 current_buffer
= Fcurrent_buffer ();
3071 /* For a local variable, record both the symbol and which
3072 buffer's or frame's value we are saving. */
3073 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3074 where
= current_buffer
;
3075 else if (!BUFFER_OBJFWDP (valcontents
)
3076 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3077 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3081 /* We're not using the `unused' slot in the specbinding
3082 structure because this would mean we have to do more
3083 work for simple variables. */
3084 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3086 /* If SYMBOL is a per-buffer variable which doesn't have a
3087 buffer-local value here, make the `let' change the global
3088 value by changing the value of SYMBOL in all buffers not
3089 having their own value. This is consistent with what
3090 happens with other buffer-local variables. */
3092 && BUFFER_OBJFWDP (valcontents
))
3095 Fset_default (symbol
, value
);
3100 specpdl_ptr
->symbol
= symbol
;
3103 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3104 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3106 set_internal (symbol
, value
, 0, 1);
3111 record_unwind_protect (function
, arg
)
3112 Lisp_Object (*function
) P_ ((Lisp_Object
));
3115 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3117 specpdl_ptr
->func
= function
;
3118 specpdl_ptr
->symbol
= Qnil
;
3119 specpdl_ptr
->old_value
= arg
;
3124 unbind_to (count
, value
)
3128 int quitf
= !NILP (Vquit_flag
);
3129 struct gcpro gcpro1
;
3134 while (specpdl_ptr
!= specpdl
+ count
)
3136 /* Copy the binding, and decrement specpdl_ptr, before we do
3137 the work to unbind it. We decrement first
3138 so that an error in unbinding won't try to unbind
3139 the same entry again, and we copy the binding first
3140 in case more bindings are made during some of the code we run. */
3142 struct specbinding this_binding
;
3143 this_binding
= *--specpdl_ptr
;
3145 if (this_binding
.func
!= 0)
3146 (*this_binding
.func
) (this_binding
.old_value
);
3147 /* If the symbol is a list, it is really (SYMBOL WHERE
3148 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3149 frame. If WHERE is a buffer or frame, this indicates we
3150 bound a variable that had a buffer-local or frame-local
3151 binding. WHERE nil means that the variable had the default
3152 value when it was bound. CURRENT-BUFFER is the buffer that
3153 was current when the variable was bound. */
3154 else if (CONSP (this_binding
.symbol
))
3156 Lisp_Object symbol
, where
;
3158 symbol
= XCAR (this_binding
.symbol
);
3159 where
= XCAR (XCDR (this_binding
.symbol
));
3162 Fset_default (symbol
, this_binding
.old_value
);
3163 else if (BUFFERP (where
))
3164 set_internal (symbol
, this_binding
.old_value
, XBUFFER (where
), 1);
3166 set_internal (symbol
, this_binding
.old_value
, NULL
, 1);
3170 /* If variable has a trivial value (no forwarding), we can
3171 just set it. No need to check for constant symbols here,
3172 since that was already done by specbind. */
3173 if (!MISCP (SYMBOL_VALUE (this_binding
.symbol
)))
3174 SET_SYMBOL_VALUE (this_binding
.symbol
, this_binding
.old_value
);
3176 set_internal (this_binding
.symbol
, this_binding
.old_value
, 0, 1);
3180 if (NILP (Vquit_flag
) && quitf
)
3187 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3188 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3189 The debugger is entered when that frame exits, if the flag is non-nil. */)
3191 Lisp_Object level
, flag
;
3193 register struct backtrace
*backlist
= backtrace_list
;
3196 CHECK_NUMBER (level
);
3198 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3200 backlist
= backlist
->next
;
3204 backlist
->debug_on_exit
= !NILP (flag
);
3209 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3210 doc
: /* Print a trace of Lisp function calls currently active.
3211 Output stream used is value of `standard-output'. */)
3214 register struct backtrace
*backlist
= backtrace_list
;
3218 extern Lisp_Object Vprint_level
;
3219 struct gcpro gcpro1
;
3221 XSETFASTINT (Vprint_level
, 3);
3228 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3229 if (backlist
->nargs
== UNEVALLED
)
3231 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3232 write_string ("\n", -1);
3236 tem
= *backlist
->function
;
3237 Fprin1 (tem
, Qnil
); /* This can QUIT */
3238 write_string ("(", -1);
3239 if (backlist
->nargs
== MANY
)
3241 for (tail
= *backlist
->args
, i
= 0;
3243 tail
= Fcdr (tail
), i
++)
3245 if (i
) write_string (" ", -1);
3246 Fprin1 (Fcar (tail
), Qnil
);
3251 for (i
= 0; i
< backlist
->nargs
; i
++)
3253 if (i
) write_string (" ", -1);
3254 Fprin1 (backlist
->args
[i
], Qnil
);
3257 write_string (")\n", -1);
3259 backlist
= backlist
->next
;
3262 Vprint_level
= Qnil
;
3267 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3268 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3269 If that frame has not evaluated the arguments yet (or is a special form),
3270 the value is (nil FUNCTION ARG-FORMS...).
3271 If that frame has evaluated its arguments and called its function already,
3272 the value is (t FUNCTION ARG-VALUES...).
3273 A &rest arg is represented as the tail of the list ARG-VALUES.
3274 FUNCTION is whatever was supplied as car of evaluated list,
3275 or a lambda expression for macro calls.
3276 If NFRAMES is more than the number of frames, the value is nil. */)
3278 Lisp_Object nframes
;
3280 register struct backtrace
*backlist
= backtrace_list
;
3284 CHECK_NATNUM (nframes
);
3286 /* Find the frame requested. */
3287 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3288 backlist
= backlist
->next
;
3292 if (backlist
->nargs
== UNEVALLED
)
3293 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3296 if (backlist
->nargs
== MANY
)
3297 tem
= *backlist
->args
;
3299 tem
= Flist (backlist
->nargs
, backlist
->args
);
3301 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3309 register struct backtrace
*backlist
;
3312 for (backlist
= backtrace_list
; backlist
; backlist
= backlist
->next
)
3314 mark_object (*backlist
->function
);
3316 if (backlist
->nargs
== UNEVALLED
|| backlist
->nargs
== MANY
)
3319 i
= backlist
->nargs
- 1;
3321 mark_object (backlist
->args
[i
]);
3328 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3329 doc
: /* *Limit on number of Lisp variable bindings & unwind-protects.
3330 If Lisp code tries to make more than this many at once,
3331 an error is signaled.
3332 You can safely use a value considerably larger than the default value,
3333 if that proves inconveniently small. However, if you increase it too far,
3334 Emacs could run out of memory trying to make the stack bigger. */);
3336 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3337 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3339 This limit serves to catch infinite recursions for you before they cause
3340 actual stack overflow in C, which would be fatal for Emacs.
3341 You can safely make it considerably larger than its default value,
3342 if that proves inconveniently small. However, if you increase it too far,
3343 Emacs could overflow the real C stack, and crash. */);
3345 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3346 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3347 If the value is t, that means do an ordinary quit.
3348 If the value equals `throw-on-input', that means quit by throwing
3349 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3350 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3351 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3354 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3355 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3356 Note that `quit-flag' will still be set by typing C-g,
3357 so a quit will be signaled as soon as `inhibit-quit' is nil.
3358 To prevent this happening, set `quit-flag' to nil
3359 before making `inhibit-quit' nil. */);
3360 Vinhibit_quit
= Qnil
;
3362 Qinhibit_quit
= intern ("inhibit-quit");
3363 staticpro (&Qinhibit_quit
);
3365 Qautoload
= intern ("autoload");
3366 staticpro (&Qautoload
);
3368 Qdebug_on_error
= intern ("debug-on-error");
3369 staticpro (&Qdebug_on_error
);
3371 Qmacro
= intern ("macro");
3372 staticpro (&Qmacro
);
3374 Qdeclare
= intern ("declare");
3375 staticpro (&Qdeclare
);
3377 /* Note that the process handling also uses Qexit, but we don't want
3378 to staticpro it twice, so we just do it here. */
3379 Qexit
= intern ("exit");
3382 Qinteractive
= intern ("interactive");
3383 staticpro (&Qinteractive
);
3385 Qcommandp
= intern ("commandp");
3386 staticpro (&Qcommandp
);
3388 Qdefun
= intern ("defun");
3389 staticpro (&Qdefun
);
3391 Qand_rest
= intern ("&rest");
3392 staticpro (&Qand_rest
);
3394 Qand_optional
= intern ("&optional");
3395 staticpro (&Qand_optional
);
3397 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3398 doc
: /* *Non-nil means errors display a backtrace buffer.
3399 More precisely, this happens for any error that is handled
3400 by the editor command loop.
3401 If the value is a list, an error only means to display a backtrace
3402 if one of its condition symbols appears in the list. */);
3403 Vstack_trace_on_error
= Qnil
;
3405 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3406 doc
: /* *Non-nil means enter debugger if an error is signaled.
3407 Does not apply to errors handled by `condition-case' or those
3408 matched by `debug-ignored-errors'.
3409 If the value is a list, an error only means to enter the debugger
3410 if one of its condition symbols appears in the list.
3411 When you evaluate an expression interactively, this variable
3412 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3413 See also variable `debug-on-quit'. */);
3414 Vdebug_on_error
= Qnil
;
3416 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3417 doc
: /* *List of errors for which the debugger should not be called.
3418 Each element may be a condition-name or a regexp that matches error messages.
3419 If any element applies to a given error, that error skips the debugger
3420 and just returns to top level.
3421 This overrides the variable `debug-on-error'.
3422 It does not apply to errors handled by `condition-case'. */);
3423 Vdebug_ignored_errors
= Qnil
;
3425 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3426 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3427 Does not apply if quit is handled by a `condition-case'.
3428 When you evaluate an expression interactively, this variable
3429 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
3432 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3433 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3435 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3436 doc
: /* Non-nil means debugger may continue execution.
3437 This is nil when the debugger is called under circumstances where it
3438 might not be safe to continue. */);
3439 debugger_may_continue
= 1;
3441 DEFVAR_LISP ("debugger", &Vdebugger
,
3442 doc
: /* Function to call to invoke debugger.
3443 If due to frame exit, args are `exit' and the value being returned;
3444 this function's value will be returned instead of that.
3445 If due to error, args are `error' and a list of the args to `signal'.
3446 If due to `apply' or `funcall' entry, one arg, `lambda'.
3447 If due to `eval' entry, one arg, t. */);
3450 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3451 doc
: /* If non-nil, this is a function for `signal' to call.
3452 It receives the same arguments that `signal' was given.
3453 The Edebug package uses this to regain control. */);
3454 Vsignal_hook_function
= Qnil
;
3456 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3457 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3458 Note that `debug-on-error', `debug-on-quit' and friends
3459 still determine whether to handle the particular condition. */);
3460 Vdebug_on_signal
= Qnil
;
3462 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3463 doc
: /* Function to process declarations in a macro definition.
3464 The function will be called with two args MACRO and DECL.
3465 MACRO is the name of the macro being defined.
3466 DECL is a list `(declare ...)' containing the declarations.
3467 The value the function returns is not used. */);
3468 Vmacro_declaration_function
= Qnil
;
3470 Vrun_hooks
= intern ("run-hooks");
3471 staticpro (&Vrun_hooks
);
3473 staticpro (&Vautoload_queue
);
3474 Vautoload_queue
= Qnil
;
3475 staticpro (&Vsignaling_function
);
3476 Vsignaling_function
= Qnil
;
3487 defsubr (&Sfunction
);
3489 defsubr (&Sdefmacro
);
3491 defsubr (&Sdefvaralias
);
3492 defsubr (&Sdefconst
);
3493 defsubr (&Suser_variable_p
);
3497 defsubr (&Smacroexpand
);
3500 defsubr (&Sunwind_protect
);
3501 defsubr (&Scondition_case
);
3503 defsubr (&Sinteractive_p
);
3504 defsubr (&Scalled_interactively_p
);
3505 defsubr (&Scommandp
);
3506 defsubr (&Sautoload
);
3509 defsubr (&Sfuncall
);
3510 defsubr (&Srun_hooks
);
3511 defsubr (&Srun_hook_with_args
);
3512 defsubr (&Srun_hook_with_args_until_success
);
3513 defsubr (&Srun_hook_with_args_until_failure
);
3514 defsubr (&Sfetch_bytecode
);
3515 defsubr (&Sbacktrace_debug
);
3516 defsubr (&Sbacktrace
);
3517 defsubr (&Sbacktrace_frame
);
3520 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3521 (do not change this comment) */