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
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, or (at your option)
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; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
26 #include "blockinput.h"
29 #include "dispextern.h"
36 /* This definition is duplicated in alloc.c and keyboard.c */
37 /* Putting it in lisp.h makes cc bomb out! */
41 struct backtrace
*next
;
42 Lisp_Object
*function
;
43 Lisp_Object
*args
; /* Points to vector of args. */
44 int nargs
; /* Length of vector.
45 If nargs is UNEVALLED, args points to slot holding
46 list of unevalled args */
48 /* Nonzero means call value of debugger when done with this operation. */
52 struct backtrace
*backtrace_list
;
54 /* This structure helps implement the `catch' and `throw' control
55 structure. A struct catchtag contains all the information needed
56 to restore the state of the interpreter after a non-local jump.
58 Handlers for error conditions (represented by `struct handler'
59 structures) just point to a catch tag to do the cleanup required
62 catchtag structures are chained together in the C calling stack;
63 the `next' member points to the next outer catchtag.
65 A call like (throw TAG VAL) searches for a catchtag whose `tag'
66 member is TAG, and then unbinds to it. The `val' member is used to
67 hold VAL while the stack is unwound; `val' is returned as the value
70 All the other members are concerned with restoring the interpreter
77 struct catchtag
*next
;
80 struct backtrace
*backlist
;
81 struct handler
*handlerlist
;
84 int poll_suppress_count
;
85 int interrupt_input_blocked
;
86 struct byte_stack
*byte_stack
;
89 struct catchtag
*catchlist
;
92 /* Count levels of GCPRO to detect failure to UNGCPRO. */
96 Lisp_Object Qautoload
, Qmacro
, Qexit
, Qinteractive
, Qcommandp
, Qdefun
;
97 Lisp_Object Qinhibit_quit
, Vinhibit_quit
, Vquit_flag
;
98 Lisp_Object Qand_rest
, Qand_optional
;
99 Lisp_Object Qdebug_on_error
;
100 Lisp_Object Qdeclare
;
103 /* This holds either the symbol `run-hooks' or nil.
104 It is nil at an early stage of startup, and when Emacs
107 Lisp_Object Vrun_hooks
;
109 /* Non-nil means record all fset's and provide's, to be undone
110 if the file being autoloaded is not fully loaded.
111 They are recorded by being consed onto the front of Vautoload_queue:
112 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
114 Lisp_Object Vautoload_queue
;
116 /* Current number of specbindings allocated in specpdl. */
120 /* Pointer to beginning of specpdl. */
122 struct specbinding
*specpdl
;
124 /* Pointer to first unused element in specpdl. */
126 struct specbinding
*specpdl_ptr
;
128 /* Maximum size allowed for specpdl allocation */
130 EMACS_INT max_specpdl_size
;
132 /* Depth in Lisp evaluations and function calls. */
136 /* Maximum allowed depth in Lisp evaluations and function calls. */
138 EMACS_INT max_lisp_eval_depth
;
140 /* Nonzero means enter debugger before next function call */
142 int debug_on_next_call
;
144 /* Non-zero means debugger may continue. This is zero when the
145 debugger is called during redisplay, where it might not be safe to
146 continue the interrupted redisplay. */
148 int debugger_may_continue
;
150 /* List of conditions (non-nil atom means all) which cause a backtrace
151 if an error is handled by the command loop's error handler. */
153 Lisp_Object Vstack_trace_on_error
;
155 /* List of conditions (non-nil atom means all) which enter the debugger
156 if an error is handled by the command loop's error handler. */
158 Lisp_Object Vdebug_on_error
;
160 /* List of conditions and regexps specifying error messages which
161 do not enter the debugger even if Vdebug_on_error says they should. */
163 Lisp_Object Vdebug_ignored_errors
;
165 /* Non-nil means call the debugger even if the error will be handled. */
167 Lisp_Object Vdebug_on_signal
;
169 /* Hook for edebug to use. */
171 Lisp_Object Vsignal_hook_function
;
173 /* Nonzero means enter debugger if a quit signal
174 is handled by the command loop's error handler. */
178 /* The value of num_nonmacro_input_events as of the last time we
179 started to enter the debugger. If we decide to enter the debugger
180 again when this is still equal to num_nonmacro_input_events, then we
181 know that the debugger itself has an error, and we should just
182 signal the error instead of entering an infinite loop of debugger
185 int when_entered_debugger
;
187 Lisp_Object Vdebugger
;
189 /* The function from which the last `signal' was called. Set in
192 Lisp_Object Vsignaling_function
;
194 /* Set to non-zero while processing X events. Checked in Feval to
195 make sure the Lisp interpreter isn't called from a signal handler,
196 which is unsafe because the interpreter isn't reentrant. */
200 /* Function to process declarations in defmacro forms. */
202 Lisp_Object Vmacro_declaration_function
;
204 extern Lisp_Object Qrisky_local_variable
;
206 static Lisp_Object funcall_lambda
P_ ((Lisp_Object
, int, Lisp_Object
*));
207 static void unwind_to_catch
P_ ((struct catchtag
*, Lisp_Object
)) NO_RETURN
;
210 /* "gcc -O3" enables automatic function inlining, which optimizes out
211 the arguments for the invocations of these functions, whereas they
212 expect these values on the stack. */
213 Lisp_Object
apply1 () __attribute__((noinline
));
214 Lisp_Object
call2 () __attribute__((noinline
));
221 specpdl
= (struct specbinding
*) xmalloc (specpdl_size
* sizeof (struct specbinding
));
222 specpdl_ptr
= specpdl
;
223 /* Don't forget to update docs (lispref node "Local Variables"). */
224 max_specpdl_size
= 1000;
225 max_lisp_eval_depth
= 400;
233 specpdl_ptr
= specpdl
;
238 debug_on_next_call
= 0;
243 /* This is less than the initial value of num_nonmacro_input_events. */
244 when_entered_debugger
= -1;
247 /* unwind-protect function used by call_debugger. */
250 restore_stack_limits (data
)
253 max_specpdl_size
= XINT (XCAR (data
));
254 max_lisp_eval_depth
= XINT (XCDR (data
));
258 /* Call the Lisp debugger, giving it argument ARG. */
264 int debug_while_redisplaying
;
265 int count
= SPECPDL_INDEX ();
267 int old_max
= max_specpdl_size
;
269 /* Temporarily bump up the stack limits,
270 so the debugger won't run out of stack. */
272 max_specpdl_size
+= 1;
273 record_unwind_protect (restore_stack_limits
,
274 Fcons (make_number (old_max
),
275 make_number (max_lisp_eval_depth
)));
276 max_specpdl_size
= old_max
;
278 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
279 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
281 if (SPECPDL_INDEX () + 100 > max_specpdl_size
)
282 max_specpdl_size
= SPECPDL_INDEX () + 100;
284 #ifdef HAVE_X_WINDOWS
285 if (display_hourglass_p
)
289 debug_on_next_call
= 0;
290 when_entered_debugger
= num_nonmacro_input_events
;
292 /* Resetting redisplaying_p to 0 makes sure that debug output is
293 displayed if the debugger is invoked during redisplay. */
294 debug_while_redisplaying
= redisplaying_p
;
296 specbind (intern ("debugger-may-continue"),
297 debug_while_redisplaying
? Qnil
: Qt
);
298 specbind (Qinhibit_redisplay
, Qnil
);
299 specbind (Qdebug_on_error
, Qnil
);
301 #if 0 /* Binding this prevents execution of Lisp code during
302 redisplay, which necessarily leads to display problems. */
303 specbind (Qinhibit_eval_during_redisplay
, Qt
);
306 val
= apply1 (Vdebugger
, arg
);
308 /* Interrupting redisplay and resuming it later is not safe under
309 all circumstances. So, when the debugger returns, abort the
310 interrupted redisplay by going back to the top-level. */
311 if (debug_while_redisplaying
)
314 return unbind_to (count
, val
);
318 do_debug_on_call (code
)
321 debug_on_next_call
= 0;
322 backtrace_list
->debug_on_exit
= 1;
323 call_debugger (Fcons (code
, Qnil
));
326 /* NOTE!!! Every function that can call EVAL must protect its args
327 and temporaries from garbage collection while it needs them.
328 The definition of `For' shows what you have to do. */
330 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
331 doc
: /* Eval args until one of them yields non-nil, then return that value.
332 The remaining args are not evalled at all.
333 If all args return nil, return nil.
334 usage: (or CONDITIONS...) */)
338 register Lisp_Object val
= Qnil
;
345 val
= Feval (XCAR (args
));
355 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
356 doc
: /* Eval args until one of them yields nil, then return nil.
357 The remaining args are not evalled at all.
358 If no arg yields nil, return the last arg's value.
359 usage: (and CONDITIONS...) */)
363 register Lisp_Object val
= Qt
;
370 val
= Feval (XCAR (args
));
380 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
381 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
382 Returns the value of THEN or the value of the last of the ELSE's.
383 THEN must be one expression, but ELSE... can be zero or more expressions.
384 If COND yields nil, and there are no ELSE's, the value is nil.
385 usage: (if COND THEN ELSE...) */)
389 register Lisp_Object cond
;
393 cond
= Feval (Fcar (args
));
397 return Feval (Fcar (Fcdr (args
)));
398 return Fprogn (Fcdr (Fcdr (args
)));
401 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
402 doc
: /* Try each clause until one succeeds.
403 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
404 and, if the value is non-nil, this clause succeeds:
405 then the expressions in BODY are evaluated and the last one's
406 value is the value of the cond-form.
407 If no clause succeeds, cond returns nil.
408 If a clause has one element, as in (CONDITION),
409 CONDITION's value if non-nil is returned from the cond-form.
410 usage: (cond CLAUSES...) */)
414 register Lisp_Object clause
, val
;
421 clause
= Fcar (args
);
422 val
= Feval (Fcar (clause
));
425 if (!EQ (XCDR (clause
), Qnil
))
426 val
= Fprogn (XCDR (clause
));
436 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
437 doc
: /* Eval BODY forms sequentially and return value of last one.
438 usage: (progn BODY...) */)
442 register Lisp_Object val
= Qnil
;
449 val
= Feval (XCAR (args
));
457 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
458 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
459 The value of FIRST is saved during the evaluation of the remaining args,
460 whose values are discarded.
461 usage: (prog1 FIRST BODY...) */)
466 register Lisp_Object args_left
;
467 struct gcpro gcpro1
, gcpro2
;
468 register int argnum
= 0;
480 val
= Feval (Fcar (args_left
));
482 Feval (Fcar (args_left
));
483 args_left
= Fcdr (args_left
);
485 while (!NILP(args_left
));
491 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
492 doc
: /* Eval FORM1, FORM2 and BODY sequentially; value from FORM2.
493 The value of FORM2 is saved during the evaluation of the
494 remaining args, whose values are discarded.
495 usage: (prog2 FORM1 FORM2 BODY...) */)
500 register Lisp_Object args_left
;
501 struct gcpro gcpro1
, gcpro2
;
502 register int argnum
= -1;
516 val
= Feval (Fcar (args_left
));
518 Feval (Fcar (args_left
));
519 args_left
= Fcdr (args_left
);
521 while (!NILP (args_left
));
527 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
528 doc
: /* Set each SYM to the value of its VAL.
529 The symbols SYM are variables; they are literal (not evaluated).
530 The values VAL are expressions; they are evaluated.
531 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
532 The second VAL is not computed until after the first SYM is set, and so on;
533 each VAL can use the new value of variables set earlier in the `setq'.
534 The return value of the `setq' form is the value of the last VAL.
535 usage: (setq [SYM VAL]...) */)
539 register Lisp_Object args_left
;
540 register Lisp_Object val
, sym
;
551 val
= Feval (Fcar (Fcdr (args_left
)));
552 sym
= Fcar (args_left
);
554 args_left
= Fcdr (Fcdr (args_left
));
556 while (!NILP(args_left
));
562 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
563 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
564 usage: (quote ARG) */)
571 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
572 doc
: /* Like `quote', but preferred for objects which are functions.
573 In byte compilation, `function' causes its argument to be compiled.
574 `quote' cannot do that.
575 usage: (function ARG) */)
583 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
584 doc
: /* Return t if the function was run directly by user input.
585 This means that the function was called with `call-interactively'
586 \(which includes being called as the binding of a key)
587 and input is currently coming from the keyboard (not in keyboard macro),
588 and Emacs is not running in batch mode (`noninteractive' is nil).
590 The only known proper use of `interactive-p' is in deciding whether to
591 display a helpful message, or how to display it. If you're thinking
592 of using it for any other purpose, it is quite likely that you're
593 making a mistake. Think: what do you want to do when the command is
594 called from a keyboard macro?
596 If you want to test whether your function was called with
597 `call-interactively', the way to do that is by adding an extra
598 optional argument, and making the `interactive' spec specify non-nil
599 unconditionally for that argument. (`p' is a good way to do this.) */)
602 return (INTERACTIVE
&& interactive_p (1)) ? Qt
: Qnil
;
606 DEFUN ("called-interactively-p", Fcalled_interactively_p
, Scalled_interactively_p
, 0, 0, 0,
607 doc
: /* Return t if the function using this was called with `call-interactively'.
608 This is used for implementing advice and other function-modifying
611 The cleanest way to test whether your function was called with
612 `call-interactively' is by adding an extra optional argument,
613 and making the `interactive' spec specify non-nil unconditionally
614 for that argument. (`p' is a good way to do this.) */)
617 return interactive_p (1) ? Qt
: Qnil
;
621 /* Return 1 if function in which this appears was called using
624 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
625 called is a built-in. */
628 interactive_p (exclude_subrs_p
)
631 struct backtrace
*btp
;
634 btp
= backtrace_list
;
636 /* If this isn't a byte-compiled function, there may be a frame at
637 the top for Finteractive_p. If so, skip it. */
638 fun
= Findirect_function (*btp
->function
, Qnil
);
639 if (SUBRP (fun
) && (XSUBR (fun
) == &Sinteractive_p
640 || XSUBR (fun
) == &Scalled_interactively_p
))
643 /* If we're running an Emacs 18-style byte-compiled function, there
644 may be a frame for Fbytecode at the top level. In any version of
645 Emacs there can be Fbytecode frames for subexpressions evaluated
646 inside catch and condition-case. Skip past them.
648 If this isn't a byte-compiled function, then we may now be
649 looking at several frames for special forms. Skip past them. */
651 && (EQ (*btp
->function
, Qbytecode
)
652 || btp
->nargs
== UNEVALLED
))
655 /* btp now points at the frame of the innermost function that isn't
656 a special form, ignoring frames for Finteractive_p and/or
657 Fbytecode at the top. If this frame is for a built-in function
658 (such as load or eval-region) return nil. */
659 fun
= Findirect_function (*btp
->function
, Qnil
);
660 if (exclude_subrs_p
&& SUBRP (fun
))
663 /* btp points to the frame of a Lisp function that called interactive-p.
664 Return t if that function was called interactively. */
665 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
671 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
672 doc
: /* Define NAME as a function.
673 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
674 See also the function `interactive'.
675 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
679 register Lisp_Object fn_name
;
680 register Lisp_Object defn
;
682 fn_name
= Fcar (args
);
683 CHECK_SYMBOL (fn_name
);
684 defn
= Fcons (Qlambda
, Fcdr (args
));
685 if (!NILP (Vpurify_flag
))
686 defn
= Fpurecopy (defn
);
687 if (CONSP (XSYMBOL (fn_name
)->function
)
688 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
689 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
690 Ffset (fn_name
, defn
);
691 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
695 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
696 doc
: /* Define NAME as a macro.
697 The actual definition looks like
698 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
699 When the macro is called, as in (NAME ARGS...),
700 the function (lambda ARGLIST BODY...) is applied to
701 the list ARGS... as it appears in the expression,
702 and the result should be a form to be evaluated instead of the original.
704 DECL is a declaration, optional, which can specify how to indent
705 calls to this macro and how Edebug should handle it. It looks like this:
707 The elements can look like this:
709 Set NAME's `lisp-indent-function' property to INDENT.
712 Set NAME's `edebug-form-spec' property to DEBUG. (This is
713 equivalent to writing a `def-edebug-spec' for the macro.)
714 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
718 register Lisp_Object fn_name
;
719 register Lisp_Object defn
;
720 Lisp_Object lambda_list
, doc
, tail
;
722 fn_name
= Fcar (args
);
723 CHECK_SYMBOL (fn_name
);
724 lambda_list
= Fcar (Fcdr (args
));
725 tail
= Fcdr (Fcdr (args
));
728 if (STRINGP (Fcar (tail
)))
734 while (CONSP (Fcar (tail
))
735 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
737 if (!NILP (Vmacro_declaration_function
))
741 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
749 tail
= Fcons (lambda_list
, tail
);
751 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
752 defn
= Fcons (Qmacro
, Fcons (Qlambda
, tail
));
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
772 The return value is BASE-VARIABLE. */)
773 (new_alias
, base_variable
, docstring
)
774 Lisp_Object new_alias
, base_variable
, docstring
;
776 struct Lisp_Symbol
*sym
;
778 CHECK_SYMBOL (new_alias
);
779 CHECK_SYMBOL (base_variable
);
781 if (SYMBOL_CONSTANT_P (new_alias
))
782 error ("Cannot make a constant an alias");
784 sym
= XSYMBOL (new_alias
);
785 sym
->indirect_variable
= 1;
786 sym
->value
= base_variable
;
787 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
788 LOADHIST_ATTACH (new_alias
);
789 if (!NILP (docstring
))
790 Fput (new_alias
, Qvariable_documentation
, docstring
);
792 Fput (new_alias
, Qvariable_documentation
, Qnil
);
794 return base_variable
;
798 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
799 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
800 You are not required to define a variable in order to use it,
801 but the definition can supply documentation and an initial value
802 in a way that tags can recognize.
804 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
805 If SYMBOL is buffer-local, its default value is what is set;
806 buffer-local values are not affected.
807 INITVALUE and DOCSTRING are optional.
808 If DOCSTRING starts with *, this variable is identified as a user option.
809 This means that M-x set-variable recognizes it.
810 See also `user-variable-p'.
811 If INITVALUE is missing, SYMBOL's value is not set.
813 If SYMBOL has a local binding, then this form affects the local
814 binding. This is usually not what you want. Thus, if you need to
815 load a file defining variables, with this form or with `defconst' or
816 `defcustom', you should always load that file _outside_ any bindings
817 for these variables. \(`defconst' and `defcustom' behave similarly in
819 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
823 register Lisp_Object sym
, tem
, tail
;
827 if (!NILP (Fcdr (Fcdr (tail
))))
828 error ("Too many arguments");
830 tem
= Fdefault_boundp (sym
);
833 if (SYMBOL_CONSTANT_P (sym
))
835 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
836 Lisp_Object tem
= Fcar (tail
);
838 && EQ (XCAR (tem
), Qquote
)
839 && CONSP (XCDR (tem
))
840 && EQ (XCAR (XCDR (tem
)), sym
)))
841 error ("Constant symbol `%s' specified in defvar",
842 SDATA (SYMBOL_NAME (sym
)));
846 Fset_default (sym
, Feval (Fcar (tail
)));
848 { /* Check if there is really a global binding rather than just a let
849 binding that shadows the global unboundness of the var. */
850 volatile struct specbinding
*pdl
= specpdl_ptr
;
851 while (--pdl
>= specpdl
)
853 if (EQ (pdl
->symbol
, sym
) && !pdl
->func
854 && EQ (pdl
->old_value
, Qunbound
))
856 message_with_string ("Warning: defvar ignored because %s is let-bound",
857 SYMBOL_NAME (sym
), 1);
866 if (!NILP (Vpurify_flag
))
867 tem
= Fpurecopy (tem
);
868 Fput (sym
, Qvariable_documentation
, tem
);
870 LOADHIST_ATTACH (sym
);
873 /* Simple (defvar <var>) should not count as a definition at all.
874 It could get in the way of other definitions, and unloading this
875 package could try to make the variable unbound. */
881 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
882 doc
: /* Define SYMBOL as a constant variable.
883 The intent is that neither programs nor users should ever change this value.
884 Always sets the value of SYMBOL to the result of evalling INITVALUE.
885 If SYMBOL is buffer-local, its default value is what is set;
886 buffer-local values are not affected.
887 DOCSTRING is optional.
889 If SYMBOL has a local binding, then this form sets the local binding's
890 value. However, you should normally not make local bindings for
891 variables defined with this form.
892 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
896 register Lisp_Object sym
, tem
;
899 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
900 error ("Too many arguments");
902 tem
= Feval (Fcar (Fcdr (args
)));
903 if (!NILP (Vpurify_flag
))
904 tem
= Fpurecopy (tem
);
905 Fset_default (sym
, tem
);
906 tem
= Fcar (Fcdr (Fcdr (args
)));
909 if (!NILP (Vpurify_flag
))
910 tem
= Fpurecopy (tem
);
911 Fput (sym
, Qvariable_documentation
, tem
);
913 Fput (sym
, Qrisky_local_variable
, Qt
);
914 LOADHIST_ATTACH (sym
);
918 /* Error handler used in Fuser_variable_p. */
920 user_variable_p_eh (ignore
)
926 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
927 doc
: /* Return t if VARIABLE is intended to be set and modified by users.
928 \(The alternative is a variable used internally in a Lisp program.)
929 A variable is a user variable if
930 \(1) the first character of its documentation is `*', or
931 \(2) it is customizable (its property list contains a non-nil value
932 of `standard-value' or `custom-autoload'), or
933 \(3) it is an alias for another user variable.
934 Return nil if VARIABLE is an alias and there is a loop in the
935 chain of symbols. */)
937 Lisp_Object variable
;
939 Lisp_Object documentation
;
941 if (!SYMBOLP (variable
))
944 /* If indirect and there's an alias loop, don't check anything else. */
945 if (XSYMBOL (variable
)->indirect_variable
946 && NILP (internal_condition_case_1 (indirect_variable
, variable
,
947 Qt
, user_variable_p_eh
)))
952 documentation
= Fget (variable
, Qvariable_documentation
);
953 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
955 if (STRINGP (documentation
)
956 && ((unsigned char) SREF (documentation
, 0) == '*'))
958 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
959 if (CONSP (documentation
)
960 && STRINGP (XCAR (documentation
))
961 && INTEGERP (XCDR (documentation
))
962 && XINT (XCDR (documentation
)) < 0)
964 /* Customizable? See `custom-variable-p'. */
965 if ((!NILP (Fget (variable
, intern ("standard-value"))))
966 || (!NILP (Fget (variable
, intern ("custom-autoload")))))
969 if (!XSYMBOL (variable
)->indirect_variable
)
972 /* An indirect variable? Let's follow the chain. */
973 variable
= XSYMBOL (variable
)->value
;
977 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
978 doc
: /* Bind variables according to VARLIST then eval BODY.
979 The value of the last form in BODY is returned.
980 Each element of VARLIST is a symbol (which is bound to nil)
981 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
982 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
983 usage: (let* VARLIST BODY...) */)
987 Lisp_Object varlist
, val
, elt
;
988 int count
= SPECPDL_INDEX ();
989 struct gcpro gcpro1
, gcpro2
, gcpro3
;
991 GCPRO3 (args
, elt
, varlist
);
993 varlist
= Fcar (args
);
994 while (!NILP (varlist
))
997 elt
= Fcar (varlist
);
999 specbind (elt
, Qnil
);
1000 else if (! NILP (Fcdr (Fcdr (elt
))))
1001 signal_error ("`let' bindings can have only one value-form", elt
);
1004 val
= Feval (Fcar (Fcdr (elt
)));
1005 specbind (Fcar (elt
), val
);
1007 varlist
= Fcdr (varlist
);
1010 val
= Fprogn (Fcdr (args
));
1011 return unbind_to (count
, val
);
1014 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
1015 doc
: /* Bind variables according to VARLIST then eval BODY.
1016 The value of the last form in BODY is returned.
1017 Each element of VARLIST is a symbol (which is bound to nil)
1018 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1019 All the VALUEFORMs are evalled before any symbols are bound.
1020 usage: (let VARLIST BODY...) */)
1024 Lisp_Object
*temps
, tem
;
1025 register Lisp_Object elt
, varlist
;
1026 int count
= SPECPDL_INDEX ();
1027 register int argnum
;
1028 struct gcpro gcpro1
, gcpro2
;
1030 varlist
= Fcar (args
);
1032 /* Make space to hold the values to give the bound variables */
1033 elt
= Flength (varlist
);
1034 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
1036 /* Compute the values and store them in `temps' */
1038 GCPRO2 (args
, *temps
);
1041 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
1044 elt
= Fcar (varlist
);
1046 temps
[argnum
++] = Qnil
;
1047 else if (! NILP (Fcdr (Fcdr (elt
))))
1048 signal_error ("`let' bindings can have only one value-form", elt
);
1050 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
1051 gcpro2
.nvars
= argnum
;
1055 varlist
= Fcar (args
);
1056 for (argnum
= 0; !NILP (varlist
); varlist
= Fcdr (varlist
))
1058 elt
= Fcar (varlist
);
1059 tem
= temps
[argnum
++];
1061 specbind (elt
, tem
);
1063 specbind (Fcar (elt
), tem
);
1066 elt
= Fprogn (Fcdr (args
));
1067 return unbind_to (count
, elt
);
1070 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
1071 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
1072 The order of execution is thus TEST, BODY, TEST, BODY and so on
1073 until TEST returns nil.
1074 usage: (while TEST BODY...) */)
1078 Lisp_Object test
, body
;
1079 struct gcpro gcpro1
, gcpro2
;
1081 GCPRO2 (test
, body
);
1085 while (!NILP (Feval (test
)))
1095 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1096 doc
: /* Return result of expanding macros at top level of FORM.
1097 If FORM is not a macro call, it is returned unchanged.
1098 Otherwise, the macro is expanded and the expansion is considered
1099 in place of FORM. When a non-macro-call results, it is returned.
1101 The second optional arg ENVIRONMENT specifies an environment of macro
1102 definitions to shadow the loaded ones for use in file byte-compilation. */)
1105 Lisp_Object environment
;
1107 /* With cleanups from Hallvard Furuseth. */
1108 register Lisp_Object expander
, sym
, def
, tem
;
1112 /* Come back here each time we expand a macro call,
1113 in case it expands into another macro call. */
1116 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1117 def
= sym
= XCAR (form
);
1119 /* Trace symbols aliases to other symbols
1120 until we get a symbol that is not an alias. */
1121 while (SYMBOLP (def
))
1125 tem
= Fassq (sym
, environment
);
1128 def
= XSYMBOL (sym
)->function
;
1129 if (!EQ (def
, Qunbound
))
1134 /* Right now TEM is the result from SYM in ENVIRONMENT,
1135 and if TEM is nil then DEF is SYM's function definition. */
1138 /* SYM is not mentioned in ENVIRONMENT.
1139 Look at its function definition. */
1140 if (EQ (def
, Qunbound
) || !CONSP (def
))
1141 /* Not defined or definition not suitable */
1143 if (EQ (XCAR (def
), Qautoload
))
1145 /* Autoloading function: will it be a macro when loaded? */
1146 tem
= Fnth (make_number (4), def
);
1147 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1148 /* Yes, load it and try again. */
1150 struct gcpro gcpro1
;
1152 do_autoload (def
, sym
);
1159 else if (!EQ (XCAR (def
), Qmacro
))
1161 else expander
= XCDR (def
);
1165 expander
= XCDR (tem
);
1166 if (NILP (expander
))
1169 form
= apply1 (expander
, XCDR (form
));
1174 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1175 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1176 TAG is evalled to get the tag to use; it must not be nil.
1178 Then the BODY is executed.
1179 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1180 If no throw happens, `catch' returns the value of the last BODY form.
1181 If a throw happens, it specifies the value to return from `catch'.
1182 usage: (catch TAG BODY...) */)
1186 register Lisp_Object tag
;
1187 struct gcpro gcpro1
;
1190 tag
= Feval (Fcar (args
));
1192 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1195 /* Set up a catch, then call C function FUNC on argument ARG.
1196 FUNC should return a Lisp_Object.
1197 This is how catches are done from within C code. */
1200 internal_catch (tag
, func
, arg
)
1202 Lisp_Object (*func
) ();
1205 /* This structure is made part of the chain `catchlist'. */
1208 /* Fill in the components of c, and put it on the list. */
1212 c
.backlist
= backtrace_list
;
1213 c
.handlerlist
= handlerlist
;
1214 c
.lisp_eval_depth
= lisp_eval_depth
;
1215 c
.pdlcount
= SPECPDL_INDEX ();
1216 c
.poll_suppress_count
= poll_suppress_count
;
1217 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1218 c
.gcpro
= gcprolist
;
1219 c
.byte_stack
= byte_stack_list
;
1223 if (! _setjmp (c
.jmp
))
1224 c
.val
= (*func
) (arg
);
1226 /* Throw works by a longjmp that comes right here. */
1231 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1232 jump to that CATCH, returning VALUE as the value of that catch.
1234 This is the guts Fthrow and Fsignal; they differ only in the way
1235 they choose the catch tag to throw to. A catch tag for a
1236 condition-case form has a TAG of Qnil.
1238 Before each catch is discarded, unbind all special bindings and
1239 execute all unwind-protect clauses made above that catch. Unwind
1240 the handler stack as we go, so that the proper handlers are in
1241 effect for each unwind-protect clause we run. At the end, restore
1242 some static info saved in CATCH, and longjmp to the location
1245 This is used for correct unwinding in Fthrow and Fsignal. */
1248 unwind_to_catch (catch, value
)
1249 struct catchtag
*catch;
1252 register int last_time
;
1254 /* Save the value in the tag. */
1257 /* Restore certain special C variables. */
1258 set_poll_suppress_count (catch->poll_suppress_count
);
1259 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked
);
1260 handling_signal
= 0;
1265 last_time
= catchlist
== catch;
1267 /* Unwind the specpdl stack, and then restore the proper set of
1269 unbind_to (catchlist
->pdlcount
, Qnil
);
1270 handlerlist
= catchlist
->handlerlist
;
1271 catchlist
= catchlist
->next
;
1273 while (! last_time
);
1276 /* If x_catch_errors was done, turn it off now.
1277 (First we give unbind_to a chance to do that.) */
1278 x_fully_uncatch_errors ();
1281 byte_stack_list
= catch->byte_stack
;
1282 gcprolist
= catch->gcpro
;
1285 gcpro_level
= gcprolist
->level
+ 1;
1289 backtrace_list
= catch->backlist
;
1290 lisp_eval_depth
= catch->lisp_eval_depth
;
1292 _longjmp (catch->jmp
, 1);
1295 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1296 doc
: /* Throw to the catch for TAG and return VALUE from it.
1297 Both TAG and VALUE are evalled. */)
1299 register Lisp_Object tag
, value
;
1301 register struct catchtag
*c
;
1304 for (c
= catchlist
; c
; c
= c
->next
)
1306 if (EQ (c
->tag
, tag
))
1307 unwind_to_catch (c
, value
);
1309 xsignal2 (Qno_catch
, tag
, value
);
1313 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1314 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1315 If BODYFORM completes normally, its value is returned
1316 after executing the UNWINDFORMS.
1317 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1318 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1323 int count
= SPECPDL_INDEX ();
1325 record_unwind_protect (Fprogn
, Fcdr (args
));
1326 val
= Feval (Fcar (args
));
1327 return unbind_to (count
, val
);
1330 /* Chain of condition handlers currently in effect.
1331 The elements of this chain are contained in the stack frames
1332 of Fcondition_case and internal_condition_case.
1333 When an error is signaled (by calling Fsignal, below),
1334 this chain is searched for an element that applies. */
1336 struct handler
*handlerlist
;
1338 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1339 doc
: /* Regain control when an error is signaled.
1340 Executes BODYFORM and returns its value if no error happens.
1341 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1342 where the BODY is made of Lisp expressions.
1344 A handler is applicable to an error
1345 if CONDITION-NAME is one of the error's condition names.
1346 If an error happens, the first applicable handler is run.
1348 The car of a handler may be a list of condition names
1349 instead of a single condition name. Then it handles all of them.
1351 When a handler handles an error, control returns to the `condition-case'
1352 and it executes the handler's BODY...
1353 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA) from the error.
1354 (If VAR is nil, the handler can't access that information.)
1355 Then the value of the last BODY form is returned from the `condition-case'
1358 See also the function `signal' for more info.
1359 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1363 register Lisp_Object bodyform
, handlers
;
1364 volatile Lisp_Object var
;
1367 bodyform
= Fcar (Fcdr (args
));
1368 handlers
= Fcdr (Fcdr (args
));
1370 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1373 /* Like Fcondition_case, but the args are separate
1374 rather than passed in a list. Used by Fbyte_code. */
1377 internal_lisp_condition_case (var
, bodyform
, handlers
)
1378 volatile Lisp_Object var
;
1379 Lisp_Object bodyform
, handlers
;
1387 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1393 && (SYMBOLP (XCAR (tem
))
1394 || CONSP (XCAR (tem
))))))
1395 error ("Invalid condition handler", tem
);
1400 c
.backlist
= backtrace_list
;
1401 c
.handlerlist
= handlerlist
;
1402 c
.lisp_eval_depth
= lisp_eval_depth
;
1403 c
.pdlcount
= SPECPDL_INDEX ();
1404 c
.poll_suppress_count
= poll_suppress_count
;
1405 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1406 c
.gcpro
= gcprolist
;
1407 c
.byte_stack
= byte_stack_list
;
1408 if (_setjmp (c
.jmp
))
1411 specbind (h
.var
, c
.val
);
1412 val
= Fprogn (Fcdr (h
.chosen_clause
));
1414 /* Note that this just undoes the binding of h.var; whoever
1415 longjumped to us unwound the stack to c.pdlcount before
1417 unbind_to (c
.pdlcount
, Qnil
);
1424 h
.handler
= handlers
;
1425 h
.next
= handlerlist
;
1429 val
= Feval (bodyform
);
1431 handlerlist
= h
.next
;
1435 /* Call the function BFUN with no arguments, catching errors within it
1436 according to HANDLERS. If there is an error, call HFUN with
1437 one argument which is the data that describes the error:
1440 HANDLERS can be a list of conditions to catch.
1441 If HANDLERS is Qt, catch all errors.
1442 If HANDLERS is Qerror, catch all errors
1443 but allow the debugger to run if that is enabled. */
1446 internal_condition_case (bfun
, handlers
, hfun
)
1447 Lisp_Object (*bfun
) ();
1448 Lisp_Object handlers
;
1449 Lisp_Object (*hfun
) ();
1455 /* Since Fsignal will close off all calls to x_catch_errors,
1456 we will get the wrong results if some are not closed now. */
1458 if (x_catching_errors ())
1464 c
.backlist
= backtrace_list
;
1465 c
.handlerlist
= handlerlist
;
1466 c
.lisp_eval_depth
= lisp_eval_depth
;
1467 c
.pdlcount
= SPECPDL_INDEX ();
1468 c
.poll_suppress_count
= poll_suppress_count
;
1469 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1470 c
.gcpro
= gcprolist
;
1471 c
.byte_stack
= byte_stack_list
;
1472 if (_setjmp (c
.jmp
))
1474 return (*hfun
) (c
.val
);
1478 h
.handler
= handlers
;
1480 h
.next
= handlerlist
;
1486 handlerlist
= h
.next
;
1490 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1493 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1494 Lisp_Object (*bfun
) ();
1496 Lisp_Object handlers
;
1497 Lisp_Object (*hfun
) ();
1503 /* Since Fsignal will close off all calls to x_catch_errors,
1504 we will get the wrong results if some are not closed now. */
1506 if (x_catching_errors ())
1512 c
.backlist
= backtrace_list
;
1513 c
.handlerlist
= handlerlist
;
1514 c
.lisp_eval_depth
= lisp_eval_depth
;
1515 c
.pdlcount
= SPECPDL_INDEX ();
1516 c
.poll_suppress_count
= poll_suppress_count
;
1517 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1518 c
.gcpro
= gcprolist
;
1519 c
.byte_stack
= byte_stack_list
;
1520 if (_setjmp (c
.jmp
))
1522 return (*hfun
) (c
.val
);
1526 h
.handler
= handlers
;
1528 h
.next
= handlerlist
;
1532 val
= (*bfun
) (arg
);
1534 handlerlist
= h
.next
;
1539 /* Like internal_condition_case but call BFUN with NARGS as first,
1540 and ARGS as second argument. */
1543 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1544 Lisp_Object (*bfun
) ();
1547 Lisp_Object handlers
;
1548 Lisp_Object (*hfun
) ();
1554 /* Since Fsignal will close off all calls to x_catch_errors,
1555 we will get the wrong results if some are not closed now. */
1557 if (x_catching_errors ())
1563 c
.backlist
= backtrace_list
;
1564 c
.handlerlist
= handlerlist
;
1565 c
.lisp_eval_depth
= lisp_eval_depth
;
1566 c
.pdlcount
= SPECPDL_INDEX ();
1567 c
.poll_suppress_count
= poll_suppress_count
;
1568 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1569 c
.gcpro
= gcprolist
;
1570 c
.byte_stack
= byte_stack_list
;
1571 if (_setjmp (c
.jmp
))
1573 return (*hfun
) (c
.val
);
1577 h
.handler
= handlers
;
1579 h
.next
= handlerlist
;
1583 val
= (*bfun
) (nargs
, args
);
1585 handlerlist
= h
.next
;
1590 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1591 Lisp_Object
, Lisp_Object
,
1594 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1595 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1596 This function does not return.
1598 An error symbol is a symbol with an `error-conditions' property
1599 that is a list of condition names.
1600 A handler for any of those names will get to handle this signal.
1601 The symbol `error' should normally be one of them.
1603 DATA should be a list. Its elements are printed as part of the error message.
1604 See Info anchor `(elisp)Definition of signal' for some details on how this
1605 error message is constructed.
1606 If the signal is handled, DATA is made available to the handler.
1607 See also the function `condition-case'. */)
1608 (error_symbol
, data
)
1609 Lisp_Object error_symbol
, data
;
1611 /* When memory is full, ERROR-SYMBOL is nil,
1612 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1613 That is a special case--don't do this in other situations. */
1614 register struct handler
*allhandlers
= handlerlist
;
1615 Lisp_Object conditions
;
1616 extern int gc_in_progress
;
1617 extern int waiting_for_input
;
1618 Lisp_Object debugger_value
;
1620 Lisp_Object real_error_symbol
;
1621 struct backtrace
*bp
;
1623 immediate_quit
= handling_signal
= 0;
1625 if (gc_in_progress
|| waiting_for_input
)
1628 if (NILP (error_symbol
))
1629 real_error_symbol
= Fcar (data
);
1631 real_error_symbol
= error_symbol
;
1633 #if 0 /* rms: I don't know why this was here,
1634 but it is surely wrong for an error that is handled. */
1635 #ifdef HAVE_X_WINDOWS
1636 if (display_hourglass_p
)
1637 cancel_hourglass ();
1641 /* This hook is used by edebug. */
1642 if (! NILP (Vsignal_hook_function
)
1643 && ! NILP (error_symbol
))
1645 /* Edebug takes care of restoring these variables when it exits. */
1646 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1647 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1649 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1650 max_specpdl_size
= SPECPDL_INDEX () + 40;
1652 call2 (Vsignal_hook_function
, error_symbol
, data
);
1655 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1657 /* Remember from where signal was called. Skip over the frame for
1658 `signal' itself. If a frame for `error' follows, skip that,
1659 too. Don't do this when ERROR_SYMBOL is nil, because that
1660 is a memory-full error. */
1661 Vsignaling_function
= Qnil
;
1662 if (backtrace_list
&& !NILP (error_symbol
))
1664 bp
= backtrace_list
->next
;
1665 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1667 if (bp
&& bp
->function
)
1668 Vsignaling_function
= *bp
->function
;
1671 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1673 register Lisp_Object clause
;
1675 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1676 error_symbol
, data
, &debugger_value
);
1678 if (EQ (clause
, Qlambda
))
1680 /* We can't return values to code which signaled an error, but we
1681 can continue code which has signaled a quit. */
1682 if (EQ (real_error_symbol
, Qquit
))
1685 error ("Cannot return from the debugger in an error");
1690 Lisp_Object unwind_data
;
1691 struct handler
*h
= handlerlist
;
1693 handlerlist
= allhandlers
;
1695 if (NILP (error_symbol
))
1698 unwind_data
= Fcons (error_symbol
, data
);
1699 h
->chosen_clause
= clause
;
1700 unwind_to_catch (h
->tag
, unwind_data
);
1704 handlerlist
= allhandlers
;
1705 /* If no handler is present now, try to run the debugger,
1706 and if that fails, throw to top level. */
1707 find_handler_clause (Qerror
, conditions
, error_symbol
, data
, &debugger_value
);
1709 Fthrow (Qtop_level
, Qt
);
1711 if (! NILP (error_symbol
))
1712 data
= Fcons (error_symbol
, data
);
1714 string
= Ferror_message_string (data
);
1715 fatal ("%s", SDATA (string
), 0);
1718 /* Internal version of Fsignal that never returns.
1719 Used for anything but Qquit (which can return from Fsignal). */
1722 xsignal (error_symbol
, data
)
1723 Lisp_Object error_symbol
, data
;
1725 Fsignal (error_symbol
, data
);
1729 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1732 xsignal0 (error_symbol
)
1733 Lisp_Object error_symbol
;
1735 xsignal (error_symbol
, Qnil
);
1739 xsignal1 (error_symbol
, arg
)
1740 Lisp_Object error_symbol
, arg
;
1742 xsignal (error_symbol
, list1 (arg
));
1746 xsignal2 (error_symbol
, arg1
, arg2
)
1747 Lisp_Object error_symbol
, arg1
, arg2
;
1749 xsignal (error_symbol
, list2 (arg1
, arg2
));
1753 xsignal3 (error_symbol
, arg1
, arg2
, arg3
)
1754 Lisp_Object error_symbol
, arg1
, arg2
, arg3
;
1756 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1759 /* Signal `error' with message S, and additional arg ARG.
1760 If ARG is not a genuine list, make it a one-element list. */
1763 signal_error (s
, arg
)
1767 Lisp_Object tortoise
, hare
;
1769 hare
= tortoise
= arg
;
1770 while (CONSP (hare
))
1777 tortoise
= XCDR (tortoise
);
1779 if (EQ (hare
, tortoise
))
1784 arg
= Fcons (arg
, Qnil
); /* Make it a list. */
1786 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1790 /* Return nonzero if LIST is a non-nil atom or
1791 a list containing one of CONDITIONS. */
1794 wants_debugger (list
, conditions
)
1795 Lisp_Object list
, conditions
;
1802 while (CONSP (conditions
))
1804 Lisp_Object
this, tail
;
1805 this = XCAR (conditions
);
1806 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1807 if (EQ (XCAR (tail
), this))
1809 conditions
= XCDR (conditions
);
1814 /* Return 1 if an error with condition-symbols CONDITIONS,
1815 and described by SIGNAL-DATA, should skip the debugger
1816 according to debugger-ignored-errors. */
1819 skip_debugger (conditions
, data
)
1820 Lisp_Object conditions
, data
;
1823 int first_string
= 1;
1824 Lisp_Object error_message
;
1826 error_message
= Qnil
;
1827 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1829 if (STRINGP (XCAR (tail
)))
1833 error_message
= Ferror_message_string (data
);
1837 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1842 Lisp_Object contail
;
1844 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1845 if (EQ (XCAR (tail
), XCAR (contail
)))
1853 /* Value of Qlambda means we have called debugger and user has continued.
1854 There are two ways to pass SIG and DATA:
1855 = SIG is the error symbol, and DATA is the rest of the data.
1856 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1857 This is for memory-full errors only.
1859 Store value returned from debugger into *DEBUGGER_VALUE_PTR.
1861 We need to increase max_specpdl_size temporarily around
1862 anything we do that can push on the specpdl, so as not to get
1863 a second error here in case we're handling specpdl overflow. */
1866 find_handler_clause (handlers
, conditions
, sig
, data
, debugger_value_ptr
)
1867 Lisp_Object handlers
, conditions
, sig
, data
;
1868 Lisp_Object
*debugger_value_ptr
;
1870 register Lisp_Object h
;
1871 register Lisp_Object tem
;
1873 if (EQ (handlers
, Qt
)) /* t is used by handlers for all conditions, set up by C code. */
1875 /* error is used similarly, but means print an error message
1876 and run the debugger if that is enabled. */
1877 if (EQ (handlers
, Qerror
)
1878 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1879 there is a handler. */
1881 int debugger_called
= 0;
1882 Lisp_Object sig_symbol
, combined_data
;
1883 /* This is set to 1 if we are handling a memory-full error,
1884 because these must not run the debugger.
1885 (There is no room in memory to do that!) */
1886 int no_debugger
= 0;
1890 combined_data
= data
;
1891 sig_symbol
= Fcar (data
);
1896 combined_data
= Fcons (sig
, data
);
1900 if (wants_debugger (Vstack_trace_on_error
, conditions
))
1904 internal_with_output_to_temp_buffer ("*Backtrace*",
1905 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1908 internal_with_output_to_temp_buffer ("*Backtrace*",
1914 /* Don't try to run the debugger with interrupts blocked.
1915 The editing loop would return anyway. */
1916 && ! INPUT_BLOCKED_P
1917 && (EQ (sig_symbol
, Qquit
)
1919 : wants_debugger (Vdebug_on_error
, conditions
))
1920 && ! skip_debugger (conditions
, combined_data
)
1921 && when_entered_debugger
< num_nonmacro_input_events
)
1924 = call_debugger (Fcons (Qerror
,
1925 Fcons (combined_data
, Qnil
)));
1926 debugger_called
= 1;
1928 /* If there is no handler, return saying whether we ran the debugger. */
1929 if (EQ (handlers
, Qerror
))
1931 if (debugger_called
)
1936 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1938 Lisp_Object handler
, condit
;
1941 if (!CONSP (handler
))
1943 condit
= Fcar (handler
);
1944 /* Handle a single condition name in handler HANDLER. */
1945 if (SYMBOLP (condit
))
1947 tem
= Fmemq (Fcar (handler
), conditions
);
1951 /* Handle a list of condition names in handler HANDLER. */
1952 else if (CONSP (condit
))
1954 while (CONSP (condit
))
1956 tem
= Fmemq (Fcar (condit
), conditions
);
1959 condit
= XCDR (condit
);
1966 /* dump an error message; called like printf */
1970 error (m
, a1
, a2
, a3
)
1990 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
1995 buffer
= (char *) xrealloc (buffer
, size
);
1998 buffer
= (char *) xmalloc (size
);
2003 string
= build_string (buffer
);
2007 xsignal1 (Qerror
, string
);
2010 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
2011 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
2012 This means it contains a description for how to read arguments to give it.
2013 The value is nil for an invalid function or a symbol with no function
2016 Interactively callable functions include strings and vectors (treated
2017 as keyboard macros), lambda-expressions that contain a top-level call
2018 to `interactive', autoload definitions made by `autoload' with non-nil
2019 fourth argument, and some of the built-in functions of Lisp.
2021 Also, a symbol satisfies `commandp' if its function definition does so.
2023 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
2024 then strings and vectors are not accepted. */)
2025 (function
, for_call_interactively
)
2026 Lisp_Object function
, for_call_interactively
;
2028 register Lisp_Object fun
;
2029 register Lisp_Object funcar
;
2033 fun
= indirect_function (fun
);
2034 if (EQ (fun
, Qunbound
))
2037 /* Emacs primitives are interactive if their DEFUN specifies an
2038 interactive spec. */
2041 if (XSUBR (fun
)->prompt
)
2047 /* Bytecode objects are interactive if they are long enough to
2048 have an element whose index is COMPILED_INTERACTIVE, which is
2049 where the interactive spec is stored. */
2050 else if (COMPILEDP (fun
))
2051 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
2054 /* Strings and vectors are keyboard macros. */
2055 if (NILP (for_call_interactively
) && (STRINGP (fun
) || VECTORP (fun
)))
2058 /* Lists may represent commands. */
2061 funcar
= XCAR (fun
);
2062 if (EQ (funcar
, Qlambda
))
2063 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
2064 if (EQ (funcar
, Qautoload
))
2065 return Fcar (Fcdr (Fcdr (XCDR (fun
))));
2071 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
2072 doc
: /* Define FUNCTION to autoload from FILE.
2073 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2074 Third arg DOCSTRING is documentation for the function.
2075 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2076 Fifth arg TYPE indicates the type of the object:
2077 nil or omitted says FUNCTION is a function,
2078 `keymap' says FUNCTION is really a keymap, and
2079 `macro' or t says FUNCTION is really a macro.
2080 Third through fifth args give info about the real definition.
2081 They default to nil.
2082 If FUNCTION is already defined other than as an autoload,
2083 this does nothing and returns nil. */)
2084 (function
, file
, docstring
, interactive
, type
)
2085 Lisp_Object function
, file
, docstring
, interactive
, type
;
2088 Lisp_Object args
[4];
2091 CHECK_SYMBOL (function
);
2092 CHECK_STRING (file
);
2094 /* If function is defined and not as an autoload, don't override */
2095 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
2096 && !(CONSP (XSYMBOL (function
)->function
)
2097 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
2100 if (NILP (Vpurify_flag
))
2101 /* Only add entries after dumping, because the ones before are
2102 not useful and else we get loads of them from the loaddefs.el. */
2103 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
2107 args
[1] = docstring
;
2108 args
[2] = interactive
;
2111 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
2112 #else /* NO_ARG_ARRAY */
2113 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
2114 #endif /* not NO_ARG_ARRAY */
2118 un_autoload (oldqueue
)
2119 Lisp_Object oldqueue
;
2121 register Lisp_Object queue
, first
, second
;
2123 /* Queue to unwind is current value of Vautoload_queue.
2124 oldqueue is the shadowed value to leave in Vautoload_queue. */
2125 queue
= Vautoload_queue
;
2126 Vautoload_queue
= oldqueue
;
2127 while (CONSP (queue
))
2129 first
= XCAR (queue
);
2130 second
= Fcdr (first
);
2131 first
= Fcar (first
);
2132 if (EQ (first
, make_number (0)))
2135 Ffset (first
, second
);
2136 queue
= XCDR (queue
);
2141 /* Load an autoloaded function.
2142 FUNNAME is the symbol which is the function's name.
2143 FUNDEF is the autoload definition (a list). */
2146 do_autoload (fundef
, funname
)
2147 Lisp_Object fundef
, funname
;
2149 int count
= SPECPDL_INDEX ();
2151 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2153 /* This is to make sure that loadup.el gives a clear picture
2154 of what files are preloaded and when. */
2155 if (! NILP (Vpurify_flag
))
2156 error ("Attempt to autoload %s while preparing to dump",
2157 SDATA (SYMBOL_NAME (funname
)));
2160 CHECK_SYMBOL (funname
);
2161 GCPRO3 (fun
, funname
, fundef
);
2163 /* Preserve the match data. */
2164 record_unwind_save_match_data ();
2166 /* If autoloading gets an error (which includes the error of failing
2167 to define the function being called), we use Vautoload_queue
2168 to undo function definitions and `provide' calls made by
2169 the function. We do this in the specific case of autoloading
2170 because autoloading is not an explicit request "load this file",
2171 but rather a request to "call this function".
2173 The value saved here is to be restored into Vautoload_queue. */
2174 record_unwind_protect (un_autoload
, Vautoload_queue
);
2175 Vautoload_queue
= Qt
;
2176 Fload (Fcar (Fcdr (fundef
)), Qnil
, noninteractive
? Qt
: Qnil
, Qnil
, Qt
);
2178 /* Once loading finishes, don't undo it. */
2179 Vautoload_queue
= Qt
;
2180 unbind_to (count
, Qnil
);
2182 fun
= Findirect_function (fun
, Qnil
);
2184 if (!NILP (Fequal (fun
, fundef
)))
2185 error ("Autoloading failed to define function %s",
2186 SDATA (SYMBOL_NAME (funname
)));
2191 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
2192 doc
: /* Evaluate FORM and return its value. */)
2196 Lisp_Object fun
, val
, original_fun
, original_args
;
2198 struct backtrace backtrace
;
2199 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2201 if (handling_signal
)
2205 return Fsymbol_value (form
);
2210 if ((consing_since_gc
> gc_cons_threshold
2211 && consing_since_gc
> gc_relative_threshold
)
2213 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2216 Fgarbage_collect ();
2220 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2222 if (max_lisp_eval_depth
< 100)
2223 max_lisp_eval_depth
= 100;
2224 if (lisp_eval_depth
> max_lisp_eval_depth
)
2225 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2228 original_fun
= Fcar (form
);
2229 original_args
= Fcdr (form
);
2231 backtrace
.next
= backtrace_list
;
2232 backtrace_list
= &backtrace
;
2233 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2234 backtrace
.args
= &original_args
;
2235 backtrace
.nargs
= UNEVALLED
;
2236 backtrace
.evalargs
= 1;
2237 backtrace
.debug_on_exit
= 0;
2239 if (debug_on_next_call
)
2240 do_debug_on_call (Qt
);
2242 /* At this point, only original_fun and original_args
2243 have values that will be used below */
2246 /* Optimize for no indirection. */
2248 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2249 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2250 fun
= indirect_function (fun
);
2254 Lisp_Object numargs
;
2255 Lisp_Object argvals
[8];
2256 Lisp_Object args_left
;
2257 register int i
, maxargs
;
2259 args_left
= original_args
;
2260 numargs
= Flength (args_left
);
2264 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2265 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2266 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2268 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2270 backtrace
.evalargs
= 0;
2271 val
= (*XSUBR (fun
)->function
) (args_left
);
2275 if (XSUBR (fun
)->max_args
== MANY
)
2277 /* Pass a vector of evaluated arguments */
2279 register int argnum
= 0;
2281 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2283 GCPRO3 (args_left
, fun
, fun
);
2287 while (!NILP (args_left
))
2289 vals
[argnum
++] = Feval (Fcar (args_left
));
2290 args_left
= Fcdr (args_left
);
2291 gcpro3
.nvars
= argnum
;
2294 backtrace
.args
= vals
;
2295 backtrace
.nargs
= XINT (numargs
);
2297 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2302 GCPRO3 (args_left
, fun
, fun
);
2303 gcpro3
.var
= argvals
;
2306 maxargs
= XSUBR (fun
)->max_args
;
2307 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2309 argvals
[i
] = Feval (Fcar (args_left
));
2315 backtrace
.args
= argvals
;
2316 backtrace
.nargs
= XINT (numargs
);
2321 val
= (*XSUBR (fun
)->function
) ();
2324 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2327 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2330 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2334 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2335 argvals
[2], argvals
[3]);
2338 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2339 argvals
[3], argvals
[4]);
2342 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2343 argvals
[3], argvals
[4], argvals
[5]);
2346 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2347 argvals
[3], argvals
[4], argvals
[5],
2352 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2353 argvals
[3], argvals
[4], argvals
[5],
2354 argvals
[6], argvals
[7]);
2358 /* Someone has created a subr that takes more arguments than
2359 is supported by this code. We need to either rewrite the
2360 subr to use a different argument protocol, or add more
2361 cases to this switch. */
2365 if (COMPILEDP (fun
))
2366 val
= apply_lambda (fun
, original_args
, 1);
2369 if (EQ (fun
, Qunbound
))
2370 xsignal1 (Qvoid_function
, original_fun
);
2372 xsignal1 (Qinvalid_function
, original_fun
);
2373 funcar
= XCAR (fun
);
2374 if (!SYMBOLP (funcar
))
2375 xsignal1 (Qinvalid_function
, original_fun
);
2376 if (EQ (funcar
, Qautoload
))
2378 do_autoload (fun
, original_fun
);
2381 if (EQ (funcar
, Qmacro
))
2382 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2383 else if (EQ (funcar
, Qlambda
))
2384 val
= apply_lambda (fun
, original_args
, 1);
2386 xsignal1 (Qinvalid_function
, original_fun
);
2392 if (backtrace
.debug_on_exit
)
2393 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2394 backtrace_list
= backtrace
.next
;
2399 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2400 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2401 Then return the value FUNCTION returns.
2402 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2403 usage: (apply FUNCTION &rest ARGUMENTS) */)
2408 register int i
, numargs
;
2409 register Lisp_Object spread_arg
;
2410 register Lisp_Object
*funcall_args
;
2412 struct gcpro gcpro1
;
2416 spread_arg
= args
[nargs
- 1];
2417 CHECK_LIST (spread_arg
);
2419 numargs
= XINT (Flength (spread_arg
));
2422 return Ffuncall (nargs
- 1, args
);
2423 else if (numargs
== 1)
2425 args
[nargs
- 1] = XCAR (spread_arg
);
2426 return Ffuncall (nargs
, args
);
2429 numargs
+= nargs
- 2;
2431 /* Optimize for no indirection. */
2432 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2433 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2434 fun
= indirect_function (fun
);
2435 if (EQ (fun
, Qunbound
))
2437 /* Let funcall get the error */
2444 if (numargs
< XSUBR (fun
)->min_args
2445 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2446 goto funcall
; /* Let funcall get the error */
2447 else if (XSUBR (fun
)->max_args
> numargs
)
2449 /* Avoid making funcall cons up a yet another new vector of arguments
2450 by explicitly supplying nil's for optional values */
2451 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2452 * sizeof (Lisp_Object
));
2453 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2454 funcall_args
[++i
] = Qnil
;
2455 GCPRO1 (*funcall_args
);
2456 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2460 /* We add 1 to numargs because funcall_args includes the
2461 function itself as well as its arguments. */
2464 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2465 * sizeof (Lisp_Object
));
2466 GCPRO1 (*funcall_args
);
2467 gcpro1
.nvars
= 1 + numargs
;
2470 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2471 /* Spread the last arg we got. Its first element goes in
2472 the slot that it used to occupy, hence this value of I. */
2474 while (!NILP (spread_arg
))
2476 funcall_args
[i
++] = XCAR (spread_arg
);
2477 spread_arg
= XCDR (spread_arg
);
2480 /* By convention, the caller needs to gcpro Ffuncall's args. */
2481 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2484 /* Run hook variables in various ways. */
2486 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2487 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2488 enum run_hooks_condition
));
2490 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2491 doc
: /* Run each hook in HOOKS.
2492 Each argument should be a symbol, a hook variable.
2493 These symbols are processed in the order specified.
2494 If a hook symbol has a non-nil value, that value may be a function
2495 or a list of functions to be called to run the hook.
2496 If the value is a function, it is called with no arguments.
2497 If it is a list, the elements are called, in order, with no arguments.
2499 Major modes should not use this function directly to run their mode
2500 hook; they should use `run-mode-hooks' instead.
2502 Do not use `make-local-variable' to make a hook variable buffer-local.
2503 Instead, use `add-hook' and specify t for the LOCAL argument.
2504 usage: (run-hooks &rest HOOKS) */)
2509 Lisp_Object hook
[1];
2512 for (i
= 0; i
< nargs
; i
++)
2515 run_hook_with_args (1, hook
, to_completion
);
2521 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2522 Srun_hook_with_args
, 1, MANY
, 0,
2523 doc
: /* Run HOOK with the specified arguments ARGS.
2524 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2525 value, that value may be a function or a list of functions to be
2526 called to run the hook. If the value is a function, it is called with
2527 the given arguments and its return value is returned. If it is a list
2528 of functions, those functions are called, in order,
2529 with the given arguments ARGS.
2530 It is best not to depend on the value returned by `run-hook-with-args',
2533 Do not use `make-local-variable' to make a hook variable buffer-local.
2534 Instead, use `add-hook' and specify t for the LOCAL argument.
2535 usage: (run-hook-with-args HOOK &rest ARGS) */)
2540 return run_hook_with_args (nargs
, args
, to_completion
);
2543 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2544 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2545 doc
: /* Run HOOK with the specified arguments ARGS.
2546 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2547 value, that value may be a function or a list of functions to be
2548 called to run the hook. If the value is a function, it is called with
2549 the given arguments and its return value is returned.
2550 If it is a list of functions, those functions are called, in order,
2551 with the given arguments ARGS, until one of them
2552 returns a non-nil value. Then we return that value.
2553 However, if they all return nil, we return nil.
2555 Do not use `make-local-variable' to make a hook variable buffer-local.
2556 Instead, use `add-hook' and specify t for the LOCAL argument.
2557 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2562 return run_hook_with_args (nargs
, args
, until_success
);
2565 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2566 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2567 doc
: /* Run HOOK with the specified arguments ARGS.
2568 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2569 value, that value may be a function or a list of functions to be
2570 called to run the hook. If the value is a function, it is called with
2571 the given arguments and its return value is returned.
2572 If it is a list of functions, those functions are called, in order,
2573 with the given arguments ARGS, until one of them returns nil.
2574 Then we return nil. However, if they all return non-nil, we return non-nil.
2576 Do not use `make-local-variable' to make a hook variable buffer-local.
2577 Instead, use `add-hook' and specify t for the LOCAL argument.
2578 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2583 return run_hook_with_args (nargs
, args
, until_failure
);
2586 /* ARGS[0] should be a hook symbol.
2587 Call each of the functions in the hook value, passing each of them
2588 as arguments all the rest of ARGS (all NARGS - 1 elements).
2589 COND specifies a condition to test after each call
2590 to decide whether to stop.
2591 The caller (or its caller, etc) must gcpro all of ARGS,
2592 except that it isn't necessary to gcpro ARGS[0]. */
2595 run_hook_with_args (nargs
, args
, cond
)
2598 enum run_hooks_condition cond
;
2600 Lisp_Object sym
, val
, ret
;
2601 Lisp_Object globals
;
2602 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2604 /* If we are dying or still initializing,
2605 don't do anything--it would probably crash if we tried. */
2606 if (NILP (Vrun_hooks
))
2610 val
= find_symbol_value (sym
);
2611 ret
= (cond
== until_failure
? Qt
: Qnil
);
2613 if (EQ (val
, Qunbound
) || NILP (val
))
2615 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2618 return Ffuncall (nargs
, args
);
2623 GCPRO3 (sym
, val
, globals
);
2626 CONSP (val
) && ((cond
== to_completion
)
2627 || (cond
== until_success
? NILP (ret
)
2631 if (EQ (XCAR (val
), Qt
))
2633 /* t indicates this hook has a local binding;
2634 it means to run the global binding too. */
2636 for (globals
= Fdefault_value (sym
);
2637 CONSP (globals
) && ((cond
== to_completion
)
2638 || (cond
== until_success
? NILP (ret
)
2640 globals
= XCDR (globals
))
2642 args
[0] = XCAR (globals
);
2643 /* In a global value, t should not occur. If it does, we
2644 must ignore it to avoid an endless loop. */
2645 if (!EQ (args
[0], Qt
))
2646 ret
= Ffuncall (nargs
, args
);
2651 args
[0] = XCAR (val
);
2652 ret
= Ffuncall (nargs
, args
);
2661 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2662 present value of that symbol.
2663 Call each element of FUNLIST,
2664 passing each of them the rest of ARGS.
2665 The caller (or its caller, etc) must gcpro all of ARGS,
2666 except that it isn't necessary to gcpro ARGS[0]. */
2669 run_hook_list_with_args (funlist
, nargs
, args
)
2670 Lisp_Object funlist
;
2676 Lisp_Object globals
;
2677 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2681 GCPRO3 (sym
, val
, globals
);
2683 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2685 if (EQ (XCAR (val
), Qt
))
2687 /* t indicates this hook has a local binding;
2688 it means to run the global binding too. */
2690 for (globals
= Fdefault_value (sym
);
2692 globals
= XCDR (globals
))
2694 args
[0] = XCAR (globals
);
2695 /* In a global value, t should not occur. If it does, we
2696 must ignore it to avoid an endless loop. */
2697 if (!EQ (args
[0], Qt
))
2698 Ffuncall (nargs
, args
);
2703 args
[0] = XCAR (val
);
2704 Ffuncall (nargs
, args
);
2711 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2714 run_hook_with_args_2 (hook
, arg1
, arg2
)
2715 Lisp_Object hook
, arg1
, arg2
;
2717 Lisp_Object temp
[3];
2722 Frun_hook_with_args (3, temp
);
2725 /* Apply fn to arg */
2728 Lisp_Object fn
, arg
;
2730 struct gcpro gcpro1
;
2734 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2738 Lisp_Object args
[2];
2742 RETURN_UNGCPRO (Fapply (2, args
));
2744 #else /* not NO_ARG_ARRAY */
2745 RETURN_UNGCPRO (Fapply (2, &fn
));
2746 #endif /* not NO_ARG_ARRAY */
2749 /* Call function fn on no arguments */
2754 struct gcpro gcpro1
;
2757 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2760 /* Call function fn with 1 argument arg1 */
2764 Lisp_Object fn
, arg1
;
2766 struct gcpro gcpro1
;
2768 Lisp_Object args
[2];
2774 RETURN_UNGCPRO (Ffuncall (2, args
));
2775 #else /* not NO_ARG_ARRAY */
2778 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2779 #endif /* not NO_ARG_ARRAY */
2782 /* Call function fn with 2 arguments arg1, arg2 */
2785 call2 (fn
, arg1
, arg2
)
2786 Lisp_Object fn
, arg1
, arg2
;
2788 struct gcpro gcpro1
;
2790 Lisp_Object args
[3];
2796 RETURN_UNGCPRO (Ffuncall (3, args
));
2797 #else /* not NO_ARG_ARRAY */
2800 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2801 #endif /* not NO_ARG_ARRAY */
2804 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2807 call3 (fn
, arg1
, arg2
, arg3
)
2808 Lisp_Object fn
, arg1
, arg2
, arg3
;
2810 struct gcpro gcpro1
;
2812 Lisp_Object args
[4];
2819 RETURN_UNGCPRO (Ffuncall (4, args
));
2820 #else /* not NO_ARG_ARRAY */
2823 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2824 #endif /* not NO_ARG_ARRAY */
2827 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2830 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2831 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2833 struct gcpro gcpro1
;
2835 Lisp_Object args
[5];
2843 RETURN_UNGCPRO (Ffuncall (5, args
));
2844 #else /* not NO_ARG_ARRAY */
2847 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2848 #endif /* not NO_ARG_ARRAY */
2851 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2854 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2855 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2857 struct gcpro gcpro1
;
2859 Lisp_Object args
[6];
2868 RETURN_UNGCPRO (Ffuncall (6, args
));
2869 #else /* not NO_ARG_ARRAY */
2872 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2873 #endif /* not NO_ARG_ARRAY */
2876 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2879 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2880 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2882 struct gcpro gcpro1
;
2884 Lisp_Object args
[7];
2894 RETURN_UNGCPRO (Ffuncall (7, args
));
2895 #else /* not NO_ARG_ARRAY */
2898 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2899 #endif /* not NO_ARG_ARRAY */
2902 /* The caller should GCPRO all the elements of ARGS. */
2904 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2905 doc
: /* Call first argument as a function, passing remaining arguments to it.
2906 Return the value that function returns.
2907 Thus, (funcall 'cons 'x 'y) returns (x . y).
2908 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2913 Lisp_Object fun
, original_fun
;
2915 int numargs
= nargs
- 1;
2916 Lisp_Object lisp_numargs
;
2918 struct backtrace backtrace
;
2919 register Lisp_Object
*internal_args
;
2923 if ((consing_since_gc
> gc_cons_threshold
2924 && consing_since_gc
> gc_relative_threshold
)
2926 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2927 Fgarbage_collect ();
2929 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2931 if (max_lisp_eval_depth
< 100)
2932 max_lisp_eval_depth
= 100;
2933 if (lisp_eval_depth
> max_lisp_eval_depth
)
2934 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2937 backtrace
.next
= backtrace_list
;
2938 backtrace_list
= &backtrace
;
2939 backtrace
.function
= &args
[0];
2940 backtrace
.args
= &args
[1];
2941 backtrace
.nargs
= nargs
- 1;
2942 backtrace
.evalargs
= 0;
2943 backtrace
.debug_on_exit
= 0;
2945 if (debug_on_next_call
)
2946 do_debug_on_call (Qlambda
);
2950 original_fun
= args
[0];
2954 /* Optimize for no indirection. */
2956 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2957 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2958 fun
= indirect_function (fun
);
2962 if (numargs
< XSUBR (fun
)->min_args
2963 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2965 XSETFASTINT (lisp_numargs
, numargs
);
2966 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
2969 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2970 xsignal1 (Qinvalid_function
, original_fun
);
2972 if (XSUBR (fun
)->max_args
== MANY
)
2974 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
2978 if (XSUBR (fun
)->max_args
> numargs
)
2980 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
2981 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
2982 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
2983 internal_args
[i
] = Qnil
;
2986 internal_args
= args
+ 1;
2987 switch (XSUBR (fun
)->max_args
)
2990 val
= (*XSUBR (fun
)->function
) ();
2993 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
2996 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1]);
2999 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3003 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3004 internal_args
[2], internal_args
[3]);
3007 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3008 internal_args
[2], internal_args
[3],
3012 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3013 internal_args
[2], internal_args
[3],
3014 internal_args
[4], internal_args
[5]);
3017 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3018 internal_args
[2], internal_args
[3],
3019 internal_args
[4], internal_args
[5],
3024 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3025 internal_args
[2], internal_args
[3],
3026 internal_args
[4], internal_args
[5],
3027 internal_args
[6], internal_args
[7]);
3032 /* If a subr takes more than 8 arguments without using MANY
3033 or UNEVALLED, we need to extend this function to support it.
3034 Until this is done, there is no way to call the function. */
3038 if (COMPILEDP (fun
))
3039 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3042 if (EQ (fun
, Qunbound
))
3043 xsignal1 (Qvoid_function
, original_fun
);
3045 xsignal1 (Qinvalid_function
, original_fun
);
3046 funcar
= XCAR (fun
);
3047 if (!SYMBOLP (funcar
))
3048 xsignal1 (Qinvalid_function
, original_fun
);
3049 if (EQ (funcar
, Qlambda
))
3050 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3051 else if (EQ (funcar
, Qautoload
))
3053 do_autoload (fun
, original_fun
);
3058 xsignal1 (Qinvalid_function
, original_fun
);
3063 if (backtrace
.debug_on_exit
)
3064 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
3065 backtrace_list
= backtrace
.next
;
3070 apply_lambda (fun
, args
, eval_flag
)
3071 Lisp_Object fun
, args
;
3074 Lisp_Object args_left
;
3075 Lisp_Object numargs
;
3076 register Lisp_Object
*arg_vector
;
3077 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3079 register Lisp_Object tem
;
3081 numargs
= Flength (args
);
3082 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
3085 GCPRO3 (*arg_vector
, args_left
, fun
);
3088 for (i
= 0; i
< XINT (numargs
);)
3090 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
3091 if (eval_flag
) tem
= Feval (tem
);
3092 arg_vector
[i
++] = tem
;
3100 backtrace_list
->args
= arg_vector
;
3101 backtrace_list
->nargs
= i
;
3103 backtrace_list
->evalargs
= 0;
3104 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
3106 /* Do the debug-on-exit now, while arg_vector still exists. */
3107 if (backtrace_list
->debug_on_exit
)
3108 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
3109 /* Don't do it again when we return to eval. */
3110 backtrace_list
->debug_on_exit
= 0;
3114 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3115 and return the result of evaluation.
3116 FUN must be either a lambda-expression or a compiled-code object. */
3119 funcall_lambda (fun
, nargs
, arg_vector
)
3122 register Lisp_Object
*arg_vector
;
3124 Lisp_Object val
, syms_left
, next
;
3125 int count
= SPECPDL_INDEX ();
3126 int i
, optional
, rest
;
3130 syms_left
= XCDR (fun
);
3131 if (CONSP (syms_left
))
3132 syms_left
= XCAR (syms_left
);
3134 xsignal1 (Qinvalid_function
, fun
);
3136 else if (COMPILEDP (fun
))
3137 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
3141 i
= optional
= rest
= 0;
3142 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
3146 next
= XCAR (syms_left
);
3147 if (!SYMBOLP (next
))
3148 xsignal1 (Qinvalid_function
, fun
);
3150 if (EQ (next
, Qand_rest
))
3152 else if (EQ (next
, Qand_optional
))
3156 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
3160 specbind (next
, arg_vector
[i
++]);
3162 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3164 specbind (next
, Qnil
);
3167 if (!NILP (syms_left
))
3168 xsignal1 (Qinvalid_function
, fun
);
3170 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3173 val
= Fprogn (XCDR (XCDR (fun
)));
3176 /* If we have not actually read the bytecode string
3177 and constants vector yet, fetch them from the file. */
3178 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3179 Ffetch_bytecode (fun
);
3180 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
3181 AREF (fun
, COMPILED_CONSTANTS
),
3182 AREF (fun
, COMPILED_STACK_DEPTH
));
3185 return unbind_to (count
, val
);
3188 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3190 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3196 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3198 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3201 tem
= AREF (object
, COMPILED_BYTECODE
);
3202 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3203 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3205 error ("Invalid byte code");
3207 AREF (object
, COMPILED_BYTECODE
) = XCAR (tem
);
3208 AREF (object
, COMPILED_CONSTANTS
) = XCDR (tem
);
3216 register int count
= SPECPDL_INDEX ();
3217 if (specpdl_size
>= max_specpdl_size
)
3219 if (max_specpdl_size
< 400)
3220 max_specpdl_size
= 400;
3221 if (specpdl_size
>= max_specpdl_size
)
3222 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil
);
3225 if (specpdl_size
> max_specpdl_size
)
3226 specpdl_size
= max_specpdl_size
;
3227 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
3228 specpdl_ptr
= specpdl
+ count
;
3232 specbind (symbol
, value
)
3233 Lisp_Object symbol
, value
;
3236 Lisp_Object valcontents
;
3238 CHECK_SYMBOL (symbol
);
3239 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3242 /* The most common case is that of a non-constant symbol with a
3243 trivial value. Make that as fast as we can. */
3244 valcontents
= SYMBOL_VALUE (symbol
);
3245 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3247 specpdl_ptr
->symbol
= symbol
;
3248 specpdl_ptr
->old_value
= valcontents
;
3249 specpdl_ptr
->func
= NULL
;
3251 SET_SYMBOL_VALUE (symbol
, value
);
3255 Lisp_Object valcontents
;
3257 ovalue
= find_symbol_value (symbol
);
3258 specpdl_ptr
->func
= 0;
3259 specpdl_ptr
->old_value
= ovalue
;
3261 valcontents
= XSYMBOL (symbol
)->value
;
3263 if (BUFFER_LOCAL_VALUEP (valcontents
)
3264 || SOME_BUFFER_LOCAL_VALUEP (valcontents
)
3265 || BUFFER_OBJFWDP (valcontents
))
3267 Lisp_Object where
, current_buffer
;
3269 current_buffer
= Fcurrent_buffer ();
3271 /* For a local variable, record both the symbol and which
3272 buffer's or frame's value we are saving. */
3273 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3274 where
= current_buffer
;
3275 else if (!BUFFER_OBJFWDP (valcontents
)
3276 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3277 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3281 /* We're not using the `unused' slot in the specbinding
3282 structure because this would mean we have to do more
3283 work for simple variables. */
3284 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3286 /* If SYMBOL is a per-buffer variable which doesn't have a
3287 buffer-local value here, make the `let' change the global
3288 value by changing the value of SYMBOL in all buffers not
3289 having their own value. This is consistent with what
3290 happens with other buffer-local variables. */
3292 && BUFFER_OBJFWDP (valcontents
))
3295 Fset_default (symbol
, value
);
3300 specpdl_ptr
->symbol
= symbol
;
3303 if (BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
))
3304 store_symval_forwarding (symbol
, ovalue
, value
, NULL
);
3306 set_internal (symbol
, value
, 0, 1);
3311 record_unwind_protect (function
, arg
)
3312 Lisp_Object (*function
) P_ ((Lisp_Object
));
3315 eassert (!handling_signal
);
3317 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3319 specpdl_ptr
->func
= function
;
3320 specpdl_ptr
->symbol
= Qnil
;
3321 specpdl_ptr
->old_value
= arg
;
3326 unbind_to (count
, value
)
3330 Lisp_Object quitf
= Vquit_flag
;
3331 struct gcpro gcpro1
, gcpro2
;
3333 GCPRO2 (value
, quitf
);
3336 while (specpdl_ptr
!= specpdl
+ count
)
3338 /* Copy the binding, and decrement specpdl_ptr, before we do
3339 the work to unbind it. We decrement first
3340 so that an error in unbinding won't try to unbind
3341 the same entry again, and we copy the binding first
3342 in case more bindings are made during some of the code we run. */
3344 struct specbinding this_binding
;
3345 this_binding
= *--specpdl_ptr
;
3347 if (this_binding
.func
!= 0)
3348 (*this_binding
.func
) (this_binding
.old_value
);
3349 /* If the symbol is a list, it is really (SYMBOL WHERE
3350 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3351 frame. If WHERE is a buffer or frame, this indicates we
3352 bound a variable that had a buffer-local or frame-local
3353 binding. WHERE nil means that the variable had the default
3354 value when it was bound. CURRENT-BUFFER is the buffer that
3355 was current when the variable was bound. */
3356 else if (CONSP (this_binding
.symbol
))
3358 Lisp_Object symbol
, where
;
3360 symbol
= XCAR (this_binding
.symbol
);
3361 where
= XCAR (XCDR (this_binding
.symbol
));
3364 Fset_default (symbol
, this_binding
.old_value
);
3365 else if (BUFFERP (where
))
3366 set_internal (symbol
, this_binding
.old_value
, XBUFFER (where
), 1);
3368 set_internal (symbol
, this_binding
.old_value
, NULL
, 1);
3372 /* If variable has a trivial value (no forwarding), we can
3373 just set it. No need to check for constant symbols here,
3374 since that was already done by specbind. */
3375 if (!MISCP (SYMBOL_VALUE (this_binding
.symbol
)))
3376 SET_SYMBOL_VALUE (this_binding
.symbol
, this_binding
.old_value
);
3378 set_internal (this_binding
.symbol
, this_binding
.old_value
, 0, 1);
3382 if (NILP (Vquit_flag
) && !NILP (quitf
))
3389 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3390 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3391 The debugger is entered when that frame exits, if the flag is non-nil. */)
3393 Lisp_Object level
, flag
;
3395 register struct backtrace
*backlist
= backtrace_list
;
3398 CHECK_NUMBER (level
);
3400 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3402 backlist
= backlist
->next
;
3406 backlist
->debug_on_exit
= !NILP (flag
);
3411 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3412 doc
: /* Print a trace of Lisp function calls currently active.
3413 Output stream used is value of `standard-output'. */)
3416 register struct backtrace
*backlist
= backtrace_list
;
3420 extern Lisp_Object Vprint_level
;
3421 struct gcpro gcpro1
;
3423 XSETFASTINT (Vprint_level
, 3);
3430 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3431 if (backlist
->nargs
== UNEVALLED
)
3433 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3434 write_string ("\n", -1);
3438 tem
= *backlist
->function
;
3439 Fprin1 (tem
, Qnil
); /* This can QUIT */
3440 write_string ("(", -1);
3441 if (backlist
->nargs
== MANY
)
3443 for (tail
= *backlist
->args
, i
= 0;
3445 tail
= Fcdr (tail
), i
++)
3447 if (i
) write_string (" ", -1);
3448 Fprin1 (Fcar (tail
), Qnil
);
3453 for (i
= 0; i
< backlist
->nargs
; i
++)
3455 if (i
) write_string (" ", -1);
3456 Fprin1 (backlist
->args
[i
], Qnil
);
3459 write_string (")\n", -1);
3461 backlist
= backlist
->next
;
3464 Vprint_level
= Qnil
;
3469 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3470 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3471 If that frame has not evaluated the arguments yet (or is a special form),
3472 the value is (nil FUNCTION ARG-FORMS...).
3473 If that frame has evaluated its arguments and called its function already,
3474 the value is (t FUNCTION ARG-VALUES...).
3475 A &rest arg is represented as the tail of the list ARG-VALUES.
3476 FUNCTION is whatever was supplied as car of evaluated list,
3477 or a lambda expression for macro calls.
3478 If NFRAMES is more than the number of frames, the value is nil. */)
3480 Lisp_Object nframes
;
3482 register struct backtrace
*backlist
= backtrace_list
;
3486 CHECK_NATNUM (nframes
);
3488 /* Find the frame requested. */
3489 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3490 backlist
= backlist
->next
;
3494 if (backlist
->nargs
== UNEVALLED
)
3495 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3498 if (backlist
->nargs
== MANY
)
3499 tem
= *backlist
->args
;
3501 tem
= Flist (backlist
->nargs
, backlist
->args
);
3503 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3511 register struct backtrace
*backlist
;
3514 for (backlist
= backtrace_list
; backlist
; backlist
= backlist
->next
)
3516 mark_object (*backlist
->function
);
3518 if (backlist
->nargs
== UNEVALLED
|| backlist
->nargs
== MANY
)
3521 i
= backlist
->nargs
- 1;
3523 mark_object (backlist
->args
[i
]);
3530 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3531 doc
: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3532 If Lisp code tries to increase the total number past this amount,
3533 an error is signaled.
3534 You can safely use a value considerably larger than the default value,
3535 if that proves inconveniently small. However, if you increase it too far,
3536 Emacs could run out of memory trying to make the stack bigger. */);
3538 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3539 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3541 This limit serves to catch infinite recursions for you before they cause
3542 actual stack overflow in C, which would be fatal for Emacs.
3543 You can safely make it considerably larger than its default value,
3544 if that proves inconveniently small. However, if you increase it too far,
3545 Emacs could overflow the real C stack, and crash. */);
3547 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3548 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3549 If the value is t, that means do an ordinary quit.
3550 If the value equals `throw-on-input', that means quit by throwing
3551 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3552 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3553 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3556 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3557 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3558 Note that `quit-flag' will still be set by typing C-g,
3559 so a quit will be signaled as soon as `inhibit-quit' is nil.
3560 To prevent this happening, set `quit-flag' to nil
3561 before making `inhibit-quit' nil. */);
3562 Vinhibit_quit
= Qnil
;
3564 Qinhibit_quit
= intern ("inhibit-quit");
3565 staticpro (&Qinhibit_quit
);
3567 Qautoload
= intern ("autoload");
3568 staticpro (&Qautoload
);
3570 Qdebug_on_error
= intern ("debug-on-error");
3571 staticpro (&Qdebug_on_error
);
3573 Qmacro
= intern ("macro");
3574 staticpro (&Qmacro
);
3576 Qdeclare
= intern ("declare");
3577 staticpro (&Qdeclare
);
3579 /* Note that the process handling also uses Qexit, but we don't want
3580 to staticpro it twice, so we just do it here. */
3581 Qexit
= intern ("exit");
3584 Qinteractive
= intern ("interactive");
3585 staticpro (&Qinteractive
);
3587 Qcommandp
= intern ("commandp");
3588 staticpro (&Qcommandp
);
3590 Qdefun
= intern ("defun");
3591 staticpro (&Qdefun
);
3593 Qand_rest
= intern ("&rest");
3594 staticpro (&Qand_rest
);
3596 Qand_optional
= intern ("&optional");
3597 staticpro (&Qand_optional
);
3599 Qdebug
= intern ("debug");
3600 staticpro (&Qdebug
);
3602 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3603 doc
: /* *Non-nil means errors display a backtrace buffer.
3604 More precisely, this happens for any error that is handled
3605 by the editor command loop.
3606 If the value is a list, an error only means to display a backtrace
3607 if one of its condition symbols appears in the list. */);
3608 Vstack_trace_on_error
= Qnil
;
3610 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3611 doc
: /* *Non-nil means enter debugger if an error is signaled.
3612 Does not apply to errors handled by `condition-case' or those
3613 matched by `debug-ignored-errors'.
3614 If the value is a list, an error only means to enter the debugger
3615 if one of its condition symbols appears in the list.
3616 When you evaluate an expression interactively, this variable
3617 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3618 See also variable `debug-on-quit'. */);
3619 Vdebug_on_error
= Qnil
;
3621 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3622 doc
: /* *List of errors for which the debugger should not be called.
3623 Each element may be a condition-name or a regexp that matches error messages.
3624 If any element applies to a given error, that error skips the debugger
3625 and just returns to top level.
3626 This overrides the variable `debug-on-error'.
3627 It does not apply to errors handled by `condition-case'. */);
3628 Vdebug_ignored_errors
= Qnil
;
3630 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3631 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3632 Does not apply if quit is handled by a `condition-case'. */);
3635 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3636 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3638 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3639 doc
: /* Non-nil means debugger may continue execution.
3640 This is nil when the debugger is called under circumstances where it
3641 might not be safe to continue. */);
3642 debugger_may_continue
= 1;
3644 DEFVAR_LISP ("debugger", &Vdebugger
,
3645 doc
: /* Function to call to invoke debugger.
3646 If due to frame exit, args are `exit' and the value being returned;
3647 this function's value will be returned instead of that.
3648 If due to error, args are `error' and a list of the args to `signal'.
3649 If due to `apply' or `funcall' entry, one arg, `lambda'.
3650 If due to `eval' entry, one arg, t. */);
3653 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3654 doc
: /* If non-nil, this is a function for `signal' to call.
3655 It receives the same arguments that `signal' was given.
3656 The Edebug package uses this to regain control. */);
3657 Vsignal_hook_function
= Qnil
;
3659 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3660 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3661 Note that `debug-on-error', `debug-on-quit' and friends
3662 still determine whether to handle the particular condition. */);
3663 Vdebug_on_signal
= Qnil
;
3665 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3666 doc
: /* Function to process declarations in a macro definition.
3667 The function will be called with two args MACRO and DECL.
3668 MACRO is the name of the macro being defined.
3669 DECL is a list `(declare ...)' containing the declarations.
3670 The value the function returns is not used. */);
3671 Vmacro_declaration_function
= Qnil
;
3673 Vrun_hooks
= intern ("run-hooks");
3674 staticpro (&Vrun_hooks
);
3676 staticpro (&Vautoload_queue
);
3677 Vautoload_queue
= Qnil
;
3678 staticpro (&Vsignaling_function
);
3679 Vsignaling_function
= Qnil
;
3690 defsubr (&Sfunction
);
3692 defsubr (&Sdefmacro
);
3694 defsubr (&Sdefvaralias
);
3695 defsubr (&Sdefconst
);
3696 defsubr (&Suser_variable_p
);
3700 defsubr (&Smacroexpand
);
3703 defsubr (&Sunwind_protect
);
3704 defsubr (&Scondition_case
);
3706 defsubr (&Sinteractive_p
);
3707 defsubr (&Scalled_interactively_p
);
3708 defsubr (&Scommandp
);
3709 defsubr (&Sautoload
);
3712 defsubr (&Sfuncall
);
3713 defsubr (&Srun_hooks
);
3714 defsubr (&Srun_hook_with_args
);
3715 defsubr (&Srun_hook_with_args_until_success
);
3716 defsubr (&Srun_hook_with_args_until_failure
);
3717 defsubr (&Sfetch_bytecode
);
3718 defsubr (&Sbacktrace_debug
);
3719 defsubr (&Sbacktrace
);
3720 defsubr (&Sbacktrace_frame
);
3723 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3724 (do not change this comment) */