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
778 The return value is BASE-VARIABLE. */)
779 (new_alias
, base_variable
, docstring
)
780 Lisp_Object new_alias
, base_variable
, docstring
;
782 struct Lisp_Symbol
*sym
;
784 CHECK_SYMBOL (new_alias
);
785 CHECK_SYMBOL (base_variable
);
787 if (SYMBOL_CONSTANT_P (new_alias
))
788 error ("Cannot make a constant an alias");
790 sym
= XSYMBOL (new_alias
);
791 sym
->indirect_variable
= 1;
792 sym
->value
= base_variable
;
793 sym
->constant
= SYMBOL_CONSTANT_P (base_variable
);
794 LOADHIST_ATTACH (new_alias
);
795 if (!NILP (docstring
))
796 Fput (new_alias
, Qvariable_documentation
, docstring
);
798 Fput (new_alias
, Qvariable_documentation
, Qnil
);
800 return base_variable
;
804 DEFUN ("defvar", Fdefvar
, Sdefvar
, 1, UNEVALLED
, 0,
805 doc
: /* Define SYMBOL as a variable, and return SYMBOL.
806 You are not required to define a variable in order to use it,
807 but the definition can supply documentation and an initial value
808 in a way that tags can recognize.
810 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
811 If SYMBOL is buffer-local, its default value is what is set;
812 buffer-local values are not affected.
813 INITVALUE and DOCSTRING are optional.
814 If DOCSTRING starts with *, this variable is identified as a user option.
815 This means that M-x set-variable recognizes it.
816 See also `user-variable-p'.
817 If INITVALUE is missing, SYMBOL's value is not set.
819 If SYMBOL has a local binding, then this form affects the local
820 binding. This is usually not what you want. Thus, if you need to
821 load a file defining variables, with this form or with `defconst' or
822 `defcustom', you should always load that file _outside_ any bindings
823 for these variables. \(`defconst' and `defcustom' behave similarly in
825 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
829 register Lisp_Object sym
, tem
, tail
;
833 if (!NILP (Fcdr (Fcdr (tail
))))
834 error ("Too many arguments");
836 tem
= Fdefault_boundp (sym
);
839 if (SYMBOL_CONSTANT_P (sym
))
841 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
842 Lisp_Object tem
= Fcar (tail
);
844 && EQ (XCAR (tem
), Qquote
)
845 && CONSP (XCDR (tem
))
846 && EQ (XCAR (XCDR (tem
)), sym
)))
847 error ("Constant symbol `%s' specified in defvar",
848 SDATA (SYMBOL_NAME (sym
)));
852 Fset_default (sym
, Feval (Fcar (tail
)));
854 { /* Check if there is really a global binding rather than just a let
855 binding that shadows the global unboundness of the var. */
856 volatile struct specbinding
*pdl
= specpdl_ptr
;
857 while (--pdl
>= specpdl
)
859 if (EQ (pdl
->symbol
, sym
) && !pdl
->func
860 && EQ (pdl
->old_value
, Qunbound
))
862 message_with_string ("Warning: defvar ignored because %s is let-bound",
863 SYMBOL_NAME (sym
), 1);
872 if (!NILP (Vpurify_flag
))
873 tem
= Fpurecopy (tem
);
874 Fput (sym
, Qvariable_documentation
, tem
);
876 LOADHIST_ATTACH (sym
);
879 /* Simple (defvar <var>) should not count as a definition at all.
880 It could get in the way of other definitions, and unloading this
881 package could try to make the variable unbound. */
887 DEFUN ("defconst", Fdefconst
, Sdefconst
, 2, UNEVALLED
, 0,
888 doc
: /* Define SYMBOL as a constant variable.
889 The intent is that neither programs nor users should ever change this value.
890 Always sets the value of SYMBOL to the result of evalling INITVALUE.
891 If SYMBOL is buffer-local, its default value is what is set;
892 buffer-local values are not affected.
893 DOCSTRING is optional.
895 If SYMBOL has a local binding, then this form sets the local binding's
896 value. However, you should normally not make local bindings for
897 variables defined with this form.
898 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
902 register Lisp_Object sym
, tem
;
905 if (!NILP (Fcdr (Fcdr (Fcdr (args
)))))
906 error ("Too many arguments");
908 tem
= Feval (Fcar (Fcdr (args
)));
909 if (!NILP (Vpurify_flag
))
910 tem
= Fpurecopy (tem
);
911 Fset_default (sym
, tem
);
912 tem
= Fcar (Fcdr (Fcdr (args
)));
915 if (!NILP (Vpurify_flag
))
916 tem
= Fpurecopy (tem
);
917 Fput (sym
, Qvariable_documentation
, tem
);
919 Fput (sym
, Qrisky_local_variable
, Qt
);
920 LOADHIST_ATTACH (sym
);
924 /* Error handler used in Fuser_variable_p. */
926 user_variable_p_eh (ignore
)
932 DEFUN ("user-variable-p", Fuser_variable_p
, Suser_variable_p
, 1, 1, 0,
933 doc
: /* Return t if VARIABLE is intended to be set and modified by users.
934 \(The alternative is a variable used internally in a Lisp program.)
935 A variable is a user variable if
936 \(1) the first character of its documentation is `*', or
937 \(2) it is customizable (its property list contains a non-nil value
938 of `standard-value' or `custom-autoload'), or
939 \(3) it is an alias for another user variable.
940 Return nil if VARIABLE is an alias and there is a loop in the
941 chain of symbols. */)
943 Lisp_Object variable
;
945 Lisp_Object documentation
;
947 if (!SYMBOLP (variable
))
950 /* If indirect and there's an alias loop, don't check anything else. */
951 if (XSYMBOL (variable
)->indirect_variable
952 && NILP (internal_condition_case_1 (indirect_variable
, variable
,
953 Qt
, user_variable_p_eh
)))
958 documentation
= Fget (variable
, Qvariable_documentation
);
959 if (INTEGERP (documentation
) && XINT (documentation
) < 0)
961 if (STRINGP (documentation
)
962 && ((unsigned char) SREF (documentation
, 0) == '*'))
964 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
965 if (CONSP (documentation
)
966 && STRINGP (XCAR (documentation
))
967 && INTEGERP (XCDR (documentation
))
968 && XINT (XCDR (documentation
)) < 0)
970 /* Customizable? See `custom-variable-p'. */
971 if ((!NILP (Fget (variable
, intern ("standard-value"))))
972 || (!NILP (Fget (variable
, intern ("custom-autoload")))))
975 if (!XSYMBOL (variable
)->indirect_variable
)
978 /* An indirect variable? Let's follow the chain. */
979 variable
= XSYMBOL (variable
)->value
;
983 DEFUN ("let*", FletX
, SletX
, 1, UNEVALLED
, 0,
984 doc
: /* Bind variables according to VARLIST then eval BODY.
985 The value of the last form in BODY is returned.
986 Each element of VARLIST is a symbol (which is bound to nil)
987 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
988 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
989 usage: (let* VARLIST BODY...) */)
993 Lisp_Object varlist
, val
, elt
;
994 int count
= SPECPDL_INDEX ();
995 struct gcpro gcpro1
, gcpro2
, gcpro3
;
997 GCPRO3 (args
, elt
, varlist
);
999 varlist
= Fcar (args
);
1000 while (!NILP (varlist
))
1003 elt
= Fcar (varlist
);
1005 specbind (elt
, Qnil
);
1006 else if (! NILP (Fcdr (Fcdr (elt
))))
1007 signal_error ("`let' bindings can have only one value-form", elt
);
1010 val
= Feval (Fcar (Fcdr (elt
)));
1011 specbind (Fcar (elt
), val
);
1013 varlist
= Fcdr (varlist
);
1016 val
= Fprogn (Fcdr (args
));
1017 return unbind_to (count
, val
);
1020 DEFUN ("let", Flet
, Slet
, 1, UNEVALLED
, 0,
1021 doc
: /* Bind variables according to VARLIST then eval BODY.
1022 The value of the last form in BODY is returned.
1023 Each element of VARLIST is a symbol (which is bound to nil)
1024 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1025 All the VALUEFORMs are evalled before any symbols are bound.
1026 usage: (let VARLIST BODY...) */)
1030 Lisp_Object
*temps
, tem
;
1031 register Lisp_Object elt
, varlist
;
1032 int count
= SPECPDL_INDEX ();
1033 register int argnum
;
1034 struct gcpro gcpro1
, gcpro2
;
1036 varlist
= Fcar (args
);
1038 /* Make space to hold the values to give the bound variables */
1039 elt
= Flength (varlist
);
1040 temps
= (Lisp_Object
*) alloca (XFASTINT (elt
) * sizeof (Lisp_Object
));
1042 /* Compute the values and store them in `temps' */
1044 GCPRO2 (args
, *temps
);
1047 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
1050 elt
= XCAR (varlist
);
1052 temps
[argnum
++] = Qnil
;
1053 else if (! NILP (Fcdr (Fcdr (elt
))))
1054 signal_error ("`let' bindings can have only one value-form", elt
);
1056 temps
[argnum
++] = Feval (Fcar (Fcdr (elt
)));
1057 gcpro2
.nvars
= argnum
;
1061 varlist
= Fcar (args
);
1062 for (argnum
= 0; CONSP (varlist
); varlist
= XCDR (varlist
))
1064 elt
= XCAR (varlist
);
1065 tem
= temps
[argnum
++];
1067 specbind (elt
, tem
);
1069 specbind (Fcar (elt
), tem
);
1072 elt
= Fprogn (Fcdr (args
));
1073 return unbind_to (count
, elt
);
1076 DEFUN ("while", Fwhile
, Swhile
, 1, UNEVALLED
, 0,
1077 doc
: /* If TEST yields non-nil, eval BODY... and repeat.
1078 The order of execution is thus TEST, BODY, TEST, BODY and so on
1079 until TEST returns nil.
1080 usage: (while TEST BODY...) */)
1084 Lisp_Object test
, body
;
1085 struct gcpro gcpro1
, gcpro2
;
1087 GCPRO2 (test
, body
);
1091 while (!NILP (Feval (test
)))
1101 DEFUN ("macroexpand", Fmacroexpand
, Smacroexpand
, 1, 2, 0,
1102 doc
: /* Return result of expanding macros at top level of FORM.
1103 If FORM is not a macro call, it is returned unchanged.
1104 Otherwise, the macro is expanded and the expansion is considered
1105 in place of FORM. When a non-macro-call results, it is returned.
1107 The second optional arg ENVIRONMENT specifies an environment of macro
1108 definitions to shadow the loaded ones for use in file byte-compilation. */)
1111 Lisp_Object environment
;
1113 /* With cleanups from Hallvard Furuseth. */
1114 register Lisp_Object expander
, sym
, def
, tem
;
1118 /* Come back here each time we expand a macro call,
1119 in case it expands into another macro call. */
1122 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
1123 def
= sym
= XCAR (form
);
1125 /* Trace symbols aliases to other symbols
1126 until we get a symbol that is not an alias. */
1127 while (SYMBOLP (def
))
1131 tem
= Fassq (sym
, environment
);
1134 def
= XSYMBOL (sym
)->function
;
1135 if (!EQ (def
, Qunbound
))
1140 /* Right now TEM is the result from SYM in ENVIRONMENT,
1141 and if TEM is nil then DEF is SYM's function definition. */
1144 /* SYM is not mentioned in ENVIRONMENT.
1145 Look at its function definition. */
1146 if (EQ (def
, Qunbound
) || !CONSP (def
))
1147 /* Not defined or definition not suitable */
1149 if (EQ (XCAR (def
), Qautoload
))
1151 /* Autoloading function: will it be a macro when loaded? */
1152 tem
= Fnth (make_number (4), def
);
1153 if (EQ (tem
, Qt
) || EQ (tem
, Qmacro
))
1154 /* Yes, load it and try again. */
1156 struct gcpro gcpro1
;
1158 do_autoload (def
, sym
);
1165 else if (!EQ (XCAR (def
), Qmacro
))
1167 else expander
= XCDR (def
);
1171 expander
= XCDR (tem
);
1172 if (NILP (expander
))
1175 form
= apply1 (expander
, XCDR (form
));
1180 DEFUN ("catch", Fcatch
, Scatch
, 1, UNEVALLED
, 0,
1181 doc
: /* Eval BODY allowing nonlocal exits using `throw'.
1182 TAG is evalled to get the tag to use; it must not be nil.
1184 Then the BODY is executed.
1185 Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
1186 If no throw happens, `catch' returns the value of the last BODY form.
1187 If a throw happens, it specifies the value to return from `catch'.
1188 usage: (catch TAG BODY...) */)
1192 register Lisp_Object tag
;
1193 struct gcpro gcpro1
;
1196 tag
= Feval (Fcar (args
));
1198 return internal_catch (tag
, Fprogn
, Fcdr (args
));
1201 /* Set up a catch, then call C function FUNC on argument ARG.
1202 FUNC should return a Lisp_Object.
1203 This is how catches are done from within C code. */
1206 internal_catch (tag
, func
, arg
)
1208 Lisp_Object (*func
) ();
1211 /* This structure is made part of the chain `catchlist'. */
1214 /* Fill in the components of c, and put it on the list. */
1218 c
.backlist
= backtrace_list
;
1219 c
.handlerlist
= handlerlist
;
1220 c
.lisp_eval_depth
= lisp_eval_depth
;
1221 c
.pdlcount
= SPECPDL_INDEX ();
1222 c
.poll_suppress_count
= poll_suppress_count
;
1223 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1224 c
.gcpro
= gcprolist
;
1225 c
.byte_stack
= byte_stack_list
;
1229 if (! _setjmp (c
.jmp
))
1230 c
.val
= (*func
) (arg
);
1232 /* Throw works by a longjmp that comes right here. */
1237 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
1238 jump to that CATCH, returning VALUE as the value of that catch.
1240 This is the guts Fthrow and Fsignal; they differ only in the way
1241 they choose the catch tag to throw to. A catch tag for a
1242 condition-case form has a TAG of Qnil.
1244 Before each catch is discarded, unbind all special bindings and
1245 execute all unwind-protect clauses made above that catch. Unwind
1246 the handler stack as we go, so that the proper handlers are in
1247 effect for each unwind-protect clause we run. At the end, restore
1248 some static info saved in CATCH, and longjmp to the location
1251 This is used for correct unwinding in Fthrow and Fsignal. */
1254 unwind_to_catch (catch, value
)
1255 struct catchtag
*catch;
1258 register int last_time
;
1260 /* Save the value in the tag. */
1263 /* Restore certain special C variables. */
1264 set_poll_suppress_count (catch->poll_suppress_count
);
1265 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked
);
1266 handling_signal
= 0;
1271 last_time
= catchlist
== catch;
1273 /* Unwind the specpdl stack, and then restore the proper set of
1275 unbind_to (catchlist
->pdlcount
, Qnil
);
1276 handlerlist
= catchlist
->handlerlist
;
1277 catchlist
= catchlist
->next
;
1279 while (! last_time
);
1282 /* If x_catch_errors was done, turn it off now.
1283 (First we give unbind_to a chance to do that.) */
1284 #if 0 /* This would disable x_catch_errors after x_connection_closed.
1285 * The catch must remain in effect during that delicate
1286 * state. --lorentey */
1287 x_fully_uncatch_errors ();
1291 byte_stack_list
= catch->byte_stack
;
1292 gcprolist
= catch->gcpro
;
1295 gcpro_level
= gcprolist
->level
+ 1;
1299 backtrace_list
= catch->backlist
;
1300 lisp_eval_depth
= catch->lisp_eval_depth
;
1302 _longjmp (catch->jmp
, 1);
1305 DEFUN ("throw", Fthrow
, Sthrow
, 2, 2, 0,
1306 doc
: /* Throw to the catch for TAG and return VALUE from it.
1307 Both TAG and VALUE are evalled. */)
1309 register Lisp_Object tag
, value
;
1311 register struct catchtag
*c
;
1314 for (c
= catchlist
; c
; c
= c
->next
)
1316 if (EQ (c
->tag
, tag
))
1317 unwind_to_catch (c
, value
);
1319 xsignal2 (Qno_catch
, tag
, value
);
1323 DEFUN ("unwind-protect", Funwind_protect
, Sunwind_protect
, 1, UNEVALLED
, 0,
1324 doc
: /* Do BODYFORM, protecting with UNWINDFORMS.
1325 If BODYFORM completes normally, its value is returned
1326 after executing the UNWINDFORMS.
1327 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1328 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
1333 int count
= SPECPDL_INDEX ();
1335 record_unwind_protect (Fprogn
, Fcdr (args
));
1336 val
= Feval (Fcar (args
));
1337 return unbind_to (count
, val
);
1340 /* Chain of condition handlers currently in effect.
1341 The elements of this chain are contained in the stack frames
1342 of Fcondition_case and internal_condition_case.
1343 When an error is signaled (by calling Fsignal, below),
1344 this chain is searched for an element that applies. */
1346 struct handler
*handlerlist
;
1348 DEFUN ("condition-case", Fcondition_case
, Scondition_case
, 2, UNEVALLED
, 0,
1349 doc
: /* Regain control when an error is signaled.
1350 Executes BODYFORM and returns its value if no error happens.
1351 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1352 where the BODY is made of Lisp expressions.
1354 A handler is applicable to an error
1355 if CONDITION-NAME is one of the error's condition names.
1356 If an error happens, the first applicable handler is run.
1358 The car of a handler may be a list of condition names
1359 instead of a single condition name. Then it handles all of them.
1361 When a handler handles an error, control returns to the `condition-case'
1362 and it executes the handler's BODY...
1363 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA) from the error.
1364 (If VAR is nil, the handler can't access that information.)
1365 Then the value of the last BODY form is returned from the `condition-case'
1368 See also the function `signal' for more info.
1369 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
1373 register Lisp_Object bodyform
, handlers
;
1374 volatile Lisp_Object var
;
1377 bodyform
= Fcar (Fcdr (args
));
1378 handlers
= Fcdr (Fcdr (args
));
1380 return internal_lisp_condition_case (var
, bodyform
, handlers
);
1383 /* Like Fcondition_case, but the args are separate
1384 rather than passed in a list. Used by Fbyte_code. */
1387 internal_lisp_condition_case (var
, bodyform
, handlers
)
1388 volatile Lisp_Object var
;
1389 Lisp_Object bodyform
, handlers
;
1397 for (val
= handlers
; CONSP (val
); val
= XCDR (val
))
1403 && (SYMBOLP (XCAR (tem
))
1404 || CONSP (XCAR (tem
))))))
1405 error ("Invalid condition handler", tem
);
1410 c
.backlist
= backtrace_list
;
1411 c
.handlerlist
= handlerlist
;
1412 c
.lisp_eval_depth
= lisp_eval_depth
;
1413 c
.pdlcount
= SPECPDL_INDEX ();
1414 c
.poll_suppress_count
= poll_suppress_count
;
1415 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1416 c
.gcpro
= gcprolist
;
1417 c
.byte_stack
= byte_stack_list
;
1418 if (_setjmp (c
.jmp
))
1421 specbind (h
.var
, c
.val
);
1422 val
= Fprogn (Fcdr (h
.chosen_clause
));
1424 /* Note that this just undoes the binding of h.var; whoever
1425 longjumped to us unwound the stack to c.pdlcount before
1427 unbind_to (c
.pdlcount
, Qnil
);
1434 h
.handler
= handlers
;
1435 h
.next
= handlerlist
;
1439 val
= Feval (bodyform
);
1441 handlerlist
= h
.next
;
1445 /* Call the function BFUN with no arguments, catching errors within it
1446 according to HANDLERS. If there is an error, call HFUN with
1447 one argument which is the data that describes the error:
1450 HANDLERS can be a list of conditions to catch.
1451 If HANDLERS is Qt, catch all errors.
1452 If HANDLERS is Qerror, catch all errors
1453 but allow the debugger to run if that is enabled. */
1456 internal_condition_case (bfun
, handlers
, hfun
)
1457 Lisp_Object (*bfun
) ();
1458 Lisp_Object handlers
;
1459 Lisp_Object (*hfun
) ();
1465 /* Since Fsignal will close off all calls to x_catch_errors,
1466 we will get the wrong results if some are not closed now. */
1468 if (x_catching_errors ())
1474 c
.backlist
= backtrace_list
;
1475 c
.handlerlist
= handlerlist
;
1476 c
.lisp_eval_depth
= lisp_eval_depth
;
1477 c
.pdlcount
= SPECPDL_INDEX ();
1478 c
.poll_suppress_count
= poll_suppress_count
;
1479 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1480 c
.gcpro
= gcprolist
;
1481 c
.byte_stack
= byte_stack_list
;
1482 if (_setjmp (c
.jmp
))
1484 return (*hfun
) (c
.val
);
1488 h
.handler
= handlers
;
1490 h
.next
= handlerlist
;
1496 handlerlist
= h
.next
;
1500 /* Like internal_condition_case but call BFUN with ARG as its argument. */
1503 internal_condition_case_1 (bfun
, arg
, handlers
, hfun
)
1504 Lisp_Object (*bfun
) ();
1506 Lisp_Object handlers
;
1507 Lisp_Object (*hfun
) ();
1513 /* Since Fsignal will close off all calls to x_catch_errors,
1514 we will get the wrong results if some are not closed now. */
1516 if (x_catching_errors ())
1522 c
.backlist
= backtrace_list
;
1523 c
.handlerlist
= handlerlist
;
1524 c
.lisp_eval_depth
= lisp_eval_depth
;
1525 c
.pdlcount
= SPECPDL_INDEX ();
1526 c
.poll_suppress_count
= poll_suppress_count
;
1527 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1528 c
.gcpro
= gcprolist
;
1529 c
.byte_stack
= byte_stack_list
;
1530 if (_setjmp (c
.jmp
))
1532 return (*hfun
) (c
.val
);
1536 h
.handler
= handlers
;
1538 h
.next
= handlerlist
;
1542 val
= (*bfun
) (arg
);
1544 handlerlist
= h
.next
;
1549 /* Like internal_condition_case but call BFUN with NARGS as first,
1550 and ARGS as second argument. */
1553 internal_condition_case_2 (bfun
, nargs
, args
, handlers
, hfun
)
1554 Lisp_Object (*bfun
) ();
1557 Lisp_Object handlers
;
1558 Lisp_Object (*hfun
) ();
1564 /* Since Fsignal will close off all calls to x_catch_errors,
1565 we will get the wrong results if some are not closed now. */
1567 if (x_catching_errors ())
1573 c
.backlist
= backtrace_list
;
1574 c
.handlerlist
= handlerlist
;
1575 c
.lisp_eval_depth
= lisp_eval_depth
;
1576 c
.pdlcount
= SPECPDL_INDEX ();
1577 c
.poll_suppress_count
= poll_suppress_count
;
1578 c
.interrupt_input_blocked
= interrupt_input_blocked
;
1579 c
.gcpro
= gcprolist
;
1580 c
.byte_stack
= byte_stack_list
;
1581 if (_setjmp (c
.jmp
))
1583 return (*hfun
) (c
.val
);
1587 h
.handler
= handlers
;
1589 h
.next
= handlerlist
;
1593 val
= (*bfun
) (nargs
, args
);
1595 handlerlist
= h
.next
;
1600 static Lisp_Object find_handler_clause
P_ ((Lisp_Object
, Lisp_Object
,
1601 Lisp_Object
, Lisp_Object
));
1603 DEFUN ("signal", Fsignal
, Ssignal
, 2, 2, 0,
1604 doc
: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1605 This function does not return.
1607 An error symbol is a symbol with an `error-conditions' property
1608 that is a list of condition names.
1609 A handler for any of those names will get to handle this signal.
1610 The symbol `error' should normally be one of them.
1612 DATA should be a list. Its elements are printed as part of the error message.
1613 See Info anchor `(elisp)Definition of signal' for some details on how this
1614 error message is constructed.
1615 If the signal is handled, DATA is made available to the handler.
1616 See also the function `condition-case'. */)
1617 (error_symbol
, data
)
1618 Lisp_Object error_symbol
, data
;
1620 /* When memory is full, ERROR-SYMBOL is nil,
1621 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1622 That is a special case--don't do this in other situations. */
1623 register struct handler
*allhandlers
= handlerlist
;
1624 Lisp_Object conditions
;
1625 extern int gc_in_progress
;
1626 extern int waiting_for_input
;
1628 Lisp_Object real_error_symbol
;
1629 struct backtrace
*bp
;
1631 immediate_quit
= handling_signal
= 0;
1633 if (gc_in_progress
|| waiting_for_input
)
1636 if (NILP (error_symbol
))
1637 real_error_symbol
= Fcar (data
);
1639 real_error_symbol
= error_symbol
;
1641 #if 0 /* rms: I don't know why this was here,
1642 but it is surely wrong for an error that is handled. */
1643 #ifdef HAVE_WINDOW_SYSTEM
1644 if (display_hourglass_p
)
1645 cancel_hourglass ();
1649 /* This hook is used by edebug. */
1650 if (! NILP (Vsignal_hook_function
)
1651 && ! NILP (error_symbol
))
1653 /* Edebug takes care of restoring these variables when it exits. */
1654 if (lisp_eval_depth
+ 20 > max_lisp_eval_depth
)
1655 max_lisp_eval_depth
= lisp_eval_depth
+ 20;
1657 if (SPECPDL_INDEX () + 40 > max_specpdl_size
)
1658 max_specpdl_size
= SPECPDL_INDEX () + 40;
1660 call2 (Vsignal_hook_function
, error_symbol
, data
);
1663 conditions
= Fget (real_error_symbol
, Qerror_conditions
);
1665 /* Remember from where signal was called. Skip over the frame for
1666 `signal' itself. If a frame for `error' follows, skip that,
1667 too. Don't do this when ERROR_SYMBOL is nil, because that
1668 is a memory-full error. */
1669 Vsignaling_function
= Qnil
;
1670 if (backtrace_list
&& !NILP (error_symbol
))
1672 bp
= backtrace_list
->next
;
1673 if (bp
&& bp
->function
&& EQ (*bp
->function
, Qerror
))
1675 if (bp
&& bp
->function
)
1676 Vsignaling_function
= *bp
->function
;
1679 for (; handlerlist
; handlerlist
= handlerlist
->next
)
1681 register Lisp_Object clause
;
1683 clause
= find_handler_clause (handlerlist
->handler
, conditions
,
1684 error_symbol
, data
);
1686 if (EQ (clause
, Qlambda
))
1688 /* We can't return values to code which signaled an error, but we
1689 can continue code which has signaled a quit. */
1690 if (EQ (real_error_symbol
, Qquit
))
1693 error ("Cannot return from the debugger in an error");
1698 Lisp_Object unwind_data
;
1699 struct handler
*h
= handlerlist
;
1701 handlerlist
= allhandlers
;
1703 if (NILP (error_symbol
))
1706 unwind_data
= Fcons (error_symbol
, data
);
1707 h
->chosen_clause
= clause
;
1708 unwind_to_catch (h
->tag
, unwind_data
);
1712 handlerlist
= allhandlers
;
1713 /* If no handler is present now, try to run the debugger,
1714 and if that fails, throw to top level. */
1715 find_handler_clause (Qerror
, conditions
, error_symbol
, data
);
1717 Fthrow (Qtop_level
, Qt
);
1719 if (! NILP (error_symbol
))
1720 data
= Fcons (error_symbol
, data
);
1722 string
= Ferror_message_string (data
);
1723 fatal ("%s", SDATA (string
), 0);
1726 /* Internal version of Fsignal that never returns.
1727 Used for anything but Qquit (which can return from Fsignal). */
1730 xsignal (error_symbol
, data
)
1731 Lisp_Object error_symbol
, data
;
1733 Fsignal (error_symbol
, data
);
1737 /* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1740 xsignal0 (error_symbol
)
1741 Lisp_Object error_symbol
;
1743 xsignal (error_symbol
, Qnil
);
1747 xsignal1 (error_symbol
, arg
)
1748 Lisp_Object error_symbol
, arg
;
1750 xsignal (error_symbol
, list1 (arg
));
1754 xsignal2 (error_symbol
, arg1
, arg2
)
1755 Lisp_Object error_symbol
, arg1
, arg2
;
1757 xsignal (error_symbol
, list2 (arg1
, arg2
));
1761 xsignal3 (error_symbol
, arg1
, arg2
, arg3
)
1762 Lisp_Object error_symbol
, arg1
, arg2
, arg3
;
1764 xsignal (error_symbol
, list3 (arg1
, arg2
, arg3
));
1767 /* Signal `error' with message S, and additional arg ARG.
1768 If ARG is not a genuine list, make it a one-element list. */
1771 signal_error (s
, arg
)
1775 Lisp_Object tortoise
, hare
;
1777 hare
= tortoise
= arg
;
1778 while (CONSP (hare
))
1785 tortoise
= XCDR (tortoise
);
1787 if (EQ (hare
, tortoise
))
1792 arg
= Fcons (arg
, Qnil
); /* Make it a list. */
1794 xsignal (Qerror
, Fcons (build_string (s
), arg
));
1798 /* Return nonzero if LIST is a non-nil atom or
1799 a list containing one of CONDITIONS. */
1802 wants_debugger (list
, conditions
)
1803 Lisp_Object list
, conditions
;
1810 while (CONSP (conditions
))
1812 Lisp_Object
this, tail
;
1813 this = XCAR (conditions
);
1814 for (tail
= list
; CONSP (tail
); tail
= XCDR (tail
))
1815 if (EQ (XCAR (tail
), this))
1817 conditions
= XCDR (conditions
);
1822 /* Return 1 if an error with condition-symbols CONDITIONS,
1823 and described by SIGNAL-DATA, should skip the debugger
1824 according to debugger-ignored-errors. */
1827 skip_debugger (conditions
, data
)
1828 Lisp_Object conditions
, data
;
1831 int first_string
= 1;
1832 Lisp_Object error_message
;
1834 error_message
= Qnil
;
1835 for (tail
= Vdebug_ignored_errors
; CONSP (tail
); tail
= XCDR (tail
))
1837 if (STRINGP (XCAR (tail
)))
1841 error_message
= Ferror_message_string (data
);
1845 if (fast_string_match (XCAR (tail
), error_message
) >= 0)
1850 Lisp_Object contail
;
1852 for (contail
= conditions
; CONSP (contail
); contail
= XCDR (contail
))
1853 if (EQ (XCAR (tail
), XCAR (contail
)))
1861 /* Value of Qlambda means we have called debugger and user has continued.
1862 There are two ways to pass SIG and DATA:
1863 = SIG is the error symbol, and DATA is the rest of the data.
1864 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1865 This is for memory-full errors only.
1867 We need to increase max_specpdl_size temporarily around
1868 anything we do that can push on the specpdl, so as not to get
1869 a second error here in case we're handling specpdl overflow. */
1872 find_handler_clause (handlers
, conditions
, sig
, data
)
1873 Lisp_Object handlers
, conditions
, sig
, data
;
1875 register Lisp_Object h
;
1876 register Lisp_Object tem
;
1877 int debugger_called
= 0;
1878 int debugger_considered
= 0;
1880 /* t is used by handlers for all conditions, set up by C code. */
1881 if (EQ (handlers
, Qt
))
1884 /* Don't run the debugger for a memory-full error.
1885 (There is no room in memory to do that!) */
1887 debugger_considered
= 1;
1889 /* error is used similarly, but means print an error message
1890 and run the debugger if that is enabled. */
1891 if (EQ (handlers
, Qerror
)
1892 || !NILP (Vdebug_on_signal
)) /* This says call debugger even if
1893 there is a handler. */
1895 if (!NILP (sig
) && wants_debugger (Vstack_trace_on_error
, conditions
))
1899 internal_with_output_to_temp_buffer ("*Backtrace*",
1900 (Lisp_Object (*) (Lisp_Object
)) Fbacktrace
,
1903 internal_with_output_to_temp_buffer ("*Backtrace*",
1909 if (!debugger_considered
)
1911 debugger_considered
= 1;
1912 debugger_called
= maybe_call_debugger (conditions
, sig
, data
);
1915 /* If there is no handler, return saying whether we ran the debugger. */
1916 if (EQ (handlers
, Qerror
))
1918 if (debugger_called
)
1924 for (h
= handlers
; CONSP (h
); h
= Fcdr (h
))
1926 Lisp_Object handler
, condit
;
1929 if (!CONSP (handler
))
1931 condit
= Fcar (handler
);
1932 /* Handle a single condition name in handler HANDLER. */
1933 if (SYMBOLP (condit
))
1935 tem
= Fmemq (Fcar (handler
), conditions
);
1939 /* Handle a list of condition names in handler HANDLER. */
1940 else if (CONSP (condit
))
1943 for (tail
= condit
; CONSP (tail
); tail
= XCDR (tail
))
1945 tem
= Fmemq (Fcar (tail
), conditions
);
1948 /* This handler is going to apply.
1949 Does it allow the debugger to run first? */
1950 if (! debugger_considered
&& !NILP (Fmemq (Qdebug
, condit
)))
1951 maybe_call_debugger (conditions
, sig
, data
);
1961 /* Call the debugger if calling it is currently enabled for CONDITIONS.
1962 SIG and DATA describe the signal, as in find_handler_clause. */
1965 maybe_call_debugger (conditions
, sig
, data
)
1966 Lisp_Object conditions
, sig
, data
;
1968 Lisp_Object combined_data
;
1970 combined_data
= Fcons (sig
, data
);
1973 /* Don't try to run the debugger with interrupts blocked.
1974 The editing loop would return anyway. */
1976 /* Does user wants to enter debugger for this kind of error? */
1979 : wants_debugger (Vdebug_on_error
, conditions
))
1980 && ! skip_debugger (conditions
, combined_data
)
1981 /* rms: what's this for? */
1982 && when_entered_debugger
< num_nonmacro_input_events
)
1984 call_debugger (Fcons (Qerror
, Fcons (combined_data
, Qnil
)));
1991 /* dump an error message; called like printf */
1995 error (m
, a1
, a2
, a3
)
2015 int used
= doprnt (buffer
, size
, m
, m
+ mlen
, 3, args
);
2020 buffer
= (char *) xrealloc (buffer
, size
);
2023 buffer
= (char *) xmalloc (size
);
2028 string
= build_string (buffer
);
2032 xsignal1 (Qerror
, string
);
2035 DEFUN ("commandp", Fcommandp
, Scommandp
, 1, 2, 0,
2036 doc
: /* Non-nil if FUNCTION makes provisions for interactive calling.
2037 This means it contains a description for how to read arguments to give it.
2038 The value is nil for an invalid function or a symbol with no function
2041 Interactively callable functions include strings and vectors (treated
2042 as keyboard macros), lambda-expressions that contain a top-level call
2043 to `interactive', autoload definitions made by `autoload' with non-nil
2044 fourth argument, and some of the built-in functions of Lisp.
2046 Also, a symbol satisfies `commandp' if its function definition does so.
2048 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
2049 then strings and vectors are not accepted. */)
2050 (function
, for_call_interactively
)
2051 Lisp_Object function
, for_call_interactively
;
2053 register Lisp_Object fun
;
2054 register Lisp_Object funcar
;
2055 Lisp_Object if_prop
= Qnil
;
2059 fun
= indirect_function (fun
); /* Check cycles. */
2060 if (NILP (fun
) || EQ (fun
, Qunbound
))
2063 /* Check an `interactive-form' property if present, analogous to the
2064 function-documentation property. */
2066 while (SYMBOLP (fun
))
2068 Lisp_Object tmp
= Fget (fun
, intern ("interactive-form"));
2071 fun
= Fsymbol_function (fun
);
2074 /* Emacs primitives are interactive if their DEFUN specifies an
2075 interactive spec. */
2077 return XSUBR (fun
)->intspec
? Qt
: if_prop
;
2079 /* Bytecode objects are interactive if they are long enough to
2080 have an element whose index is COMPILED_INTERACTIVE, which is
2081 where the interactive spec is stored. */
2082 else if (COMPILEDP (fun
))
2083 return ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
2086 /* Strings and vectors are keyboard macros. */
2087 if (STRINGP (fun
) || VECTORP (fun
))
2088 return (NILP (for_call_interactively
) ? Qt
: Qnil
);
2090 /* Lists may represent commands. */
2093 funcar
= XCAR (fun
);
2094 if (EQ (funcar
, Qlambda
))
2095 return !NILP (Fassq (Qinteractive
, Fcdr (XCDR (fun
)))) ? Qt
: if_prop
;
2096 if (EQ (funcar
, Qautoload
))
2097 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun
))))) ? Qt
: if_prop
;
2103 DEFUN ("autoload", Fautoload
, Sautoload
, 2, 5, 0,
2104 doc
: /* Define FUNCTION to autoload from FILE.
2105 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2106 Third arg DOCSTRING is documentation for the function.
2107 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2108 Fifth arg TYPE indicates the type of the object:
2109 nil or omitted says FUNCTION is a function,
2110 `keymap' says FUNCTION is really a keymap, and
2111 `macro' or t says FUNCTION is really a macro.
2112 Third through fifth args give info about the real definition.
2113 They default to nil.
2114 If FUNCTION is already defined other than as an autoload,
2115 this does nothing and returns nil. */)
2116 (function
, file
, docstring
, interactive
, type
)
2117 Lisp_Object function
, file
, docstring
, interactive
, type
;
2120 Lisp_Object args
[4];
2123 CHECK_SYMBOL (function
);
2124 CHECK_STRING (file
);
2126 /* If function is defined and not as an autoload, don't override */
2127 if (!EQ (XSYMBOL (function
)->function
, Qunbound
)
2128 && !(CONSP (XSYMBOL (function
)->function
)
2129 && EQ (XCAR (XSYMBOL (function
)->function
), Qautoload
)))
2132 if (NILP (Vpurify_flag
))
2133 /* Only add entries after dumping, because the ones before are
2134 not useful and else we get loads of them from the loaddefs.el. */
2135 LOADHIST_ATTACH (Fcons (Qautoload
, function
));
2139 args
[1] = docstring
;
2140 args
[2] = interactive
;
2143 return Ffset (function
, Fcons (Qautoload
, Flist (4, &args
[0])));
2144 #else /* NO_ARG_ARRAY */
2145 return Ffset (function
, Fcons (Qautoload
, Flist (4, &file
)));
2146 #endif /* not NO_ARG_ARRAY */
2150 un_autoload (oldqueue
)
2151 Lisp_Object oldqueue
;
2153 register Lisp_Object queue
, first
, second
;
2155 /* Queue to unwind is current value of Vautoload_queue.
2156 oldqueue is the shadowed value to leave in Vautoload_queue. */
2157 queue
= Vautoload_queue
;
2158 Vautoload_queue
= oldqueue
;
2159 while (CONSP (queue
))
2161 first
= XCAR (queue
);
2162 second
= Fcdr (first
);
2163 first
= Fcar (first
);
2164 if (EQ (first
, make_number (0)))
2167 Ffset (first
, second
);
2168 queue
= XCDR (queue
);
2173 /* Load an autoloaded function.
2174 FUNNAME is the symbol which is the function's name.
2175 FUNDEF is the autoload definition (a list). */
2178 do_autoload (fundef
, funname
)
2179 Lisp_Object fundef
, funname
;
2181 int count
= SPECPDL_INDEX ();
2183 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2185 /* This is to make sure that loadup.el gives a clear picture
2186 of what files are preloaded and when. */
2187 if (! NILP (Vpurify_flag
))
2188 error ("Attempt to autoload %s while preparing to dump",
2189 SDATA (SYMBOL_NAME (funname
)));
2192 CHECK_SYMBOL (funname
);
2193 GCPRO3 (fun
, funname
, fundef
);
2195 /* Preserve the match data. */
2196 record_unwind_save_match_data ();
2198 /* If autoloading gets an error (which includes the error of failing
2199 to define the function being called), we use Vautoload_queue
2200 to undo function definitions and `provide' calls made by
2201 the function. We do this in the specific case of autoloading
2202 because autoloading is not an explicit request "load this file",
2203 but rather a request to "call this function".
2205 The value saved here is to be restored into Vautoload_queue. */
2206 record_unwind_protect (un_autoload
, Vautoload_queue
);
2207 Vautoload_queue
= Qt
;
2208 Fload (Fcar (Fcdr (fundef
)), Qnil
, Qt
, Qnil
, Qt
);
2210 /* Once loading finishes, don't undo it. */
2211 Vautoload_queue
= Qt
;
2212 unbind_to (count
, Qnil
);
2214 fun
= Findirect_function (fun
, Qnil
);
2216 if (!NILP (Fequal (fun
, fundef
)))
2217 error ("Autoloading failed to define function %s",
2218 SDATA (SYMBOL_NAME (funname
)));
2223 DEFUN ("eval", Feval
, Seval
, 1, 1, 0,
2224 doc
: /* Evaluate FORM and return its value. */)
2228 Lisp_Object fun
, val
, original_fun
, original_args
;
2230 struct backtrace backtrace
;
2231 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2233 if (handling_signal
)
2237 return Fsymbol_value (form
);
2242 if ((consing_since_gc
> gc_cons_threshold
2243 && consing_since_gc
> gc_relative_threshold
)
2245 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2248 Fgarbage_collect ();
2252 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2254 if (max_lisp_eval_depth
< 100)
2255 max_lisp_eval_depth
= 100;
2256 if (lisp_eval_depth
> max_lisp_eval_depth
)
2257 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2260 original_fun
= Fcar (form
);
2261 original_args
= Fcdr (form
);
2263 backtrace
.next
= backtrace_list
;
2264 backtrace_list
= &backtrace
;
2265 backtrace
.function
= &original_fun
; /* This also protects them from gc */
2266 backtrace
.args
= &original_args
;
2267 backtrace
.nargs
= UNEVALLED
;
2268 backtrace
.evalargs
= 1;
2269 backtrace
.debug_on_exit
= 0;
2271 if (debug_on_next_call
)
2272 do_debug_on_call (Qt
);
2274 /* At this point, only original_fun and original_args
2275 have values that will be used below */
2278 /* Optimize for no indirection. */
2280 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2281 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2282 fun
= indirect_function (fun
);
2286 Lisp_Object numargs
;
2287 Lisp_Object argvals
[8];
2288 Lisp_Object args_left
;
2289 register int i
, maxargs
;
2291 args_left
= original_args
;
2292 numargs
= Flength (args_left
);
2296 if (XINT (numargs
) < XSUBR (fun
)->min_args
||
2297 (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< XINT (numargs
)))
2298 xsignal2 (Qwrong_number_of_arguments
, original_fun
, numargs
);
2300 if (XSUBR (fun
)->max_args
== UNEVALLED
)
2302 backtrace
.evalargs
= 0;
2303 val
= (*XSUBR (fun
)->function
) (args_left
);
2307 if (XSUBR (fun
)->max_args
== MANY
)
2309 /* Pass a vector of evaluated arguments */
2311 register int argnum
= 0;
2313 vals
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
2315 GCPRO3 (args_left
, fun
, fun
);
2319 while (!NILP (args_left
))
2321 vals
[argnum
++] = Feval (Fcar (args_left
));
2322 args_left
= Fcdr (args_left
);
2323 gcpro3
.nvars
= argnum
;
2326 backtrace
.args
= vals
;
2327 backtrace
.nargs
= XINT (numargs
);
2329 val
= (*XSUBR (fun
)->function
) (XINT (numargs
), vals
);
2334 GCPRO3 (args_left
, fun
, fun
);
2335 gcpro3
.var
= argvals
;
2338 maxargs
= XSUBR (fun
)->max_args
;
2339 for (i
= 0; i
< maxargs
; args_left
= Fcdr (args_left
))
2341 argvals
[i
] = Feval (Fcar (args_left
));
2347 backtrace
.args
= argvals
;
2348 backtrace
.nargs
= XINT (numargs
);
2353 val
= (*XSUBR (fun
)->function
) ();
2356 val
= (*XSUBR (fun
)->function
) (argvals
[0]);
2359 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1]);
2362 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2366 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1],
2367 argvals
[2], argvals
[3]);
2370 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2371 argvals
[3], argvals
[4]);
2374 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2375 argvals
[3], argvals
[4], argvals
[5]);
2378 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2379 argvals
[3], argvals
[4], argvals
[5],
2384 val
= (*XSUBR (fun
)->function
) (argvals
[0], argvals
[1], argvals
[2],
2385 argvals
[3], argvals
[4], argvals
[5],
2386 argvals
[6], argvals
[7]);
2390 /* Someone has created a subr that takes more arguments than
2391 is supported by this code. We need to either rewrite the
2392 subr to use a different argument protocol, or add more
2393 cases to this switch. */
2397 if (COMPILEDP (fun
))
2398 val
= apply_lambda (fun
, original_args
, 1);
2401 if (EQ (fun
, Qunbound
))
2402 xsignal1 (Qvoid_function
, original_fun
);
2404 xsignal1 (Qinvalid_function
, original_fun
);
2405 funcar
= XCAR (fun
);
2406 if (!SYMBOLP (funcar
))
2407 xsignal1 (Qinvalid_function
, original_fun
);
2408 if (EQ (funcar
, Qautoload
))
2410 do_autoload (fun
, original_fun
);
2413 if (EQ (funcar
, Qmacro
))
2414 val
= Feval (apply1 (Fcdr (fun
), original_args
));
2415 else if (EQ (funcar
, Qlambda
))
2416 val
= apply_lambda (fun
, original_args
, 1);
2418 xsignal1 (Qinvalid_function
, original_fun
);
2424 if (backtrace
.debug_on_exit
)
2425 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
2426 backtrace_list
= backtrace
.next
;
2431 DEFUN ("apply", Fapply
, Sapply
, 2, MANY
, 0,
2432 doc
: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2433 Then return the value FUNCTION returns.
2434 Thus, (apply '+ 1 2 '(3 4)) returns 10.
2435 usage: (apply FUNCTION &rest ARGUMENTS) */)
2440 register int i
, numargs
;
2441 register Lisp_Object spread_arg
;
2442 register Lisp_Object
*funcall_args
;
2444 struct gcpro gcpro1
;
2448 spread_arg
= args
[nargs
- 1];
2449 CHECK_LIST (spread_arg
);
2451 numargs
= XINT (Flength (spread_arg
));
2454 return Ffuncall (nargs
- 1, args
);
2455 else if (numargs
== 1)
2457 args
[nargs
- 1] = XCAR (spread_arg
);
2458 return Ffuncall (nargs
, args
);
2461 numargs
+= nargs
- 2;
2463 /* Optimize for no indirection. */
2464 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2465 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2466 fun
= indirect_function (fun
);
2467 if (EQ (fun
, Qunbound
))
2469 /* Let funcall get the error */
2476 if (numargs
< XSUBR (fun
)->min_args
2477 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2478 goto funcall
; /* Let funcall get the error */
2479 else if (XSUBR (fun
)->max_args
> numargs
)
2481 /* Avoid making funcall cons up a yet another new vector of arguments
2482 by explicitly supplying nil's for optional values */
2483 funcall_args
= (Lisp_Object
*) alloca ((1 + XSUBR (fun
)->max_args
)
2484 * sizeof (Lisp_Object
));
2485 for (i
= numargs
; i
< XSUBR (fun
)->max_args
;)
2486 funcall_args
[++i
] = Qnil
;
2487 GCPRO1 (*funcall_args
);
2488 gcpro1
.nvars
= 1 + XSUBR (fun
)->max_args
;
2492 /* We add 1 to numargs because funcall_args includes the
2493 function itself as well as its arguments. */
2496 funcall_args
= (Lisp_Object
*) alloca ((1 + numargs
)
2497 * sizeof (Lisp_Object
));
2498 GCPRO1 (*funcall_args
);
2499 gcpro1
.nvars
= 1 + numargs
;
2502 bcopy (args
, funcall_args
, nargs
* sizeof (Lisp_Object
));
2503 /* Spread the last arg we got. Its first element goes in
2504 the slot that it used to occupy, hence this value of I. */
2506 while (!NILP (spread_arg
))
2508 funcall_args
[i
++] = XCAR (spread_arg
);
2509 spread_arg
= XCDR (spread_arg
);
2512 /* By convention, the caller needs to gcpro Ffuncall's args. */
2513 RETURN_UNGCPRO (Ffuncall (gcpro1
.nvars
, funcall_args
));
2516 /* Run hook variables in various ways. */
2518 enum run_hooks_condition
{to_completion
, until_success
, until_failure
};
2519 static Lisp_Object run_hook_with_args
P_ ((int, Lisp_Object
*,
2520 enum run_hooks_condition
));
2522 DEFUN ("run-hooks", Frun_hooks
, Srun_hooks
, 0, MANY
, 0,
2523 doc
: /* Run each hook in HOOKS.
2524 Each argument should be a symbol, a hook variable.
2525 These symbols are processed in the order specified.
2526 If a hook symbol has a non-nil value, that value may be a function
2527 or a list of functions to be called to run the hook.
2528 If the value is a function, it is called with no arguments.
2529 If it is a list, the elements are called, in order, with no arguments.
2531 Major modes should not use this function directly to run their mode
2532 hook; they should use `run-mode-hooks' instead.
2534 Do not use `make-local-variable' to make a hook variable buffer-local.
2535 Instead, use `add-hook' and specify t for the LOCAL argument.
2536 usage: (run-hooks &rest HOOKS) */)
2541 Lisp_Object hook
[1];
2544 for (i
= 0; i
< nargs
; i
++)
2547 run_hook_with_args (1, hook
, to_completion
);
2553 DEFUN ("run-hook-with-args", Frun_hook_with_args
,
2554 Srun_hook_with_args
, 1, MANY
, 0,
2555 doc
: /* Run HOOK with the specified arguments ARGS.
2556 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2557 value, that value may be a function or a list of functions to be
2558 called to run the hook. If the value is a function, it is called with
2559 the given arguments and its return value is returned. If it is a list
2560 of functions, those functions are called, in order,
2561 with the given arguments ARGS.
2562 It is best not to depend on the value returned by `run-hook-with-args',
2565 Do not use `make-local-variable' to make a hook variable buffer-local.
2566 Instead, use `add-hook' and specify t for the LOCAL argument.
2567 usage: (run-hook-with-args HOOK &rest ARGS) */)
2572 return run_hook_with_args (nargs
, args
, to_completion
);
2575 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success
,
2576 Srun_hook_with_args_until_success
, 1, MANY
, 0,
2577 doc
: /* Run HOOK with the specified arguments ARGS.
2578 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2579 value, that value may be a function or a list of functions to be
2580 called to run the hook. If the value is a function, it is called with
2581 the given arguments and its return value is returned.
2582 If it is a list of functions, those functions are called, in order,
2583 with the given arguments ARGS, until one of them
2584 returns a non-nil value. Then we return that value.
2585 However, if they all return nil, we return nil.
2587 Do not use `make-local-variable' to make a hook variable buffer-local.
2588 Instead, use `add-hook' and specify t for the LOCAL argument.
2589 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
2594 return run_hook_with_args (nargs
, args
, until_success
);
2597 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure
,
2598 Srun_hook_with_args_until_failure
, 1, MANY
, 0,
2599 doc
: /* Run HOOK with the specified arguments ARGS.
2600 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2601 value, that value may be a function or a list of functions to be
2602 called to run the hook. If the value is a function, it is called with
2603 the given arguments and its return value is returned.
2604 If it is a list of functions, those functions are called, in order,
2605 with the given arguments ARGS, until one of them returns nil.
2606 Then we return nil. However, if they all return non-nil, we return non-nil.
2608 Do not use `make-local-variable' to make a hook variable buffer-local.
2609 Instead, use `add-hook' and specify t for the LOCAL argument.
2610 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
2615 return run_hook_with_args (nargs
, args
, until_failure
);
2618 /* ARGS[0] should be a hook symbol.
2619 Call each of the functions in the hook value, passing each of them
2620 as arguments all the rest of ARGS (all NARGS - 1 elements).
2621 COND specifies a condition to test after each call
2622 to decide whether to stop.
2623 The caller (or its caller, etc) must gcpro all of ARGS,
2624 except that it isn't necessary to gcpro ARGS[0]. */
2627 run_hook_with_args (nargs
, args
, cond
)
2630 enum run_hooks_condition cond
;
2632 Lisp_Object sym
, val
, ret
;
2633 Lisp_Object globals
;
2634 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2636 /* If we are dying or still initializing,
2637 don't do anything--it would probably crash if we tried. */
2638 if (NILP (Vrun_hooks
))
2642 val
= find_symbol_value (sym
);
2643 ret
= (cond
== until_failure
? Qt
: Qnil
);
2645 if (EQ (val
, Qunbound
) || NILP (val
))
2647 else if (!CONSP (val
) || EQ (XCAR (val
), Qlambda
))
2650 return Ffuncall (nargs
, args
);
2655 GCPRO3 (sym
, val
, globals
);
2658 CONSP (val
) && ((cond
== to_completion
)
2659 || (cond
== until_success
? NILP (ret
)
2663 if (EQ (XCAR (val
), Qt
))
2665 /* t indicates this hook has a local binding;
2666 it means to run the global binding too. */
2668 for (globals
= Fdefault_value (sym
);
2669 CONSP (globals
) && ((cond
== to_completion
)
2670 || (cond
== until_success
? NILP (ret
)
2672 globals
= XCDR (globals
))
2674 args
[0] = XCAR (globals
);
2675 /* In a global value, t should not occur. If it does, we
2676 must ignore it to avoid an endless loop. */
2677 if (!EQ (args
[0], Qt
))
2678 ret
= Ffuncall (nargs
, args
);
2683 args
[0] = XCAR (val
);
2684 ret
= Ffuncall (nargs
, args
);
2693 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
2694 present value of that symbol.
2695 Call each element of FUNLIST,
2696 passing each of them the rest of ARGS.
2697 The caller (or its caller, etc) must gcpro all of ARGS,
2698 except that it isn't necessary to gcpro ARGS[0]. */
2701 run_hook_list_with_args (funlist
, nargs
, args
)
2702 Lisp_Object funlist
;
2708 Lisp_Object globals
;
2709 struct gcpro gcpro1
, gcpro2
, gcpro3
;
2713 GCPRO3 (sym
, val
, globals
);
2715 for (val
= funlist
; CONSP (val
); val
= XCDR (val
))
2717 if (EQ (XCAR (val
), Qt
))
2719 /* t indicates this hook has a local binding;
2720 it means to run the global binding too. */
2722 for (globals
= Fdefault_value (sym
);
2724 globals
= XCDR (globals
))
2726 args
[0] = XCAR (globals
);
2727 /* In a global value, t should not occur. If it does, we
2728 must ignore it to avoid an endless loop. */
2729 if (!EQ (args
[0], Qt
))
2730 Ffuncall (nargs
, args
);
2735 args
[0] = XCAR (val
);
2736 Ffuncall (nargs
, args
);
2743 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2746 run_hook_with_args_2 (hook
, arg1
, arg2
)
2747 Lisp_Object hook
, arg1
, arg2
;
2749 Lisp_Object temp
[3];
2754 Frun_hook_with_args (3, temp
);
2757 /* Apply fn to arg */
2760 Lisp_Object fn
, arg
;
2762 struct gcpro gcpro1
;
2766 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2770 Lisp_Object args
[2];
2774 RETURN_UNGCPRO (Fapply (2, args
));
2776 #else /* not NO_ARG_ARRAY */
2777 RETURN_UNGCPRO (Fapply (2, &fn
));
2778 #endif /* not NO_ARG_ARRAY */
2781 /* Call function fn on no arguments */
2786 struct gcpro gcpro1
;
2789 RETURN_UNGCPRO (Ffuncall (1, &fn
));
2792 /* Call function fn with 1 argument arg1 */
2796 Lisp_Object fn
, arg1
;
2798 struct gcpro gcpro1
;
2800 Lisp_Object args
[2];
2806 RETURN_UNGCPRO (Ffuncall (2, args
));
2807 #else /* not NO_ARG_ARRAY */
2810 RETURN_UNGCPRO (Ffuncall (2, &fn
));
2811 #endif /* not NO_ARG_ARRAY */
2814 /* Call function fn with 2 arguments arg1, arg2 */
2817 call2 (fn
, arg1
, arg2
)
2818 Lisp_Object fn
, arg1
, arg2
;
2820 struct gcpro gcpro1
;
2822 Lisp_Object args
[3];
2828 RETURN_UNGCPRO (Ffuncall (3, args
));
2829 #else /* not NO_ARG_ARRAY */
2832 RETURN_UNGCPRO (Ffuncall (3, &fn
));
2833 #endif /* not NO_ARG_ARRAY */
2836 /* Call function fn with 3 arguments arg1, arg2, arg3 */
2839 call3 (fn
, arg1
, arg2
, arg3
)
2840 Lisp_Object fn
, arg1
, arg2
, arg3
;
2842 struct gcpro gcpro1
;
2844 Lisp_Object args
[4];
2851 RETURN_UNGCPRO (Ffuncall (4, args
));
2852 #else /* not NO_ARG_ARRAY */
2855 RETURN_UNGCPRO (Ffuncall (4, &fn
));
2856 #endif /* not NO_ARG_ARRAY */
2859 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
2862 call4 (fn
, arg1
, arg2
, arg3
, arg4
)
2863 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
;
2865 struct gcpro gcpro1
;
2867 Lisp_Object args
[5];
2875 RETURN_UNGCPRO (Ffuncall (5, args
));
2876 #else /* not NO_ARG_ARRAY */
2879 RETURN_UNGCPRO (Ffuncall (5, &fn
));
2880 #endif /* not NO_ARG_ARRAY */
2883 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
2886 call5 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
)
2887 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
;
2889 struct gcpro gcpro1
;
2891 Lisp_Object args
[6];
2900 RETURN_UNGCPRO (Ffuncall (6, args
));
2901 #else /* not NO_ARG_ARRAY */
2904 RETURN_UNGCPRO (Ffuncall (6, &fn
));
2905 #endif /* not NO_ARG_ARRAY */
2908 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
2911 call6 (fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
)
2912 Lisp_Object fn
, arg1
, arg2
, arg3
, arg4
, arg5
, arg6
;
2914 struct gcpro gcpro1
;
2916 Lisp_Object args
[7];
2926 RETURN_UNGCPRO (Ffuncall (7, args
));
2927 #else /* not NO_ARG_ARRAY */
2930 RETURN_UNGCPRO (Ffuncall (7, &fn
));
2931 #endif /* not NO_ARG_ARRAY */
2934 /* The caller should GCPRO all the elements of ARGS. */
2936 DEFUN ("funcall", Ffuncall
, Sfuncall
, 1, MANY
, 0,
2937 doc
: /* Call first argument as a function, passing remaining arguments to it.
2938 Return the value that function returns.
2939 Thus, (funcall 'cons 'x 'y) returns (x . y).
2940 usage: (funcall FUNCTION &rest ARGUMENTS) */)
2945 Lisp_Object fun
, original_fun
;
2947 int numargs
= nargs
- 1;
2948 Lisp_Object lisp_numargs
;
2950 struct backtrace backtrace
;
2951 register Lisp_Object
*internal_args
;
2955 if ((consing_since_gc
> gc_cons_threshold
2956 && consing_since_gc
> gc_relative_threshold
)
2958 (!NILP (Vmemory_full
) && consing_since_gc
> memory_full_cons_threshold
))
2959 Fgarbage_collect ();
2961 if (++lisp_eval_depth
> max_lisp_eval_depth
)
2963 if (max_lisp_eval_depth
< 100)
2964 max_lisp_eval_depth
= 100;
2965 if (lisp_eval_depth
> max_lisp_eval_depth
)
2966 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2969 backtrace
.next
= backtrace_list
;
2970 backtrace_list
= &backtrace
;
2971 backtrace
.function
= &args
[0];
2972 backtrace
.args
= &args
[1];
2973 backtrace
.nargs
= nargs
- 1;
2974 backtrace
.evalargs
= 0;
2975 backtrace
.debug_on_exit
= 0;
2977 if (debug_on_next_call
)
2978 do_debug_on_call (Qlambda
);
2982 original_fun
= args
[0];
2986 /* Optimize for no indirection. */
2988 if (SYMBOLP (fun
) && !EQ (fun
, Qunbound
)
2989 && (fun
= XSYMBOL (fun
)->function
, SYMBOLP (fun
)))
2990 fun
= indirect_function (fun
);
2994 if (numargs
< XSUBR (fun
)->min_args
2995 || (XSUBR (fun
)->max_args
>= 0 && XSUBR (fun
)->max_args
< numargs
))
2997 XSETFASTINT (lisp_numargs
, numargs
);
2998 xsignal2 (Qwrong_number_of_arguments
, original_fun
, lisp_numargs
);
3001 if (XSUBR (fun
)->max_args
== UNEVALLED
)
3002 xsignal1 (Qinvalid_function
, original_fun
);
3004 if (XSUBR (fun
)->max_args
== MANY
)
3006 val
= (*XSUBR (fun
)->function
) (numargs
, args
+ 1);
3010 if (XSUBR (fun
)->max_args
> numargs
)
3012 internal_args
= (Lisp_Object
*) alloca (XSUBR (fun
)->max_args
* sizeof (Lisp_Object
));
3013 bcopy (args
+ 1, internal_args
, numargs
* sizeof (Lisp_Object
));
3014 for (i
= numargs
; i
< XSUBR (fun
)->max_args
; i
++)
3015 internal_args
[i
] = Qnil
;
3018 internal_args
= args
+ 1;
3019 switch (XSUBR (fun
)->max_args
)
3022 val
= (*XSUBR (fun
)->function
) ();
3025 val
= (*XSUBR (fun
)->function
) (internal_args
[0]);
3028 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1]);
3031 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3035 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3036 internal_args
[2], internal_args
[3]);
3039 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3040 internal_args
[2], internal_args
[3],
3044 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3045 internal_args
[2], internal_args
[3],
3046 internal_args
[4], internal_args
[5]);
3049 val
= (*XSUBR (fun
)->function
) (internal_args
[0], internal_args
[1],
3050 internal_args
[2], internal_args
[3],
3051 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],
3059 internal_args
[6], internal_args
[7]);
3064 /* If a subr takes more than 8 arguments without using MANY
3065 or UNEVALLED, we need to extend this function to support it.
3066 Until this is done, there is no way to call the function. */
3070 if (COMPILEDP (fun
))
3071 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3074 if (EQ (fun
, Qunbound
))
3075 xsignal1 (Qvoid_function
, original_fun
);
3077 xsignal1 (Qinvalid_function
, original_fun
);
3078 funcar
= XCAR (fun
);
3079 if (!SYMBOLP (funcar
))
3080 xsignal1 (Qinvalid_function
, original_fun
);
3081 if (EQ (funcar
, Qlambda
))
3082 val
= funcall_lambda (fun
, numargs
, args
+ 1);
3083 else if (EQ (funcar
, Qautoload
))
3085 do_autoload (fun
, original_fun
);
3090 xsignal1 (Qinvalid_function
, original_fun
);
3095 if (backtrace
.debug_on_exit
)
3096 val
= call_debugger (Fcons (Qexit
, Fcons (val
, Qnil
)));
3097 backtrace_list
= backtrace
.next
;
3102 apply_lambda (fun
, args
, eval_flag
)
3103 Lisp_Object fun
, args
;
3106 Lisp_Object args_left
;
3107 Lisp_Object numargs
;
3108 register Lisp_Object
*arg_vector
;
3109 struct gcpro gcpro1
, gcpro2
, gcpro3
;
3111 register Lisp_Object tem
;
3113 numargs
= Flength (args
);
3114 arg_vector
= (Lisp_Object
*) alloca (XINT (numargs
) * sizeof (Lisp_Object
));
3117 GCPRO3 (*arg_vector
, args_left
, fun
);
3120 for (i
= 0; i
< XINT (numargs
);)
3122 tem
= Fcar (args_left
), args_left
= Fcdr (args_left
);
3123 if (eval_flag
) tem
= Feval (tem
);
3124 arg_vector
[i
++] = tem
;
3132 backtrace_list
->args
= arg_vector
;
3133 backtrace_list
->nargs
= i
;
3135 backtrace_list
->evalargs
= 0;
3136 tem
= funcall_lambda (fun
, XINT (numargs
), arg_vector
);
3138 /* Do the debug-on-exit now, while arg_vector still exists. */
3139 if (backtrace_list
->debug_on_exit
)
3140 tem
= call_debugger (Fcons (Qexit
, Fcons (tem
, Qnil
)));
3141 /* Don't do it again when we return to eval. */
3142 backtrace_list
->debug_on_exit
= 0;
3146 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3147 and return the result of evaluation.
3148 FUN must be either a lambda-expression or a compiled-code object. */
3151 funcall_lambda (fun
, nargs
, arg_vector
)
3154 register Lisp_Object
*arg_vector
;
3156 Lisp_Object val
, syms_left
, next
;
3157 int count
= SPECPDL_INDEX ();
3158 int i
, optional
, rest
;
3162 syms_left
= XCDR (fun
);
3163 if (CONSP (syms_left
))
3164 syms_left
= XCAR (syms_left
);
3166 xsignal1 (Qinvalid_function
, fun
);
3168 else if (COMPILEDP (fun
))
3169 syms_left
= AREF (fun
, COMPILED_ARGLIST
);
3173 i
= optional
= rest
= 0;
3174 for (; CONSP (syms_left
); syms_left
= XCDR (syms_left
))
3178 next
= XCAR (syms_left
);
3179 if (!SYMBOLP (next
))
3180 xsignal1 (Qinvalid_function
, fun
);
3182 if (EQ (next
, Qand_rest
))
3184 else if (EQ (next
, Qand_optional
))
3188 specbind (next
, Flist (nargs
- i
, &arg_vector
[i
]));
3192 specbind (next
, arg_vector
[i
++]);
3194 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3196 specbind (next
, Qnil
);
3199 if (!NILP (syms_left
))
3200 xsignal1 (Qinvalid_function
, fun
);
3202 xsignal2 (Qwrong_number_of_arguments
, fun
, make_number (nargs
));
3205 val
= Fprogn (XCDR (XCDR (fun
)));
3208 /* If we have not actually read the bytecode string
3209 and constants vector yet, fetch them from the file. */
3210 if (CONSP (AREF (fun
, COMPILED_BYTECODE
)))
3211 Ffetch_bytecode (fun
);
3212 val
= Fbyte_code (AREF (fun
, COMPILED_BYTECODE
),
3213 AREF (fun
, COMPILED_CONSTANTS
),
3214 AREF (fun
, COMPILED_STACK_DEPTH
));
3217 return unbind_to (count
, val
);
3220 DEFUN ("fetch-bytecode", Ffetch_bytecode
, Sfetch_bytecode
,
3222 doc
: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
3228 if (COMPILEDP (object
) && CONSP (AREF (object
, COMPILED_BYTECODE
)))
3230 tem
= read_doc_string (AREF (object
, COMPILED_BYTECODE
));
3233 tem
= AREF (object
, COMPILED_BYTECODE
);
3234 if (CONSP (tem
) && STRINGP (XCAR (tem
)))
3235 error ("Invalid byte code in %s", SDATA (XCAR (tem
)));
3237 error ("Invalid byte code");
3239 ASET (object
, COMPILED_BYTECODE
, XCAR (tem
));
3240 ASET (object
, COMPILED_CONSTANTS
, XCDR (tem
));
3248 register int count
= SPECPDL_INDEX ();
3249 if (specpdl_size
>= max_specpdl_size
)
3251 if (max_specpdl_size
< 400)
3252 max_specpdl_size
= 400;
3253 if (specpdl_size
>= max_specpdl_size
)
3254 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil
);
3257 if (specpdl_size
> max_specpdl_size
)
3258 specpdl_size
= max_specpdl_size
;
3259 specpdl
= (struct specbinding
*) xrealloc (specpdl
, specpdl_size
* sizeof (struct specbinding
));
3260 specpdl_ptr
= specpdl
+ count
;
3264 specbind (symbol
, value
)
3265 Lisp_Object symbol
, value
;
3267 Lisp_Object valcontents
;
3269 CHECK_SYMBOL (symbol
);
3270 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3273 /* The most common case is that of a non-constant symbol with a
3274 trivial value. Make that as fast as we can. */
3275 valcontents
= SYMBOL_VALUE (symbol
);
3276 if (!MISCP (valcontents
) && !SYMBOL_CONSTANT_P (symbol
))
3278 specpdl_ptr
->symbol
= symbol
;
3279 specpdl_ptr
->old_value
= valcontents
;
3280 specpdl_ptr
->func
= NULL
;
3282 SET_SYMBOL_VALUE (symbol
, value
);
3286 Lisp_Object ovalue
= find_symbol_value (symbol
);
3287 specpdl_ptr
->func
= 0;
3288 specpdl_ptr
->old_value
= ovalue
;
3290 valcontents
= XSYMBOL (symbol
)->value
;
3292 if (BUFFER_LOCAL_VALUEP (valcontents
)
3293 || BUFFER_OBJFWDP (valcontents
))
3295 Lisp_Object where
, current_buffer
;
3297 current_buffer
= Fcurrent_buffer ();
3299 /* For a local variable, record both the symbol and which
3300 buffer's or frame's value we are saving. */
3301 if (!NILP (Flocal_variable_p (symbol
, Qnil
)))
3302 where
= current_buffer
;
3303 else if (BUFFER_LOCAL_VALUEP (valcontents
)
3304 && XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
3305 where
= XBUFFER_LOCAL_VALUE (valcontents
)->frame
;
3309 /* We're not using the `unused' slot in the specbinding
3310 structure because this would mean we have to do more
3311 work for simple variables. */
3312 specpdl_ptr
->symbol
= Fcons (symbol
, Fcons (where
, current_buffer
));
3314 /* If SYMBOL is a per-buffer variable which doesn't have a
3315 buffer-local value here, make the `let' change the global
3316 value by changing the value of SYMBOL in all buffers not
3317 having their own value. This is consistent with what
3318 happens with other buffer-local variables. */
3320 && BUFFER_OBJFWDP (valcontents
))
3323 Fset_default (symbol
, value
);
3328 specpdl_ptr
->symbol
= symbol
;
3332 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
3333 store_symval_forwarding (symbol, ovalue, value, NULL);
3335 but ovalue comes from find_symbol_value which should never return
3336 such an internal value. */
3337 eassert (!(BUFFER_OBJFWDP (ovalue
) || KBOARD_OBJFWDP (ovalue
)));
3338 set_internal (symbol
, value
, 0, 1);
3343 record_unwind_protect (function
, arg
)
3344 Lisp_Object (*function
) P_ ((Lisp_Object
));
3347 eassert (!handling_signal
);
3349 if (specpdl_ptr
== specpdl
+ specpdl_size
)
3351 specpdl_ptr
->func
= function
;
3352 specpdl_ptr
->symbol
= Qnil
;
3353 specpdl_ptr
->old_value
= arg
;
3358 unbind_to (count
, value
)
3362 Lisp_Object quitf
= Vquit_flag
;
3363 struct gcpro gcpro1
, gcpro2
;
3365 GCPRO2 (value
, quitf
);
3368 while (specpdl_ptr
!= specpdl
+ count
)
3370 /* Copy the binding, and decrement specpdl_ptr, before we do
3371 the work to unbind it. We decrement first
3372 so that an error in unbinding won't try to unbind
3373 the same entry again, and we copy the binding first
3374 in case more bindings are made during some of the code we run. */
3376 struct specbinding this_binding
;
3377 this_binding
= *--specpdl_ptr
;
3379 if (this_binding
.func
!= 0)
3380 (*this_binding
.func
) (this_binding
.old_value
);
3381 /* If the symbol is a list, it is really (SYMBOL WHERE
3382 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3383 frame. If WHERE is a buffer or frame, this indicates we
3384 bound a variable that had a buffer-local or frame-local
3385 binding. WHERE nil means that the variable had the default
3386 value when it was bound. CURRENT-BUFFER is the buffer that
3387 was current when the variable was bound. */
3388 else if (CONSP (this_binding
.symbol
))
3390 Lisp_Object symbol
, where
;
3392 symbol
= XCAR (this_binding
.symbol
);
3393 where
= XCAR (XCDR (this_binding
.symbol
));
3396 Fset_default (symbol
, this_binding
.old_value
);
3397 else if (BUFFERP (where
))
3398 set_internal (symbol
, this_binding
.old_value
, XBUFFER (where
), 1);
3400 set_internal (symbol
, this_binding
.old_value
, NULL
, 1);
3404 /* If variable has a trivial value (no forwarding), we can
3405 just set it. No need to check for constant symbols here,
3406 since that was already done by specbind. */
3407 if (!MISCP (SYMBOL_VALUE (this_binding
.symbol
)))
3408 SET_SYMBOL_VALUE (this_binding
.symbol
, this_binding
.old_value
);
3410 set_internal (this_binding
.symbol
, this_binding
.old_value
, 0, 1);
3414 if (NILP (Vquit_flag
) && !NILP (quitf
))
3421 DEFUN ("backtrace-debug", Fbacktrace_debug
, Sbacktrace_debug
, 2, 2, 0,
3422 doc
: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3423 The debugger is entered when that frame exits, if the flag is non-nil. */)
3425 Lisp_Object level
, flag
;
3427 register struct backtrace
*backlist
= backtrace_list
;
3430 CHECK_NUMBER (level
);
3432 for (i
= 0; backlist
&& i
< XINT (level
); i
++)
3434 backlist
= backlist
->next
;
3438 backlist
->debug_on_exit
= !NILP (flag
);
3443 DEFUN ("backtrace", Fbacktrace
, Sbacktrace
, 0, 0, "",
3444 doc
: /* Print a trace of Lisp function calls currently active.
3445 Output stream used is value of `standard-output'. */)
3448 register struct backtrace
*backlist
= backtrace_list
;
3452 extern Lisp_Object Vprint_level
;
3453 struct gcpro gcpro1
;
3455 XSETFASTINT (Vprint_level
, 3);
3462 write_string (backlist
->debug_on_exit
? "* " : " ", 2);
3463 if (backlist
->nargs
== UNEVALLED
)
3465 Fprin1 (Fcons (*backlist
->function
, *backlist
->args
), Qnil
);
3466 write_string ("\n", -1);
3470 tem
= *backlist
->function
;
3471 Fprin1 (tem
, Qnil
); /* This can QUIT */
3472 write_string ("(", -1);
3473 if (backlist
->nargs
== MANY
)
3475 for (tail
= *backlist
->args
, i
= 0;
3477 tail
= Fcdr (tail
), i
++)
3479 if (i
) write_string (" ", -1);
3480 Fprin1 (Fcar (tail
), Qnil
);
3485 for (i
= 0; i
< backlist
->nargs
; i
++)
3487 if (i
) write_string (" ", -1);
3488 Fprin1 (backlist
->args
[i
], Qnil
);
3491 write_string (")\n", -1);
3493 backlist
= backlist
->next
;
3496 Vprint_level
= Qnil
;
3501 DEFUN ("backtrace-frame", Fbacktrace_frame
, Sbacktrace_frame
, 1, 1, NULL
,
3502 doc
: /* Return the function and arguments NFRAMES up from current execution point.
3503 If that frame has not evaluated the arguments yet (or is a special form),
3504 the value is (nil FUNCTION ARG-FORMS...).
3505 If that frame has evaluated its arguments and called its function already,
3506 the value is (t FUNCTION ARG-VALUES...).
3507 A &rest arg is represented as the tail of the list ARG-VALUES.
3508 FUNCTION is whatever was supplied as car of evaluated list,
3509 or a lambda expression for macro calls.
3510 If NFRAMES is more than the number of frames, the value is nil. */)
3512 Lisp_Object nframes
;
3514 register struct backtrace
*backlist
= backtrace_list
;
3518 CHECK_NATNUM (nframes
);
3520 /* Find the frame requested. */
3521 for (i
= 0; backlist
&& i
< XFASTINT (nframes
); i
++)
3522 backlist
= backlist
->next
;
3526 if (backlist
->nargs
== UNEVALLED
)
3527 return Fcons (Qnil
, Fcons (*backlist
->function
, *backlist
->args
));
3530 if (backlist
->nargs
== MANY
)
3531 tem
= *backlist
->args
;
3533 tem
= Flist (backlist
->nargs
, backlist
->args
);
3535 return Fcons (Qt
, Fcons (*backlist
->function
, tem
));
3543 register struct backtrace
*backlist
;
3546 for (backlist
= backtrace_list
; backlist
; backlist
= backlist
->next
)
3548 mark_object (*backlist
->function
);
3550 if (backlist
->nargs
== UNEVALLED
|| backlist
->nargs
== MANY
)
3553 i
= backlist
->nargs
- 1;
3555 mark_object (backlist
->args
[i
]);
3562 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size
,
3563 doc
: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
3564 If Lisp code tries to increase the total number past this amount,
3565 an error is signaled.
3566 You can safely use a value considerably larger than the default value,
3567 if that proves inconveniently small. However, if you increase it too far,
3568 Emacs could run out of memory trying to make the stack bigger. */);
3570 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth
,
3571 doc
: /* *Limit on depth in `eval', `apply' and `funcall' before error.
3573 This limit serves to catch infinite recursions for you before they cause
3574 actual stack overflow in C, which would be fatal for Emacs.
3575 You can safely make it considerably larger than its default value,
3576 if that proves inconveniently small. However, if you increase it too far,
3577 Emacs could overflow the real C stack, and crash. */);
3579 DEFVAR_LISP ("quit-flag", &Vquit_flag
,
3580 doc
: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
3581 If the value is t, that means do an ordinary quit.
3582 If the value equals `throw-on-input', that means quit by throwing
3583 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3584 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3585 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
3588 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit
,
3589 doc
: /* Non-nil inhibits C-g quitting from happening immediately.
3590 Note that `quit-flag' will still be set by typing C-g,
3591 so a quit will be signaled as soon as `inhibit-quit' is nil.
3592 To prevent this happening, set `quit-flag' to nil
3593 before making `inhibit-quit' nil. */);
3594 Vinhibit_quit
= Qnil
;
3596 Qinhibit_quit
= intern ("inhibit-quit");
3597 staticpro (&Qinhibit_quit
);
3599 Qautoload
= intern ("autoload");
3600 staticpro (&Qautoload
);
3602 Qdebug_on_error
= intern ("debug-on-error");
3603 staticpro (&Qdebug_on_error
);
3605 Qmacro
= intern ("macro");
3606 staticpro (&Qmacro
);
3608 Qdeclare
= intern ("declare");
3609 staticpro (&Qdeclare
);
3611 /* Note that the process handling also uses Qexit, but we don't want
3612 to staticpro it twice, so we just do it here. */
3613 Qexit
= intern ("exit");
3616 Qinteractive
= intern ("interactive");
3617 staticpro (&Qinteractive
);
3619 Qcommandp
= intern ("commandp");
3620 staticpro (&Qcommandp
);
3622 Qdefun
= intern ("defun");
3623 staticpro (&Qdefun
);
3625 Qand_rest
= intern ("&rest");
3626 staticpro (&Qand_rest
);
3628 Qand_optional
= intern ("&optional");
3629 staticpro (&Qand_optional
);
3631 Qdebug
= intern ("debug");
3632 staticpro (&Qdebug
);
3634 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error
,
3635 doc
: /* *Non-nil means errors display a backtrace buffer.
3636 More precisely, this happens for any error that is handled
3637 by the editor command loop.
3638 If the value is a list, an error only means to display a backtrace
3639 if one of its condition symbols appears in the list. */);
3640 Vstack_trace_on_error
= Qnil
;
3642 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error
,
3643 doc
: /* *Non-nil means enter debugger if an error is signaled.
3644 Does not apply to errors handled by `condition-case' or those
3645 matched by `debug-ignored-errors'.
3646 If the value is a list, an error only means to enter the debugger
3647 if one of its condition symbols appears in the list.
3648 When you evaluate an expression interactively, this variable
3649 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
3650 See also variable `debug-on-quit'. */);
3651 Vdebug_on_error
= Qnil
;
3653 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors
,
3654 doc
: /* *List of errors for which the debugger should not be called.
3655 Each element may be a condition-name or a regexp that matches error messages.
3656 If any element applies to a given error, that error skips the debugger
3657 and just returns to top level.
3658 This overrides the variable `debug-on-error'.
3659 It does not apply to errors handled by `condition-case'. */);
3660 Vdebug_ignored_errors
= Qnil
;
3662 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit
,
3663 doc
: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3664 Does not apply if quit is handled by a `condition-case'. */);
3667 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call
,
3668 doc
: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
3670 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue
,
3671 doc
: /* Non-nil means debugger may continue execution.
3672 This is nil when the debugger is called under circumstances where it
3673 might not be safe to continue. */);
3674 debugger_may_continue
= 1;
3676 DEFVAR_LISP ("debugger", &Vdebugger
,
3677 doc
: /* Function to call to invoke debugger.
3678 If due to frame exit, args are `exit' and the value being returned;
3679 this function's value will be returned instead of that.
3680 If due to error, args are `error' and a list of the args to `signal'.
3681 If due to `apply' or `funcall' entry, one arg, `lambda'.
3682 If due to `eval' entry, one arg, t. */);
3685 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function
,
3686 doc
: /* If non-nil, this is a function for `signal' to call.
3687 It receives the same arguments that `signal' was given.
3688 The Edebug package uses this to regain control. */);
3689 Vsignal_hook_function
= Qnil
;
3691 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal
,
3692 doc
: /* *Non-nil means call the debugger regardless of condition handlers.
3693 Note that `debug-on-error', `debug-on-quit' and friends
3694 still determine whether to handle the particular condition. */);
3695 Vdebug_on_signal
= Qnil
;
3697 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function
,
3698 doc
: /* Function to process declarations in a macro definition.
3699 The function will be called with two args MACRO and DECL.
3700 MACRO is the name of the macro being defined.
3701 DECL is a list `(declare ...)' containing the declarations.
3702 The value the function returns is not used. */);
3703 Vmacro_declaration_function
= Qnil
;
3705 Vrun_hooks
= intern ("run-hooks");
3706 staticpro (&Vrun_hooks
);
3708 staticpro (&Vautoload_queue
);
3709 Vautoload_queue
= Qnil
;
3710 staticpro (&Vsignaling_function
);
3711 Vsignaling_function
= Qnil
;
3722 defsubr (&Sfunction
);
3724 defsubr (&Sdefmacro
);
3726 defsubr (&Sdefvaralias
);
3727 defsubr (&Sdefconst
);
3728 defsubr (&Suser_variable_p
);
3732 defsubr (&Smacroexpand
);
3735 defsubr (&Sunwind_protect
);
3736 defsubr (&Scondition_case
);
3738 defsubr (&Sinteractive_p
);
3739 defsubr (&Scalled_interactively_p
);
3740 defsubr (&Scommandp
);
3741 defsubr (&Sautoload
);
3744 defsubr (&Sfuncall
);
3745 defsubr (&Srun_hooks
);
3746 defsubr (&Srun_hook_with_args
);
3747 defsubr (&Srun_hook_with_args_until_success
);
3748 defsubr (&Srun_hook_with_args_until_failure
);
3749 defsubr (&Sfetch_bytecode
);
3750 defsubr (&Sbacktrace_debug
);
3751 defsubr (&Sbacktrace
);
3752 defsubr (&Sbacktrace_frame
);
3755 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
3756 (do not change this comment) */