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 extern Lisp_Object Qfunction
;
208 static Lisp_Object funcall_lambda
P_ ((Lisp_Object
, int, Lisp_Object
*));
209 static void unwind_to_catch
P_ ((struct catchtag
*, Lisp_Object
)) NO_RETURN
;
212 /* "gcc -O3" enables automatic function inlining, which optimizes out
213 the arguments for the invocations of these functions, whereas they
214 expect these values on the stack. */
215 Lisp_Object
apply1 () __attribute__((noinline
));
216 Lisp_Object
call2 () __attribute__((noinline
));
223 specpdl
= (struct specbinding
*) xmalloc (specpdl_size
* sizeof (struct specbinding
));
224 specpdl_ptr
= specpdl
;
225 /* Don't forget to update docs (lispref node "Local Variables"). */
226 max_specpdl_size
= 1000;
227 max_lisp_eval_depth
= 400;
235 specpdl_ptr
= specpdl
;
240 debug_on_next_call
= 0;
245 /* This is less than the initial value of num_nonmacro_input_events. */
246 when_entered_debugger
= -1;
249 /* unwind-protect function used by call_debugger. */
252 restore_stack_limits (data
)
255 max_specpdl_size
= XINT (XCAR (data
));
256 max_lisp_eval_depth
= XINT (XCDR (data
));
260 /* Call the Lisp debugger, giving it argument ARG. */
266 int debug_while_redisplaying
;
267 int count
= SPECPDL_INDEX ();
269 int old_max
= max_specpdl_size
;
271 /* Temporarily bump up the stack limits,
272 so the debugger won't run out of stack. */
274 max_specpdl_size
+= 1;
275 record_unwind_protect (restore_stack_limits
,
276 Fcons (make_number (old_max
),
277 make_number (max_lisp_eval_depth
)));
278 max_specpdl_size
= old_max
;
280 if (lisp_eval_depth
+ 40 > max_lisp_eval_depth
)
281 max_lisp_eval_depth
= lisp_eval_depth
+ 40;
283 if (SPECPDL_INDEX () + 100 > max_specpdl_size
)
284 max_specpdl_size
= SPECPDL_INDEX () + 100;
286 #ifdef HAVE_WINDOW_SYSTEM
287 if (display_hourglass_p
)
291 debug_on_next_call
= 0;
292 when_entered_debugger
= num_nonmacro_input_events
;
294 /* Resetting redisplaying_p to 0 makes sure that debug output is
295 displayed if the debugger is invoked during redisplay. */
296 debug_while_redisplaying
= redisplaying_p
;
298 specbind (intern ("debugger-may-continue"),
299 debug_while_redisplaying
? Qnil
: Qt
);
300 specbind (Qinhibit_redisplay
, Qnil
);
301 specbind (Qdebug_on_error
, Qnil
);
303 #if 0 /* Binding this prevents execution of Lisp code during
304 redisplay, which necessarily leads to display problems. */
305 specbind (Qinhibit_eval_during_redisplay
, Qt
);
308 val
= apply1 (Vdebugger
, arg
);
310 /* Interrupting redisplay and resuming it later is not safe under
311 all circumstances. So, when the debugger returns, abort the
312 interrupted redisplay by going back to the top-level. */
313 if (debug_while_redisplaying
)
316 return unbind_to (count
, val
);
320 do_debug_on_call (code
)
323 debug_on_next_call
= 0;
324 backtrace_list
->debug_on_exit
= 1;
325 call_debugger (Fcons (code
, Qnil
));
328 /* NOTE!!! Every function that can call EVAL must protect its args
329 and temporaries from garbage collection while it needs them.
330 The definition of `For' shows what you have to do. */
332 DEFUN ("or", For
, Sor
, 0, UNEVALLED
, 0,
333 doc
: /* Eval args until one of them yields non-nil, then return that value.
334 The remaining args are not evalled at all.
335 If all args return nil, return nil.
336 usage: (or CONDITIONS...) */)
340 register Lisp_Object val
= Qnil
;
347 val
= Feval (XCAR (args
));
357 DEFUN ("and", Fand
, Sand
, 0, UNEVALLED
, 0,
358 doc
: /* Eval args until one of them yields nil, then return nil.
359 The remaining args are not evalled at all.
360 If no arg yields nil, return the last arg's value.
361 usage: (and CONDITIONS...) */)
365 register Lisp_Object val
= Qt
;
372 val
= Feval (XCAR (args
));
382 DEFUN ("if", Fif
, Sif
, 2, UNEVALLED
, 0,
383 doc
: /* If COND yields non-nil, do THEN, else do ELSE...
384 Returns the value of THEN or the value of the last of the ELSE's.
385 THEN must be one expression, but ELSE... can be zero or more expressions.
386 If COND yields nil, and there are no ELSE's, the value is nil.
387 usage: (if COND THEN ELSE...) */)
391 register Lisp_Object cond
;
395 cond
= Feval (Fcar (args
));
399 return Feval (Fcar (Fcdr (args
)));
400 return Fprogn (Fcdr (Fcdr (args
)));
403 DEFUN ("cond", Fcond
, Scond
, 0, UNEVALLED
, 0,
404 doc
: /* Try each clause until one succeeds.
405 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
406 and, if the value is non-nil, this clause succeeds:
407 then the expressions in BODY are evaluated and the last one's
408 value is the value of the cond-form.
409 If no clause succeeds, cond returns nil.
410 If a clause has one element, as in (CONDITION),
411 CONDITION's value if non-nil is returned from the cond-form.
412 usage: (cond CLAUSES...) */)
416 register Lisp_Object clause
, val
;
423 clause
= Fcar (args
);
424 val
= Feval (Fcar (clause
));
427 if (!EQ (XCDR (clause
), Qnil
))
428 val
= Fprogn (XCDR (clause
));
438 DEFUN ("progn", Fprogn
, Sprogn
, 0, UNEVALLED
, 0,
439 doc
: /* Eval BODY forms sequentially and return value of last one.
440 usage: (progn BODY...) */)
444 register Lisp_Object val
= Qnil
;
451 val
= Feval (XCAR (args
));
459 DEFUN ("prog1", Fprog1
, Sprog1
, 1, UNEVALLED
, 0,
460 doc
: /* Eval FIRST and BODY sequentially; value from FIRST.
461 The value of FIRST is saved during the evaluation of the remaining args,
462 whose values are discarded.
463 usage: (prog1 FIRST BODY...) */)
468 register Lisp_Object args_left
;
469 struct gcpro gcpro1
, gcpro2
;
470 register int argnum
= 0;
482 val
= Feval (Fcar (args_left
));
484 Feval (Fcar (args_left
));
485 args_left
= Fcdr (args_left
);
487 while (!NILP(args_left
));
493 DEFUN ("prog2", Fprog2
, Sprog2
, 2, UNEVALLED
, 0,
494 doc
: /* Eval FORM1, FORM2 and BODY sequentially; value from FORM2.
495 The value of FORM2 is saved during the evaluation of the
496 remaining args, whose values are discarded.
497 usage: (prog2 FORM1 FORM2 BODY...) */)
502 register Lisp_Object args_left
;
503 struct gcpro gcpro1
, gcpro2
;
504 register int argnum
= -1;
518 val
= Feval (Fcar (args_left
));
520 Feval (Fcar (args_left
));
521 args_left
= Fcdr (args_left
);
523 while (!NILP (args_left
));
529 DEFUN ("setq", Fsetq
, Ssetq
, 0, UNEVALLED
, 0,
530 doc
: /* Set each SYM to the value of its VAL.
531 The symbols SYM are variables; they are literal (not evaluated).
532 The values VAL are expressions; they are evaluated.
533 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
534 The second VAL is not computed until after the first SYM is set, and so on;
535 each VAL can use the new value of variables set earlier in the `setq'.
536 The return value of the `setq' form is the value of the last VAL.
537 usage: (setq [SYM VAL]...) */)
541 register Lisp_Object args_left
;
542 register Lisp_Object val
, sym
;
553 val
= Feval (Fcar (Fcdr (args_left
)));
554 sym
= Fcar (args_left
);
556 args_left
= Fcdr (Fcdr (args_left
));
558 while (!NILP(args_left
));
564 DEFUN ("quote", Fquote
, Squote
, 1, UNEVALLED
, 0,
565 doc
: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
566 usage: (quote ARG) */)
570 if (!NILP (Fcdr (args
)))
571 xsignal2 (Qwrong_number_of_arguments
, Qquote
, Flength (args
));
575 DEFUN ("function", Ffunction
, Sfunction
, 1, UNEVALLED
, 0,
576 doc
: /* Like `quote', but preferred for objects which are functions.
577 In byte compilation, `function' causes its argument to be compiled.
578 `quote' cannot do that.
579 usage: (function ARG) */)
583 if (!NILP (Fcdr (args
)))
584 xsignal2 (Qwrong_number_of_arguments
, Qfunction
, Flength (args
));
589 DEFUN ("interactive-p", Finteractive_p
, Sinteractive_p
, 0, 0, 0,
590 doc
: /* Return t if the function was run directly by user input.
591 This means that the function was called with `call-interactively'
592 \(which includes being called as the binding of a key)
593 and input is currently coming from the keyboard (not in keyboard macro),
594 and Emacs is not running in batch mode (`noninteractive' is nil).
596 The only known proper use of `interactive-p' is in deciding whether to
597 display a helpful message, or how to display it. If you're thinking
598 of using it for any other purpose, it is quite likely that you're
599 making a mistake. Think: what do you want to do when the command is
600 called from a keyboard macro?
602 If you want to test whether your function was called with
603 `call-interactively', the way to do that is by adding an extra
604 optional argument, and making the `interactive' spec specify non-nil
605 unconditionally for that argument. (`p' is a good way to do this.) */)
608 return (INTERACTIVE
&& interactive_p (1)) ? Qt
: Qnil
;
612 DEFUN ("called-interactively-p", Fcalled_interactively_p
, Scalled_interactively_p
, 0, 0, 0,
613 doc
: /* Return t if the function using this was called with `call-interactively'.
614 This is used for implementing advice and other function-modifying
617 The cleanest way to test whether your function was called with
618 `call-interactively' is by adding an extra optional argument,
619 and making the `interactive' spec specify non-nil unconditionally
620 for that argument. (`p' is a good way to do this.) */)
623 return interactive_p (1) ? Qt
: Qnil
;
627 /* Return 1 if function in which this appears was called using
630 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
631 called is a built-in. */
634 interactive_p (exclude_subrs_p
)
637 struct backtrace
*btp
;
640 btp
= backtrace_list
;
642 /* If this isn't a byte-compiled function, there may be a frame at
643 the top for Finteractive_p. If so, skip it. */
644 fun
= Findirect_function (*btp
->function
, Qnil
);
645 if (SUBRP (fun
) && (XSUBR (fun
) == &Sinteractive_p
646 || XSUBR (fun
) == &Scalled_interactively_p
))
649 /* If we're running an Emacs 18-style byte-compiled function, there
650 may be a frame for Fbytecode at the top level. In any version of
651 Emacs there can be Fbytecode frames for subexpressions evaluated
652 inside catch and condition-case. Skip past them.
654 If this isn't a byte-compiled function, then we may now be
655 looking at several frames for special forms. Skip past them. */
657 && (EQ (*btp
->function
, Qbytecode
)
658 || btp
->nargs
== UNEVALLED
))
661 /* btp now points at the frame of the innermost function that isn't
662 a special form, ignoring frames for Finteractive_p and/or
663 Fbytecode at the top. If this frame is for a built-in function
664 (such as load or eval-region) return nil. */
665 fun
= Findirect_function (*btp
->function
, Qnil
);
666 if (exclude_subrs_p
&& SUBRP (fun
))
669 /* btp points to the frame of a Lisp function that called interactive-p.
670 Return t if that function was called interactively. */
671 if (btp
&& btp
->next
&& EQ (*btp
->next
->function
, Qcall_interactively
))
677 DEFUN ("defun", Fdefun
, Sdefun
, 2, UNEVALLED
, 0,
678 doc
: /* Define NAME as a function.
679 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
680 See also the function `interactive'.
681 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
685 register Lisp_Object fn_name
;
686 register Lisp_Object defn
;
688 fn_name
= Fcar (args
);
689 CHECK_SYMBOL (fn_name
);
690 defn
= Fcons (Qlambda
, Fcdr (args
));
691 if (!NILP (Vpurify_flag
))
692 defn
= Fpurecopy (defn
);
693 if (CONSP (XSYMBOL (fn_name
)->function
)
694 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
695 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
696 Ffset (fn_name
, defn
);
697 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
701 DEFUN ("defmacro", Fdefmacro
, Sdefmacro
, 2, UNEVALLED
, 0,
702 doc
: /* Define NAME as a macro.
703 The actual definition looks like
704 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
705 When the macro is called, as in (NAME ARGS...),
706 the function (lambda ARGLIST BODY...) is applied to
707 the list ARGS... as it appears in the expression,
708 and the result should be a form to be evaluated instead of the original.
710 DECL is a declaration, optional, which can specify how to indent
711 calls to this macro and how Edebug should handle it. It looks like this:
713 The elements can look like this:
715 Set NAME's `lisp-indent-function' property to INDENT.
718 Set NAME's `edebug-form-spec' property to DEBUG. (This is
719 equivalent to writing a `def-edebug-spec' for the macro.)
720 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
724 register Lisp_Object fn_name
;
725 register Lisp_Object defn
;
726 Lisp_Object lambda_list
, doc
, tail
;
728 fn_name
= Fcar (args
);
729 CHECK_SYMBOL (fn_name
);
730 lambda_list
= Fcar (Fcdr (args
));
731 tail
= Fcdr (Fcdr (args
));
734 if (STRINGP (Fcar (tail
)))
740 while (CONSP (Fcar (tail
))
741 && EQ (Fcar (Fcar (tail
)), Qdeclare
))
743 if (!NILP (Vmacro_declaration_function
))
747 call2 (Vmacro_declaration_function
, fn_name
, Fcar (tail
));
755 tail
= Fcons (lambda_list
, tail
);
757 tail
= Fcons (lambda_list
, Fcons (doc
, tail
));
758 defn
= Fcons (Qmacro
, Fcons (Qlambda
, tail
));
760 if (!NILP (Vpurify_flag
))
761 defn
= Fpurecopy (defn
);
762 if (CONSP (XSYMBOL (fn_name
)->function
)
763 && EQ (XCAR (XSYMBOL (fn_name
)->function
), Qautoload
))
764 LOADHIST_ATTACH (Fcons (Qt
, fn_name
));
765 Ffset (fn_name
, defn
);
766 LOADHIST_ATTACH (Fcons (Qdefun
, fn_name
));
771 DEFUN ("defvaralias", Fdefvaralias
, Sdefvaralias
, 2, 3, 0,
772 doc
: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
773 Aliased variables always have the same value; setting one sets the other.
774 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
775 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
776 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
777 itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
778 then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
779 The return value is BASE-VARIABLE. */)
780 (new_alias
, base_variable
, docstring
)
781 Lisp_Object new_alias
, base_variable
, docstring
;
783 struct Lisp_Symbol
*sym
;
785 CHECK_SYMBOL (new_alias
);
786 CHECK_SYMBOL (base_variable
);
788 if (SYMBOL_CONSTANT_P (new_alias
))
789 error ("Cannot make a constant an alias");
791 sym
= XSYMBOL (new_alias
);
792 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
793 If n_a is bound, but b_v is not, set the value of b_v to n_a.
794 This is for the sake of define-obsolete-variable-alias and user
796 if (NILP (Fboundp (base_variable
)) && !NILP (Fboundp (new_alias
)))
797 XSYMBOL(base_variable
)->value
= sym
->value
;
798 sym
->indirect_variable
= 1;
799 sym
->value
= base_variable
;
800 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
801 LOADHIST_ATTACH (new_alias
);
802 if (!NILP (docstring
))
803 Fput (new_alias
, Qvariable_documentation
, docstring
);
805 Fput (new_alias
, Qvariable_documentation
, Qnil
);
807 return base_variable
;
811 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
812 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
813 You are not required to define a variable in order to use it,
814 but the definition can supply documentation and an initial value
815 in a way that tags can recognize.
817 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
818 If SYMBOL is buffer-local, its default value is what is set;
819 buffer-local values are not affected.
820 INITVALUE and DOCSTRING are optional.
821 If DOCSTRING starts with *, this variable is identified as a user option.
822 This means that M-x set-variable recognizes it.
823 See also `user-variable-p'.
824 If INITVALUE is missing, SYMBOL's value is not set.
826 If SYMBOL has a local binding, then this form affects the local
827 binding. This is usually not what you want. Thus, if you need to
828 load a file defining variables, with this form or with `defconst' or
829 `defcustom', you should always load that file _outside_ any bindings
830 for these variables. \(`defconst' and `defcustom' behave similarly in
832 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
836 register Lisp_Object sym
, tem
, tail
;
840 if (!NILP (Fcdr (Fcdr (tail
))))
841 error ("Too many arguments");
843 tem
= Fdefault_boundp (sym
);
846 if (SYMBOL_CONSTANT_P (sym
))
848 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
849 Lisp_Object tem
= Fcar (tail
);
851 && EQ (XCAR (tem
), Qquote
)
852 && CONSP (XCDR (tem
))
853 && EQ (XCAR (XCDR (tem
)), sym
)))
854 error ("Constant symbol `%s' specified in defvar",
855 SDATA (SYMBOL_NAME (sym
)));
859 Fset_default (sym
, Feval (Fcar (tail
)));
861 { /* Check if there is really a global binding rather than just a let
862 binding that shadows the global unboundness of the var. */
863 volatile struct specbinding
*pdl
= specpdl_ptr
;
864 while (--pdl
>= specpdl
)
866 if (EQ (pdl
->symbol
, sym
) && !pdl
->func
867 && EQ (pdl
->old_value
, Qunbound
))
869 message_with_string ("Warning: defvar ignored because %s is let-bound",
870 SYMBOL_NAME (sym
), 1);
879 if (!NILP (Vpurify_flag
))
880 tem
= Fpurecopy (tem
);
881 Fput (sym
, Qvariable_documentation
, tem
);
883 LOADHIST_ATTACH (sym
);
886 /* Simple (defvar <var>) should not count as a definition at all.
887 It could get in the way of other definitions, and unloading this
888 package could try to make the variable unbound. */
894 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
895 doc
: /* Define SYMBOL as a constant variable.
896 The intent is that neither programs nor users should ever change this value.
897 Always sets the value of SYMBOL to the result of evalling INITVALUE.
898 If SYMBOL is buffer-local, its default value is what is set;
899 buffer-local values are not affected.
900 DOCSTRING is optional.
902 If SYMBOL has a local binding, then this form sets the local binding's
903 value. However, you should normally not make local bindings for
904 variables defined with this form.
905 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
909 register Lisp_Object sym
, tem
;
912 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
913 error ("Too many arguments");
915 tem
= Feval (Fcar (Fcdr (args
)));
916 if (!NILP (Vpurify_flag
))
917 tem
= Fpurecopy (tem
);
918 Fset_default (sym
, tem
);
919 tem
= Fcar (Fcdr (Fcdr (args
)));
922 if (!NILP (Vpurify_flag
))
923 tem
= Fpurecopy (tem
);
924 Fput (sym
, Qvariable_documentation
, tem
);
926 Fput (sym
, Qrisky_local_variable
, Qt
);
927 LOADHIST_ATTACH (sym
);
931 /* Error handler used in Fuser_variable_p. */
933 user_variable_p_eh (ignore
)
939 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
940 doc
: /* Return t if VARIABLE is intended to be set and modified by users.
941 \(The alternative is a variable used internally in a Lisp program.)
942 A variable is a user variable if
943 \(1) the first character of its documentation is `*', or
944 \(2) it is customizable (its property list contains a non-nil value
945 of `standard-value' or `custom-autoload'), or
946 \(3) it is an alias for another user variable.
947 Return nil if VARIABLE is an alias and there is a loop in the
948 chain of symbols. */)
950 Lisp_Object variable
;
952 Lisp_Object documentation
;
954 if (!SYMBOLP (variable
))
957 /* If indirect and there's an alias loop, don't check anything else. */
958 if (XSYMBOL (variable
)->indirect_variable
959 && NILP (internal_condition_case_1 (indirect_variable
, variable
,
960 Qt
, user_variable_p_eh
)))
965 documentation
= Fget (variable
, Qvariable_documentation
);
966 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
968 if (STRINGP (documentation
)
969 && ((unsigned char) SREF (documentation
, 0) == '*'))
971 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
972 if (CONSP (documentation
)
973 && STRINGP (XCAR (documentation
))
974 && INTEGERP (XCDR (documentation
))
975 && XINT (XCDR (documentation
)) < 0)
977 /* Customizable? See `custom-variable-p'. */
978 if ((!NILP (Fget (variable
, intern ("standard-value"))))
979 || (!NILP (Fget (variable
, intern ("custom-autoload")))))
982 if (!XSYMBOL (variable
)->indirect_variable
)
985 /* An indirect variable? Let's follow the chain. */
986 variable
= XSYMBOL (variable
)->value
;
990 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
991 doc
: /* Bind variables according to VARLIST then eval BODY.
992 The value of the last form in BODY is returned.
993 Each element of VARLIST is a symbol (which is bound to nil)
994 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
995 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
996 usage: (let* VARLIST BODY...) */)
1000 Lisp_Object varlist
, val
, elt
;
1001 int count
= SPECPDL_INDEX ();
1002 struct gcpro gcpro1
, gcpro2
, gcpro3
;
1004 GCPRO3 (args
, elt
, varlist
);
1006 varlist
= Fcar (args
);
1007 while (!NILP (varlist
))
1010 elt
= Fcar (varlist
);
1012 specbind (elt
, Qnil
);
1013 else if (! NILP (Fcdr (Fcdr (elt
))))
1014 signal_error ("`let' bindings can have only one value-form", elt
);
1017 val
= Feval (Fcar (Fcdr (elt
)));
1018 specbind (Fcar (elt
), val
);
1020 varlist
= Fcdr (varlist
);
1023 val
= Fprogn (Fcdr (args
));
1024 return unbind_to (count
, val
);
1027 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
1028 doc
: /* Bind variables according to VARLIST then eval BODY.
1029 The value of the last form in BODY is returned.
1030 Each element of VARLIST is a symbol (which is bound to nil)
1031 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1032 All the VALUEFORMs are evalled before any symbols are bound.
1033 usage: (let VARLIST BODY...) */)
1037 Lisp_Object
*temps
, tem
;
1038 register Lisp_Object elt
, varlist
;
1039 int count
= SPECPDL_INDEX ();
1040 register int argnum
;
1041 struct gcpro gcpro1
, gcpro2
;
1043 varlist
= Fcar (args
);
1045 /* Make space to hold the values to give the bound variables */
1046 elt
= Flength (varlist
);
1047 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
1049 /* Compute the values and store them in `temps' */
1051 GCPRO2 (args
, *temps
);
1054 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
1057 elt
= XCAR (varlist
);
1059 temps
[argnum
++] = Qnil
;
1060 else if (! NILP (Fcdr (Fcdr (elt
))))
1061 signal_error ("`let' bindings can have only one value-form", elt
);
1063 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
1064 gcpro2
.nvars
= argnum
;
1068 varlist
= Fcar (args
);
1069 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
1071 elt
= XCAR (varlist
);
1072 tem
= temps
[argnum
++];
1074 specbind (elt
, tem
);
1076 specbind (Fcar (elt
), tem
);
1079 elt
= Fprogn (Fcdr (args
));
1080 return unbind_to (count
, elt
);
1083 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
1084 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
1085 The order of execution is thus TEST, BODY, TEST, BODY and so on
1086 until TEST returns nil.
1087 usage: (while TEST BODY...) */)
1091 Lisp_Object test
, body
;
1092 struct gcpro gcpro1
, gcpro2
;
1094 GCPRO2 (test
, body
);
1098 while (!NILP (Feval (test
)))
1108 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1109 doc
: /* Return result of expanding macros at top level of FORM.
1110 If FORM is not a macro call, it is returned unchanged.
1111 Otherwise, the macro is expanded and the expansion is considered
1112 in place of FORM. When a non-macro-call results, it is returned.
1114 The second optional arg ENVIRONMENT specifies an environment of macro
1115 definitions to shadow the loaded ones for use in file byte-compilation. */)
1118 Lisp_Object environment
;
1120 /* With cleanups from Hallvard Furuseth. */
1121 register Lisp_Object expander
, sym
, def
, tem
;
1125 /* Come back here each time we expand a macro call,
1126 in case it expands into another macro call. */
1129 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1130 def
= sym
= XCAR (form
);
1132 /* Trace symbols aliases to other symbols
1133 until we get a symbol that is not an alias. */
1134 while (SYMBOLP (def
))
1138 tem
= Fassq (sym
, environment
);
1141 def
= XSYMBOL (sym
)->function
;
1142 if (!EQ (def
, Qunbound
))
1147 /* Right now TEM is the result from SYM in ENVIRONMENT,
1148 and if TEM is nil then DEF is SYM's function definition. */
1151 /* SYM is not mentioned in ENVIRONMENT.
1152 Look at its function definition. */
1153 if (EQ (def
, Qunbound
) || !CONSP (def
))
1154 /* Not defined or definition not suitable */
1156 if (EQ (XCAR (def
), Qautoload
))
1158 /* Autoloading function: will it be a macro when loaded? */
1159 tem
= Fnth (make_number (4), def
);
1160 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1161 /* Yes, load it and try again. */
1163 struct gcpro gcpro1
;
1165 do_autoload (def
, sym
);
1172 else if (!EQ (XCAR (def
), Qmacro
))
1174 else expander
= XCDR (def
);
1178 expander
= XCDR (tem
);
1179 if (NILP (expander
))
1182 form
= apply1 (expander
, XCDR (form
));
1187 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1188 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1189 TAG is evalled to get the tag to use; it must not be nil.
1191 Then the BODY is executed.
1192 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1193 If no throw happens, `catch' returns the value of the last BODY form.
1194 If a throw happens, it specifies the value to return from `catch'.
1195 usage: (catch TAG BODY...) */)
1199 register Lisp_Object tag
;
1200 struct gcpro gcpro1
;
1203 tag
= Feval (Fcar (args
));
1205 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1208 /* Set up a catch, then call C function FUNC on argument ARG.
1209 FUNC should return a Lisp_Object.
1210 This is how catches are done from within C code. */
1213 internal_catch (tag
, func
, arg
)
1215 Lisp_Object (*func
) ();
1218 /* This structure is made part of the chain `catchlist'. */
1221 /* Fill in the components of c, and put it on the list. */
1225 c
.backlist
= backtrace_list
;
1226 c
.handlerlist
= handlerlist
;
1227 c
.lisp_eval_depth
= lisp_eval_depth
;
1228 c
.pdlcount
= SPECPDL_INDEX ();
1229 c
.poll_suppress_count
= poll_suppress_count
;
1230 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1231 c
.gcpro
= gcprolist
;
1232 c
.byte_stack
= byte_stack_list
;
1236 if (! _setjmp (c
.jmp
))
1237 c
.val
= (*func
) (arg
);
1239 /* Throw works by a longjmp that comes right here. */
1244 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1245 jump to that CATCH, returning VALUE as the value of that catch.
1247 This is the guts Fthrow and Fsignal; they differ only in the way
1248 they choose the catch tag to throw to. A catch tag for a
1249 condition-case form has a TAG of Qnil.
1251 Before each catch is discarded, unbind all special bindings and
1252 execute all unwind-protect clauses made above that catch. Unwind
1253 the handler stack as we go, so that the proper handlers are in
1254 effect for each unwind-protect clause we run. At the end, restore
1255 some static info saved in CATCH, and longjmp to the location
1258 This is used for correct unwinding in Fthrow and Fsignal. */
1261 unwind_to_catch (catch, value
)
1262 struct catchtag
*catch;
1265 register int last_time
;
1267 /* Save the value in the tag. */
1270 /* Restore certain special C variables. */
1271 set_poll_suppress_count (catch->poll_suppress_count
);
1272 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked
);
1273 handling_signal
= 0;
1278 last_time
= catchlist
== catch;
1280 /* Unwind the specpdl stack, and then restore the proper set of
1282 unbind_to (catchlist
->pdlcount
, Qnil
);
1283 handlerlist
= catchlist
->handlerlist
;
1284 catchlist
= catchlist
->next
;
1286 while (! last_time
);
1289 /* If x_catch_errors was done, turn it off now.
1290 (First we give unbind_to a chance to do that.) */
1291 #if 0 /* This would disable x_catch_errors after x_connection_closed.
1292 * The catch must remain in effect during that delicate
1293 * state. --lorentey */
1294 x_fully_uncatch_errors ();
1298 byte_stack_list
= catch->byte_stack
;
1299 gcprolist
= catch->gcpro
;
1302 gcpro_level
= gcprolist
->level
+ 1;
1306 backtrace_list
= catch->backlist
;
1307 lisp_eval_depth
= catch->lisp_eval_depth
;
1309 _longjmp (catch->jmp
, 1);
1312 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1313 doc
: /* Throw to the catch for TAG and return VALUE from it.
1314 Both TAG and VALUE are evalled. */)
1316 register Lisp_Object tag
, value
;
1318 register struct catchtag
*c
;
1321 for (c
= catchlist
; c
; c
= c
->next
)
1323 if (EQ (c
->tag
, tag
))
1324 unwind_to_catch (c
, value
);
1326 xsignal2 (Qno_catch
, tag
, value
);
1330 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1331 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1332 If BODYFORM completes normally, its value is returned
1333 after executing the UNWINDFORMS.
1334 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1335 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1340 int count
= SPECPDL_INDEX ();
1342 record_unwind_protect (Fprogn
, Fcdr (args
));
1343 val
= Feval (Fcar (args
));
1344 return unbind_to (count
, val
);
1347 /* Chain of condition handlers currently in effect.
1348 The elements of this chain are contained in the stack frames
1349 of Fcondition_case and internal_condition_case.
1350 When an error is signaled (by calling Fsignal, below),
1351 this chain is searched for an element that applies. */
1353 struct handler
*handlerlist
;
1355 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1356 doc
: /* Regain control when an error is signaled.
1357 Executes BODYFORM and returns its value if no error happens.
1358 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1359 where the BODY is made of Lisp expressions.
1361 A handler is applicable to an error
1362 if CONDITION-NAME is one of the error's condition names.
1363 If an error happens, the first applicable handler is run.
1365 The car of a handler may be a list of condition names
1366 instead of a single condition name. Then it handles all of them.
1368 When a handler handles an error, control returns to the `condition-case'
1369 and it executes the handler's BODY...
1370 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA) from the error.
1371 (If VAR is nil, the handler can't access that information.)
1372 Then the value of the last BODY form is returned from the `condition-case'
1375 See also the function `signal' for more info.
1376 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1380 register Lisp_Object bodyform
, handlers
;
1381 volatile Lisp_Object var
;
1384 bodyform
= Fcar (Fcdr (args
));
1385 handlers
= Fcdr (Fcdr (args
));
1387 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1390 /* Like Fcondition_case, but the args are separate
1391 rather than passed in a list. Used by Fbyte_code. */
1394 internal_lisp_condition_case (var
, bodyform
, handlers
)
1395 volatile Lisp_Object var
;
1396 Lisp_Object bodyform
, handlers
;
1404 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1410 && (SYMBOLP (XCAR (tem
))
1411 || CONSP (XCAR (tem
))))))
1412 error ("Invalid condition handler", tem
);
1417 c
.backlist
= backtrace_list
;
1418 c
.handlerlist
= handlerlist
;
1419 c
.lisp_eval_depth
= lisp_eval_depth
;
1420 c
.pdlcount
= SPECPDL_INDEX ();
1421 c
.poll_suppress_count
= poll_suppress_count
;
1422 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1423 c
.gcpro
= gcprolist
;
1424 c
.byte_stack
= byte_stack_list
;
1425 if (_setjmp (c
.jmp
))
1428 specbind (h
.var
, c
.val
);
1429 val
= Fprogn (Fcdr (h
.chosen_clause
));
1431 /* Note that this just undoes the binding of h.var; whoever
1432 longjumped to us unwound the stack to c.pdlcount before
1434 unbind_to (c
.pdlcount
, Qnil
);
1441 h
.handler
= handlers
;
1442 h
.next
= handlerlist
;
1446 val
= Feval (bodyform
);
1448 handlerlist
= h
.next
;
1452 /* Call the function BFUN with no arguments, catching errors within it
1453 according to HANDLERS. If there is an error, call HFUN with
1454 one argument which is the data that describes the error:
1457 HANDLERS can be a list of conditions to catch.
1458 If HANDLERS is Qt, catch all errors.
1459 If HANDLERS is Qerror, catch all errors
1460 but allow the debugger to run if that is enabled. */
1463 internal_condition_case (bfun
, handlers
, hfun
)
1464 Lisp_Object (*bfun
) ();
1465 Lisp_Object handlers
;
1466 Lisp_Object (*hfun
) ();
1472 /* Since Fsignal will close off all calls to x_catch_errors,
1473 we will get the wrong results if some are not closed now. */
1475 if (x_catching_errors ())
1481 c
.backlist
= backtrace_list
;
1482 c
.handlerlist
= handlerlist
;
1483 c
.lisp_eval_depth
= lisp_eval_depth
;
1484 c
.pdlcount
= SPECPDL_INDEX ();
1485 c
.poll_suppress_count
= poll_suppress_count
;
1486 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1487 c
.gcpro
= gcprolist
;
1488 c
.byte_stack
= byte_stack_list
;
1489 if (_setjmp (c
.jmp
))
1491 return (*hfun
) (c
.val
);
1495 h
.handler
= handlers
;
1497 h
.next
= handlerlist
;
1503 handlerlist
= h
.next
;
1507 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1510 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1511 Lisp_Object (*bfun
) ();
1513 Lisp_Object handlers
;
1514 Lisp_Object (*hfun
) ();
1520 /* Since Fsignal will close off all calls to x_catch_errors,
1521 we will get the wrong results if some are not closed now. */
1523 if (x_catching_errors ())
1529 c
.backlist
= backtrace_list
;
1530 c
.handlerlist
= handlerlist
;
1531 c
.lisp_eval_depth
= lisp_eval_depth
;
1532 c
.pdlcount
= SPECPDL_INDEX ();
1533 c
.poll_suppress_count
= poll_suppress_count
;
1534 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1535 c
.gcpro
= gcprolist
;
1536 c
.byte_stack
= byte_stack_list
;
1537 if (_setjmp (c
.jmp
))
1539 return (*hfun
) (c
.val
);
1543 h
.handler
= handlers
;
1545 h
.next
= handlerlist
;
1549 val
= (*bfun
) (arg
);
1551 handlerlist
= h
.next
;
1556 /* Like internal_condition_case but call BFUN with NARGS as first,
1557 and ARGS as second argument. */
1560 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1561 Lisp_Object (*bfun
) ();
1564 Lisp_Object handlers
;
1565 Lisp_Object (*hfun
) ();
1571 /* Since Fsignal will close off all calls to x_catch_errors,
1572 we will get the wrong results if some are not closed now. */
1574 if (x_catching_errors ())
1580 c
.backlist
= backtrace_list
;
1581 c
.handlerlist
= handlerlist
;
1582 c
.lisp_eval_depth
= lisp_eval_depth
;
1583 c
.pdlcount
= SPECPDL_INDEX ();
1584 c
.poll_suppress_count
= poll_suppress_count
;
1585 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1586 c
.gcpro
= gcprolist
;
1587 c
.byte_stack
= byte_stack_list
;
1588 if (_setjmp (c
.jmp
))
1590 return (*hfun
) (c
.val
);
1594 h
.handler
= handlers
;
1596 h
.next
= handlerlist
;
1600 val
= (*bfun
) (nargs
, args
);
1602 handlerlist
= h
.next
;
1607 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1608 Lisp_Object
, Lisp_Object
));
1610 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1611 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1612 This function does not return.
1614 An error symbol is a symbol with an `error-conditions' property
1615 that is a list of condition names.
1616 A handler for any of those names will get to handle this signal.
1617 The symbol `error' should normally be one of them.
1619 DATA should be a list. Its elements are printed as part of the error message.
1620 See Info anchor `(elisp)Definition of signal' for some details on how this
1621 error message is constructed.
1622 If the signal is handled, DATA is made available to the handler.
1623 See also the function `condition-case'. */)
1624 (error_symbol
, data
)
1625 Lisp_Object error_symbol
, data
;
1627 /* When memory is full, ERROR-SYMBOL is nil,
1628 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1629 That is a special case--don't do this in other situations. */
1630 register struct handler
*allhandlers
= handlerlist
;
1631 Lisp_Object conditions
;
1632 extern int gc_in_progress
;
1633 extern int waiting_for_input
;
1635 Lisp_Object real_error_symbol
;
1636 struct backtrace
*bp
;
1638 immediate_quit
= handling_signal
= 0;
1640 if (gc_in_progress
|| waiting_for_input
)
1643 if (NILP (error_symbol
))
1644 real_error_symbol
= Fcar (data
);
1646 real_error_symbol
= error_symbol
;
1648 #if 0 /* rms: I don't know why this was here,
1649 but it is surely wrong for an error that is handled. */
1650 #ifdef HAVE_WINDOW_SYSTEM
1651 if (display_hourglass_p
)
1652 cancel_hourglass ();
1656 /* This hook is used by edebug. */
1657 if (! NILP (Vsignal_hook_function
)
1658 && ! NILP (error_symbol
))
1660 /* Edebug takes care of restoring these variables when it exits. */
1661 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1662 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1664 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1665 max_specpdl_size
= SPECPDL_INDEX () + 40;
1667 call2 (Vsignal_hook_function
, error_symbol
, data
);
1670 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1672 /* Remember from where signal was called. Skip over the frame for
1673 `signal' itself. If a frame for `error' follows, skip that,
1674 too. Don't do this when ERROR_SYMBOL is nil, because that
1675 is a memory-full error. */
1676 Vsignaling_function
= Qnil
;
1677 if (backtrace_list
&& !NILP (error_symbol
))
1679 bp
= backtrace_list
->next
;
1680 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1682 if (bp
&& bp
->function
)
1683 Vsignaling_function
= *bp
->function
;
1686 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1688 register Lisp_Object clause
;
1690 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1691 error_symbol
, data
);
1693 if (EQ (clause
, Qlambda
))
1695 /* We can't return values to code which signaled an error, but we
1696 can continue code which has signaled a quit. */
1697 if (EQ (real_error_symbol
, Qquit
))
1700 error ("Cannot return from the debugger in an error");
1705 Lisp_Object unwind_data
;
1706 struct handler
*h
= handlerlist
;
1708 handlerlist
= allhandlers
;
1710 if (NILP (error_symbol
))
1713 unwind_data
= Fcons (error_symbol
, data
);
1714 h
->chosen_clause
= clause
;
1715 unwind_to_catch (h
->tag
, unwind_data
);
1719 handlerlist
= allhandlers
;
1720 /* If no handler is present now, try to run the debugger,
1721 and if that fails, throw to top level. */
1722 find_handler_clause (Qerror
, conditions
, error_symbol
, data
);
1724 Fthrow (Qtop_level
, Qt
);
1726 if (! NILP (error_symbol
))
1727 data
= Fcons (error_symbol
, data
);
1729 string
= Ferror_message_string (data
);
1730 fatal ("%s", SDATA (string
), 0);
1733 /* Internal version of Fsignal that never returns.
1734 Used for anything but Qquit (which can return from Fsignal). */
1737 xsignal (error_symbol
, data
)
1738 Lisp_Object error_symbol
, data
;
1740 Fsignal (error_symbol
, data
);
1744 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1747 xsignal0 (error_symbol
)
1748 Lisp_Object error_symbol
;
1750 xsignal (error_symbol
, Qnil
);
1754 xsignal1 (error_symbol
, arg
)
1755 Lisp_Object error_symbol
, arg
;
1757 xsignal (error_symbol
, list1 (arg
));
1761 xsignal2 (error_symbol
, arg1
, arg2
)
1762 Lisp_Object error_symbol
, arg1
, arg2
;
1764 xsignal (error_symbol
, list2 (arg1
, arg2
));
1768 xsignal3 (error_symbol
, arg1
, arg2
, arg3
)
1769 Lisp_Object error_symbol
, arg1
, arg2
, arg3
;
1771 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1774 /* Signal `error' with message S, and additional arg ARG.
1775 If ARG is not a genuine list, make it a one-element list. */
1778 signal_error (s
, arg
)
1782 Lisp_Object tortoise
, hare
;
1784 hare
= tortoise
= arg
;
1785 while (CONSP (hare
))
1792 tortoise
= XCDR (tortoise
);
1794 if (EQ (hare
, tortoise
))
1799 arg
= Fcons (arg
, Qnil
); /* Make it a list. */
1801 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1805 /* Return nonzero if LIST is a non-nil atom or
1806 a list containing one of CONDITIONS. */
1809 wants_debugger (list
, conditions
)
1810 Lisp_Object list
, conditions
;
1817 while (CONSP (conditions
))
1819 Lisp_Object
this, tail
;
1820 this = XCAR (conditions
);
1821 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1822 if (EQ (XCAR (tail
), this))
1824 conditions
= XCDR (conditions
);
1829 /* Return 1 if an error with condition-symbols CONDITIONS,
1830 and described by SIGNAL-DATA, should skip the debugger
1831 according to debugger-ignored-errors. */
1834 skip_debugger (conditions
, data
)
1835 Lisp_Object conditions
, data
;
1838 int first_string
= 1;
1839 Lisp_Object error_message
;
1841 error_message
= Qnil
;
1842 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1844 if (STRINGP (XCAR (tail
)))
1848 error_message
= Ferror_message_string (data
);
1852 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1857 Lisp_Object contail
;
1859 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1860 if (EQ (XCAR (tail
), XCAR (contail
)))
1868 /* Value of Qlambda means we have called debugger and user has continued.
1869 There are two ways to pass SIG and DATA:
1870 = SIG is the error symbol, and DATA is the rest of the data.
1871 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1872 This is for memory-full errors only.
1874 We need to increase max_specpdl_size temporarily around
1875 anything we do that can push on the specpdl, so as not to get
1876 a second error here in case we're handling specpdl overflow. */
1879 find_handler_clause (handlers
, conditions
, sig
, data
)
1880 Lisp_Object handlers
, conditions
, sig
, data
;
1882 register Lisp_Object h
;
1883 register Lisp_Object tem
;
1884 int debugger_called
= 0;
1885 int debugger_considered
= 0;
1887 /* t is used by handlers for all conditions, set up by C code. */
1888 if (EQ (handlers
, Qt
))
1891 /* Don't run the debugger for a memory-full error.
1892 (There is no room in memory to do that!) */
1894 debugger_considered
= 1;
1896 /* error is used similarly, but means print an error message
1897 and run the debugger if that is enabled. */
1898 if (EQ (handlers
, Qerror
)
1899 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1900 there is a handler. */
1902 if (!NILP (sig
) && wants_debugger (Vstack_trace_on_error
, conditions
))
1906 internal_with_output_to_temp_buffer ("*Backtrace*",
1907 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1910 internal_with_output_to_temp_buffer ("*Backtrace*",
1916 if (!debugger_considered
)
1918 debugger_considered
= 1;
1919 debugger_called
= maybe_call_debugger (conditions
, sig
, data
);
1922 /* If there is no handler, return saying whether we ran the debugger. */
1923 if (EQ (handlers
, Qerror
))
1925 if (debugger_called
)
1931 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1933 Lisp_Object handler
, condit
;
1936 if (!CONSP (handler
))
1938 condit
= Fcar (handler
);
1939 /* Handle a single condition name in handler HANDLER. */
1940 if (SYMBOLP (condit
))
1942 tem
= Fmemq (Fcar (handler
), conditions
);
1946 /* Handle a list of condition names in handler HANDLER. */
1947 else if (CONSP (condit
))
1950 for (tail
= condit
; CONSP (tail
); tail
= XCDR (tail
))
1952 tem
= Fmemq (Fcar (tail
), conditions
);
1955 /* This handler is going to apply.
1956 Does it allow the debugger to run first? */
1957 if (! debugger_considered
&& !NILP (Fmemq (Qdebug
, condit
)))
1958 maybe_call_debugger (conditions
, sig
, data
);
1968 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1969 SIG and DATA describe the signal, as in find_handler_clause. */
1972 maybe_call_debugger (conditions
, sig
, data
)
1973 Lisp_Object conditions
, sig
, data
;
1975 Lisp_Object combined_data
;
1977 combined_data
= Fcons (sig
, data
);
1980 /* Don't try to run the debugger with interrupts blocked.
1981 The editing loop would return anyway. */
1983 /* Does user wants to enter debugger for this kind of error? */
1986 : wants_debugger (Vdebug_on_error
, conditions
))
1987 && ! skip_debugger (conditions
, combined_data
)
1988 /* rms: what's this for? */
1989 && when_entered_debugger
< num_nonmacro_input_events
)
1991 call_debugger (Fcons (Qerror
, Fcons (combined_data
, Qnil
)));
1998 /* dump an error message; called like printf */
2002 error (m
, a1
, a2
, a3
)
2022 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
2027 buffer
= (char *) xrealloc (buffer
, size
);
2030 buffer
= (char *) xmalloc (size
);
2035 string
= build_string (buffer
);
2039 xsignal1 (Qerror
, string
);
2042 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
2043 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
2044 This means it contains a description for how to read arguments to give it.
2045 The value is nil for an invalid function or a symbol with no function
2048 Interactively callable functions include strings and vectors (treated
2049 as keyboard macros), lambda-expressions that contain a top-level call
2050 to `interactive', autoload definitions made by `autoload' with non-nil
2051 fourth argument, and some of the built-in functions of Lisp.
2053 Also, a symbol satisfies `commandp' if its function definition does so.
2055 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
2056 then strings and vectors are not accepted. */)
2057 (function
, for_call_interactively
)
2058 Lisp_Object function
, for_call_interactively
;
2060 register Lisp_Object fun
;
2061 register Lisp_Object funcar
;
2062 Lisp_Object if_prop
= Qnil
;
2066 fun
= indirect_function (fun
); /* Check cycles. */
2067 if (NILP (fun
) || EQ (fun
, Qunbound
))
2070 /* Check an `interactive-form' property if present, analogous to the
2071 function-documentation property. */
2073 while (SYMBOLP (fun
))
2075 Lisp_Object tmp
= Fget (fun
, intern ("interactive-form"));
2078 fun
= Fsymbol_function (fun
);
2081 /* Emacs primitives are interactive if their DEFUN specifies an
2082 interactive spec. */
2084 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
2086 /* Bytecode objects are interactive if they are long enough to
2087 have an element whose index is COMPILED_INTERACTIVE, which is
2088 where the interactive spec is stored. */
2089 else if (COMPILEDP (fun
))
2090 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
2093 /* Strings and vectors are keyboard macros. */
2094 if (STRINGP (fun
) || VECTORP (fun
))
2095 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
2097 /* Lists may represent commands. */
2100 funcar
= XCAR (fun
);
2101 if (EQ (funcar
, Qlambda
))
2102 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
2103 if (EQ (funcar
, Qautoload
))
2104 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
2110 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
2111 doc
: /* Define FUNCTION to autoload from FILE.
2112 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2113 Third arg DOCSTRING is documentation for the function.
2114 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2115 Fifth arg TYPE indicates the type of the object:
2116 nil or omitted says FUNCTION is a function,
2117 `keymap' says FUNCTION is really a keymap, and
2118 `macro' or t says FUNCTION is really a macro.
2119 Third through fifth args give info about the real definition.
2120 They default to nil.
2121 If FUNCTION is already defined other than as an autoload,
2122 this does nothing and returns nil. */)
2123 (function
, file
, docstring
, interactive
, type
)
2124 Lisp_Object function
, file
, docstring
, interactive
, type
;
2127 Lisp_Object args
[4];
2130 CHECK_SYMBOL (function
);
2131 CHECK_STRING (file
);
2133 /* If function is defined and not as an autoload, don't override */
2134 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
2135 && !(CONSP (XSYMBOL (function
)->function
)
2136 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
2139 if (NILP (Vpurify_flag
))
2140 /* Only add entries after dumping, because the ones before are
2141 not useful and else we get loads of them from the loaddefs.el. */
2142 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
2146 args
[1] = docstring
;
2147 args
[2] = interactive
;
2150 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
2151 #else /* NO_ARG_ARRAY */
2152 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
2153 #endif /* not NO_ARG_ARRAY */
2157 un_autoload (oldqueue
)
2158 Lisp_Object oldqueue
;
2160 register Lisp_Object queue
, first
, second
;
2162 /* Queue to unwind is current value of Vautoload_queue.
2163 oldqueue is the shadowed value to leave in Vautoload_queue. */
2164 queue
= Vautoload_queue
;
2165 Vautoload_queue
= oldqueue
;
2166 while (CONSP (queue
))
2168 first
= XCAR (queue
);
2169 second
= Fcdr (first
);
2170 first
= Fcar (first
);
2171 if (EQ (first
, make_number (0)))
2174 Ffset (first
, second
);
2175 queue
= XCDR (queue
);
2180 /* Load an autoloaded function.
2181 FUNNAME is the symbol which is the function's name.
2182 FUNDEF is the autoload definition (a list). */
2185 do_autoload (fundef
, funname
)
2186 Lisp_Object fundef
, funname
;
2188 int count
= SPECPDL_INDEX ();
2190 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2192 /* This is to make sure that loadup.el gives a clear picture
2193 of what files are preloaded and when. */
2194 if (! NILP (Vpurify_flag
))
2195 error ("Attempt to autoload %s while preparing to dump",
2196 SDATA (SYMBOL_NAME (funname
)));
2199 CHECK_SYMBOL (funname
);
2200 GCPRO3 (fun
, funname
, fundef
);
2202 /* Preserve the match data. */
2203 record_unwind_save_match_data ();
2205 /* If autoloading gets an error (which includes the error of failing
2206 to define the function being called), we use Vautoload_queue
2207 to undo function definitions and `provide' calls made by
2208 the function. We do this in the specific case of autoloading
2209 because autoloading is not an explicit request "load this file",
2210 but rather a request to "call this function".
2212 The value saved here is to be restored into Vautoload_queue. */
2213 record_unwind_protect (un_autoload
, Vautoload_queue
);
2214 Vautoload_queue
= Qt
;
2215 Fload (Fcar (Fcdr (fundef
)), Qnil
, Qt
, Qnil
, Qt
);
2217 /* Once loading finishes, don't undo it. */
2218 Vautoload_queue
= Qt
;
2219 unbind_to (count
, Qnil
);
2221 fun
= Findirect_function (fun
, Qnil
);
2223 if (!NILP (Fequal (fun
, fundef
)))
2224 error ("Autoloading failed to define function %s",
2225 SDATA (SYMBOL_NAME (funname
)));
2230 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
2231 doc
: /* Evaluate FORM and return its value. */)
2235 Lisp_Object fun
, val
, original_fun
, original_args
;
2237 struct backtrace backtrace
;
2238 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2240 if (handling_signal
)
2244 return Fsymbol_value (form
);
2249 if ((consing_since_gc
> gc_cons_threshold
2250 && consing_since_gc
> gc_relative_threshold
)
2252 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2255 Fgarbage_collect ();
2259 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2261 if (max_lisp_eval_depth
< 100)
2262 max_lisp_eval_depth
= 100;
2263 if (lisp_eval_depth
> max_lisp_eval_depth
)
2264 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2267 original_fun
= Fcar (form
);
2268 original_args
= Fcdr (form
);
2270 backtrace
.next
= backtrace_list
;
2271 backtrace_list
= &backtrace
;
2272 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2273 backtrace
.args
= &original_args
;
2274 backtrace
.nargs
= UNEVALLED
;
2275 backtrace
.evalargs
= 1;
2276 backtrace
.debug_on_exit
= 0;
2278 if (debug_on_next_call
)
2279 do_debug_on_call (Qt
);
2281 /* At this point, only original_fun and original_args
2282 have values that will be used below */
2285 /* Optimize for no indirection. */
2287 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2288 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2289 fun
= indirect_function (fun
);
2293 Lisp_Object numargs
;
2294 Lisp_Object argvals
[8];
2295 Lisp_Object args_left
;
2296 register int i
, maxargs
;
2298 args_left
= original_args
;
2299 numargs
= Flength (args_left
);
2303 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2304 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2305 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2307 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2309 backtrace
.evalargs
= 0;
2310 val
= (*XSUBR (fun
)->function
) (args_left
);
2314 if (XSUBR (fun
)->max_args
== MANY
)
2316 /* Pass a vector of evaluated arguments */
2318 register int argnum
= 0;
2320 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2322 GCPRO3 (args_left
, fun
, fun
);
2326 while (!NILP (args_left
))
2328 vals
[argnum
++] = Feval (Fcar (args_left
));
2329 args_left
= Fcdr (args_left
);
2330 gcpro3
.nvars
= argnum
;
2333 backtrace
.args
= vals
;
2334 backtrace
.nargs
= XINT (numargs
);
2336 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2341 GCPRO3 (args_left
, fun
, fun
);
2342 gcpro3
.var
= argvals
;
2345 maxargs
= XSUBR (fun
)->max_args
;
2346 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2348 argvals
[i
] = Feval (Fcar (args_left
));
2354 backtrace
.args
= argvals
;
2355 backtrace
.nargs
= XINT (numargs
);
2360 val
= (*XSUBR (fun
)->function
) ();
2363 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2366 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2369 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2373 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2374 argvals
[2], argvals
[3]);
2377 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2378 argvals
[3], argvals
[4]);
2381 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2382 argvals
[3], argvals
[4], argvals
[5]);
2385 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2386 argvals
[3], argvals
[4], argvals
[5],
2391 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2392 argvals
[3], argvals
[4], argvals
[5],
2393 argvals
[6], argvals
[7]);
2397 /* Someone has created a subr that takes more arguments than
2398 is supported by this code. We need to either rewrite the
2399 subr to use a different argument protocol, or add more
2400 cases to this switch. */
2404 if (COMPILEDP (fun
))
2405 val
= apply_lambda (fun
, original_args
, 1);
2408 if (EQ (fun
, Qunbound
))
2409 xsignal1 (Qvoid_function
, original_fun
);
2411 xsignal1 (Qinvalid_function
, original_fun
);
2412 funcar
= XCAR (fun
);
2413 if (!SYMBOLP (funcar
))
2414 xsignal1 (Qinvalid_function
, original_fun
);
2415 if (EQ (funcar
, Qautoload
))
2417 do_autoload (fun
, original_fun
);
2420 if (EQ (funcar
, Qmacro
))
2421 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2422 else if (EQ (funcar
, Qlambda
))
2423 val
= apply_lambda (fun
, original_args
, 1);
2425 xsignal1 (Qinvalid_function
, original_fun
);
2431 if (backtrace
.debug_on_exit
)
2432 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2433 backtrace_list
= backtrace
.next
;
2438 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2439 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2440 Then return the value FUNCTION returns.
2441 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2442 usage: (apply FUNCTION &rest ARGUMENTS) */)
2447 register int i
, numargs
;
2448 register Lisp_Object spread_arg
;
2449 register Lisp_Object
*funcall_args
;
2451 struct gcpro gcpro1
;
2455 spread_arg
= args
[nargs
- 1];
2456 CHECK_LIST (spread_arg
);
2458 numargs
= XINT (Flength (spread_arg
));
2461 return Ffuncall (nargs
- 1, args
);
2462 else if (numargs
== 1)
2464 args
[nargs
- 1] = XCAR (spread_arg
);
2465 return Ffuncall (nargs
, args
);
2468 numargs
+= nargs
- 2;
2470 /* Optimize for no indirection. */
2471 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2472 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2473 fun
= indirect_function (fun
);
2474 if (EQ (fun
, Qunbound
))
2476 /* Let funcall get the error */
2483 if (numargs
< XSUBR (fun
)->min_args
2484 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2485 goto funcall
; /* Let funcall get the error */
2486 else if (XSUBR (fun
)->max_args
> numargs
)
2488 /* Avoid making funcall cons up a yet another new vector of arguments
2489 by explicitly supplying nil's for optional values */
2490 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2491 * sizeof (Lisp_Object
));
2492 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2493 funcall_args
[++i
] = Qnil
;
2494 GCPRO1 (*funcall_args
);
2495 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2499 /* We add 1 to numargs because funcall_args includes the
2500 function itself as well as its arguments. */
2503 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2504 * sizeof (Lisp_Object
));
2505 GCPRO1 (*funcall_args
);
2506 gcpro1
.nvars
= 1 + numargs
;
2509 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2510 /* Spread the last arg we got. Its first element goes in
2511 the slot that it used to occupy, hence this value of I. */
2513 while (!NILP (spread_arg
))
2515 funcall_args
[i
++] = XCAR (spread_arg
);
2516 spread_arg
= XCDR (spread_arg
);
2519 /* By convention, the caller needs to gcpro Ffuncall's args. */
2520 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2523 /* Run hook variables in various ways. */
2525 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2526 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2527 enum run_hooks_condition
));
2529 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2530 doc
: /* Run each hook in HOOKS.
2531 Each argument should be a symbol, a hook variable.
2532 These symbols are processed in the order specified.
2533 If a hook symbol has a non-nil value, that value may be a function
2534 or a list of functions to be called to run the hook.
2535 If the value is a function, it is called with no arguments.
2536 If it is a list, the elements are called, in order, with no arguments.
2538 Major modes should not use this function directly to run their mode
2539 hook; they should use `run-mode-hooks' instead.
2541 Do not use `make-local-variable' to make a hook variable buffer-local.
2542 Instead, use `add-hook' and specify t for the LOCAL argument.
2543 usage: (run-hooks &rest HOOKS) */)
2548 Lisp_Object hook
[1];
2551 for (i
= 0; i
< nargs
; i
++)
2554 run_hook_with_args (1, hook
, to_completion
);
2560 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2561 Srun_hook_with_args
, 1, MANY
, 0,
2562 doc
: /* Run HOOK with the specified arguments ARGS.
2563 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2564 value, that value may be a function or a list of functions to be
2565 called to run the hook. If the value is a function, it is called with
2566 the given arguments and its return value is returned. If it is a list
2567 of functions, those functions are called, in order,
2568 with the given arguments ARGS.
2569 It is best not to depend on the value returned by `run-hook-with-args',
2572 Do not use `make-local-variable' to make a hook variable buffer-local.
2573 Instead, use `add-hook' and specify t for the LOCAL argument.
2574 usage: (run-hook-with-args HOOK &rest ARGS) */)
2579 return run_hook_with_args (nargs
, args
, to_completion
);
2582 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2583 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2584 doc
: /* Run HOOK with the specified arguments ARGS.
2585 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2586 value, that value may be a function or a list of functions to be
2587 called to run the hook. If the value is a function, it is called with
2588 the given arguments and its return value is returned.
2589 If it is a list of functions, those functions are called, in order,
2590 with the given arguments ARGS, until one of them
2591 returns a non-nil value. Then we return that value.
2592 However, if they all return nil, we return nil.
2594 Do not use `make-local-variable' to make a hook variable buffer-local.
2595 Instead, use `add-hook' and specify t for the LOCAL argument.
2596 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2601 return run_hook_with_args (nargs
, args
, until_success
);
2604 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2605 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2606 doc
: /* Run HOOK with the specified arguments ARGS.
2607 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2608 value, that value may be a function or a list of functions to be
2609 called to run the hook. If the value is a function, it is called with
2610 the given arguments and its return value is returned.
2611 If it is a list of functions, those functions are called, in order,
2612 with the given arguments ARGS, until one of them returns nil.
2613 Then we return nil. However, if they all return non-nil, we return non-nil.
2615 Do not use `make-local-variable' to make a hook variable buffer-local.
2616 Instead, use `add-hook' and specify t for the LOCAL argument.
2617 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2622 return run_hook_with_args (nargs
, args
, until_failure
);
2625 /* ARGS[0] should be a hook symbol.
2626 Call each of the functions in the hook value, passing each of them
2627 as arguments all the rest of ARGS (all NARGS - 1 elements).
2628 COND specifies a condition to test after each call
2629 to decide whether to stop.
2630 The caller (or its caller, etc) must gcpro all of ARGS,
2631 except that it isn't necessary to gcpro ARGS[0]. */
2634 run_hook_with_args (nargs
, args
, cond
)
2637 enum run_hooks_condition cond
;
2639 Lisp_Object sym
, val
, ret
;
2640 Lisp_Object globals
;
2641 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2643 /* If we are dying or still initializing,
2644 don't do anything--it would probably crash if we tried. */
2645 if (NILP (Vrun_hooks
))
2649 val
= find_symbol_value (sym
);
2650 ret
= (cond
== until_failure
? Qt
: Qnil
);
2652 if (EQ (val
, Qunbound
) || NILP (val
))
2654 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2657 return Ffuncall (nargs
, args
);
2662 GCPRO3 (sym
, val
, globals
);
2665 CONSP (val
) && ((cond
== to_completion
)
2666 || (cond
== until_success
? NILP (ret
)
2670 if (EQ (XCAR (val
), Qt
))
2672 /* t indicates this hook has a local binding;
2673 it means to run the global binding too. */
2675 for (globals
= Fdefault_value (sym
);
2676 CONSP (globals
) && ((cond
== to_completion
)
2677 || (cond
== until_success
? NILP (ret
)
2679 globals
= XCDR (globals
))
2681 args
[0] = XCAR (globals
);
2682 /* In a global value, t should not occur. If it does, we
2683 must ignore it to avoid an endless loop. */
2684 if (!EQ (args
[0], Qt
))
2685 ret
= Ffuncall (nargs
, args
);
2690 args
[0] = XCAR (val
);
2691 ret
= Ffuncall (nargs
, args
);
2700 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2701 present value of that symbol.
2702 Call each element of FUNLIST,
2703 passing each of them the rest of ARGS.
2704 The caller (or its caller, etc) must gcpro all of ARGS,
2705 except that it isn't necessary to gcpro ARGS[0]. */
2708 run_hook_list_with_args (funlist
, nargs
, args
)
2709 Lisp_Object funlist
;
2715 Lisp_Object globals
;
2716 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2720 GCPRO3 (sym
, val
, globals
);
2722 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2724 if (EQ (XCAR (val
), Qt
))
2726 /* t indicates this hook has a local binding;
2727 it means to run the global binding too. */
2729 for (globals
= Fdefault_value (sym
);
2731 globals
= XCDR (globals
))
2733 args
[0] = XCAR (globals
);
2734 /* In a global value, t should not occur. If it does, we
2735 must ignore it to avoid an endless loop. */
2736 if (!EQ (args
[0], Qt
))
2737 Ffuncall (nargs
, args
);
2742 args
[0] = XCAR (val
);
2743 Ffuncall (nargs
, args
);
2750 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2753 run_hook_with_args_2 (hook
, arg1
, arg2
)
2754 Lisp_Object hook
, arg1
, arg2
;
2756 Lisp_Object temp
[3];
2761 Frun_hook_with_args (3, temp
);
2764 /* Apply fn to arg */
2767 Lisp_Object fn
, arg
;
2769 struct gcpro gcpro1
;
2773 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2777 Lisp_Object args
[2];
2781 RETURN_UNGCPRO (Fapply (2, args
));
2783 #else /* not NO_ARG_ARRAY */
2784 RETURN_UNGCPRO (Fapply (2, &fn
));
2785 #endif /* not NO_ARG_ARRAY */
2788 /* Call function fn on no arguments */
2793 struct gcpro gcpro1
;
2796 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2799 /* Call function fn with 1 argument arg1 */
2803 Lisp_Object fn
, arg1
;
2805 struct gcpro gcpro1
;
2807 Lisp_Object args
[2];
2813 RETURN_UNGCPRO (Ffuncall (2, args
));
2814 #else /* not NO_ARG_ARRAY */
2817 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2818 #endif /* not NO_ARG_ARRAY */
2821 /* Call function fn with 2 arguments arg1, arg2 */
2824 call2 (fn
, arg1
, arg2
)
2825 Lisp_Object fn
, arg1
, arg2
;
2827 struct gcpro gcpro1
;
2829 Lisp_Object args
[3];
2835 RETURN_UNGCPRO (Ffuncall (3, args
));
2836 #else /* not NO_ARG_ARRAY */
2839 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2840 #endif /* not NO_ARG_ARRAY */
2843 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2846 call3 (fn
, arg1
, arg2
, arg3
)
2847 Lisp_Object fn
, arg1
, arg2
, arg3
;
2849 struct gcpro gcpro1
;
2851 Lisp_Object args
[4];
2858 RETURN_UNGCPRO (Ffuncall (4, args
));
2859 #else /* not NO_ARG_ARRAY */
2862 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2863 #endif /* not NO_ARG_ARRAY */
2866 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2869 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2870 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2872 struct gcpro gcpro1
;
2874 Lisp_Object args
[5];
2882 RETURN_UNGCPRO (Ffuncall (5, args
));
2883 #else /* not NO_ARG_ARRAY */
2886 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2887 #endif /* not NO_ARG_ARRAY */
2890 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2893 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2894 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2896 struct gcpro gcpro1
;
2898 Lisp_Object args
[6];
2907 RETURN_UNGCPRO (Ffuncall (6, args
));
2908 #else /* not NO_ARG_ARRAY */
2911 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2912 #endif /* not NO_ARG_ARRAY */
2915 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2918 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2919 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2921 struct gcpro gcpro1
;
2923 Lisp_Object args
[7];
2933 RETURN_UNGCPRO (Ffuncall (7, args
));
2934 #else /* not NO_ARG_ARRAY */
2937 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2938 #endif /* not NO_ARG_ARRAY */
2941 /* The caller should GCPRO all the elements of ARGS. */
2943 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2944 doc
: /* Call first argument as a function, passing remaining arguments to it.
2945 Return the value that function returns.
2946 Thus, (funcall 'cons 'x 'y) returns (x . y).
2947 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2952 Lisp_Object fun
, original_fun
;
2954 int numargs
= nargs
- 1;
2955 Lisp_Object lisp_numargs
;
2957 struct backtrace backtrace
;
2958 register Lisp_Object
*internal_args
;
2962 if ((consing_since_gc
> gc_cons_threshold
2963 && consing_since_gc
> gc_relative_threshold
)
2965 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2966 Fgarbage_collect ();
2968 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2970 if (max_lisp_eval_depth
< 100)
2971 max_lisp_eval_depth
= 100;
2972 if (lisp_eval_depth
> max_lisp_eval_depth
)
2973 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2976 backtrace
.next
= backtrace_list
;
2977 backtrace_list
= &backtrace
;
2978 backtrace
.function
= &args
[0];
2979 backtrace
.args
= &args
[1];
2980 backtrace
.nargs
= nargs
- 1;
2981 backtrace
.evalargs
= 0;
2982 backtrace
.debug_on_exit
= 0;
2984 if (debug_on_next_call
)
2985 do_debug_on_call (Qlambda
);
2989 original_fun
= args
[0];
2993 /* Optimize for no indirection. */
2995 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2996 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2997 fun
= indirect_function (fun
);
3001 if (numargs
< XSUBR (fun
)->min_args
3002 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
3004 XSETFASTINT (lisp_numargs
, numargs
);
3005 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
3008 if (XSUBR (fun
)->max_args
== UNEVALLED
)
3009 xsignal1 (Qinvalid_function
, original_fun
);
3011 if (XSUBR (fun
)->max_args
== MANY
)
3013 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
3017 if (XSUBR (fun
)->max_args
> numargs
)
3019 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
3020 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
3021 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
3022 internal_args
[i
] = Qnil
;
3025 internal_args
= args
+ 1;
3026 switch (XSUBR (fun
)->max_args
)
3029 val
= (*XSUBR (fun
)->function
) ();
3032 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
3035 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1]);
3038 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3042 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3043 internal_args
[2], internal_args
[3]);
3046 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3047 internal_args
[2], internal_args
[3],
3051 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3052 internal_args
[2], internal_args
[3],
3053 internal_args
[4], internal_args
[5]);
3056 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3057 internal_args
[2], internal_args
[3],
3058 internal_args
[4], internal_args
[5],
3063 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3064 internal_args
[2], internal_args
[3],
3065 internal_args
[4], internal_args
[5],
3066 internal_args
[6], internal_args
[7]);
3071 /* If a subr takes more than 8 arguments without using MANY
3072 or UNEVALLED, we need to extend this function to support it.
3073 Until this is done, there is no way to call the function. */
3077 if (COMPILEDP (fun
))
3078 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3081 if (EQ (fun
, Qunbound
))
3082 xsignal1 (Qvoid_function
, original_fun
);
3084 xsignal1 (Qinvalid_function
, original_fun
);
3085 funcar
= XCAR (fun
);
3086 if (!SYMBOLP (funcar
))
3087 xsignal1 (Qinvalid_function
, original_fun
);
3088 if (EQ (funcar
, Qlambda
))
3089 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3090 else if (EQ (funcar
, Qautoload
))
3092 do_autoload (fun
, original_fun
);
3097 xsignal1 (Qinvalid_function
, original_fun
);
3102 if (backtrace
.debug_on_exit
)
3103 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
3104 backtrace_list
= backtrace
.next
;
3109 apply_lambda (fun
, args
, eval_flag
)
3110 Lisp_Object fun
, args
;
3113 Lisp_Object args_left
;
3114 Lisp_Object numargs
;
3115 register Lisp_Object
*arg_vector
;
3116 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3118 register Lisp_Object tem
;
3120 numargs
= Flength (args
);
3121 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
3124 GCPRO3 (*arg_vector
, args_left
, fun
);
3127 for (i
= 0; i
< XINT (numargs
);)
3129 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
3130 if (eval_flag
) tem
= Feval (tem
);
3131 arg_vector
[i
++] = tem
;
3139 backtrace_list
->args
= arg_vector
;
3140 backtrace_list
->nargs
= i
;
3142 backtrace_list
->evalargs
= 0;
3143 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
3145 /* Do the debug-on-exit now, while arg_vector still exists. */
3146 if (backtrace_list
->debug_on_exit
)
3147 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
3148 /* Don't do it again when we return to eval. */
3149 backtrace_list
->debug_on_exit
= 0;
3153 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3154 and return the result of evaluation.
3155 FUN must be either a lambda-expression or a compiled-code object. */
3158 funcall_lambda (fun
, nargs
, arg_vector
)
3161 register Lisp_Object
*arg_vector
;
3163 Lisp_Object val
, syms_left
, next
;
3164 int count
= SPECPDL_INDEX ();
3165 int i
, optional
, rest
;
3169 syms_left
= XCDR (fun
);
3170 if (CONSP (syms_left
))
3171 syms_left
= XCAR (syms_left
);
3173 xsignal1 (Qinvalid_function
, fun
);
3175 else if (COMPILEDP (fun
))
3176 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
3180 i
= optional
= rest
= 0;
3181 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
3185 next
= XCAR (syms_left
);
3186 if (!SYMBOLP (next
))
3187 xsignal1 (Qinvalid_function
, fun
);
3189 if (EQ (next
, Qand_rest
))
3191 else if (EQ (next
, Qand_optional
))
3195 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
3199 specbind (next
, arg_vector
[i
++]);
3201 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3203 specbind (next
, Qnil
);
3206 if (!NILP (syms_left
))
3207 xsignal1 (Qinvalid_function
, fun
);
3209 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3212 val
= Fprogn (XCDR (XCDR (fun
)));
3215 /* If we have not actually read the bytecode string
3216 and constants vector yet, fetch them from the file. */
3217 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3218 Ffetch_bytecode (fun
);
3219 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
3220 AREF (fun
, COMPILED_CONSTANTS
),
3221 AREF (fun
, COMPILED_STACK_DEPTH
));
3224 return unbind_to (count
, val
);
3227 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3229 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3235 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3237 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3240 tem
= AREF (object
, COMPILED_BYTECODE
);
3241 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3242 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3244 error ("Invalid byte code");
3246 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
3247 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
3255 register int count
= SPECPDL_INDEX ();
3256 if (specpdl_size
>= max_specpdl_size
)
3258 if (max_specpdl_size
< 400)
3259 max_specpdl_size
= 400;
3260 if (specpdl_size
>= max_specpdl_size
)
3261 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil
);
3264 if (specpdl_size
> max_specpdl_size
)
3265 specpdl_size
= max_specpdl_size
;
3266 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
3267 specpdl_ptr
= specpdl
+ count
;
3271 specbind (symbol
, value
)
3272 Lisp_Object symbol
, value
;
3274 Lisp_Object valcontents
;
3276 CHECK_SYMBOL (symbol
);
3277 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3280 /* The most common case is that of a non-constant symbol with a
3281 trivial value. Make that as fast as we can. */
3282 valcontents
= SYMBOL_VALUE (symbol
);
3283 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3285 specpdl_ptr
->symbol
= symbol
;
3286 specpdl_ptr
->old_value
= valcontents
;
3287 specpdl_ptr
->func
= NULL
;
3289 SET_SYMBOL_VALUE (symbol
, value
);
3293 Lisp_Object ovalue
= find_symbol_value (symbol
);
3294 specpdl_ptr
->func
= 0;
3295 specpdl_ptr
->old_value
= ovalue
;
3297 valcontents
= XSYMBOL (symbol
)->value
;
3299 if (BUFFER_LOCAL_VALUEP (valcontents
)
3300 || BUFFER_OBJFWDP (valcontents
))
3302 Lisp_Object where
, current_buffer
;
3304 current_buffer
= Fcurrent_buffer ();
3306 /* For a local variable, record both the symbol and which
3307 buffer's or frame's value we are saving. */
3308 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3309 where
= current_buffer
;
3310 else if (BUFFER_LOCAL_VALUEP (valcontents
)
3311 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3312 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3316 /* We're not using the `unused' slot in the specbinding
3317 structure because this would mean we have to do more
3318 work for simple variables. */
3319 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3321 /* If SYMBOL is a per-buffer variable which doesn't have a
3322 buffer-local value here, make the `let' change the global
3323 value by changing the value of SYMBOL in all buffers not
3324 having their own value. This is consistent with what
3325 happens with other buffer-local variables. */
3327 && BUFFER_OBJFWDP (valcontents
))
3330 Fset_default (symbol
, value
);
3335 specpdl_ptr
->symbol
= symbol
;
3339 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3340 store_symval_forwarding (symbol, ovalue, value, NULL);
3342 but ovalue comes from find_symbol_value which should never return
3343 such an internal value. */
3344 eassert (!(BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
)));
3345 set_internal (symbol
, value
, 0, 1);
3350 record_unwind_protect (function
, arg
)
3351 Lisp_Object (*function
) P_ ((Lisp_Object
));
3354 eassert (!handling_signal
);
3356 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3358 specpdl_ptr
->func
= function
;
3359 specpdl_ptr
->symbol
= Qnil
;
3360 specpdl_ptr
->old_value
= arg
;
3365 unbind_to (count
, value
)
3369 Lisp_Object quitf
= Vquit_flag
;
3370 struct gcpro gcpro1
, gcpro2
;
3372 GCPRO2 (value
, quitf
);
3375 while (specpdl_ptr
!= specpdl
+ count
)
3377 /* Copy the binding, and decrement specpdl_ptr, before we do
3378 the work to unbind it. We decrement first
3379 so that an error in unbinding won't try to unbind
3380 the same entry again, and we copy the binding first
3381 in case more bindings are made during some of the code we run. */
3383 struct specbinding this_binding
;
3384 this_binding
= *--specpdl_ptr
;
3386 if (this_binding
.func
!= 0)
3387 (*this_binding
.func
) (this_binding
.old_value
);
3388 /* If the symbol is a list, it is really (SYMBOL WHERE
3389 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3390 frame. If WHERE is a buffer or frame, this indicates we
3391 bound a variable that had a buffer-local or frame-local
3392 binding. WHERE nil means that the variable had the default
3393 value when it was bound. CURRENT-BUFFER is the buffer that
3394 was current when the variable was bound. */
3395 else if (CONSP (this_binding
.symbol
))
3397 Lisp_Object symbol
, where
;
3399 symbol
= XCAR (this_binding
.symbol
);
3400 where
= XCAR (XCDR (this_binding
.symbol
));
3403 Fset_default (symbol
, this_binding
.old_value
);
3404 else if (BUFFERP (where
))
3405 set_internal (symbol
, this_binding
.old_value
, XBUFFER (where
), 1);
3407 set_internal (symbol
, this_binding
.old_value
, NULL
, 1);
3411 /* If variable has a trivial value (no forwarding), we can
3412 just set it. No need to check for constant symbols here,
3413 since that was already done by specbind. */
3414 if (!MISCP (SYMBOL_VALUE (this_binding
.symbol
)))
3415 SET_SYMBOL_VALUE (this_binding
.symbol
, this_binding
.old_value
);
3417 set_internal (this_binding
.symbol
, this_binding
.old_value
, 0, 1);
3421 if (NILP (Vquit_flag
) && !NILP (quitf
))
3428 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3429 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3430 The debugger is entered when that frame exits, if the flag is non-nil. */)
3432 Lisp_Object level
, flag
;
3434 register struct backtrace
*backlist
= backtrace_list
;
3437 CHECK_NUMBER (level
);
3439 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3441 backlist
= backlist
->next
;
3445 backlist
->debug_on_exit
= !NILP (flag
);
3450 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3451 doc
: /* Print a trace of Lisp function calls currently active.
3452 Output stream used is value of `standard-output'. */)
3455 register struct backtrace
*backlist
= backtrace_list
;
3459 extern Lisp_Object Vprint_level
;
3460 struct gcpro gcpro1
;
3462 XSETFASTINT (Vprint_level
, 3);
3469 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3470 if (backlist
->nargs
== UNEVALLED
)
3472 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3473 write_string ("\n", -1);
3477 tem
= *backlist
->function
;
3478 Fprin1 (tem
, Qnil
); /* This can QUIT */
3479 write_string ("(", -1);
3480 if (backlist
->nargs
== MANY
)
3482 for (tail
= *backlist
->args
, i
= 0;
3484 tail
= Fcdr (tail
), i
++)
3486 if (i
) write_string (" ", -1);
3487 Fprin1 (Fcar (tail
), Qnil
);
3492 for (i
= 0; i
< backlist
->nargs
; i
++)
3494 if (i
) write_string (" ", -1);
3495 Fprin1 (backlist
->args
[i
], Qnil
);
3498 write_string (")\n", -1);
3500 backlist
= backlist
->next
;
3503 Vprint_level
= Qnil
;
3508 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3509 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3510 If that frame has not evaluated the arguments yet (or is a special form),
3511 the value is (nil FUNCTION ARG-FORMS...).
3512 If that frame has evaluated its arguments and called its function already,
3513 the value is (t FUNCTION ARG-VALUES...).
3514 A &rest arg is represented as the tail of the list ARG-VALUES.
3515 FUNCTION is whatever was supplied as car of evaluated list,
3516 or a lambda expression for macro calls.
3517 If NFRAMES is more than the number of frames, the value is nil. */)
3519 Lisp_Object nframes
;
3521 register struct backtrace
*backlist
= backtrace_list
;
3525 CHECK_NATNUM (nframes
);
3527 /* Find the frame requested. */
3528 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3529 backlist
= backlist
->next
;
3533 if (backlist
->nargs
== UNEVALLED
)
3534 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3537 if (backlist
->nargs
== MANY
)
3538 tem
= *backlist
->args
;
3540 tem
= Flist (backlist
->nargs
, backlist
->args
);
3542 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3550 register struct backtrace
*backlist
;
3553 for (backlist
= backtrace_list
; backlist
; backlist
= backlist
->next
)
3555 mark_object (*backlist
->function
);
3557 if (backlist
->nargs
== UNEVALLED
|| backlist
->nargs
== MANY
)
3560 i
= backlist
->nargs
- 1;
3562 mark_object (backlist
->args
[i
]);
3569 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3570 doc
: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3571 If Lisp code tries to increase the total number past this amount,
3572 an error is signaled.
3573 You can safely use a value considerably larger than the default value,
3574 if that proves inconveniently small. However, if you increase it too far,
3575 Emacs could run out of memory trying to make the stack bigger. */);
3577 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3578 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3580 This limit serves to catch infinite recursions for you before they cause
3581 actual stack overflow in C, which would be fatal for Emacs.
3582 You can safely make it considerably larger than its default value,
3583 if that proves inconveniently small. However, if you increase it too far,
3584 Emacs could overflow the real C stack, and crash. */);
3586 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3587 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3588 If the value is t, that means do an ordinary quit.
3589 If the value equals `throw-on-input', that means quit by throwing
3590 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3591 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3592 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3595 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3596 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3597 Note that `quit-flag' will still be set by typing C-g,
3598 so a quit will be signaled as soon as `inhibit-quit' is nil.
3599 To prevent this happening, set `quit-flag' to nil
3600 before making `inhibit-quit' nil. */);
3601 Vinhibit_quit
= Qnil
;
3603 Qinhibit_quit
= intern ("inhibit-quit");
3604 staticpro (&Qinhibit_quit
);
3606 Qautoload
= intern ("autoload");
3607 staticpro (&Qautoload
);
3609 Qdebug_on_error
= intern ("debug-on-error");
3610 staticpro (&Qdebug_on_error
);
3612 Qmacro
= intern ("macro");
3613 staticpro (&Qmacro
);
3615 Qdeclare
= intern ("declare");
3616 staticpro (&Qdeclare
);
3618 /* Note that the process handling also uses Qexit, but we don't want
3619 to staticpro it twice, so we just do it here. */
3620 Qexit
= intern ("exit");
3623 Qinteractive
= intern ("interactive");
3624 staticpro (&Qinteractive
);
3626 Qcommandp
= intern ("commandp");
3627 staticpro (&Qcommandp
);
3629 Qdefun
= intern ("defun");
3630 staticpro (&Qdefun
);
3632 Qand_rest
= intern ("&rest");
3633 staticpro (&Qand_rest
);
3635 Qand_optional
= intern ("&optional");
3636 staticpro (&Qand_optional
);
3638 Qdebug
= intern ("debug");
3639 staticpro (&Qdebug
);
3641 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3642 doc
: /* *Non-nil means errors display a backtrace buffer.
3643 More precisely, this happens for any error that is handled
3644 by the editor command loop.
3645 If the value is a list, an error only means to display a backtrace
3646 if one of its condition symbols appears in the list. */);
3647 Vstack_trace_on_error
= Qnil
;
3649 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3650 doc
: /* *Non-nil means enter debugger if an error is signaled.
3651 Does not apply to errors handled by `condition-case' or those
3652 matched by `debug-ignored-errors'.
3653 If the value is a list, an error only means to enter the debugger
3654 if one of its condition symbols appears in the list.
3655 When you evaluate an expression interactively, this variable
3656 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3657 See also variable `debug-on-quit'. */);
3658 Vdebug_on_error
= Qnil
;
3660 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3661 doc
: /* *List of errors for which the debugger should not be called.
3662 Each element may be a condition-name or a regexp that matches error messages.
3663 If any element applies to a given error, that error skips the debugger
3664 and just returns to top level.
3665 This overrides the variable `debug-on-error'.
3666 It does not apply to errors handled by `condition-case'. */);
3667 Vdebug_ignored_errors
= Qnil
;
3669 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3670 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3671 Does not apply if quit is handled by a `condition-case'. */);
3674 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3675 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3677 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3678 doc
: /* Non-nil means debugger may continue execution.
3679 This is nil when the debugger is called under circumstances where it
3680 might not be safe to continue. */);
3681 debugger_may_continue
= 1;
3683 DEFVAR_LISP ("debugger", &Vdebugger
,
3684 doc
: /* Function to call to invoke debugger.
3685 If due to frame exit, args are `exit' and the value being returned;
3686 this function's value will be returned instead of that.
3687 If due to error, args are `error' and a list of the args to `signal'.
3688 If due to `apply' or `funcall' entry, one arg, `lambda'.
3689 If due to `eval' entry, one arg, t. */);
3692 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3693 doc
: /* If non-nil, this is a function for `signal' to call.
3694 It receives the same arguments that `signal' was given.
3695 The Edebug package uses this to regain control. */);
3696 Vsignal_hook_function
= Qnil
;
3698 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3699 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3700 Note that `debug-on-error', `debug-on-quit' and friends
3701 still determine whether to handle the particular condition. */);
3702 Vdebug_on_signal
= Qnil
;
3704 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3705 doc
: /* Function to process declarations in a macro definition.
3706 The function will be called with two args MACRO and DECL.
3707 MACRO is the name of the macro being defined.
3708 DECL is a list `(declare ...)' containing the declarations.
3709 The value the function returns is not used. */);
3710 Vmacro_declaration_function
= Qnil
;
3712 Vrun_hooks
= intern ("run-hooks");
3713 staticpro (&Vrun_hooks
);
3715 staticpro (&Vautoload_queue
);
3716 Vautoload_queue
= Qnil
;
3717 staticpro (&Vsignaling_function
);
3718 Vsignaling_function
= Qnil
;
3729 defsubr (&Sfunction
);
3731 defsubr (&Sdefmacro
);
3733 defsubr (&Sdefvaralias
);
3734 defsubr (&Sdefconst
);
3735 defsubr (&Suser_variable_p
);
3739 defsubr (&Smacroexpand
);
3742 defsubr (&Sunwind_protect
);
3743 defsubr (&Scondition_case
);
3745 defsubr (&Sinteractive_p
);
3746 defsubr (&Scalled_interactively_p
);
3747 defsubr (&Scommandp
);
3748 defsubr (&Sautoload
);
3751 defsubr (&Sfuncall
);
3752 defsubr (&Srun_hooks
);
3753 defsubr (&Srun_hook_with_args
);
3754 defsubr (&Srun_hook_with_args_until_success
);
3755 defsubr (&Srun_hook_with_args_until_failure
);
3756 defsubr (&Sfetch_bytecode
);
3757 defsubr (&Sbacktrace_debug
);
3758 defsubr (&Sbacktrace
);
3759 defsubr (&Sbacktrace_frame
);
3762 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3763 (do not change this comment) */