* src/eval.c (Fsignal): Handle `debug' symbol in error handler.
[bpt/emacs.git] / src / eval.c
CommitLineData
db9f0278 1/* Evaluator for GNU Emacs Lisp interpreter.
73b0cd50 2 Copyright (C) 1985-1987, 1993-1995, 1999-2011 Free Software Foundation, Inc.
db9f0278
JB
3
4This file is part of GNU Emacs.
5
9ec0b715 6GNU Emacs is free software: you can redistribute it and/or modify
db9f0278 7it under the terms of the GNU General Public License as published by
9ec0b715
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
db9f0278
JB
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
9ec0b715 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
db9f0278
JB
18
19
18160b98 20#include <config.h>
eb3f1cc8 21#include <limits.h>
d7306fe6 22#include <setjmp.h>
4e2fe2e6 23#include <stdio.h>
db9f0278 24#include "lisp.h"
9ac0d9e0 25#include "blockinput.h"
db9f0278 26#include "commands.h"
1f98fa48 27#include "keyboard.h"
3648c842 28#include "dispextern.h"
94b612ad 29#include "frame.h" /* For XFRAME. */
db9f0278 30
b70e1a2b
SM
31#if HAVE_X_WINDOWS
32#include "xterm.h"
33#endif
34
db9f0278 35struct backtrace
4c576a83
GM
36{
37 struct backtrace *next;
38 Lisp_Object *function;
f6d62986 39 Lisp_Object *args; /* Points to vector of args. */
bbc6b304 40 ptrdiff_t nargs; /* Length of vector. */
f6d62986 41 /* Nonzero means call value of debugger when done with this operation. */
bbc6b304 42 unsigned int debug_on_exit : 1;
4c576a83 43};
db9f0278 44
57a96f5c 45static struct backtrace *backtrace_list;
244ed907
PE
46
47#if !BYTE_MARK_STACK
48static
49#endif
db9f0278
JB
50struct catchtag *catchlist;
51
244ed907
PE
52/* Chain of condition handlers currently in effect.
53 The elements of this chain are contained in the stack frames
54 of Fcondition_case and internal_condition_case.
55 When an error is signaled (by calling Fsignal, below),
56 this chain is searched for an element that applies. */
57
58#if !BYTE_MARK_STACK
59static
60#endif
61struct handler *handlerlist;
62
15934ffa
RS
63#ifdef DEBUG_GCPRO
64/* Count levels of GCPRO to detect failure to UNGCPRO. */
65int gcpro_level;
66#endif
67
6fd797f5 68Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
29208e82 69Lisp_Object Qinhibit_quit;
955cbe7b
PE
70Lisp_Object Qand_rest;
71static Lisp_Object Qand_optional;
72static Lisp_Object Qdebug_on_error;
73static Lisp_Object Qdeclare;
b9598260
SM
74Lisp_Object Qinternal_interpreter_environment, Qclosure;
75
ed008a6d 76static Lisp_Object Qdebug;
db9f0278 77
6e6e9f08
RS
78/* This holds either the symbol `run-hooks' or nil.
79 It is nil at an early stage of startup, and when Emacs
80 is shutting down. */
4c576a83 81
db9f0278
JB
82Lisp_Object Vrun_hooks;
83
84/* Non-nil means record all fset's and provide's, to be undone
85 if the file being autoloaded is not fully loaded.
86 They are recorded by being consed onto the front of Vautoload_queue:
47b82df9 87 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */
db9f0278
JB
88
89Lisp_Object Vautoload_queue;
90
91/* Current number of specbindings allocated in specpdl. */
4c576a83 92
5816888b 93EMACS_INT specpdl_size;
db9f0278
JB
94
95/* Pointer to beginning of specpdl. */
4c576a83 96
db9f0278
JB
97struct specbinding *specpdl;
98
99/* Pointer to first unused element in specpdl. */
4c576a83 100
ab837828 101struct specbinding *specpdl_ptr;
db9f0278 102
db9f0278 103/* Depth in Lisp evaluations and function calls. */
4c576a83 104
57a96f5c 105static EMACS_INT lisp_eval_depth;
db9f0278 106
be857679 107/* The value of num_nonmacro_input_events as of the last time we
82da7701 108 started to enter the debugger. If we decide to enter the debugger
be857679 109 again when this is still equal to num_nonmacro_input_events, then we
82da7701
JB
110 know that the debugger itself has an error, and we should just
111 signal the error instead of entering an infinite loop of debugger
112 invocations. */
4c576a83 113
57a96f5c 114static int when_entered_debugger;
db9f0278 115
a2ff3819
GM
116/* The function from which the last `signal' was called. Set in
117 Fsignal. */
118
119Lisp_Object Vsignaling_function;
120
4c576a83
GM
121/* Set to non-zero while processing X events. Checked in Feval to
122 make sure the Lisp interpreter isn't called from a signal handler,
123 which is unsafe because the interpreter isn't reentrant. */
124
125int handling_signal;
126
f66c7cf8 127static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
f57e2426 128static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN;
2f7c71a1 129static int interactive_p (int);
7200d79c 130static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
cd64ea1d 131static Lisp_Object Ffetch_bytecode (Lisp_Object);
873759d5 132\f
dfcf069d 133void
d3da34e0 134init_eval_once (void)
db9f0278
JB
135{
136 specpdl_size = 50;
716acfce 137 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
270e8074 138 specpdl_ptr = specpdl;
6588243d 139 /* Don't forget to update docs (lispref node "Local Variables"). */
c530e1c2 140 max_specpdl_size = 1300; /* 1000 is not enough for CEDET's c-by.el. */
d46f6bbb 141 max_lisp_eval_depth = 600;
34d470ba
RS
142
143 Vrun_hooks = Qnil;
db9f0278
JB
144}
145
dfcf069d 146void
d3da34e0 147init_eval (void)
db9f0278
JB
148{
149 specpdl_ptr = specpdl;
150 catchlist = 0;
151 handlerlist = 0;
152 backtrace_list = 0;
153 Vquit_flag = Qnil;
154 debug_on_next_call = 0;
155 lisp_eval_depth = 0;
87e21fbd 156#ifdef DEBUG_GCPRO
15934ffa 157 gcpro_level = 0;
87e21fbd 158#endif
be857679 159 /* This is less than the initial value of num_nonmacro_input_events. */
b5b911f9 160 when_entered_debugger = -1;
db9f0278
JB
161}
162
f6d62986 163/* Unwind-protect function used by call_debugger. */
9f5903bb
RS
164
165static Lisp_Object
d3da34e0 166restore_stack_limits (Lisp_Object data)
9f5903bb
RS
167{
168 max_specpdl_size = XINT (XCAR (data));
169 max_lisp_eval_depth = XINT (XCDR (data));
538f78c3 170 return Qnil;
9f5903bb
RS
171}
172
173/* Call the Lisp debugger, giving it argument ARG. */
174
475545b5 175static Lisp_Object
d3da34e0 176call_debugger (Lisp_Object arg)
db9f0278 177{
3648c842 178 int debug_while_redisplaying;
aed13378 179 int count = SPECPDL_INDEX ();
3648c842 180 Lisp_Object val;
5816888b 181 EMACS_INT old_max = max_specpdl_size;
177c0ea7 182
9f5903bb
RS
183 /* Temporarily bump up the stack limits,
184 so the debugger won't run out of stack. */
177c0ea7 185
9f5903bb
RS
186 max_specpdl_size += 1;
187 record_unwind_protect (restore_stack_limits,
188 Fcons (make_number (old_max),
189 make_number (max_lisp_eval_depth)));
190 max_specpdl_size = old_max;
191
192 if (lisp_eval_depth + 40 > max_lisp_eval_depth)
193 max_lisp_eval_depth = lisp_eval_depth + 40;
194
195 if (SPECPDL_INDEX () + 100 > max_specpdl_size)
196 max_specpdl_size = SPECPDL_INDEX () + 100;
177c0ea7 197
d148e14d 198#ifdef HAVE_WINDOW_SYSTEM
df6c90d8
GM
199 if (display_hourglass_p)
200 cancel_hourglass ();
237c23b0
GM
201#endif
202
db9f0278 203 debug_on_next_call = 0;
be857679 204 when_entered_debugger = num_nonmacro_input_events;
3648c842
GM
205
206 /* Resetting redisplaying_p to 0 makes sure that debug output is
207 displayed if the debugger is invoked during redisplay. */
208 debug_while_redisplaying = redisplaying_p;
209 redisplaying_p = 0;
556d7314
GM
210 specbind (intern ("debugger-may-continue"),
211 debug_while_redisplaying ? Qnil : Qt);
8efb6cc7 212 specbind (Qinhibit_redisplay, Qnil);
9f5903bb 213 specbind (Qdebug_on_error, Qnil);
9db6f6b4
GM
214
215#if 0 /* Binding this prevents execution of Lisp code during
216 redisplay, which necessarily leads to display problems. */
8efb6cc7 217 specbind (Qinhibit_eval_during_redisplay, Qt);
9db6f6b4 218#endif
177c0ea7 219
3648c842
GM
220 val = apply1 (Vdebugger, arg);
221
222 /* Interrupting redisplay and resuming it later is not safe under
223 all circumstances. So, when the debugger returns, abort the
1b1acc13 224 interrupted redisplay by going back to the top-level. */
3648c842
GM
225 if (debug_while_redisplaying)
226 Ftop_level ();
227
556d7314 228 return unbind_to (count, val);
db9f0278
JB
229}
230
475545b5 231static void
d3da34e0 232do_debug_on_call (Lisp_Object code)
db9f0278
JB
233{
234 debug_on_next_call = 0;
235 backtrace_list->debug_on_exit = 1;
236 call_debugger (Fcons (code, Qnil));
237}
238\f
239/* NOTE!!! Every function that can call EVAL must protect its args
240 and temporaries from garbage collection while it needs them.
241 The definition of `For' shows what you have to do. */
242
243DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
9dbc9081
PJ
244 doc: /* Eval args until one of them yields non-nil, then return that value.
245The remaining args are not evalled at all.
246If all args return nil, return nil.
533eb34b 247usage: (or CONDITIONS...) */)
5842a27b 248 (Lisp_Object args)
db9f0278 249{
e509f168 250 register Lisp_Object val = Qnil;
db9f0278
JB
251 struct gcpro gcpro1;
252
e509f168 253 GCPRO1 (args);
db9f0278 254
e509f168 255 while (CONSP (args))
db9f0278 256 {
defb1411 257 val = eval_sub (XCAR (args));
265a9e55 258 if (!NILP (val))
db9f0278 259 break;
e509f168 260 args = XCDR (args);
db9f0278 261 }
db9f0278
JB
262
263 UNGCPRO;
264 return val;
265}
266
267DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
b8de5714 268 doc: /* Eval args until one of them yields nil, then return nil.
9dbc9081
PJ
269The remaining args are not evalled at all.
270If no arg yields nil, return the last arg's value.
533eb34b 271usage: (and CONDITIONS...) */)
5842a27b 272 (Lisp_Object args)
db9f0278 273{
e509f168 274 register Lisp_Object val = Qt;
db9f0278
JB
275 struct gcpro gcpro1;
276
e509f168 277 GCPRO1 (args);
db9f0278 278
e509f168 279 while (CONSP (args))
db9f0278 280 {
defb1411 281 val = eval_sub (XCAR (args));
265a9e55 282 if (NILP (val))
db9f0278 283 break;
e509f168 284 args = XCDR (args);
db9f0278 285 }
db9f0278
JB
286
287 UNGCPRO;
288 return val;
289}
290
291DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
b8de5714 292 doc: /* If COND yields non-nil, do THEN, else do ELSE...
9dbc9081
PJ
293Returns the value of THEN or the value of the last of the ELSE's.
294THEN must be one expression, but ELSE... can be zero or more expressions.
295If COND yields nil, and there are no ELSE's, the value is nil.
7a25dc6d 296usage: (if COND THEN ELSE...) */)
5842a27b 297 (Lisp_Object args)
db9f0278
JB
298{
299 register Lisp_Object cond;
300 struct gcpro gcpro1;
301
302 GCPRO1 (args);
defb1411 303 cond = eval_sub (Fcar (args));
db9f0278
JB
304 UNGCPRO;
305
265a9e55 306 if (!NILP (cond))
defb1411 307 return eval_sub (Fcar (Fcdr (args)));
db9f0278
JB
308 return Fprogn (Fcdr (Fcdr (args)));
309}
310
311DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
9dbc9081
PJ
312 doc: /* Try each clause until one succeeds.
313Each clause looks like (CONDITION BODY...). CONDITION is evaluated
314and, if the value is non-nil, this clause succeeds:
315then the expressions in BODY are evaluated and the last one's
316value is the value of the cond-form.
317If no clause succeeds, cond returns nil.
318If a clause has one element, as in (CONDITION),
319CONDITION's value if non-nil is returned from the cond-form.
7a25dc6d 320usage: (cond CLAUSES...) */)
5842a27b 321 (Lisp_Object args)
db9f0278
JB
322{
323 register Lisp_Object clause, val;
324 struct gcpro gcpro1;
325
326 val = Qnil;
327 GCPRO1 (args);
265a9e55 328 while (!NILP (args))
db9f0278
JB
329 {
330 clause = Fcar (args);
defb1411 331 val = eval_sub (Fcar (clause));
265a9e55 332 if (!NILP (val))
db9f0278 333 {
03699b14
KR
334 if (!EQ (XCDR (clause), Qnil))
335 val = Fprogn (XCDR (clause));
db9f0278
JB
336 break;
337 }
03699b14 338 args = XCDR (args);
db9f0278
JB
339 }
340 UNGCPRO;
341
342 return val;
343}
344
a7ca3326 345DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
9dbc9081 346 doc: /* Eval BODY forms sequentially and return value of last one.
5b4a1f50 347usage: (progn BODY...) */)
5842a27b 348 (Lisp_Object args)
db9f0278 349{
e509f168 350 register Lisp_Object val = Qnil;
db9f0278
JB
351 struct gcpro gcpro1;
352
e509f168 353 GCPRO1 (args);
db9f0278 354
e509f168 355 while (CONSP (args))
db9f0278 356 {
defb1411 357 val = eval_sub (XCAR (args));
e509f168 358 args = XCDR (args);
db9f0278 359 }
db9f0278
JB
360
361 UNGCPRO;
362 return val;
363}
364
365DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
bdee2ef3 366 doc: /* Eval FIRST and BODY sequentially; return value from FIRST.
9dbc9081
PJ
367The value of FIRST is saved during the evaluation of the remaining args,
368whose values are discarded.
7a25dc6d 369usage: (prog1 FIRST BODY...) */)
5842a27b 370 (Lisp_Object args)
db9f0278
JB
371{
372 Lisp_Object val;
373 register Lisp_Object args_left;
374 struct gcpro gcpro1, gcpro2;
375 register int argnum = 0;
376
9ac66b45 377 if (NILP (args))
db9f0278
JB
378 return Qnil;
379
380 args_left = args;
381 val = Qnil;
382 GCPRO2 (args, val);
383
384 do
385 {
ba83908c 386 Lisp_Object tem = eval_sub (XCAR (args_left));
db9f0278 387 if (!(argnum++))
ba83908c
SM
388 val = tem;
389 args_left = XCDR (args_left);
db9f0278 390 }
ba83908c 391 while (CONSP (args_left));
db9f0278
JB
392
393 UNGCPRO;
394 return val;
395}
396
397DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
bdee2ef3 398 doc: /* Eval FORM1, FORM2 and BODY sequentially; return value from FORM2.
82fc29a1
JB
399The value of FORM2 is saved during the evaluation of the
400remaining args, whose values are discarded.
401usage: (prog2 FORM1 FORM2 BODY...) */)
5842a27b 402 (Lisp_Object args)
db9f0278
JB
403{
404 Lisp_Object val;
405 register Lisp_Object args_left;
406 struct gcpro gcpro1, gcpro2;
407 register int argnum = -1;
408
409 val = Qnil;
410
87d238ba 411 if (NILP (args))
db9f0278
JB
412 return Qnil;
413
414 args_left = args;
415 val = Qnil;
416 GCPRO2 (args, val);
417
418 do
419 {
ba83908c 420 Lisp_Object tem = eval_sub (XCAR (args_left));
db9f0278 421 if (!(argnum++))
ba83908c
SM
422 val = tem;
423 args_left = XCDR (args_left);
db9f0278 424 }
ba83908c 425 while (CONSP (args_left));
db9f0278
JB
426
427 UNGCPRO;
428 return val;
429}
430
431DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
9dbc9081
PJ
432 doc: /* Set each SYM to the value of its VAL.
433The symbols SYM are variables; they are literal (not evaluated).
434The values VAL are expressions; they are evaluated.
435Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
436The second VAL is not computed until after the first SYM is set, and so on;
437each VAL can use the new value of variables set earlier in the `setq'.
438The return value of the `setq' form is the value of the last VAL.
819586b2 439usage: (setq [SYM VAL]...) */)
5842a27b 440 (Lisp_Object args)
db9f0278
JB
441{
442 register Lisp_Object args_left;
b9598260 443 register Lisp_Object val, sym, lex_binding;
db9f0278
JB
444 struct gcpro gcpro1;
445
1283140e 446 if (NILP (args))
db9f0278
JB
447 return Qnil;
448
449 args_left = args;
450 GCPRO1 (args);
451
452 do
453 {
defb1411 454 val = eval_sub (Fcar (Fcdr (args_left)));
db9f0278 455 sym = Fcar (args_left);
b9598260 456
defb1411 457 /* Like for eval_sub, we do not check declared_special here since
f07a954e
SM
458 it's been done when let-binding. */
459 if (!NILP (Vinternal_interpreter_environment) /* Mere optimization! */
b9598260 460 && SYMBOLP (sym)
f07a954e
SM
461 && !NILP (lex_binding
462 = Fassq (sym, Vinternal_interpreter_environment)))
b9598260
SM
463 XSETCDR (lex_binding, val); /* SYM is lexically bound. */
464 else
465 Fset (sym, val); /* SYM is dynamically bound. */
466
db9f0278
JB
467 args_left = Fcdr (Fcdr (args_left));
468 }
265a9e55 469 while (!NILP(args_left));
db9f0278
JB
470
471 UNGCPRO;
472 return val;
473}
177c0ea7 474
db9f0278 475DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
9dbc9081
PJ
476 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
477usage: (quote ARG) */)
5842a27b 478 (Lisp_Object args)
db9f0278 479{
1283140e
RS
480 if (!NILP (Fcdr (args)))
481 xsignal2 (Qwrong_number_of_arguments, Qquote, Flength (args));
db9f0278
JB
482 return Fcar (args);
483}
177c0ea7 484
db9f0278 485DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
9dbc9081
PJ
486 doc: /* Like `quote', but preferred for objects which are functions.
487In byte compilation, `function' causes its argument to be compiled.
488`quote' cannot do that.
489usage: (function ARG) */)
5842a27b 490 (Lisp_Object args)
db9f0278 491{
b9598260
SM
492 Lisp_Object quoted = XCAR (args);
493
1283140e
RS
494 if (!NILP (Fcdr (args)))
495 xsignal2 (Qwrong_number_of_arguments, Qfunction, Flength (args));
b9598260
SM
496
497 if (!NILP (Vinternal_interpreter_environment)
498 && CONSP (quoted)
499 && EQ (XCAR (quoted), Qlambda))
500 /* This is a lambda expression within a lexical environment;
501 return an interpreted closure instead of a simple lambda. */
23aba0ea
SM
502 return Fcons (Qclosure, Fcons (Vinternal_interpreter_environment,
503 XCDR (quoted)));
b9598260
SM
504 else
505 /* Simply quote the argument. */
506 return quoted;
db9f0278
JB
507}
508
e0f331ab 509
a7ca3326 510DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
84b17ab0 511 doc: /* Return t if the containing function was run directly by user input.
82fc29a1
JB
512This means that the function was called with `call-interactively'
513\(which includes being called as the binding of a key)
84b17ab0 514and input is currently coming from the keyboard (not a keyboard macro),
c63df42b
RS
515and Emacs is not running in batch mode (`noninteractive' is nil).
516
517The only known proper use of `interactive-p' is in deciding whether to
518display a helpful message, or how to display it. If you're thinking
519of using it for any other purpose, it is quite likely that you're
520making a mistake. Think: what do you want to do when the command is
521called from a keyboard macro?
522
84b17ab0
CY
523To test whether your function was called with `call-interactively',
524either (i) add an extra optional argument and give it an `interactive'
525spec that specifies non-nil unconditionally (such as \"p\"); or (ii)
526use `called-interactively-p'. */)
5842a27b 527 (void)
db9f0278 528{
b9598260 529 return interactive_p (1) ? Qt : Qnil;
e0f331ab
GM
530}
531
532
9d28c33e 533DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 1, 0,
84b17ab0 534 doc: /* Return t if the containing function was called by `call-interactively'.
9d28c33e
SM
535If KIND is `interactive', then only return t if the call was made
536interactively by the user, i.e. not in `noninteractive' mode nor
537when `executing-kbd-macro'.
538If KIND is `any', on the other hand, it will return t for any kind of
539interactive call, including being called as the binding of a key, or
540from a keyboard macro, or in `noninteractive' mode.
541
542The only known proper use of `interactive' for KIND is in deciding
543whether to display a helpful message, or how to display it. If you're
544thinking of using it for any other purpose, it is quite likely that
545you're making a mistake. Think: what do you want to do when the
546command is called from a keyboard macro?
84b17ab0
CY
547
548This function is meant for implementing advice and other
549function-modifying features. Instead of using this, it is sometimes
550cleaner to give your function an extra optional argument whose
551`interactive' spec specifies non-nil unconditionally (\"p\" is a good
9d28c33e 552way to do this), or via (not (or executing-kbd-macro noninteractive)). */)
5842a27b 553 (Lisp_Object kind)
c63df42b 554{
9d28c33e
SM
555 return ((INTERACTIVE || !EQ (kind, intern ("interactive")))
556 && interactive_p (1)) ? Qt : Qnil;
c63df42b
RS
557}
558
559
560/* Return 1 if function in which this appears was called using
561 call-interactively.
e0f331ab
GM
562
563 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
564 called is a built-in. */
565
2f7c71a1 566static int
d3da34e0 567interactive_p (int exclude_subrs_p)
e0f331ab
GM
568{
569 struct backtrace *btp;
570 Lisp_Object fun;
db9f0278 571
db9f0278 572 btp = backtrace_list;
daa37602
JB
573
574 /* If this isn't a byte-compiled function, there may be a frame at
e0f331ab 575 the top for Finteractive_p. If so, skip it. */
a7f96a35 576 fun = Findirect_function (*btp->function, Qnil);
0b31741c
RS
577 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
578 || XSUBR (fun) == &Scalled_interactively_p))
db9f0278 579 btp = btp->next;
daa37602
JB
580
581 /* If we're running an Emacs 18-style byte-compiled function, there
4402a9ed
RS
582 may be a frame for Fbytecode at the top level. In any version of
583 Emacs there can be Fbytecode frames for subexpressions evaluated
584 inside catch and condition-case. Skip past them.
daa37602 585
4402a9ed 586 If this isn't a byte-compiled function, then we may now be
daa37602 587 looking at several frames for special forms. Skip past them. */
4402a9ed
RS
588 while (btp
589 && (EQ (*btp->function, Qbytecode)
44f230aa 590 || btp->nargs == UNEVALLED))
a6e3fa71
JB
591 btp = btp->next;
592
f6d62986 593 /* `btp' now points at the frame of the innermost function that isn't
daa37602
JB
594 a special form, ignoring frames for Finteractive_p and/or
595 Fbytecode at the top. If this frame is for a built-in function
596 (such as load or eval-region) return nil. */
a7f96a35 597 fun = Findirect_function (*btp->function, Qnil);
e0f331ab
GM
598 if (exclude_subrs_p && SUBRP (fun))
599 return 0;
177c0ea7 600
f6d62986 601 /* `btp' points to the frame of a Lisp function that called interactive-p.
db9f0278
JB
602 Return t if that function was called interactively. */
603 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
e0f331ab
GM
604 return 1;
605 return 0;
db9f0278
JB
606}
607
e0f331ab 608
db9f0278 609DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
9dbc9081
PJ
610 doc: /* Define NAME as a function.
611The definition is (lambda ARGLIST [DOCSTRING] BODY...).
612See also the function `interactive'.
7a25dc6d 613usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
5842a27b 614 (Lisp_Object args)
db9f0278
JB
615{
616 register Lisp_Object fn_name;
617 register Lisp_Object defn;
618
619 fn_name = Fcar (args);
6992a868 620 CHECK_SYMBOL (fn_name);
db9f0278 621 defn = Fcons (Qlambda, Fcdr (args));
f07a954e
SM
622 if (!NILP (Vinternal_interpreter_environment)) /* Mere optimization! */
623 defn = Ffunction (Fcons (defn, Qnil));
265a9e55 624 if (!NILP (Vpurify_flag))
db9f0278 625 defn = Fpurecopy (defn);
f58e9f8c
RS
626 if (CONSP (XSYMBOL (fn_name)->function)
627 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
628 LOADHIST_ATTACH (Fcons (Qt, fn_name));
db9f0278 629 Ffset (fn_name, defn);
6fd797f5 630 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
db9f0278
JB
631 return fn_name;
632}
633
634DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
9dbc9081 635 doc: /* Define NAME as a macro.
0654d6e3
RS
636The actual definition looks like
637 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
9dbc9081
PJ
638When the macro is called, as in (NAME ARGS...),
639the function (lambda ARGLIST BODY...) is applied to
640the list ARGS... as it appears in the expression,
641and the result should be a form to be evaluated instead of the original.
0654d6e3
RS
642
643DECL is a declaration, optional, which can specify how to indent
4ba50634
JPW
644calls to this macro, how Edebug should handle it, and which argument
645should be treated as documentation. It looks like this:
0654d6e3
RS
646 (declare SPECS...)
647The elements can look like this:
648 (indent INDENT)
649 Set NAME's `lisp-indent-function' property to INDENT.
650
e509f168 651 (debug DEBUG)
0654d6e3 652 Set NAME's `edebug-form-spec' property to DEBUG. (This is
7d5c86e5 653 equivalent to writing a `def-edebug-spec' for the macro.)
4ba50634
JPW
654
655 (doc-string ELT)
656 Set NAME's `doc-string-elt' property to ELT.
657
0654d6e3 658usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
5842a27b 659 (Lisp_Object args)
db9f0278
JB
660{
661 register Lisp_Object fn_name;
662 register Lisp_Object defn;
d6edd563 663 Lisp_Object lambda_list, doc, tail;
db9f0278
JB
664
665 fn_name = Fcar (args);
8e975df9 666 CHECK_SYMBOL (fn_name);
d6edd563
GM
667 lambda_list = Fcar (Fcdr (args));
668 tail = Fcdr (Fcdr (args));
669
670 doc = Qnil;
671 if (STRINGP (Fcar (tail)))
672 {
e509f168
SM
673 doc = XCAR (tail);
674 tail = XCDR (tail);
d6edd563
GM
675 }
676
0193499f
SM
677 if (CONSP (Fcar (tail))
678 && EQ (Fcar (Fcar (tail)), Qdeclare))
d6edd563
GM
679 {
680 if (!NILP (Vmacro_declaration_function))
681 {
682 struct gcpro gcpro1;
683 GCPRO1 (args);
684 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
685 UNGCPRO;
686 }
177c0ea7 687
d6edd563
GM
688 tail = Fcdr (tail);
689 }
690
691 if (NILP (doc))
692 tail = Fcons (lambda_list, tail);
693 else
694 tail = Fcons (lambda_list, Fcons (doc, tail));
7200d79c 695
b9598260 696 defn = Fcons (Qlambda, tail);
f07a954e
SM
697 if (!NILP (Vinternal_interpreter_environment)) /* Mere optimization! */
698 defn = Ffunction (Fcons (defn, Qnil));
b9598260 699 defn = Fcons (Qmacro, defn);
177c0ea7 700
265a9e55 701 if (!NILP (Vpurify_flag))
db9f0278 702 defn = Fpurecopy (defn);
f58e9f8c
RS
703 if (CONSP (XSYMBOL (fn_name)->function)
704 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
705 LOADHIST_ATTACH (Fcons (Qt, fn_name));
db9f0278 706 Ffset (fn_name, defn);
6fd797f5 707 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
db9f0278
JB
708 return fn_name;
709}
710
19cebf5a 711
1848d15d 712DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
4a9308b8 713 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE.
e102f0d8 714Aliased variables always have the same value; setting one sets the other.
4a9308b8 715Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is
dd60787c
GM
716omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE,
717or of the variable at the end of the chain of aliases, if BASE-VARIABLE is
718itself an alias. If NEW-ALIAS is bound, and BASE-VARIABLE is not,
719then the value of BASE-VARIABLE is set to that of NEW-ALIAS.
4a9308b8 720The return value is BASE-VARIABLE. */)
5842a27b 721 (Lisp_Object new_alias, Lisp_Object base_variable, Lisp_Object docstring)
19cebf5a
GM
722{
723 struct Lisp_Symbol *sym;
1848d15d 724
4a9308b8
JB
725 CHECK_SYMBOL (new_alias);
726 CHECK_SYMBOL (base_variable);
19cebf5a 727
4a9308b8 728 sym = XSYMBOL (new_alias);
ce5b453a
SM
729
730 if (sym->constant)
178f2507
SM
731 /* Not sure why, but why not? */
732 error ("Cannot make a constant an alias");
ce5b453a
SM
733
734 switch (sym->redirect)
735 {
736 case SYMBOL_FORWARDED:
737 error ("Cannot make an internal variable an alias");
738 case SYMBOL_LOCALIZED:
739 error ("Don't know how to make a localized variable an alias");
740 }
741
dd60787c 742 /* http://lists.gnu.org/archive/html/emacs-devel/2008-04/msg00834.html
ce5b453a
SM
743 If n_a is bound, but b_v is not, set the value of b_v to n_a,
744 so that old-code that affects n_a before the aliasing is setup
745 still works. */
746 if (NILP (Fboundp (base_variable)))
94b612ad 747 set_internal (base_variable, find_symbol_value (new_alias), Qnil, 1);
ce5b453a
SM
748
749 {
750 struct specbinding *p;
751
752 for (p = specpdl_ptr - 1; p >= specpdl; p--)
753 if (p->func == NULL
754 && (EQ (new_alias,
755 CONSP (p->symbol) ? XCAR (p->symbol) : p->symbol)))
756 error ("Don't know how to make a let-bound variable an alias");
757 }
758
b9598260 759 sym->declared_special = 1;
0ac30604 760 XSYMBOL (base_variable)->declared_special = 1;
ce5b453a
SM
761 sym->redirect = SYMBOL_VARALIAS;
762 SET_SYMBOL_ALIAS (sym, XSYMBOL (base_variable));
4a9308b8
JB
763 sym->constant = SYMBOL_CONSTANT_P (base_variable);
764 LOADHIST_ATTACH (new_alias);
ce5b453a
SM
765 /* Even if docstring is nil: remove old docstring. */
766 Fput (new_alias, Qvariable_documentation, docstring);
1848d15d 767
4a9308b8 768 return base_variable;
19cebf5a
GM
769}
770
771
db9f0278 772DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
29357847 773 doc: /* Define SYMBOL as a variable, and return SYMBOL.
9dbc9081
PJ
774You are not required to define a variable in order to use it,
775but the definition can supply documentation and an initial value
776in a way that tags can recognize.
777
778INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
779If SYMBOL is buffer-local, its default value is what is set;
780 buffer-local values are not affected.
781INITVALUE and DOCSTRING are optional.
782If DOCSTRING starts with *, this variable is identified as a user option.
783 This means that M-x set-variable recognizes it.
784 See also `user-variable-p'.
785If INITVALUE is missing, SYMBOL's value is not set.
733f68b6
LT
786
787If SYMBOL has a local binding, then this form affects the local
788binding. This is usually not what you want. Thus, if you need to
789load a file defining variables, with this form or with `defconst' or
790`defcustom', you should always load that file _outside_ any bindings
791for these variables. \(`defconst' and `defcustom' behave similarly in
792this respect.)
2df5238c 793usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
5842a27b 794 (Lisp_Object args)
db9f0278 795{
a42ba017 796 register Lisp_Object sym, tem, tail;
db9f0278
JB
797
798 sym = Fcar (args);
a42ba017
RS
799 tail = Fcdr (args);
800 if (!NILP (Fcdr (Fcdr (tail))))
921baa95 801 error ("Too many arguments");
a42ba017 802
33568849 803 tem = Fdefault_boundp (sym);
a42ba017 804 if (!NILP (tail))
db9f0278 805 {
ba83908c
SM
806 /* Do it before evaluating the initial value, for self-references. */
807 XSYMBOL (sym)->declared_special = 1;
590130fb 808
1c9916a1
SM
809 if (SYMBOL_CONSTANT_P (sym))
810 {
811 /* For upward compatibility, allow (defvar :foo (quote :foo)). */
1faed8ae
PE
812 Lisp_Object tem1 = Fcar (tail);
813 if (! (CONSP (tem1)
814 && EQ (XCAR (tem1), Qquote)
815 && CONSP (XCDR (tem1))
816 && EQ (XCAR (XCDR (tem1)), sym)))
1c9916a1
SM
817 error ("Constant symbol `%s' specified in defvar",
818 SDATA (SYMBOL_NAME (sym)));
819 }
820
265a9e55 821 if (NILP (tem))
defb1411 822 Fset_default (sym, eval_sub (Fcar (tail)));
d0bce91e
SM
823 else
824 { /* Check if there is really a global binding rather than just a let
825 binding that shadows the global unboundness of the var. */
b28d0d9a 826 volatile struct specbinding *pdl = specpdl_ptr;
d0bce91e
SM
827 while (--pdl >= specpdl)
828 {
829 if (EQ (pdl->symbol, sym) && !pdl->func
830 && EQ (pdl->old_value, Qunbound))
831 {
832 message_with_string ("Warning: defvar ignored because %s is let-bound",
833 SYMBOL_NAME (sym), 1);
834 break;
835 }
836 }
837 }
33568849 838 tail = Fcdr (tail);
e509f168
SM
839 tem = Fcar (tail);
840 if (!NILP (tem))
33568849 841 {
33568849
SM
842 if (!NILP (Vpurify_flag))
843 tem = Fpurecopy (tem);
844 Fput (sym, Qvariable_documentation, tem);
845 }
6fd797f5 846 LOADHIST_ATTACH (sym);
db9f0278 847 }
f07a954e
SM
848 else if (!NILP (Vinternal_interpreter_environment)
849 && !XSYMBOL (sym)->declared_special)
850 /* A simple (defvar foo) with lexical scoping does "nothing" except
851 declare that var to be dynamically scoped *locally* (i.e. within
852 the current file or let-block). */
853 Vinternal_interpreter_environment =
854 Fcons (sym, Vinternal_interpreter_environment);
33568849 855 else
d28a2170
PE
856 {
857 /* Simple (defvar <var>) should not count as a definition at all.
858 It could get in the way of other definitions, and unloading this
859 package could try to make the variable unbound. */
860 }
addf35fd 861
db9f0278
JB
862 return sym;
863}
864
865DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
9dbc9081
PJ
866 doc: /* Define SYMBOL as a constant variable.
867The intent is that neither programs nor users should ever change this value.
868Always sets the value of SYMBOL to the result of evalling INITVALUE.
869If SYMBOL is buffer-local, its default value is what is set;
870 buffer-local values are not affected.
871DOCSTRING is optional.
733f68b6
LT
872
873If SYMBOL has a local binding, then this form sets the local binding's
874value. However, you should normally not make local bindings for
875variables defined with this form.
7a25dc6d 876usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
5842a27b 877 (Lisp_Object args)
db9f0278
JB
878{
879 register Lisp_Object sym, tem;
880
881 sym = Fcar (args);
a42ba017 882 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
921baa95 883 error ("Too many arguments");
a42ba017 884
defb1411 885 tem = eval_sub (Fcar (Fcdr (args)));
1182a7cb
DL
886 if (!NILP (Vpurify_flag))
887 tem = Fpurecopy (tem);
888 Fset_default (sym, tem);
b9598260 889 XSYMBOL (sym)->declared_special = 1;
db9f0278 890 tem = Fcar (Fcdr (Fcdr (args)));
265a9e55 891 if (!NILP (tem))
db9f0278 892 {
265a9e55 893 if (!NILP (Vpurify_flag))
db9f0278
JB
894 tem = Fpurecopy (tem);
895 Fput (sym, Qvariable_documentation, tem);
896 }
873759d5 897 Fput (sym, Qrisky_local_variable, Qt);
6fd797f5 898 LOADHIST_ATTACH (sym);
db9f0278
JB
899 return sym;
900}
901
606cdb89
JB
902/* Error handler used in Fuser_variable_p. */
903static Lisp_Object
d3da34e0 904user_variable_p_eh (Lisp_Object ignore)
606cdb89
JB
905{
906 return Qnil;
907}
908
40a69fac
SM
909static Lisp_Object
910lisp_indirect_variable (Lisp_Object sym)
911{
cfcbfb1a
PE
912 struct Lisp_Symbol *s = indirect_variable (XSYMBOL (sym));
913 XSETSYMBOL (sym, s);
40a69fac
SM
914 return sym;
915}
916
db9f0278 917DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
606cdb89 918 doc: /* Return t if VARIABLE is intended to be set and modified by users.
9dbc9081 919\(The alternative is a variable used internally in a Lisp program.)
606cdb89
JB
920A variable is a user variable if
921\(1) the first character of its documentation is `*', or
922\(2) it is customizable (its property list contains a non-nil value
923 of `standard-value' or `custom-autoload'), or
924\(3) it is an alias for another user variable.
925Return nil if VARIABLE is an alias and there is a loop in the
926chain of symbols. */)
5842a27b 927 (Lisp_Object variable)
db9f0278
JB
928{
929 Lisp_Object documentation;
177c0ea7 930
5e78e475
RS
931 if (!SYMBOLP (variable))
932 return Qnil;
933
606cdb89 934 /* If indirect and there's an alias loop, don't check anything else. */
ce5b453a 935 if (XSYMBOL (variable)->redirect == SYMBOL_VARALIAS
40a69fac 936 && NILP (internal_condition_case_1 (lisp_indirect_variable, variable,
bb8e180f 937 Qt, user_variable_p_eh)))
606cdb89
JB
938 return Qnil;
939
940 while (1)
941 {
942 documentation = Fget (variable, Qvariable_documentation);
943 if (INTEGERP (documentation) && XINT (documentation) < 0)
bb8e180f 944 return Qt;
606cdb89 945 if (STRINGP (documentation)
bb8e180f
AS
946 && ((unsigned char) SREF (documentation, 0) == '*'))
947 return Qt;
606cdb89
JB
948 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
949 if (CONSP (documentation)
bb8e180f
AS
950 && STRINGP (XCAR (documentation))
951 && INTEGERP (XCDR (documentation))
952 && XINT (XCDR (documentation)) < 0)
953 return Qt;
606cdb89
JB
954 /* Customizable? See `custom-variable-p'. */
955 if ((!NILP (Fget (variable, intern ("standard-value"))))
bb8e180f
AS
956 || (!NILP (Fget (variable, intern ("custom-autoload")))))
957 return Qt;
606cdb89 958
ce5b453a 959 if (!(XSYMBOL (variable)->redirect == SYMBOL_VARALIAS))
bb8e180f 960 return Qnil;
606cdb89
JB
961
962 /* An indirect variable? Let's follow the chain. */
ce5b453a 963 XSETSYMBOL (variable, SYMBOL_ALIAS (XSYMBOL (variable)));
606cdb89 964 }
177c0ea7 965}
db9f0278
JB
966\f
967DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
9dbc9081
PJ
968 doc: /* Bind variables according to VARLIST then eval BODY.
969The value of the last form in BODY is returned.
970Each element of VARLIST is a symbol (which is bound to nil)
971or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
972Each VALUEFORM can refer to the symbols already bound by this VARLIST.
7a25dc6d 973usage: (let* VARLIST BODY...) */)
5842a27b 974 (Lisp_Object args)
db9f0278 975{
b9598260 976 Lisp_Object varlist, var, val, elt, lexenv;
aed13378 977 int count = SPECPDL_INDEX ();
db9f0278
JB
978 struct gcpro gcpro1, gcpro2, gcpro3;
979
980 GCPRO3 (args, elt, varlist);
981
b9598260
SM
982 lexenv = Vinternal_interpreter_environment;
983
db9f0278 984 varlist = Fcar (args);
b9598260 985 while (CONSP (varlist))
db9f0278
JB
986 {
987 QUIT;
b9598260
SM
988
989 elt = XCAR (varlist);
90165123 990 if (SYMBOLP (elt))
b9598260
SM
991 {
992 var = elt;
993 val = Qnil;
994 }
08564963 995 else if (! NILP (Fcdr (Fcdr (elt))))
734d55a2 996 signal_error ("`let' bindings can have only one value-form", elt);
db9f0278
JB
997 else
998 {
b9598260 999 var = Fcar (elt);
defb1411 1000 val = eval_sub (Fcar (Fcdr (elt)));
db9f0278 1001 }
b9598260 1002
f07a954e
SM
1003 if (!NILP (lexenv) && SYMBOLP (var)
1004 && !XSYMBOL (var)->declared_special
1005 && NILP (Fmemq (var, Vinternal_interpreter_environment)))
b9598260
SM
1006 /* Lexically bind VAR by adding it to the interpreter's binding
1007 alist. */
1008 {
f07a954e
SM
1009 Lisp_Object newenv
1010 = Fcons (Fcons (var, val), Vinternal_interpreter_environment);
1011 if (EQ (Vinternal_interpreter_environment, lexenv))
1012 /* Save the old lexical environment on the specpdl stack,
1013 but only for the first lexical binding, since we'll never
1014 need to revert to one of the intermediate ones. */
1015 specbind (Qinternal_interpreter_environment, newenv);
1016 else
1017 Vinternal_interpreter_environment = newenv;
db9f0278 1018 }
b9598260
SM
1019 else
1020 specbind (var, val);
1021
1022 varlist = XCDR (varlist);
db9f0278
JB
1023 }
1024 UNGCPRO;
1025 val = Fprogn (Fcdr (args));
1026 return unbind_to (count, val);
1027}
1028
1029DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
9dbc9081
PJ
1030 doc: /* Bind variables according to VARLIST then eval BODY.
1031The value of the last form in BODY is returned.
1032Each element of VARLIST is a symbol (which is bound to nil)
1033or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
1034All the VALUEFORMs are evalled before any symbols are bound.
7a25dc6d 1035usage: (let VARLIST BODY...) */)
5842a27b 1036 (Lisp_Object args)
db9f0278 1037{
b9598260 1038 Lisp_Object *temps, tem, lexenv;
db9f0278 1039 register Lisp_Object elt, varlist;
aed13378 1040 int count = SPECPDL_INDEX ();
f66c7cf8 1041 ptrdiff_t argnum;
db9f0278 1042 struct gcpro gcpro1, gcpro2;
3a7a9129 1043 USE_SAFE_ALLOCA;
db9f0278
JB
1044
1045 varlist = Fcar (args);
1046
f6d62986 1047 /* Make space to hold the values to give the bound variables. */
db9f0278 1048 elt = Flength (varlist);
b72e0717 1049 SAFE_ALLOCA_LISP (temps, XFASTINT (elt));
db9f0278 1050
f6d62986 1051 /* Compute the values and store them in `temps'. */
db9f0278
JB
1052
1053 GCPRO2 (args, *temps);
1054 gcpro2.nvars = 0;
1055
67ee9f6e 1056 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
db9f0278
JB
1057 {
1058 QUIT;
67ee9f6e 1059 elt = XCAR (varlist);
90165123 1060 if (SYMBOLP (elt))
db9f0278 1061 temps [argnum++] = Qnil;
08564963 1062 else if (! NILP (Fcdr (Fcdr (elt))))
734d55a2 1063 signal_error ("`let' bindings can have only one value-form", elt);
db9f0278 1064 else
defb1411 1065 temps [argnum++] = eval_sub (Fcar (Fcdr (elt)));
db9f0278
JB
1066 gcpro2.nvars = argnum;
1067 }
1068 UNGCPRO;
1069
b9598260
SM
1070 lexenv = Vinternal_interpreter_environment;
1071
db9f0278 1072 varlist = Fcar (args);
67ee9f6e 1073 for (argnum = 0; CONSP (varlist); varlist = XCDR (varlist))
db9f0278 1074 {
b9598260
SM
1075 Lisp_Object var;
1076
67ee9f6e 1077 elt = XCAR (varlist);
b9598260 1078 var = SYMBOLP (elt) ? elt : Fcar (elt);
db9f0278 1079 tem = temps[argnum++];
b9598260 1080
f07a954e
SM
1081 if (!NILP (lexenv) && SYMBOLP (var)
1082 && !XSYMBOL (var)->declared_special
1083 && NILP (Fmemq (var, Vinternal_interpreter_environment)))
b9598260
SM
1084 /* Lexically bind VAR by adding it to the lexenv alist. */
1085 lexenv = Fcons (Fcons (var, tem), lexenv);
db9f0278 1086 else
b9598260
SM
1087 /* Dynamically bind VAR. */
1088 specbind (var, tem);
db9f0278
JB
1089 }
1090
b9598260
SM
1091 if (!EQ (lexenv, Vinternal_interpreter_environment))
1092 /* Instantiate a new lexical environment. */
1093 specbind (Qinternal_interpreter_environment, lexenv);
1094
db9f0278 1095 elt = Fprogn (Fcdr (args));
3a7a9129 1096 SAFE_FREE ();
db9f0278
JB
1097 return unbind_to (count, elt);
1098}
1099
1100DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
9dbc9081
PJ
1101 doc: /* If TEST yields non-nil, eval BODY... and repeat.
1102The order of execution is thus TEST, BODY, TEST, BODY and so on
1103until TEST returns nil.
7a25dc6d 1104usage: (while TEST BODY...) */)
5842a27b 1105 (Lisp_Object args)
db9f0278 1106{
2b9bde76 1107 Lisp_Object test, body;
db9f0278
JB
1108 struct gcpro gcpro1, gcpro2;
1109
1110 GCPRO2 (test, body);
1111
1112 test = Fcar (args);
1113 body = Fcdr (args);
defb1411 1114 while (!NILP (eval_sub (test)))
db9f0278
JB
1115 {
1116 QUIT;
1117 Fprogn (body);
1118 }
1119
1120 UNGCPRO;
1121 return Qnil;
1122}
1123
1124DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
9dbc9081
PJ
1125 doc: /* Return result of expanding macros at top level of FORM.
1126If FORM is not a macro call, it is returned unchanged.
1127Otherwise, the macro is expanded and the expansion is considered
1128in place of FORM. When a non-macro-call results, it is returned.
1129
1130The second optional arg ENVIRONMENT specifies an environment of macro
1131definitions to shadow the loaded ones for use in file byte-compilation. */)
5842a27b 1132 (Lisp_Object form, Lisp_Object environment)
db9f0278 1133{
23d6b5a6 1134 /* With cleanups from Hallvard Furuseth. */
db9f0278
JB
1135 register Lisp_Object expander, sym, def, tem;
1136
1137 while (1)
1138 {
1139 /* Come back here each time we expand a macro call,
1140 in case it expands into another macro call. */
90165123 1141 if (!CONSP (form))
db9f0278 1142 break;
23d6b5a6 1143 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
03699b14 1144 def = sym = XCAR (form);
23d6b5a6 1145 tem = Qnil;
db9f0278
JB
1146 /* Trace symbols aliases to other symbols
1147 until we get a symbol that is not an alias. */
90165123 1148 while (SYMBOLP (def))
db9f0278
JB
1149 {
1150 QUIT;
23d6b5a6 1151 sym = def;
79e8bfbf 1152 tem = Fassq (sym, environment);
265a9e55 1153 if (NILP (tem))
db9f0278
JB
1154 {
1155 def = XSYMBOL (sym)->function;
23d6b5a6
JB
1156 if (!EQ (def, Qunbound))
1157 continue;
db9f0278 1158 }
23d6b5a6 1159 break;
db9f0278 1160 }
79e8bfbf 1161 /* Right now TEM is the result from SYM in ENVIRONMENT,
db9f0278 1162 and if TEM is nil then DEF is SYM's function definition. */
265a9e55 1163 if (NILP (tem))
db9f0278 1164 {
79e8bfbf 1165 /* SYM is not mentioned in ENVIRONMENT.
db9f0278 1166 Look at its function definition. */
90165123 1167 if (EQ (def, Qunbound) || !CONSP (def))
f6d62986 1168 /* Not defined or definition not suitable. */
db9f0278 1169 break;
03699b14 1170 if (EQ (XCAR (def), Qautoload))
db9f0278
JB
1171 {
1172 /* Autoloading function: will it be a macro when loaded? */
ee9ee63c 1173 tem = Fnth (make_number (4), def);
47ccd8b6 1174 if (EQ (tem, Qt) || EQ (tem, Qmacro))
ee9ee63c
JB
1175 /* Yes, load it and try again. */
1176 {
ca20916b
RS
1177 struct gcpro gcpro1;
1178 GCPRO1 (form);
ee9ee63c 1179 do_autoload (def, sym);
ca20916b 1180 UNGCPRO;
ee9ee63c
JB
1181 continue;
1182 }
1183 else
db9f0278 1184 break;
db9f0278 1185 }
03699b14 1186 else if (!EQ (XCAR (def), Qmacro))
db9f0278 1187 break;
03699b14 1188 else expander = XCDR (def);
db9f0278
JB
1189 }
1190 else
1191 {
03699b14 1192 expander = XCDR (tem);
265a9e55 1193 if (NILP (expander))
db9f0278
JB
1194 break;
1195 }
03699b14 1196 form = apply1 (expander, XCDR (form));
db9f0278
JB
1197 }
1198 return form;
1199}
1200\f
1201DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
9dbc9081
PJ
1202 doc: /* Eval BODY allowing nonlocal exits using `throw'.
1203TAG is evalled to get the tag to use; it must not be nil.
1204
1205Then the BODY is executed.
1d632ccf 1206Within BODY, a call to `throw' with the same TAG exits BODY and this `catch'.
9dbc9081
PJ
1207If no throw happens, `catch' returns the value of the last BODY form.
1208If a throw happens, it specifies the value to return from `catch'.
7a25dc6d 1209usage: (catch TAG BODY...) */)
5842a27b 1210 (Lisp_Object args)
db9f0278
JB
1211{
1212 register Lisp_Object tag;
1213 struct gcpro gcpro1;
1214
1215 GCPRO1 (args);
defb1411 1216 tag = eval_sub (Fcar (args));
db9f0278
JB
1217 UNGCPRO;
1218 return internal_catch (tag, Fprogn, Fcdr (args));
1219}
1220
1221/* Set up a catch, then call C function FUNC on argument ARG.
1222 FUNC should return a Lisp_Object.
1223 This is how catches are done from within C code. */
1224
1225Lisp_Object
d3da34e0 1226internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object arg)
db9f0278
JB
1227{
1228 /* This structure is made part of the chain `catchlist'. */
1229 struct catchtag c;
1230
1231 /* Fill in the components of c, and put it on the list. */
1232 c.next = catchlist;
1233 c.tag = tag;
1234 c.val = Qnil;
1235 c.backlist = backtrace_list;
1236 c.handlerlist = handlerlist;
1237 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1238 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1239 c.poll_suppress_count = poll_suppress_count;
2659a09f 1240 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1241 c.gcpro = gcprolist;
bcf28080 1242 c.byte_stack = byte_stack_list;
db9f0278
JB
1243 catchlist = &c;
1244
1245 /* Call FUNC. */
1246 if (! _setjmp (c.jmp))
1247 c.val = (*func) (arg);
1248
1249 /* Throw works by a longjmp that comes right here. */
1250 catchlist = c.next;
1251 return c.val;
1252}
1253
ba410f40
JB
1254/* Unwind the specbind, catch, and handler stacks back to CATCH, and
1255 jump to that CATCH, returning VALUE as the value of that catch.
db9f0278 1256
ba410f40
JB
1257 This is the guts Fthrow and Fsignal; they differ only in the way
1258 they choose the catch tag to throw to. A catch tag for a
1259 condition-case form has a TAG of Qnil.
db9f0278 1260
ba410f40
JB
1261 Before each catch is discarded, unbind all special bindings and
1262 execute all unwind-protect clauses made above that catch. Unwind
1263 the handler stack as we go, so that the proper handlers are in
1264 effect for each unwind-protect clause we run. At the end, restore
1265 some static info saved in CATCH, and longjmp to the location
1266 specified in the
1267
1268 This is used for correct unwinding in Fthrow and Fsignal. */
db9f0278
JB
1269
1270static void
d3da34e0 1271unwind_to_catch (struct catchtag *catch, Lisp_Object value)
db9f0278
JB
1272{
1273 register int last_time;
1274
ba410f40
JB
1275 /* Save the value in the tag. */
1276 catch->val = value;
1277
0b31741c 1278 /* Restore certain special C variables. */
1cdc3155 1279 set_poll_suppress_count (catch->poll_suppress_count);
c1788fbc 1280 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
0b31741c 1281 handling_signal = 0;
69bbd6bd 1282 immediate_quit = 0;
82da7701 1283
db9f0278
JB
1284 do
1285 {
1286 last_time = catchlist == catch;
82da7701
JB
1287
1288 /* Unwind the specpdl stack, and then restore the proper set of
bb8e180f 1289 handlers. */
db9f0278
JB
1290 unbind_to (catchlist->pdlcount, Qnil);
1291 handlerlist = catchlist->handlerlist;
1292 catchlist = catchlist->next;
1293 }
1294 while (! last_time);
1295
a2a103bb 1296#if HAVE_X_WINDOWS
88019a63
RS
1297 /* If x_catch_errors was done, turn it off now.
1298 (First we give unbind_to a chance to do that.) */
e6aee454 1299#if 0 /* This would disable x_catch_errors after x_connection_closed.
bb8e180f
AS
1300 The catch must remain in effect during that delicate
1301 state. --lorentey */
88019a63 1302 x_fully_uncatch_errors ();
e6aee454 1303#endif
a2a103bb 1304#endif
88019a63 1305
bcf28080 1306 byte_stack_list = catch->byte_stack;
db9f0278 1307 gcprolist = catch->gcpro;
15934ffa 1308#ifdef DEBUG_GCPRO
d8e2b5ba 1309 gcpro_level = gcprolist ? gcprolist->level + 1 : 0;
15934ffa 1310#endif
db9f0278
JB
1311 backtrace_list = catch->backlist;
1312 lisp_eval_depth = catch->lisp_eval_depth;
177c0ea7 1313
ba410f40 1314 _longjmp (catch->jmp, 1);
db9f0278
JB
1315}
1316
a7ca3326 1317DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
9dbc9081
PJ
1318 doc: /* Throw to the catch for TAG and return VALUE from it.
1319Both TAG and VALUE are evalled. */)
5842a27b 1320 (register Lisp_Object tag, Lisp_Object value)
db9f0278
JB
1321{
1322 register struct catchtag *c;
1323
8788120f
KS
1324 if (!NILP (tag))
1325 for (c = catchlist; c; c = c->next)
1326 {
1327 if (EQ (c->tag, tag))
1328 unwind_to_catch (c, value);
1329 }
734d55a2 1330 xsignal2 (Qno_catch, tag, value);
db9f0278
JB
1331}
1332
1333
1334DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
9dbc9081
PJ
1335 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
1336If BODYFORM completes normally, its value is returned
1337after executing the UNWINDFORMS.
1338If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
7a25dc6d 1339usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
5842a27b 1340 (Lisp_Object args)
db9f0278
JB
1341{
1342 Lisp_Object val;
aed13378 1343 int count = SPECPDL_INDEX ();
db9f0278 1344
04b28167 1345 record_unwind_protect (Fprogn, Fcdr (args));
defb1411 1346 val = eval_sub (Fcar (args));
177c0ea7 1347 return unbind_to (count, val);
db9f0278
JB
1348}
1349\f
db9f0278 1350DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
9dbc9081 1351 doc: /* Regain control when an error is signaled.
1b1acc13 1352Executes BODYFORM and returns its value if no error happens.
9dbc9081
PJ
1353Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1354where the BODY is made of Lisp expressions.
1355
1356A handler is applicable to an error
1357if CONDITION-NAME is one of the error's condition names.
1358If an error happens, the first applicable handler is run.
1359
1360The car of a handler may be a list of condition names
c997bb25 1361instead of a single condition name. Then it handles all of them.
9dbc9081 1362
c997bb25
RS
1363When a handler handles an error, control returns to the `condition-case'
1364and it executes the handler's BODY...
d0acbbaf 1365with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error.
bb8e180f 1366\(If VAR is nil, the handler can't access that information.)
c997bb25
RS
1367Then the value of the last BODY form is returned from the `condition-case'
1368expression.
9dbc9081 1369
9dbc9081 1370See also the function `signal' for more info.
2b47b74d 1371usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
bb8e180f 1372 (Lisp_Object args)
db9f0278 1373{
17401c97
GM
1374 register Lisp_Object bodyform, handlers;
1375 volatile Lisp_Object var;
db9f0278 1376
82da7701
JB
1377 var = Fcar (args);
1378 bodyform = Fcar (Fcdr (args));
1379 handlers = Fcdr (Fcdr (args));
ee830945
RS
1380
1381 return internal_lisp_condition_case (var, bodyform, handlers);
1382}
1383
1384/* Like Fcondition_case, but the args are separate
1385 rather than passed in a list. Used by Fbyte_code. */
1386
1387Lisp_Object
d3da34e0
JB
1388internal_lisp_condition_case (volatile Lisp_Object var, Lisp_Object bodyform,
1389 Lisp_Object handlers)
ee830945
RS
1390{
1391 Lisp_Object val;
1392 struct catchtag c;
1393 struct handler h;
1394
b7826503 1395 CHECK_SYMBOL (var);
82da7701 1396
2b47b74d 1397 for (val = handlers; CONSP (val); val = XCDR (val))
82da7701
JB
1398 {
1399 Lisp_Object tem;
2b47b74d 1400 tem = XCAR (val);
5f96776a
RS
1401 if (! (NILP (tem)
1402 || (CONSP (tem)
03699b14
KR
1403 && (SYMBOLP (XCAR (tem))
1404 || CONSP (XCAR (tem))))))
e6c3da20
EZ
1405 error ("Invalid condition handler: %s",
1406 SDATA (Fprin1_to_string (tem, Qt)));
82da7701 1407 }
db9f0278
JB
1408
1409 c.tag = Qnil;
1410 c.val = Qnil;
1411 c.backlist = backtrace_list;
1412 c.handlerlist = handlerlist;
1413 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1414 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1415 c.poll_suppress_count = poll_suppress_count;
2659a09f 1416 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1417 c.gcpro = gcprolist;
bcf28080 1418 c.byte_stack = byte_stack_list;
db9f0278
JB
1419 if (_setjmp (c.jmp))
1420 {
265a9e55 1421 if (!NILP (h.var))
bb8e180f 1422 specbind (h.var, c.val);
9d58218c 1423 val = Fprogn (Fcdr (h.chosen_clause));
82da7701
JB
1424
1425 /* Note that this just undoes the binding of h.var; whoever
1426 longjumped to us unwound the stack to c.pdlcount before
1427 throwing. */
db9f0278
JB
1428 unbind_to (c.pdlcount, Qnil);
1429 return val;
1430 }
1431 c.next = catchlist;
1432 catchlist = &c;
177c0ea7 1433
82da7701
JB
1434 h.var = var;
1435 h.handler = handlers;
db9f0278 1436 h.next = handlerlist;
db9f0278
JB
1437 h.tag = &c;
1438 handlerlist = &h;
1439
defb1411 1440 val = eval_sub (bodyform);
db9f0278
JB
1441 catchlist = c.next;
1442 handlerlist = h.next;
1443 return val;
1444}
1445
f029ca5f
RS
1446/* Call the function BFUN with no arguments, catching errors within it
1447 according to HANDLERS. If there is an error, call HFUN with
1448 one argument which is the data that describes the error:
1449 (SIGNALNAME . DATA)
1450
1451 HANDLERS can be a list of conditions to catch.
1452 If HANDLERS is Qt, catch all errors.
1453 If HANDLERS is Qerror, catch all errors
1454 but allow the debugger to run if that is enabled. */
1455
db9f0278 1456Lisp_Object
d3da34e0
JB
1457internal_condition_case (Lisp_Object (*bfun) (void), Lisp_Object handlers,
1458 Lisp_Object (*hfun) (Lisp_Object))
db9f0278
JB
1459{
1460 Lisp_Object val;
1461 struct catchtag c;
1462 struct handler h;
1463
1464 c.tag = Qnil;
1465 c.val = Qnil;
1466 c.backlist = backtrace_list;
1467 c.handlerlist = handlerlist;
1468 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1469 c.pdlcount = SPECPDL_INDEX ();
db9f0278 1470 c.poll_suppress_count = poll_suppress_count;
2659a09f 1471 c.interrupt_input_blocked = interrupt_input_blocked;
db9f0278 1472 c.gcpro = gcprolist;
bcf28080 1473 c.byte_stack = byte_stack_list;
db9f0278
JB
1474 if (_setjmp (c.jmp))
1475 {
9d58218c 1476 return (*hfun) (c.val);
db9f0278
JB
1477 }
1478 c.next = catchlist;
1479 catchlist = &c;
1480 h.handler = handlers;
1481 h.var = Qnil;
db9f0278
JB
1482 h.next = handlerlist;
1483 h.tag = &c;
1484 handlerlist = &h;
1485
1486 val = (*bfun) ();
1487 catchlist = c.next;
1488 handlerlist = h.next;
1489 return val;
1490}
1491
2659a09f 1492/* Like internal_condition_case but call BFUN with ARG as its argument. */
f029ca5f 1493
d227775c 1494Lisp_Object
d3da34e0
JB
1495internal_condition_case_1 (Lisp_Object (*bfun) (Lisp_Object), Lisp_Object arg,
1496 Lisp_Object handlers, Lisp_Object (*hfun) (Lisp_Object))
d227775c
RS
1497{
1498 Lisp_Object val;
1499 struct catchtag c;
1500 struct handler h;
1501
1502 c.tag = Qnil;
1503 c.val = Qnil;
1504 c.backlist = backtrace_list;
1505 c.handlerlist = handlerlist;
1506 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1507 c.pdlcount = SPECPDL_INDEX ();
d227775c 1508 c.poll_suppress_count = poll_suppress_count;
2659a09f 1509 c.interrupt_input_blocked = interrupt_input_blocked;
d227775c 1510 c.gcpro = gcprolist;
bcf28080 1511 c.byte_stack = byte_stack_list;
d227775c
RS
1512 if (_setjmp (c.jmp))
1513 {
9d58218c 1514 return (*hfun) (c.val);
d227775c
RS
1515 }
1516 c.next = catchlist;
1517 catchlist = &c;
1518 h.handler = handlers;
1519 h.var = Qnil;
1520 h.next = handlerlist;
1521 h.tag = &c;
1522 handlerlist = &h;
1523
1524 val = (*bfun) (arg);
1525 catchlist = c.next;
1526 handlerlist = h.next;
1527 return val;
1528}
10b29d41 1529
53967e09
CY
1530/* Like internal_condition_case_1 but call BFUN with ARG1 and ARG2 as
1531 its arguments. */
1532
1533Lisp_Object
178f2507
SM
1534internal_condition_case_2 (Lisp_Object (*bfun) (Lisp_Object, Lisp_Object),
1535 Lisp_Object arg1,
1536 Lisp_Object arg2,
1537 Lisp_Object handlers,
1538 Lisp_Object (*hfun) (Lisp_Object))
53967e09
CY
1539{
1540 Lisp_Object val;
1541 struct catchtag c;
1542 struct handler h;
1543
53967e09
CY
1544 c.tag = Qnil;
1545 c.val = Qnil;
1546 c.backlist = backtrace_list;
1547 c.handlerlist = handlerlist;
1548 c.lisp_eval_depth = lisp_eval_depth;
1549 c.pdlcount = SPECPDL_INDEX ();
1550 c.poll_suppress_count = poll_suppress_count;
1551 c.interrupt_input_blocked = interrupt_input_blocked;
1552 c.gcpro = gcprolist;
1553 c.byte_stack = byte_stack_list;
1554 if (_setjmp (c.jmp))
1555 {
1556 return (*hfun) (c.val);
1557 }
1558 c.next = catchlist;
1559 catchlist = &c;
1560 h.handler = handlers;
1561 h.var = Qnil;
1562 h.next = handlerlist;
1563 h.tag = &c;
1564 handlerlist = &h;
1565
1566 val = (*bfun) (arg1, arg2);
1567 catchlist = c.next;
1568 handlerlist = h.next;
1569 return val;
1570}
10b29d41 1571
2659a09f 1572/* Like internal_condition_case but call BFUN with NARGS as first,
10b29d41
GM
1573 and ARGS as second argument. */
1574
1575Lisp_Object
f66c7cf8
PE
1576internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1577 ptrdiff_t nargs,
178f2507
SM
1578 Lisp_Object *args,
1579 Lisp_Object handlers,
1580 Lisp_Object (*hfun) (Lisp_Object))
10b29d41
GM
1581{
1582 Lisp_Object val;
1583 struct catchtag c;
1584 struct handler h;
1585
1586 c.tag = Qnil;
1587 c.val = Qnil;
1588 c.backlist = backtrace_list;
1589 c.handlerlist = handlerlist;
1590 c.lisp_eval_depth = lisp_eval_depth;
aed13378 1591 c.pdlcount = SPECPDL_INDEX ();
10b29d41 1592 c.poll_suppress_count = poll_suppress_count;
2659a09f 1593 c.interrupt_input_blocked = interrupt_input_blocked;
10b29d41
GM
1594 c.gcpro = gcprolist;
1595 c.byte_stack = byte_stack_list;
1596 if (_setjmp (c.jmp))
1597 {
1598 return (*hfun) (c.val);
1599 }
1600 c.next = catchlist;
1601 catchlist = &c;
1602 h.handler = handlers;
1603 h.var = Qnil;
1604 h.next = handlerlist;
1605 h.tag = &c;
1606 handlerlist = &h;
1607
1608 val = (*bfun) (nargs, args);
1609 catchlist = c.next;
1610 handlerlist = h.next;
1611 return val;
1612}
1613
d227775c 1614\f
7d47b580 1615static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object);
e7f7fbaa
SM
1616static int maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig,
1617 Lisp_Object data);
db9f0278 1618
a7ca3326 1619DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
9dbc9081
PJ
1620 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
1621This function does not return.
1622
1623An error symbol is a symbol with an `error-conditions' property
1624that is a list of condition names.
1625A handler for any of those names will get to handle this signal.
1626The symbol `error' should normally be one of them.
1627
1628DATA should be a list. Its elements are printed as part of the error message.
3297ec22
LT
1629See Info anchor `(elisp)Definition of signal' for some details on how this
1630error message is constructed.
9dbc9081
PJ
1631If the signal is handled, DATA is made available to the handler.
1632See also the function `condition-case'. */)
5842a27b 1633 (Lisp_Object error_symbol, Lisp_Object data)
db9f0278 1634{
bfa8ca43 1635 /* When memory is full, ERROR-SYMBOL is nil,
26631f2b
RS
1636 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
1637 That is a special case--don't do this in other situations. */
db9f0278 1638 Lisp_Object conditions;
c11d3d17 1639 Lisp_Object string;
e7f7fbaa
SM
1640 Lisp_Object real_error_symbol
1641 = (NILP (error_symbol) ? Fcar (data) : error_symbol);
1642 register Lisp_Object clause = Qnil;
1643 struct handler *h;
a2ff3819 1644 struct backtrace *bp;
db9f0278 1645
346598f1 1646 immediate_quit = handling_signal = 0;
d063129f 1647 abort_on_gc = 0;
db9f0278
JB
1648 if (gc_in_progress || waiting_for_input)
1649 abort ();
1650
26631f2b
RS
1651#if 0 /* rms: I don't know why this was here,
1652 but it is surely wrong for an error that is handled. */
d148e14d 1653#ifdef HAVE_WINDOW_SYSTEM
df6c90d8
GM
1654 if (display_hourglass_p)
1655 cancel_hourglass ();
48f8dfa3 1656#endif
177c0ea7 1657#endif
48f8dfa3 1658
61ede770 1659 /* This hook is used by edebug. */
26631f2b
RS
1660 if (! NILP (Vsignal_hook_function)
1661 && ! NILP (error_symbol))
9f5903bb
RS
1662 {
1663 /* Edebug takes care of restoring these variables when it exits. */
1664 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
1665 max_lisp_eval_depth = lisp_eval_depth + 20;
1666
1667 if (SPECPDL_INDEX () + 40 > max_specpdl_size)
1668 max_specpdl_size = SPECPDL_INDEX () + 40;
1669
1670 call2 (Vsignal_hook_function, error_symbol, data);
1671 }
61ede770 1672
1ea9dec4 1673 conditions = Fget (real_error_symbol, Qerror_conditions);
db9f0278 1674
a2ff3819
GM
1675 /* Remember from where signal was called. Skip over the frame for
1676 `signal' itself. If a frame for `error' follows, skip that,
26631f2b
RS
1677 too. Don't do this when ERROR_SYMBOL is nil, because that
1678 is a memory-full error. */
090a072f 1679 Vsignaling_function = Qnil;
26631f2b 1680 if (backtrace_list && !NILP (error_symbol))
090a072f
GM
1681 {
1682 bp = backtrace_list->next;
1683 if (bp && bp->function && EQ (*bp->function, Qerror))
1684 bp = bp->next;
1685 if (bp && bp->function)
1686 Vsignaling_function = *bp->function;
1687 }
a2ff3819 1688
e7f7fbaa 1689 for (h = handlerlist; h; h = h->next)
db9f0278 1690 {
7d47b580 1691 clause = find_handler_clause (h->handler, conditions);
265a9e55 1692 if (!NILP (clause))
e7f7fbaa 1693 break;
db9f0278 1694 }
475545b5 1695
e7f7fbaa
SM
1696 if (/* Don't run the debugger for a memory-full error.
1697 (There is no room in memory to do that!) */
1698 !NILP (error_symbol)
1699 && (!NILP (Vdebug_on_signal)
1700 /* If no handler is present now, try to run the debugger. */
1701 || NILP (clause)
bd1ba3e8
CY
1702 /* A `debug' symbol in the handler list disables the normal
1703 suppression of the debugger. */
1704 || (CONSP (clause) && CONSP (XCAR (clause))
1705 && !NILP (Fmemq (Qdebug, XCAR (clause))))
e7f7fbaa
SM
1706 /* Special handler that means "print a message and run debugger
1707 if requested". */
1708 || EQ (h->handler, Qerror)))
1709 {
1710 int debugger_called
1711 = maybe_call_debugger (conditions, error_symbol, data);
1712 /* We can't return values to code which signaled an error, but we
1713 can continue code which has signaled a quit. */
1714 if (debugger_called && EQ (real_error_symbol, Qquit))
1715 return Qnil;
475545b5 1716 }
db9f0278 1717
e7f7fbaa
SM
1718 if (!NILP (clause))
1719 {
1720 Lisp_Object unwind_data
1721 = (NILP (error_symbol) ? data : Fcons (error_symbol, data));
475545b5 1722
e7f7fbaa
SM
1723 h->chosen_clause = clause;
1724 unwind_to_catch (h->tag, unwind_data);
1725 }
1726 else
1727 {
1728 if (catchlist != 0)
1729 Fthrow (Qtop_level, Qt);
1730 }
c11d3d17 1731
1ea9dec4 1732 if (! NILP (error_symbol))
c11d3d17 1733 data = Fcons (error_symbol, data);
475545b5 1734
c11d3d17 1735 string = Ferror_message_string (data);
583f48b9 1736 fatal ("%s", SDATA (string));
db9f0278
JB
1737}
1738
734d55a2
KS
1739/* Internal version of Fsignal that never returns.
1740 Used for anything but Qquit (which can return from Fsignal). */
1741
1742void
d3da34e0 1743xsignal (Lisp_Object error_symbol, Lisp_Object data)
734d55a2
KS
1744{
1745 Fsignal (error_symbol, data);
1746 abort ();
1747}
1748
1749/* Like xsignal, but takes 0, 1, 2, or 3 args instead of a list. */
1750
1751void
d3da34e0 1752xsignal0 (Lisp_Object error_symbol)
734d55a2
KS
1753{
1754 xsignal (error_symbol, Qnil);
1755}
1756
1757void
d3da34e0 1758xsignal1 (Lisp_Object error_symbol, Lisp_Object arg)
734d55a2
KS
1759{
1760 xsignal (error_symbol, list1 (arg));
1761}
1762
1763void
d3da34e0 1764xsignal2 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2)
734d55a2
KS
1765{
1766 xsignal (error_symbol, list2 (arg1, arg2));
1767}
1768
1769void
d3da34e0 1770xsignal3 (Lisp_Object error_symbol, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
734d55a2
KS
1771{
1772 xsignal (error_symbol, list3 (arg1, arg2, arg3));
1773}
1774
1775/* Signal `error' with message S, and additional arg ARG.
1776 If ARG is not a genuine list, make it a one-element list. */
1777
1778void
a8fe7202 1779signal_error (const char *s, Lisp_Object arg)
734d55a2
KS
1780{
1781 Lisp_Object tortoise, hare;
1782
1783 hare = tortoise = arg;
1784 while (CONSP (hare))
1785 {
1786 hare = XCDR (hare);
1787 if (!CONSP (hare))
1788 break;
1789
1790 hare = XCDR (hare);
1791 tortoise = XCDR (tortoise);
1792
1793 if (EQ (hare, tortoise))
1794 break;
1795 }
1796
1797 if (!NILP (hare))
1798 arg = Fcons (arg, Qnil); /* Make it a list. */
1799
1800 xsignal (Qerror, Fcons (build_string (s), arg));
1801}
1802
1803
e0f24100 1804/* Return nonzero if LIST is a non-nil atom or
128c0f66
RM
1805 a list containing one of CONDITIONS. */
1806
1807static int
d3da34e0 1808wants_debugger (Lisp_Object list, Lisp_Object conditions)
128c0f66 1809{
4de86b16 1810 if (NILP (list))
128c0f66
RM
1811 return 0;
1812 if (! CONSP (list))
1813 return 1;
1814
ab67260b 1815 while (CONSP (conditions))
128c0f66 1816 {
ab67260b 1817 Lisp_Object this, tail;
03699b14
KR
1818 this = XCAR (conditions);
1819 for (tail = list; CONSP (tail); tail = XCDR (tail))
1820 if (EQ (XCAR (tail), this))
128c0f66 1821 return 1;
03699b14 1822 conditions = XCDR (conditions);
128c0f66 1823 }
ab67260b 1824 return 0;
128c0f66
RM
1825}
1826
fc950e09
KH
1827/* Return 1 if an error with condition-symbols CONDITIONS,
1828 and described by SIGNAL-DATA, should skip the debugger
1b1acc13 1829 according to debugger-ignored-errors. */
fc950e09
KH
1830
1831static int
d3da34e0 1832skip_debugger (Lisp_Object conditions, Lisp_Object data)
fc950e09
KH
1833{
1834 Lisp_Object tail;
1835 int first_string = 1;
1836 Lisp_Object error_message;
1837
17401c97
GM
1838 error_message = Qnil;
1839 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
fc950e09 1840 {
03699b14 1841 if (STRINGP (XCAR (tail)))
fc950e09
KH
1842 {
1843 if (first_string)
1844 {
1845 error_message = Ferror_message_string (data);
1846 first_string = 0;
1847 }
177c0ea7 1848
03699b14 1849 if (fast_string_match (XCAR (tail), error_message) >= 0)
fc950e09
KH
1850 return 1;
1851 }
1852 else
1853 {
1854 Lisp_Object contail;
1855
17401c97 1856 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
03699b14 1857 if (EQ (XCAR (tail), XCAR (contail)))
fc950e09
KH
1858 return 1;
1859 }
1860 }
1861
1862 return 0;
1863}
1864
ddaa36e1 1865/* Call the debugger if calling it is currently enabled for CONDITIONS.
7d47b580
JB
1866 SIG and DATA describe the signal. There are two ways to pass them:
1867 = SIG is the error symbol, and DATA is the rest of the data.
1868 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1869 This is for memory-full errors only. */
ddaa36e1 1870static int
d3da34e0 1871maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data)
ddaa36e1
AS
1872{
1873 Lisp_Object combined_data;
1874
1875 combined_data = Fcons (sig, data);
1876
1877 if (
1878 /* Don't try to run the debugger with interrupts blocked.
1879 The editing loop would return anyway. */
1880 ! INPUT_BLOCKED_P
1881 /* Does user want to enter debugger for this kind of error? */
1882 && (EQ (sig, Qquit)
1883 ? debug_on_quit
1884 : wants_debugger (Vdebug_on_error, conditions))
1885 && ! skip_debugger (conditions, combined_data)
f6d62986 1886 /* RMS: What's this for? */
ddaa36e1
AS
1887 && when_entered_debugger < num_nonmacro_input_events)
1888 {
1889 call_debugger (Fcons (Qerror, Fcons (combined_data, Qnil)));
1890 return 1;
1891 }
1892
1893 return 0;
1894}
1895
db9f0278 1896static Lisp_Object
7d47b580 1897find_handler_clause (Lisp_Object handlers, Lisp_Object conditions)
db9f0278
JB
1898{
1899 register Lisp_Object h;
db9f0278 1900
f01cbfdd
RS
1901 /* t is used by handlers for all conditions, set up by C code. */
1902 if (EQ (handlers, Qt))
db9f0278 1903 return Qt;
f01cbfdd 1904
61ede770
RS
1905 /* error is used similarly, but means print an error message
1906 and run the debugger if that is enabled. */
e7f7fbaa
SM
1907 if (EQ (handlers, Qerror))
1908 return Qt;
f01cbfdd 1909
e7f7fbaa 1910 for (h = handlers; CONSP (h); h = XCDR (h))
db9f0278 1911 {
e7f7fbaa
SM
1912 Lisp_Object handler = XCAR (h);
1913 Lisp_Object condit, tem;
5f96776a 1914
5f96776a 1915 if (!CONSP (handler))
db9f0278 1916 continue;
e7f7fbaa 1917 condit = XCAR (handler);
5f96776a
RS
1918 /* Handle a single condition name in handler HANDLER. */
1919 if (SYMBOLP (condit))
1920 {
1921 tem = Fmemq (Fcar (handler), conditions);
1922 if (!NILP (tem))
1923 return handler;
1924 }
1925 /* Handle a list of condition names in handler HANDLER. */
1926 else if (CONSP (condit))
1927 {
f01cbfdd
RS
1928 Lisp_Object tail;
1929 for (tail = condit; CONSP (tail); tail = XCDR (tail))
5f96776a 1930 {
e7f7fbaa 1931 tem = Fmemq (XCAR (tail), conditions);
5f96776a 1932 if (!NILP (tem))
e7f7fbaa 1933 return handler;
5f96776a
RS
1934 }
1935 }
db9f0278 1936 }
f01cbfdd 1937
db9f0278
JB
1938 return Qnil;
1939}
1940
db9f0278 1941
f6d62986 1942/* Dump an error message; called like vprintf. */
db9f0278 1943void
b3ffc17c 1944verror (const char *m, va_list ap)
db9f0278 1945{
70476b54 1946 char buf[4000];
c2d1e36d
PE
1947 ptrdiff_t size = sizeof buf;
1948 ptrdiff_t size_max = STRING_BYTES_BOUND + 1;
1949 char const *m_end = m + strlen (m);
9125da08 1950 char *buffer = buf;
c2d1e36d 1951 ptrdiff_t used;
9125da08
RS
1952 Lisp_Object string;
1953
db9f0278 1954 while (1)
9125da08 1955 {
c378da0b
PE
1956 va_list ap_copy;
1957 va_copy (ap_copy, ap);
c2d1e36d 1958 used = doprnt (buffer, size, m, m_end, ap_copy);
c378da0b 1959 va_end (ap_copy);
eb3f1cc8 1960
e6c3da20
EZ
1961 /* Note: the -1 below is because `doprnt' returns the number of bytes
1962 excluding the terminating null byte, and it always terminates with a
1963 null byte, even when producing a truncated message. */
1964 if (used < size - 1)
eb3f1cc8 1965 break;
e6c3da20
EZ
1966 if (size <= size_max / 2)
1967 size *= 2;
825cd63c
EZ
1968 else if (size < size_max)
1969 size = size_max;
e6c3da20
EZ
1970 else
1971 break; /* and leave the message truncated */
eb3f1cc8 1972
825cd63c
EZ
1973 if (buffer != buf)
1974 xfree (buffer);
1975 buffer = (char *) xmalloc (size);
9125da08
RS
1976 }
1977
5fdb398c 1978 string = make_string (buffer, used);
eb3f1cc8 1979 if (buffer != buf)
9ae6734f 1980 xfree (buffer);
9125da08 1981
734d55a2 1982 xsignal1 (Qerror, string);
db9f0278 1983}
b3ffc17c
DN
1984
1985
f6d62986 1986/* Dump an error message; called like printf. */
b3ffc17c
DN
1987
1988/* VARARGS 1 */
1989void
1990error (const char *m, ...)
1991{
1992 va_list ap;
1993 va_start (ap, m);
1994 verror (m, ap);
1995 va_end (ap);
1996}
db9f0278 1997\f
a7ca3326 1998DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
9dbc9081
PJ
1999 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
2000This means it contains a description for how to read arguments to give it.
2001The value is nil for an invalid function or a symbol with no function
2002definition.
2003
2004Interactively callable functions include strings and vectors (treated
2005as keyboard macros), lambda-expressions that contain a top-level call
2006to `interactive', autoload definitions made by `autoload' with non-nil
2007fourth argument, and some of the built-in functions of Lisp.
2008
e72706be
RS
2009Also, a symbol satisfies `commandp' if its function definition does so.
2010
2011If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
769b4fb2 2012then strings and vectors are not accepted. */)
5842a27b 2013 (Lisp_Object function, Lisp_Object for_call_interactively)
db9f0278
JB
2014{
2015 register Lisp_Object fun;
2016 register Lisp_Object funcar;
52b71f49 2017 Lisp_Object if_prop = Qnil;
db9f0278
JB
2018
2019 fun = function;
2020
52b71f49
SM
2021 fun = indirect_function (fun); /* Check cycles. */
2022 if (NILP (fun) || EQ (fun, Qunbound))
ffd56f97 2023 return Qnil;
db9f0278 2024
52b71f49
SM
2025 /* Check an `interactive-form' property if present, analogous to the
2026 function-documentation property. */
2027 fun = function;
2028 while (SYMBOLP (fun))
2029 {
2b9aa051 2030 Lisp_Object tmp = Fget (fun, Qinteractive_form);
52b71f49
SM
2031 if (!NILP (tmp))
2032 if_prop = Qt;
2033 fun = Fsymbol_function (fun);
2034 }
2035
db9f0278
JB
2036 /* Emacs primitives are interactive if their DEFUN specifies an
2037 interactive spec. */
90165123 2038 if (SUBRP (fun))
04724b69 2039 return XSUBR (fun)->intspec ? Qt : if_prop;
db9f0278
JB
2040
2041 /* Bytecode objects are interactive if they are long enough to
2042 have an element whose index is COMPILED_INTERACTIVE, which is
2043 where the interactive spec is stored. */
90165123 2044 else if (COMPILEDP (fun))
845975f5 2045 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
52b71f49 2046 ? Qt : if_prop);
db9f0278
JB
2047
2048 /* Strings and vectors are keyboard macros. */
52b71f49 2049 if (STRINGP (fun) || VECTORP (fun))
6e33efc4 2050 return (NILP (for_call_interactively) ? Qt : Qnil);
db9f0278
JB
2051
2052 /* Lists may represent commands. */
2053 if (!CONSP (fun))
2054 return Qnil;
ed16fb98 2055 funcar = XCAR (fun);
b38b1ec0 2056 if (EQ (funcar, Qclosure))
7200d79c
SM
2057 return (!NILP (Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun)))))
2058 ? Qt : if_prop);
23aba0ea 2059 else if (EQ (funcar, Qlambda))
52b71f49 2060 return !NILP (Fassq (Qinteractive, Fcdr (XCDR (fun)))) ? Qt : if_prop;
b38b1ec0 2061 else if (EQ (funcar, Qautoload))
52b71f49 2062 return !NILP (Fcar (Fcdr (Fcdr (XCDR (fun))))) ? Qt : if_prop;
db9f0278
JB
2063 else
2064 return Qnil;
2065}
2066
db9f0278 2067DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
9dbc9081
PJ
2068 doc: /* Define FUNCTION to autoload from FILE.
2069FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2070Third arg DOCSTRING is documentation for the function.
2071Fourth arg INTERACTIVE if non-nil says function can be called interactively.
2072Fifth arg TYPE indicates the type of the object:
2073 nil or omitted says FUNCTION is a function,
2074 `keymap' says FUNCTION is really a keymap, and
2075 `macro' or t says FUNCTION is really a macro.
2076Third through fifth args give info about the real definition.
2077They default to nil.
2078If FUNCTION is already defined other than as an autoload,
2079this does nothing and returns nil. */)
5842a27b 2080 (Lisp_Object function, Lisp_Object file, Lisp_Object docstring, Lisp_Object interactive, Lisp_Object type)
db9f0278 2081{
b7826503
PJ
2082 CHECK_SYMBOL (function);
2083 CHECK_STRING (file);
db9f0278 2084
f6d62986 2085 /* If function is defined and not as an autoload, don't override. */
db9f0278 2086 if (!EQ (XSYMBOL (function)->function, Qunbound)
90165123 2087 && !(CONSP (XSYMBOL (function)->function)
03699b14 2088 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
db9f0278
JB
2089 return Qnil;
2090
7973e637
SM
2091 if (NILP (Vpurify_flag))
2092 /* Only add entries after dumping, because the ones before are
2093 not useful and else we get loads of them from the loaddefs.el. */
2094 LOADHIST_ATTACH (Fcons (Qautoload, function));
905a9ed3 2095 else
a56eaaef 2096 /* We don't want the docstring in purespace (instead,
d6d23852
SM
2097 Snarf-documentation should (hopefully) overwrite it).
2098 We used to use 0 here, but that leads to accidental sharing in
2099 purecopy's hash-consing, so we use a (hopefully) unique integer
2100 instead. */
51639eac 2101 docstring = make_number (XPNTR (function));
a56eaaef
DN
2102 return Ffset (function,
2103 Fpurecopy (list5 (Qautoload, file, docstring,
2104 interactive, type)));
db9f0278
JB
2105}
2106
2107Lisp_Object
d3da34e0 2108un_autoload (Lisp_Object oldqueue)
db9f0278
JB
2109{
2110 register Lisp_Object queue, first, second;
2111
2112 /* Queue to unwind is current value of Vautoload_queue.
2113 oldqueue is the shadowed value to leave in Vautoload_queue. */
2114 queue = Vautoload_queue;
2115 Vautoload_queue = oldqueue;
2116 while (CONSP (queue))
2117 {
e509f168 2118 first = XCAR (queue);
db9f0278
JB
2119 second = Fcdr (first);
2120 first = Fcar (first);
47b82df9
RS
2121 if (EQ (first, make_number (0)))
2122 Vfeatures = second;
db9f0278
JB
2123 else
2124 Ffset (first, second);
e509f168 2125 queue = XCDR (queue);
db9f0278
JB
2126 }
2127 return Qnil;
2128}
2129
ca20916b
RS
2130/* Load an autoloaded function.
2131 FUNNAME is the symbol which is the function's name.
2132 FUNDEF is the autoload definition (a list). */
2133
045ba794 2134void
d3da34e0 2135do_autoload (Lisp_Object fundef, Lisp_Object funname)
db9f0278 2136{
aed13378 2137 int count = SPECPDL_INDEX ();
d945992e 2138 Lisp_Object fun;
ca20916b 2139 struct gcpro gcpro1, gcpro2, gcpro3;
db9f0278 2140
aea6173f
RS
2141 /* This is to make sure that loadup.el gives a clear picture
2142 of what files are preloaded and when. */
ab4db096
RS
2143 if (! NILP (Vpurify_flag))
2144 error ("Attempt to autoload %s while preparing to dump",
d5db4077 2145 SDATA (SYMBOL_NAME (funname)));
ab4db096 2146
db9f0278 2147 fun = funname;
b7826503 2148 CHECK_SYMBOL (funname);
ca20916b 2149 GCPRO3 (fun, funname, fundef);
db9f0278 2150
f87740dc 2151 /* Preserve the match data. */
89f2614d 2152 record_unwind_save_match_data ();
177c0ea7 2153
a04ee161
RS
2154 /* If autoloading gets an error (which includes the error of failing
2155 to define the function being called), we use Vautoload_queue
2156 to undo function definitions and `provide' calls made by
2157 the function. We do this in the specific case of autoloading
2158 because autoloading is not an explicit request "load this file",
2159 but rather a request to "call this function".
d3da34e0 2160
a04ee161 2161 The value saved here is to be restored into Vautoload_queue. */
db9f0278
JB
2162 record_unwind_protect (un_autoload, Vautoload_queue);
2163 Vautoload_queue = Qt;
7351b242 2164 Fload (Fcar (Fcdr (fundef)), Qnil, Qt, Qnil, Qt);
2a49b6e5 2165
db9f0278
JB
2166 /* Once loading finishes, don't undo it. */
2167 Vautoload_queue = Qt;
2168 unbind_to (count, Qnil);
2169
a7f96a35 2170 fun = Findirect_function (fun, Qnil);
ffd56f97 2171
76c2b0cc 2172 if (!NILP (Fequal (fun, fundef)))
db9f0278 2173 error ("Autoloading failed to define function %s",
d5db4077 2174 SDATA (SYMBOL_NAME (funname)));
ca20916b 2175 UNGCPRO;
db9f0278 2176}
4c576a83 2177
db9f0278 2178\f
a7ca3326 2179DEFUN ("eval", Feval, Seval, 1, 2, 0,
a0ee6f27
SM
2180 doc: /* Evaluate FORM and return its value.
2181If LEXICAL is t, evaluate using lexical scoping. */)
2182 (Lisp_Object form, Lisp_Object lexical)
defb1411
SM
2183{
2184 int count = SPECPDL_INDEX ();
a0ee6f27
SM
2185 specbind (Qinternal_interpreter_environment,
2186 NILP (lexical) ? Qnil : Fcons (Qt, Qnil));
defb1411
SM
2187 return unbind_to (count, eval_sub (form));
2188}
2189
2190/* Eval a sub-expression of the current expression (i.e. in the same
2191 lexical scope). */
2192Lisp_Object
2193eval_sub (Lisp_Object form)
db9f0278
JB
2194{
2195 Lisp_Object fun, val, original_fun, original_args;
2196 Lisp_Object funcar;
2197 struct backtrace backtrace;
2198 struct gcpro gcpro1, gcpro2, gcpro3;
2199
df470e3b 2200 if (handling_signal)
48f8dfa3 2201 abort ();
177c0ea7 2202
90165123 2203 if (SYMBOLP (form))
b9598260 2204 {
f07a954e
SM
2205 /* Look up its binding in the lexical environment.
2206 We do not pay attention to the declared_special flag here, since we
2207 already did that when let-binding the variable. */
2208 Lisp_Object lex_binding
2209 = !NILP (Vinternal_interpreter_environment) /* Mere optimization! */
2210 ? Fassq (form, Vinternal_interpreter_environment)
2211 : Qnil;
2212 if (CONSP (lex_binding))
2213 return XCDR (lex_binding);
2214 else
2215 return Fsymbol_value (form);
b9598260
SM
2216 }
2217
db9f0278
JB
2218 if (!CONSP (form))
2219 return form;
2220
2221 QUIT;
ee830945
RS
2222 if ((consing_since_gc > gc_cons_threshold
2223 && consing_since_gc > gc_relative_threshold)
2224 ||
2225 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
db9f0278
JB
2226 {
2227 GCPRO1 (form);
2228 Fgarbage_collect ();
2229 UNGCPRO;
2230 }
2231
2232 if (++lisp_eval_depth > max_lisp_eval_depth)
2233 {
2234 if (max_lisp_eval_depth < 100)
2235 max_lisp_eval_depth = 100;
2236 if (lisp_eval_depth > max_lisp_eval_depth)
921baa95 2237 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
db9f0278
JB
2238 }
2239
2240 original_fun = Fcar (form);
2241 original_args = Fcdr (form);
2242
2243 backtrace.next = backtrace_list;
2244 backtrace_list = &backtrace;
f6d62986 2245 backtrace.function = &original_fun; /* This also protects them from gc. */
db9f0278
JB
2246 backtrace.args = &original_args;
2247 backtrace.nargs = UNEVALLED;
db9f0278
JB
2248 backtrace.debug_on_exit = 0;
2249
2250 if (debug_on_next_call)
2251 do_debug_on_call (Qt);
2252
2253 /* At this point, only original_fun and original_args
f6d62986 2254 have values that will be used below. */
db9f0278 2255 retry:
8788120f
KS
2256
2257 /* Optimize for no indirection. */
2258 fun = original_fun;
2259 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2260 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2261 fun = indirect_function (fun);
db9f0278 2262
90165123 2263 if (SUBRP (fun))
db9f0278
JB
2264 {
2265 Lisp_Object numargs;
166c822d 2266 Lisp_Object argvals[8];
db9f0278
JB
2267 Lisp_Object args_left;
2268 register int i, maxargs;
2269
2270 args_left = original_args;
2271 numargs = Flength (args_left);
2272
c1788fbc
RS
2273 CHECK_CONS_LIST ();
2274
f6d62986
SM
2275 if (XINT (numargs) < XSUBR (fun)->min_args
2276 || (XSUBR (fun)->max_args >= 0
2277 && XSUBR (fun)->max_args < XINT (numargs)))
734d55a2 2278 xsignal2 (Qwrong_number_of_arguments, original_fun, numargs);
db9f0278 2279
ef1b0ba7 2280 else if (XSUBR (fun)->max_args == UNEVALLED)
bbc6b304 2281 val = (XSUBR (fun)->function.aUNEVALLED) (args_left);
ef1b0ba7 2282 else if (XSUBR (fun)->max_args == MANY)
db9f0278 2283 {
f6d62986 2284 /* Pass a vector of evaluated arguments. */
db9f0278 2285 Lisp_Object *vals;
f66c7cf8 2286 ptrdiff_t argnum = 0;
3a7a9129 2287 USE_SAFE_ALLOCA;
db9f0278 2288
b72e0717 2289 SAFE_ALLOCA_LISP (vals, XINT (numargs));
db9f0278
JB
2290
2291 GCPRO3 (args_left, fun, fun);
2292 gcpro3.var = vals;
2293 gcpro3.nvars = 0;
2294
265a9e55 2295 while (!NILP (args_left))
db9f0278 2296 {
defb1411 2297 vals[argnum++] = eval_sub (Fcar (args_left));
db9f0278
JB
2298 args_left = Fcdr (args_left);
2299 gcpro3.nvars = argnum;
2300 }
db9f0278
JB
2301
2302 backtrace.args = vals;
2303 backtrace.nargs = XINT (numargs);
2304
d5273788 2305 val = (XSUBR (fun)->function.aMANY) (XINT (numargs), vals);
a6e3fa71 2306 UNGCPRO;
3a7a9129 2307 SAFE_FREE ();
db9f0278 2308 }
ef1b0ba7 2309 else
db9f0278 2310 {
ef1b0ba7
SM
2311 GCPRO3 (args_left, fun, fun);
2312 gcpro3.var = argvals;
2313 gcpro3.nvars = 0;
db9f0278 2314
ef1b0ba7
SM
2315 maxargs = XSUBR (fun)->max_args;
2316 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
2317 {
a0ee6f27 2318 argvals[i] = eval_sub (Fcar (args_left));
ef1b0ba7
SM
2319 gcpro3.nvars = ++i;
2320 }
db9f0278 2321
ef1b0ba7 2322 UNGCPRO;
db9f0278 2323
ef1b0ba7
SM
2324 backtrace.args = argvals;
2325 backtrace.nargs = XINT (numargs);
2326
2327 switch (i)
2328 {
2329 case 0:
2330 val = (XSUBR (fun)->function.a0 ());
2331 break;
2332 case 1:
2333 val = (XSUBR (fun)->function.a1 (argvals[0]));
2334 break;
2335 case 2:
2336 val = (XSUBR (fun)->function.a2 (argvals[0], argvals[1]));
2337 break;
2338 case 3:
2339 val = (XSUBR (fun)->function.a3
2340 (argvals[0], argvals[1], argvals[2]));
2341 break;
2342 case 4:
2343 val = (XSUBR (fun)->function.a4
2344 (argvals[0], argvals[1], argvals[2], argvals[3]));
2345 break;
2346 case 5:
2347 val = (XSUBR (fun)->function.a5
2348 (argvals[0], argvals[1], argvals[2], argvals[3],
2349 argvals[4]));
2350 break;
2351 case 6:
2352 val = (XSUBR (fun)->function.a6
2353 (argvals[0], argvals[1], argvals[2], argvals[3],
2354 argvals[4], argvals[5]));
2355 break;
2356 case 7:
2357 val = (XSUBR (fun)->function.a7
2358 (argvals[0], argvals[1], argvals[2], argvals[3],
2359 argvals[4], argvals[5], argvals[6]));
2360 break;
2361
2362 case 8:
2363 val = (XSUBR (fun)->function.a8
2364 (argvals[0], argvals[1], argvals[2], argvals[3],
2365 argvals[4], argvals[5], argvals[6], argvals[7]));
2366 break;
2367
2368 default:
2369 /* Someone has created a subr that takes more arguments than
2370 is supported by this code. We need to either rewrite the
2371 subr to use a different argument protocol, or add more
2372 cases to this switch. */
2373 abort ();
2374 }
db9f0278
JB
2375 }
2376 }
ef1b0ba7 2377 else if (COMPILEDP (fun))
defb1411 2378 val = apply_lambda (fun, original_args);
db9f0278
JB
2379 else
2380 {
8788120f 2381 if (EQ (fun, Qunbound))
734d55a2 2382 xsignal1 (Qvoid_function, original_fun);
db9f0278 2383 if (!CONSP (fun))
734d55a2
KS
2384 xsignal1 (Qinvalid_function, original_fun);
2385 funcar = XCAR (fun);
90165123 2386 if (!SYMBOLP (funcar))
734d55a2 2387 xsignal1 (Qinvalid_function, original_fun);
db9f0278
JB
2388 if (EQ (funcar, Qautoload))
2389 {
2390 do_autoload (fun, original_fun);
2391 goto retry;
2392 }
2393 if (EQ (funcar, Qmacro))
defb1411
SM
2394 val = eval_sub (apply1 (Fcdr (fun), original_args));
2395 else if (EQ (funcar, Qlambda)
2396 || EQ (funcar, Qclosure))
2397 val = apply_lambda (fun, original_args);
db9f0278 2398 else
734d55a2 2399 xsignal1 (Qinvalid_function, original_fun);
db9f0278 2400 }
c1788fbc
RS
2401 CHECK_CONS_LIST ();
2402
db9f0278
JB
2403 lisp_eval_depth--;
2404 if (backtrace.debug_on_exit)
2405 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
2406 backtrace_list = backtrace.next;
824eb35e 2407
db9f0278
JB
2408 return val;
2409}
2410\f
a7ca3326 2411DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
9dbc9081
PJ
2412 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
2413Then return the value FUNCTION returns.
2414Thus, (apply '+ 1 2 '(3 4)) returns 10.
2415usage: (apply FUNCTION &rest ARGUMENTS) */)
f66c7cf8 2416 (ptrdiff_t nargs, Lisp_Object *args)
db9f0278 2417{
f66c7cf8 2418 ptrdiff_t i, numargs;
db9f0278
JB
2419 register Lisp_Object spread_arg;
2420 register Lisp_Object *funcall_args;
3a7a9129 2421 Lisp_Object fun, retval;
96d44c64 2422 struct gcpro gcpro1;
3a7a9129 2423 USE_SAFE_ALLOCA;
db9f0278
JB
2424
2425 fun = args [0];
2426 funcall_args = 0;
2427 spread_arg = args [nargs - 1];
b7826503 2428 CHECK_LIST (spread_arg);
177c0ea7 2429
db9f0278
JB
2430 numargs = XINT (Flength (spread_arg));
2431
2432 if (numargs == 0)
2433 return Ffuncall (nargs - 1, args);
2434 else if (numargs == 1)
2435 {
03699b14 2436 args [nargs - 1] = XCAR (spread_arg);
db9f0278
JB
2437 return Ffuncall (nargs, args);
2438 }
2439
a6e3fa71 2440 numargs += nargs - 2;
db9f0278 2441
8788120f
KS
2442 /* Optimize for no indirection. */
2443 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2444 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2445 fun = indirect_function (fun);
ffd56f97 2446 if (EQ (fun, Qunbound))
db9f0278 2447 {
f6d62986 2448 /* Let funcall get the error. */
ffd56f97
JB
2449 fun = args[0];
2450 goto funcall;
db9f0278
JB
2451 }
2452
90165123 2453 if (SUBRP (fun))
db9f0278
JB
2454 {
2455 if (numargs < XSUBR (fun)->min_args
2456 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
f6d62986 2457 goto funcall; /* Let funcall get the error. */
c5101a77 2458 else if (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args > numargs)
db9f0278
JB
2459 {
2460 /* Avoid making funcall cons up a yet another new vector of arguments
f6d62986 2461 by explicitly supplying nil's for optional values. */
b72e0717 2462 SAFE_ALLOCA_LISP (funcall_args, 1 + XSUBR (fun)->max_args);
db9f0278
JB
2463 for (i = numargs; i < XSUBR (fun)->max_args;)
2464 funcall_args[++i] = Qnil;
96d44c64
SM
2465 GCPRO1 (*funcall_args);
2466 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
db9f0278
JB
2467 }
2468 }
2469 funcall:
2470 /* We add 1 to numargs because funcall_args includes the
2471 function itself as well as its arguments. */
2472 if (!funcall_args)
a6e3fa71 2473 {
b72e0717 2474 SAFE_ALLOCA_LISP (funcall_args, 1 + numargs);
96d44c64
SM
2475 GCPRO1 (*funcall_args);
2476 gcpro1.nvars = 1 + numargs;
a6e3fa71
JB
2477 }
2478
72af86bd 2479 memcpy (funcall_args, args, nargs * sizeof (Lisp_Object));
db9f0278
JB
2480 /* Spread the last arg we got. Its first element goes in
2481 the slot that it used to occupy, hence this value of I. */
2482 i = nargs - 1;
265a9e55 2483 while (!NILP (spread_arg))
db9f0278 2484 {
03699b14
KR
2485 funcall_args [i++] = XCAR (spread_arg);
2486 spread_arg = XCDR (spread_arg);
db9f0278 2487 }
a6e3fa71 2488
96d44c64 2489 /* By convention, the caller needs to gcpro Ffuncall's args. */
3a7a9129
CY
2490 retval = Ffuncall (gcpro1.nvars, funcall_args);
2491 UNGCPRO;
2492 SAFE_FREE ();
2493
2494 return retval;
db9f0278
JB
2495}
2496\f
ff936e53
SM
2497/* Run hook variables in various ways. */
2498
f6d62986 2499static Lisp_Object
f66c7cf8 2500funcall_nil (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2501{
2502 Ffuncall (nargs, args);
2503 return Qnil;
2504}
ff936e53 2505
a7ca3326 2506DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
9f685258 2507 doc: /* Run each hook in HOOKS.
9dbc9081
PJ
2508Each argument should be a symbol, a hook variable.
2509These symbols are processed in the order specified.
2510If a hook symbol has a non-nil value, that value may be a function
2511or a list of functions to be called to run the hook.
2512If the value is a function, it is called with no arguments.
2513If it is a list, the elements are called, in order, with no arguments.
2514
9f685258
LK
2515Major modes should not use this function directly to run their mode
2516hook; they should use `run-mode-hooks' instead.
2517
72e85d5d
RS
2518Do not use `make-local-variable' to make a hook variable buffer-local.
2519Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2520usage: (run-hooks &rest HOOKS) */)
f66c7cf8 2521 (ptrdiff_t nargs, Lisp_Object *args)
ff936e53
SM
2522{
2523 Lisp_Object hook[1];
f66c7cf8 2524 ptrdiff_t i;
ff936e53
SM
2525
2526 for (i = 0; i < nargs; i++)
2527 {
2528 hook[0] = args[i];
f6d62986 2529 run_hook_with_args (1, hook, funcall_nil);
ff936e53
SM
2530 }
2531
2532 return Qnil;
2533}
177c0ea7 2534
a7ca3326 2535DEFUN ("run-hook-with-args", Frun_hook_with_args,
9dbc9081
PJ
2536 Srun_hook_with_args, 1, MANY, 0,
2537 doc: /* Run HOOK with the specified arguments ARGS.
2538HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2539value, that value may be a function or a list of functions to be
2540called to run the hook. If the value is a function, it is called with
2541the given arguments and its return value is returned. If it is a list
2542of functions, those functions are called, in order,
2543with the given arguments ARGS.
d5e2c90c 2544It is best not to depend on the value returned by `run-hook-with-args',
9dbc9081
PJ
2545as that may change.
2546
72e85d5d
RS
2547Do not use `make-local-variable' to make a hook variable buffer-local.
2548Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2549usage: (run-hook-with-args HOOK &rest ARGS) */)
f66c7cf8 2550 (ptrdiff_t nargs, Lisp_Object *args)
ff936e53 2551{
f6d62986 2552 return run_hook_with_args (nargs, args, funcall_nil);
ff936e53
SM
2553}
2554
a0d76c27 2555DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
9dbc9081
PJ
2556 Srun_hook_with_args_until_success, 1, MANY, 0,
2557 doc: /* Run HOOK with the specified arguments ARGS.
d5e2c90c
RS
2558HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2559value, that value may be a function or a list of functions to be
2560called to run the hook. If the value is a function, it is called with
2561the given arguments and its return value is returned.
2562If it is a list of functions, those functions are called, in order,
2563with the given arguments ARGS, until one of them
9dbc9081 2564returns a non-nil value. Then we return that value.
d5e2c90c 2565However, if they all return nil, we return nil.
9dbc9081 2566
72e85d5d
RS
2567Do not use `make-local-variable' to make a hook variable buffer-local.
2568Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2569usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
f66c7cf8 2570 (ptrdiff_t nargs, Lisp_Object *args)
b0b667cb 2571{
f6d62986
SM
2572 return run_hook_with_args (nargs, args, Ffuncall);
2573}
2574
2575static Lisp_Object
f66c7cf8 2576funcall_not (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2577{
2578 return NILP (Ffuncall (nargs, args)) ? Qt : Qnil;
ff936e53
SM
2579}
2580
a7ca3326 2581DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
9dbc9081
PJ
2582 Srun_hook_with_args_until_failure, 1, MANY, 0,
2583 doc: /* Run HOOK with the specified arguments ARGS.
d5e2c90c
RS
2584HOOK should be a symbol, a hook variable. If HOOK has a non-nil
2585value, that value may be a function or a list of functions to be
2586called to run the hook. If the value is a function, it is called with
2587the given arguments and its return value is returned.
2588If it is a list of functions, those functions are called, in order,
2589with the given arguments ARGS, until one of them returns nil.
2590Then we return nil. However, if they all return non-nil, we return non-nil.
9dbc9081 2591
72e85d5d
RS
2592Do not use `make-local-variable' to make a hook variable buffer-local.
2593Instead, use `add-hook' and specify t for the LOCAL argument.
9dbc9081 2594usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
f66c7cf8 2595 (ptrdiff_t nargs, Lisp_Object *args)
ff936e53 2596{
f6d62986 2597 return NILP (run_hook_with_args (nargs, args, funcall_not)) ? Qt : Qnil;
ff936e53
SM
2598}
2599
f6d62986 2600static Lisp_Object
f66c7cf8 2601run_hook_wrapped_funcall (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2602{
2603 Lisp_Object tmp = args[0], ret;
2604 args[0] = args[1];
2605 args[1] = tmp;
2606 ret = Ffuncall (nargs, args);
2607 args[1] = args[0];
2608 args[0] = tmp;
2609 return ret;
2610}
2611
2612DEFUN ("run-hook-wrapped", Frun_hook_wrapped, Srun_hook_wrapped, 2, MANY, 0,
2613 doc: /* Run HOOK, passing each function through WRAP-FUNCTION.
2614I.e. instead of calling each function FUN directly with arguments ARGS,
2615it calls WRAP-FUNCTION with arguments FUN and ARGS.
2616As soon as a call to WRAP-FUNCTION returns non-nil, `run-hook-wrapped'
2617aborts and returns that value.
2618usage: (run-hook-wrapped HOOK WRAP-FUNCTION &rest ARGS) */)
f66c7cf8 2619 (ptrdiff_t nargs, Lisp_Object *args)
f6d62986
SM
2620{
2621 return run_hook_with_args (nargs, args, run_hook_wrapped_funcall);
2622}
ff936e53 2623
c933ea05
RS
2624/* ARGS[0] should be a hook symbol.
2625 Call each of the functions in the hook value, passing each of them
2626 as arguments all the rest of ARGS (all NARGS - 1 elements).
f6d62986 2627 FUNCALL specifies how to call each function on the hook.
c933ea05
RS
2628 The caller (or its caller, etc) must gcpro all of ARGS,
2629 except that it isn't necessary to gcpro ARGS[0]. */
2630
f6d62986 2631Lisp_Object
f66c7cf8
PE
2632run_hook_with_args (ptrdiff_t nargs, Lisp_Object *args,
2633 Lisp_Object (*funcall) (ptrdiff_t nargs, Lisp_Object *args))
ff936e53 2634{
f6d62986 2635 Lisp_Object sym, val, ret = Qnil;
fada05d6 2636 struct gcpro gcpro1, gcpro2, gcpro3;
b0b667cb 2637
f029ca5f
RS
2638 /* If we are dying or still initializing,
2639 don't do anything--it would probably crash if we tried. */
2640 if (NILP (Vrun_hooks))
caff32a7 2641 return Qnil;
f029ca5f 2642
b0b667cb 2643 sym = args[0];
aa681b51 2644 val = find_symbol_value (sym);
ff936e53 2645
b0b667cb 2646 if (EQ (val, Qunbound) || NILP (val))
ff936e53 2647 return ret;
03699b14 2648 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
b0b667cb
KH
2649 {
2650 args[0] = val;
f6d62986 2651 return funcall (nargs, args);
b0b667cb
KH
2652 }
2653 else
2654 {
1faed8ae
PE
2655 Lisp_Object global_vals = Qnil;
2656 GCPRO3 (sym, val, global_vals);
cb9d21f8 2657
ff936e53 2658 for (;
f6d62986 2659 CONSP (val) && NILP (ret);
03699b14 2660 val = XCDR (val))
b0b667cb 2661 {
03699b14 2662 if (EQ (XCAR (val), Qt))
b0b667cb
KH
2663 {
2664 /* t indicates this hook has a local binding;
2665 it means to run the global binding too. */
1faed8ae
PE
2666 global_vals = Fdefault_value (sym);
2667 if (NILP (global_vals)) continue;
b0b667cb 2668
1faed8ae 2669 if (!CONSP (global_vals) || EQ (XCAR (global_vals), Qlambda))
b0b667cb 2670 {
1faed8ae 2671 args[0] = global_vals;
f6d62986 2672 ret = funcall (nargs, args);
8932b1c2
CY
2673 }
2674 else
2675 {
2676 for (;
f6d62986 2677 CONSP (global_vals) && NILP (ret);
1faed8ae 2678 global_vals = XCDR (global_vals))
8932b1c2 2679 {
1faed8ae 2680 args[0] = XCAR (global_vals);
8932b1c2
CY
2681 /* In a global value, t should not occur. If it does, we
2682 must ignore it to avoid an endless loop. */
2683 if (!EQ (args[0], Qt))
f6d62986 2684 ret = funcall (nargs, args);
8932b1c2 2685 }
b0b667cb
KH
2686 }
2687 }
2688 else
2689 {
03699b14 2690 args[0] = XCAR (val);
f6d62986 2691 ret = funcall (nargs, args);
b0b667cb
KH
2692 }
2693 }
cb9d21f8
RS
2694
2695 UNGCPRO;
ff936e53 2696 return ret;
b0b667cb
KH
2697 }
2698}
c933ea05 2699
7d48558f
RS
2700/* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
2701
2702void
d3da34e0 2703run_hook_with_args_2 (Lisp_Object hook, Lisp_Object arg1, Lisp_Object arg2)
7d48558f
RS
2704{
2705 Lisp_Object temp[3];
2706 temp[0] = hook;
2707 temp[1] = arg1;
2708 temp[2] = arg2;
2709
2710 Frun_hook_with_args (3, temp);
2711}
ff936e53 2712\f
f6d62986 2713/* Apply fn to arg. */
db9f0278 2714Lisp_Object
d3da34e0 2715apply1 (Lisp_Object fn, Lisp_Object arg)
db9f0278 2716{
a6e3fa71
JB
2717 struct gcpro gcpro1;
2718
2719 GCPRO1 (fn);
265a9e55 2720 if (NILP (arg))
a6e3fa71
JB
2721 RETURN_UNGCPRO (Ffuncall (1, &fn));
2722 gcpro1.nvars = 2;
db9f0278
JB
2723 {
2724 Lisp_Object args[2];
2725 args[0] = fn;
2726 args[1] = arg;
a6e3fa71
JB
2727 gcpro1.var = args;
2728 RETURN_UNGCPRO (Fapply (2, args));
db9f0278 2729 }
db9f0278
JB
2730}
2731
f6d62986 2732/* Call function fn on no arguments. */
db9f0278 2733Lisp_Object
d3da34e0 2734call0 (Lisp_Object fn)
db9f0278 2735{
a6e3fa71
JB
2736 struct gcpro gcpro1;
2737
2738 GCPRO1 (fn);
2739 RETURN_UNGCPRO (Ffuncall (1, &fn));
db9f0278
JB
2740}
2741
f6d62986 2742/* Call function fn with 1 argument arg1. */
db9f0278
JB
2743/* ARGSUSED */
2744Lisp_Object
d3da34e0 2745call1 (Lisp_Object fn, Lisp_Object arg1)
db9f0278 2746{
a6e3fa71 2747 struct gcpro gcpro1;
177c0ea7 2748 Lisp_Object args[2];
a6e3fa71 2749
db9f0278 2750 args[0] = fn;
15285f9f 2751 args[1] = arg1;
a6e3fa71
JB
2752 GCPRO1 (args[0]);
2753 gcpro1.nvars = 2;
2754 RETURN_UNGCPRO (Ffuncall (2, args));
db9f0278
JB
2755}
2756
f6d62986 2757/* Call function fn with 2 arguments arg1, arg2. */
db9f0278
JB
2758/* ARGSUSED */
2759Lisp_Object
d3da34e0 2760call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2)
db9f0278 2761{
a6e3fa71 2762 struct gcpro gcpro1;
db9f0278
JB
2763 Lisp_Object args[3];
2764 args[0] = fn;
15285f9f
RS
2765 args[1] = arg1;
2766 args[2] = arg2;
a6e3fa71
JB
2767 GCPRO1 (args[0]);
2768 gcpro1.nvars = 3;
2769 RETURN_UNGCPRO (Ffuncall (3, args));
db9f0278
JB
2770}
2771
f6d62986 2772/* Call function fn with 3 arguments arg1, arg2, arg3. */
db9f0278
JB
2773/* ARGSUSED */
2774Lisp_Object
d3da34e0 2775call3 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3)
db9f0278 2776{
a6e3fa71 2777 struct gcpro gcpro1;
db9f0278
JB
2778 Lisp_Object args[4];
2779 args[0] = fn;
15285f9f
RS
2780 args[1] = arg1;
2781 args[2] = arg2;
2782 args[3] = arg3;
a6e3fa71
JB
2783 GCPRO1 (args[0]);
2784 gcpro1.nvars = 4;
2785 RETURN_UNGCPRO (Ffuncall (4, args));
db9f0278
JB
2786}
2787
f6d62986 2788/* Call function fn with 4 arguments arg1, arg2, arg3, arg4. */
a5a44b91
JB
2789/* ARGSUSED */
2790Lisp_Object
d3da34e0
JB
2791call4 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2792 Lisp_Object arg4)
a5a44b91
JB
2793{
2794 struct gcpro gcpro1;
a5a44b91
JB
2795 Lisp_Object args[5];
2796 args[0] = fn;
15285f9f
RS
2797 args[1] = arg1;
2798 args[2] = arg2;
2799 args[3] = arg3;
2800 args[4] = arg4;
a5a44b91
JB
2801 GCPRO1 (args[0]);
2802 gcpro1.nvars = 5;
2803 RETURN_UNGCPRO (Ffuncall (5, args));
a5a44b91
JB
2804}
2805
f6d62986 2806/* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5. */
15285f9f
RS
2807/* ARGSUSED */
2808Lisp_Object
d3da34e0
JB
2809call5 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2810 Lisp_Object arg4, Lisp_Object arg5)
15285f9f
RS
2811{
2812 struct gcpro gcpro1;
15285f9f
RS
2813 Lisp_Object args[6];
2814 args[0] = fn;
2815 args[1] = arg1;
2816 args[2] = arg2;
2817 args[3] = arg3;
2818 args[4] = arg4;
2819 args[5] = arg5;
2820 GCPRO1 (args[0]);
2821 gcpro1.nvars = 6;
2822 RETURN_UNGCPRO (Ffuncall (6, args));
15285f9f
RS
2823}
2824
f6d62986 2825/* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6. */
15285f9f
RS
2826/* ARGSUSED */
2827Lisp_Object
d3da34e0
JB
2828call6 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2829 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6)
15285f9f
RS
2830{
2831 struct gcpro gcpro1;
15285f9f
RS
2832 Lisp_Object args[7];
2833 args[0] = fn;
2834 args[1] = arg1;
2835 args[2] = arg2;
2836 args[3] = arg3;
2837 args[4] = arg4;
2838 args[5] = arg5;
2839 args[6] = arg6;
2840 GCPRO1 (args[0]);
2841 gcpro1.nvars = 7;
2842 RETURN_UNGCPRO (Ffuncall (7, args));
15285f9f
RS
2843}
2844
f6d62986 2845/* Call function fn with 7 arguments arg1, arg2, arg3, arg4, arg5, arg6, arg7. */
574c05e2
KK
2846/* ARGSUSED */
2847Lisp_Object
d3da34e0
JB
2848call7 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2, Lisp_Object arg3,
2849 Lisp_Object arg4, Lisp_Object arg5, Lisp_Object arg6, Lisp_Object arg7)
574c05e2
KK
2850{
2851 struct gcpro gcpro1;
574c05e2
KK
2852 Lisp_Object args[8];
2853 args[0] = fn;
2854 args[1] = arg1;
2855 args[2] = arg2;
2856 args[3] = arg3;
2857 args[4] = arg4;
2858 args[5] = arg5;
2859 args[6] = arg6;
2860 args[7] = arg7;
2861 GCPRO1 (args[0]);
2862 gcpro1.nvars = 8;
2863 RETURN_UNGCPRO (Ffuncall (8, args));
574c05e2
KK
2864}
2865
6c2ef893
RS
2866/* The caller should GCPRO all the elements of ARGS. */
2867
a7ca3326 2868DEFUN ("functionp", Ffunctionp, Sfunctionp, 1, 1, 0,
7200d79c 2869 doc: /* Non-nil if OBJECT is a function. */)
c566235d 2870 (Lisp_Object object)
b9598260
SM
2871{
2872 if (SYMBOLP (object) && !NILP (Ffboundp (object)))
2873 {
ba83908c 2874 object = Findirect_function (object, Qt);
b9598260
SM
2875
2876 if (CONSP (object) && EQ (XCAR (object), Qautoload))
2877 {
2878 /* Autoloaded symbols are functions, except if they load
2879 macros or keymaps. */
2880 int i;
2881 for (i = 0; i < 4 && CONSP (object); i++)
2882 object = XCDR (object);
2883
2884 return (CONSP (object) && !NILP (XCAR (object))) ? Qnil : Qt;
2885 }
2886 }
2887
2888 if (SUBRP (object))
3c3ddb98 2889 return (XSUBR (object)->max_args != UNEVALLED) ? Qt : Qnil;
876c194c 2890 else if (COMPILEDP (object))
b9598260
SM
2891 return Qt;
2892 else if (CONSP (object))
2893 {
2894 Lisp_Object car = XCAR (object);
2895 return (EQ (car, Qlambda) || EQ (car, Qclosure)) ? Qt : Qnil;
2896 }
2897 else
2898 return Qnil;
2899}
2900
a7ca3326 2901DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
9dbc9081
PJ
2902 doc: /* Call first argument as a function, passing remaining arguments to it.
2903Return the value that function returns.
2904Thus, (funcall 'cons 'x 'y) returns (x . y).
2905usage: (funcall FUNCTION &rest ARGUMENTS) */)
f66c7cf8 2906 (ptrdiff_t nargs, Lisp_Object *args)
db9f0278 2907{
8788120f 2908 Lisp_Object fun, original_fun;
db9f0278 2909 Lisp_Object funcar;
f66c7cf8 2910 ptrdiff_t numargs = nargs - 1;
db9f0278
JB
2911 Lisp_Object lisp_numargs;
2912 Lisp_Object val;
2913 struct backtrace backtrace;
2914 register Lisp_Object *internal_args;
f66c7cf8 2915 ptrdiff_t i;
db9f0278
JB
2916
2917 QUIT;
ee830945
RS
2918 if ((consing_since_gc > gc_cons_threshold
2919 && consing_since_gc > gc_relative_threshold)
2920 ||
2921 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold))
a6e3fa71 2922 Fgarbage_collect ();
db9f0278
JB
2923
2924 if (++lisp_eval_depth > max_lisp_eval_depth)
2925 {
2926 if (max_lisp_eval_depth < 100)
2927 max_lisp_eval_depth = 100;
2928 if (lisp_eval_depth > max_lisp_eval_depth)
921baa95 2929 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
db9f0278
JB
2930 }
2931
2932 backtrace.next = backtrace_list;
2933 backtrace_list = &backtrace;
2934 backtrace.function = &args[0];
2935 backtrace.args = &args[1];
2936 backtrace.nargs = nargs - 1;
db9f0278
JB
2937 backtrace.debug_on_exit = 0;
2938
2939 if (debug_on_next_call)
2940 do_debug_on_call (Qlambda);
2941
fff3ff9c
KS
2942 CHECK_CONS_LIST ();
2943
8788120f
KS
2944 original_fun = args[0];
2945
db9f0278
JB
2946 retry:
2947
8788120f
KS
2948 /* Optimize for no indirection. */
2949 fun = original_fun;
2950 if (SYMBOLP (fun) && !EQ (fun, Qunbound)
2951 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun)))
2952 fun = indirect_function (fun);
db9f0278 2953
90165123 2954 if (SUBRP (fun))
db9f0278 2955 {
ef1b0ba7 2956 if (numargs < XSUBR (fun)->min_args
db9f0278
JB
2957 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
2958 {
a631e24c 2959 XSETFASTINT (lisp_numargs, numargs);
734d55a2 2960 xsignal2 (Qwrong_number_of_arguments, original_fun, lisp_numargs);
db9f0278
JB
2961 }
2962
ef1b0ba7 2963 else if (XSUBR (fun)->max_args == UNEVALLED)
734d55a2 2964 xsignal1 (Qinvalid_function, original_fun);
db9f0278 2965
ef1b0ba7
SM
2966 else if (XSUBR (fun)->max_args == MANY)
2967 val = (XSUBR (fun)->function.aMANY) (numargs, args + 1);
db9f0278 2968 else
db9f0278 2969 {
ef1b0ba7
SM
2970 if (XSUBR (fun)->max_args > numargs)
2971 {
2972 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
2973 memcpy (internal_args, args + 1, numargs * sizeof (Lisp_Object));
2974 for (i = numargs; i < XSUBR (fun)->max_args; i++)
2975 internal_args[i] = Qnil;
2976 }
2977 else
2978 internal_args = args + 1;
2979 switch (XSUBR (fun)->max_args)
2980 {
2981 case 0:
2982 val = (XSUBR (fun)->function.a0 ());
2983 break;
2984 case 1:
2985 val = (XSUBR (fun)->function.a1 (internal_args[0]));
2986 break;
2987 case 2:
2988 val = (XSUBR (fun)->function.a2
2989 (internal_args[0], internal_args[1]));
2990 break;
2991 case 3:
2992 val = (XSUBR (fun)->function.a3
2993 (internal_args[0], internal_args[1], internal_args[2]));
2994 break;
2995 case 4:
2996 val = (XSUBR (fun)->function.a4
2997 (internal_args[0], internal_args[1], internal_args[2],
2998 internal_args[3]));
2999 break;
3000 case 5:
3001 val = (XSUBR (fun)->function.a5
3002 (internal_args[0], internal_args[1], internal_args[2],
3003 internal_args[3], internal_args[4]));
3004 break;
3005 case 6:
3006 val = (XSUBR (fun)->function.a6
3007 (internal_args[0], internal_args[1], internal_args[2],
3008 internal_args[3], internal_args[4], internal_args[5]));
3009 break;
3010 case 7:
3011 val = (XSUBR (fun)->function.a7
3012 (internal_args[0], internal_args[1], internal_args[2],
3013 internal_args[3], internal_args[4], internal_args[5],
3014 internal_args[6]));
3015 break;
3016
3017 case 8:
3018 val = (XSUBR (fun)->function.a8
3019 (internal_args[0], internal_args[1], internal_args[2],
3020 internal_args[3], internal_args[4], internal_args[5],
3021 internal_args[6], internal_args[7]));
3022 break;
3023
3024 default:
3025
3026 /* If a subr takes more than 8 arguments without using MANY
3027 or UNEVALLED, we need to extend this function to support it.
3028 Until this is done, there is no way to call the function. */
3029 abort ();
3030 }
db9f0278
JB
3031 }
3032 }
ef1b0ba7 3033 else if (COMPILEDP (fun))
db9f0278
JB
3034 val = funcall_lambda (fun, numargs, args + 1);
3035 else
3036 {
8788120f 3037 if (EQ (fun, Qunbound))
734d55a2 3038 xsignal1 (Qvoid_function, original_fun);
db9f0278 3039 if (!CONSP (fun))
734d55a2
KS
3040 xsignal1 (Qinvalid_function, original_fun);
3041 funcar = XCAR (fun);
90165123 3042 if (!SYMBOLP (funcar))
734d55a2 3043 xsignal1 (Qinvalid_function, original_fun);
defb1411
SM
3044 if (EQ (funcar, Qlambda)
3045 || EQ (funcar, Qclosure))
db9f0278 3046 val = funcall_lambda (fun, numargs, args + 1);
db9f0278
JB
3047 else if (EQ (funcar, Qautoload))
3048 {
8788120f 3049 do_autoload (fun, original_fun);
fff3ff9c 3050 CHECK_CONS_LIST ();
db9f0278
JB
3051 goto retry;
3052 }
3053 else
734d55a2 3054 xsignal1 (Qinvalid_function, original_fun);
db9f0278 3055 }
c1788fbc 3056 CHECK_CONS_LIST ();
db9f0278
JB
3057 lisp_eval_depth--;
3058 if (backtrace.debug_on_exit)
3059 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
3060 backtrace_list = backtrace.next;
3061 return val;
3062}
3063\f
2f7c71a1 3064static Lisp_Object
defb1411 3065apply_lambda (Lisp_Object fun, Lisp_Object args)
db9f0278
JB
3066{
3067 Lisp_Object args_left;
f66c7cf8 3068 ptrdiff_t i, numargs;
db9f0278
JB
3069 register Lisp_Object *arg_vector;
3070 struct gcpro gcpro1, gcpro2, gcpro3;
db9f0278 3071 register Lisp_Object tem;
3a7a9129 3072 USE_SAFE_ALLOCA;
db9f0278 3073
f66c7cf8 3074 numargs = XFASTINT (Flength (args));
c5101a77 3075 SAFE_ALLOCA_LISP (arg_vector, numargs);
db9f0278
JB
3076 args_left = args;
3077
3078 GCPRO3 (*arg_vector, args_left, fun);
3079 gcpro1.nvars = 0;
3080
c5101a77 3081 for (i = 0; i < numargs; )
db9f0278
JB
3082 {
3083 tem = Fcar (args_left), args_left = Fcdr (args_left);
defb1411 3084 tem = eval_sub (tem);
db9f0278
JB
3085 arg_vector[i++] = tem;
3086 gcpro1.nvars = i;
3087 }
3088
3089 UNGCPRO;
3090
f07a954e
SM
3091 backtrace_list->args = arg_vector;
3092 backtrace_list->nargs = i;
c5101a77 3093 tem = funcall_lambda (fun, numargs, arg_vector);
db9f0278
JB
3094
3095 /* Do the debug-on-exit now, while arg_vector still exists. */
3096 if (backtrace_list->debug_on_exit)
3097 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
3098 /* Don't do it again when we return to eval. */
3099 backtrace_list->debug_on_exit = 0;
3a7a9129 3100 SAFE_FREE ();
db9f0278
JB
3101 return tem;
3102}
3103
3104/* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3105 and return the result of evaluation.
3106 FUN must be either a lambda-expression or a compiled-code object. */
3107
2901f1d1 3108static Lisp_Object
f66c7cf8 3109funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
c5101a77 3110 register Lisp_Object *arg_vector)
db9f0278 3111{
defb1411 3112 Lisp_Object val, syms_left, next, lexenv;
aed13378 3113 int count = SPECPDL_INDEX ();
f66c7cf8 3114 ptrdiff_t i;
c5101a77 3115 int optional, rest;
db9f0278 3116
90165123 3117 if (CONSP (fun))
9ab90667 3118 {
defb1411
SM
3119 if (EQ (XCAR (fun), Qclosure))
3120 {
3121 fun = XCDR (fun); /* Drop `closure'. */
3122 lexenv = XCAR (fun);
23aba0ea 3123 CHECK_LIST_CONS (fun, fun);
defb1411
SM
3124 }
3125 else
3126 lexenv = Qnil;
9ab90667
GM
3127 syms_left = XCDR (fun);
3128 if (CONSP (syms_left))
3129 syms_left = XCAR (syms_left);
3130 else
734d55a2 3131 xsignal1 (Qinvalid_function, fun);
9ab90667 3132 }
90165123 3133 else if (COMPILEDP (fun))
defb1411 3134 {
798cb644
SM
3135 syms_left = AREF (fun, COMPILED_ARGLIST);
3136 if (INTEGERP (syms_left))
876c194c
SM
3137 /* A byte-code object with a non-nil `push args' slot means we
3138 shouldn't bind any arguments, instead just call the byte-code
3139 interpreter directly; it will push arguments as necessary.
3140
9173deec 3141 Byte-code objects with either a non-existent, or a nil value for
876c194c
SM
3142 the `push args' slot (the default), have dynamically-bound
3143 arguments, and use the argument-binding code below instead (as do
3144 all interpreted functions, even lexically bound ones). */
3145 {
3146 /* If we have not actually read the bytecode string
3147 and constants vector yet, fetch them from the file. */
3148 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
3149 Ffetch_bytecode (fun);
3150 return exec_byte_code (AREF (fun, COMPILED_BYTECODE),
3151 AREF (fun, COMPILED_CONSTANTS),
3152 AREF (fun, COMPILED_STACK_DEPTH),
798cb644 3153 syms_left,
876c194c
SM
3154 nargs, arg_vector);
3155 }
defb1411
SM
3156 lexenv = Qnil;
3157 }
9ab90667
GM
3158 else
3159 abort ();
db9f0278 3160
9ab90667
GM
3161 i = optional = rest = 0;
3162 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
db9f0278
JB
3163 {
3164 QUIT;
177c0ea7 3165
9ab90667 3166 next = XCAR (syms_left);
8788120f 3167 if (!SYMBOLP (next))
734d55a2 3168 xsignal1 (Qinvalid_function, fun);
177c0ea7 3169
db9f0278
JB
3170 if (EQ (next, Qand_rest))
3171 rest = 1;
3172 else if (EQ (next, Qand_optional))
3173 optional = 1;
db9f0278 3174 else
db9f0278 3175 {
e610eaca 3176 Lisp_Object arg;
defb1411
SM
3177 if (rest)
3178 {
e610eaca 3179 arg = Flist (nargs - i, &arg_vector[i]);
defb1411
SM
3180 i = nargs;
3181 }
3182 else if (i < nargs)
e610eaca 3183 arg = arg_vector[i++];
b9598260
SM
3184 else if (!optional)
3185 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
3186 else
e610eaca 3187 arg = Qnil;
7200d79c 3188
b9598260 3189 /* Bind the argument. */
876c194c 3190 if (!NILP (lexenv) && SYMBOLP (next))
b9598260 3191 /* Lexically bind NEXT by adding it to the lexenv alist. */
e610eaca 3192 lexenv = Fcons (Fcons (next, arg), lexenv);
b9598260
SM
3193 else
3194 /* Dynamically bind NEXT. */
e610eaca 3195 specbind (next, arg);
db9f0278 3196 }
db9f0278
JB
3197 }
3198
9ab90667 3199 if (!NILP (syms_left))
734d55a2 3200 xsignal1 (Qinvalid_function, fun);
9ab90667 3201 else if (i < nargs)
734d55a2 3202 xsignal2 (Qwrong_number_of_arguments, fun, make_number (nargs));
db9f0278 3203
b9598260
SM
3204 if (!EQ (lexenv, Vinternal_interpreter_environment))
3205 /* Instantiate a new lexical environment. */
3206 specbind (Qinternal_interpreter_environment, lexenv);
3207
90165123 3208 if (CONSP (fun))
9ab90667 3209 val = Fprogn (XCDR (XCDR (fun)));
db9f0278 3210 else
ca248607
RS
3211 {
3212 /* If we have not actually read the bytecode string
3213 and constants vector yet, fetch them from the file. */
845975f5 3214 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
661c7d6e 3215 Ffetch_bytecode (fun);
b9598260
SM
3216 val = exec_byte_code (AREF (fun, COMPILED_BYTECODE),
3217 AREF (fun, COMPILED_CONSTANTS),
3218 AREF (fun, COMPILED_STACK_DEPTH),
3219 Qnil, 0, 0);
ca248607 3220 }
177c0ea7 3221
db9f0278
JB
3222 return unbind_to (count, val);
3223}
661c7d6e
KH
3224
3225DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
9dbc9081
PJ
3226 1, 1, 0,
3227 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
5842a27b 3228 (Lisp_Object object)
661c7d6e
KH
3229{
3230 Lisp_Object tem;
3231
845975f5 3232 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
661c7d6e 3233 {
845975f5 3234 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
5bbdb090 3235 if (!CONSP (tem))
845975f5
SM
3236 {
3237 tem = AREF (object, COMPILED_BYTECODE);
3238 if (CONSP (tem) && STRINGP (XCAR (tem)))
d5db4077 3239 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
845975f5
SM
3240 else
3241 error ("Invalid byte code");
3242 }
3ae565b3
SM
3243 ASET (object, COMPILED_BYTECODE, XCAR (tem));
3244 ASET (object, COMPILED_CONSTANTS, XCDR (tem));
661c7d6e
KH
3245 }
3246 return object;
3247}
db9f0278 3248\f
475545b5 3249static void
d3da34e0 3250grow_specpdl (void)
db9f0278 3251{
aed13378 3252 register int count = SPECPDL_INDEX ();
db9f0278
JB
3253 if (specpdl_size >= max_specpdl_size)
3254 {
3255 if (max_specpdl_size < 400)
3256 max_specpdl_size = 400;
3257 if (specpdl_size >= max_specpdl_size)
734d55a2 3258 signal_error ("Variable binding depth exceeds max-specpdl-size", Qnil);
db9f0278
JB
3259 }
3260 specpdl_size *= 2;
3261 if (specpdl_size > max_specpdl_size)
3262 specpdl_size = max_specpdl_size;
3263 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
3264 specpdl_ptr = specpdl + count;
3265}
3266
f6d62986 3267/* `specpdl_ptr->symbol' is a field which describes which variable is
4e2db1fe
SM
3268 let-bound, so it can be properly undone when we unbind_to.
3269 It can have the following two shapes:
3270 - SYMBOL : if it's a plain symbol, it means that we have let-bound
3271 a symbol that is not buffer-local (at least at the time
3272 the let binding started). Note also that it should not be
3273 aliased (i.e. when let-binding V1 that's aliased to V2, we want
3274 to record V2 here).
3275 - (SYMBOL WHERE . BUFFER) : this means that it is a let-binding for
3276 variable SYMBOL which can be buffer-local. WHERE tells us
3277 which buffer is affected (or nil if the let-binding affects the
3278 global value of the variable) and BUFFER tells us which buffer was
3279 current (i.e. if WHERE is non-nil, then BUFFER==WHERE, otherwise
3280 BUFFER did not yet have a buffer-local value). */
3281
db9f0278 3282void
d3da34e0 3283specbind (Lisp_Object symbol, Lisp_Object value)
db9f0278 3284{
ce5b453a
SM
3285 struct Lisp_Symbol *sym;
3286
3287 eassert (!handling_signal);
db9f0278 3288
b7826503 3289 CHECK_SYMBOL (symbol);
ce5b453a 3290 sym = XSYMBOL (symbol);
db9f0278
JB
3291 if (specpdl_ptr == specpdl + specpdl_size)
3292 grow_specpdl ();
719177b3 3293
ce5b453a
SM
3294 start:
3295 switch (sym->redirect)
719177b3 3296 {
ce5b453a
SM
3297 case SYMBOL_VARALIAS:
3298 sym = indirect_variable (sym); XSETSYMBOL (symbol, sym); goto start;
3299 case SYMBOL_PLAINVAL:
bb8e180f
AS
3300 /* The most common case is that of a non-constant symbol with a
3301 trivial value. Make that as fast as we can. */
3302 specpdl_ptr->symbol = symbol;
3303 specpdl_ptr->old_value = SYMBOL_VAL (sym);
3304 specpdl_ptr->func = NULL;
3305 ++specpdl_ptr;
3306 if (!sym->constant)
3307 SET_SYMBOL_VAL (sym, value);
3308 else
3309 set_internal (symbol, value, Qnil, 1);
3310 break;
4e2db1fe
SM
3311 case SYMBOL_LOCALIZED:
3312 if (SYMBOL_BLV (sym)->frame_local)
3313 error ("Frame-local vars cannot be let-bound");
3314 case SYMBOL_FORWARDED:
ce5b453a
SM
3315 {
3316 Lisp_Object ovalue = find_symbol_value (symbol);
3317 specpdl_ptr->func = 0;
3318 specpdl_ptr->old_value = ovalue;
3319
3320 eassert (sym->redirect != SYMBOL_LOCALIZED
3321 || (EQ (SYMBOL_BLV (sym)->where,
3322 SYMBOL_BLV (sym)->frame_local ?
3323 Fselected_frame () : Fcurrent_buffer ())));
3324
3325 if (sym->redirect == SYMBOL_LOCALIZED
3326 || BUFFER_OBJFWDP (SYMBOL_FWD (sym)))
3327 {
3328 Lisp_Object where, cur_buf = Fcurrent_buffer ();
3329
3330 /* For a local variable, record both the symbol and which
3331 buffer's or frame's value we are saving. */
3332 if (!NILP (Flocal_variable_p (symbol, Qnil)))
3333 {
3334 eassert (sym->redirect != SYMBOL_LOCALIZED
3335 || (BLV_FOUND (SYMBOL_BLV (sym))
3336 && EQ (cur_buf, SYMBOL_BLV (sym)->where)));
3337 where = cur_buf;
3338 }
3339 else if (sym->redirect == SYMBOL_LOCALIZED
3340 && BLV_FOUND (SYMBOL_BLV (sym)))
3341 where = SYMBOL_BLV (sym)->where;
3342 else
3343 where = Qnil;
3344
3345 /* We're not using the `unused' slot in the specbinding
3346 structure because this would mean we have to do more
3347 work for simple variables. */
3348 /* FIXME: The third value `current_buffer' is only used in
3349 let_shadows_buffer_binding_p which is itself only used
3350 in set_internal for local_if_set. */
4e2db1fe 3351 eassert (NILP (where) || EQ (where, cur_buf));
ce5b453a
SM
3352 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, cur_buf));
3353
3354 /* If SYMBOL is a per-buffer variable which doesn't have a
3355 buffer-local value here, make the `let' change the global
3356 value by changing the value of SYMBOL in all buffers not
3357 having their own value. This is consistent with what
3358 happens with other buffer-local variables. */
3359 if (NILP (where)
3360 && sym->redirect == SYMBOL_FORWARDED)
3361 {
3362 eassert (BUFFER_OBJFWDP (SYMBOL_FWD (sym)));
3363 ++specpdl_ptr;
3364 Fset_default (symbol, value);
3365 return;
3366 }
3367 }
3368 else
3369 specpdl_ptr->symbol = symbol;
3370
3371 specpdl_ptr++;
94b612ad 3372 set_internal (symbol, value, Qnil, 1);
ce5b453a
SM
3373 break;
3374 }
3375 default: abort ();
9ab90667 3376 }
db9f0278
JB
3377}
3378
3379void
d3da34e0 3380record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg)
db9f0278 3381{
9ba8e10d
CY
3382 eassert (!handling_signal);
3383
db9f0278
JB
3384 if (specpdl_ptr == specpdl + specpdl_size)
3385 grow_specpdl ();
3386 specpdl_ptr->func = function;
3387 specpdl_ptr->symbol = Qnil;
3388 specpdl_ptr->old_value = arg;
3389 specpdl_ptr++;
3390}
3391
3392Lisp_Object
d3da34e0 3393unbind_to (int count, Lisp_Object value)
db9f0278 3394{
5a073f50
KS
3395 Lisp_Object quitf = Vquit_flag;
3396 struct gcpro gcpro1, gcpro2;
db9f0278 3397
5a073f50 3398 GCPRO2 (value, quitf);
db9f0278
JB
3399 Vquit_flag = Qnil;
3400
3401 while (specpdl_ptr != specpdl + count)
3402 {
611a8f8c
RS
3403 /* Copy the binding, and decrement specpdl_ptr, before we do
3404 the work to unbind it. We decrement first
3405 so that an error in unbinding won't try to unbind
3406 the same entry again, and we copy the binding first
3407 in case more bindings are made during some of the code we run. */
eb700b82 3408
45f266dc
DL
3409 struct specbinding this_binding;
3410 this_binding = *--specpdl_ptr;
611a8f8c
RS
3411
3412 if (this_binding.func != 0)
3413 (*this_binding.func) (this_binding.old_value);
0967b4b0
GM
3414 /* If the symbol is a list, it is really (SYMBOL WHERE
3415 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
3416 frame. If WHERE is a buffer or frame, this indicates we
1b1acc13
PJ
3417 bound a variable that had a buffer-local or frame-local
3418 binding. WHERE nil means that the variable had the default
0967b4b0 3419 value when it was bound. CURRENT-BUFFER is the buffer that
bb8e180f 3420 was current when the variable was bound. */
611a8f8c 3421 else if (CONSP (this_binding.symbol))
719177b3 3422 {
eb700b82 3423 Lisp_Object symbol, where;
719177b3 3424
611a8f8c
RS
3425 symbol = XCAR (this_binding.symbol);
3426 where = XCAR (XCDR (this_binding.symbol));
719177b3 3427
eb700b82 3428 if (NILP (where))
611a8f8c 3429 Fset_default (symbol, this_binding.old_value);
94b612ad
SM
3430 /* If `where' is non-nil, reset the value in the appropriate
3431 local binding, but only if that binding still exists. */
4e2db1fe
SM
3432 else if (BUFFERP (where)
3433 ? !NILP (Flocal_variable_p (symbol, where))
3434 : !NILP (Fassq (symbol, XFRAME (where)->param_alist)))
3435 set_internal (symbol, this_binding.old_value, where, 1);
719177b3 3436 }
94b612ad
SM
3437 /* If variable has a trivial value (no forwarding), we can
3438 just set it. No need to check for constant symbols here,
3439 since that was already done by specbind. */
3440 else if (XSYMBOL (this_binding.symbol)->redirect == SYMBOL_PLAINVAL)
3441 SET_SYMBOL_VAL (XSYMBOL (this_binding.symbol),
3442 this_binding.old_value);
db9f0278 3443 else
94b612ad
SM
3444 /* NOTE: we only ever come here if make_local_foo was used for
3445 the first time on this var within this let. */
3446 Fset_default (this_binding.symbol, this_binding.old_value);
db9f0278 3447 }
177c0ea7 3448
5a073f50
KS
3449 if (NILP (Vquit_flag) && !NILP (quitf))
3450 Vquit_flag = quitf;
db9f0278
JB
3451
3452 UNGCPRO;
db9f0278
JB
3453 return value;
3454}
b9598260 3455
4a330052 3456DEFUN ("special-variable-p", Fspecial_variable_p, Sspecial_variable_p, 1, 1, 0,
b9598260
SM
3457 doc: /* Return non-nil if SYMBOL's global binding has been declared special.
3458A special variable is one that will be bound dynamically, even in a
3459context where binding is lexical by default. */)
c566235d 3460 (Lisp_Object symbol)
b9598260
SM
3461{
3462 CHECK_SYMBOL (symbol);
3463 return XSYMBOL (symbol)->declared_special ? Qt : Qnil;
3464}
3465
db9f0278 3466\f
db9f0278 3467DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
9dbc9081
PJ
3468 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
3469The debugger is entered when that frame exits, if the flag is non-nil. */)
5842a27b 3470 (Lisp_Object level, Lisp_Object flag)
db9f0278
JB
3471{
3472 register struct backtrace *backlist = backtrace_list;
3473 register int i;
3474
b7826503 3475 CHECK_NUMBER (level);
db9f0278
JB
3476
3477 for (i = 0; backlist && i < XINT (level); i++)
3478 {
3479 backlist = backlist->next;
3480 }
3481
3482 if (backlist)
265a9e55 3483 backlist->debug_on_exit = !NILP (flag);
db9f0278
JB
3484
3485 return flag;
3486}
3487
3488DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
9dbc9081
PJ
3489 doc: /* Print a trace of Lisp function calls currently active.
3490Output stream used is value of `standard-output'. */)
5842a27b 3491 (void)
db9f0278
JB
3492{
3493 register struct backtrace *backlist = backtrace_list;
db9f0278
JB
3494 Lisp_Object tail;
3495 Lisp_Object tem;
db9f0278 3496 struct gcpro gcpro1;
d4b6d95d 3497 Lisp_Object old_print_level = Vprint_level;
db9f0278 3498
d4b6d95d
LMI
3499 if (NILP (Vprint_level))
3500 XSETFASTINT (Vprint_level, 8);
db9f0278
JB
3501
3502 tail = Qnil;
3503 GCPRO1 (tail);
3504
3505 while (backlist)
3506 {
3507 write_string (backlist->debug_on_exit ? "* " : " ", 2);
44f230aa 3508 if (backlist->nargs == UNEVALLED)
db9f0278
JB
3509 {
3510 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
b6703b02 3511 write_string ("\n", -1);
db9f0278
JB
3512 }
3513 else
3514 {
3515 tem = *backlist->function;
f6d62986 3516 Fprin1 (tem, Qnil); /* This can QUIT. */
db9f0278 3517 write_string ("(", -1);
44f230aa
SM
3518 if (backlist->nargs == MANY)
3519 { /* FIXME: Can this happen? */
a3eed478 3520 int i;
db9f0278 3521 for (tail = *backlist->args, i = 0;
265a9e55 3522 !NILP (tail);
a3eed478 3523 tail = Fcdr (tail), i = 1)
db9f0278
JB
3524 {
3525 if (i) write_string (" ", -1);
3526 Fprin1 (Fcar (tail), Qnil);
3527 }
3528 }
3529 else
3530 {
f66c7cf8 3531 ptrdiff_t i;
db9f0278
JB
3532 for (i = 0; i < backlist->nargs; i++)
3533 {
3534 if (i) write_string (" ", -1);
3535 Fprin1 (backlist->args[i], Qnil);
3536 }
3537 }
b6703b02 3538 write_string (")\n", -1);
db9f0278 3539 }
db9f0278
JB
3540 backlist = backlist->next;
3541 }
3542
d4b6d95d 3543 Vprint_level = old_print_level;
db9f0278
JB
3544 UNGCPRO;
3545 return Qnil;
3546}
3547
17401c97 3548DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
9dbc9081
PJ
3549 doc: /* Return the function and arguments NFRAMES up from current execution point.
3550If that frame has not evaluated the arguments yet (or is a special form),
3551the value is (nil FUNCTION ARG-FORMS...).
3552If that frame has evaluated its arguments and called its function already,
3553the value is (t FUNCTION ARG-VALUES...).
3554A &rest arg is represented as the tail of the list ARG-VALUES.
3555FUNCTION is whatever was supplied as car of evaluated list,
3556or a lambda expression for macro calls.
3557If NFRAMES is more than the number of frames, the value is nil. */)
5842a27b 3558 (Lisp_Object nframes)
db9f0278
JB
3559{
3560 register struct backtrace *backlist = backtrace_list;
5d5d959d 3561 register EMACS_INT i;
db9f0278
JB
3562 Lisp_Object tem;
3563
b7826503 3564 CHECK_NATNUM (nframes);
db9f0278
JB
3565
3566 /* Find the frame requested. */
b6703b02 3567 for (i = 0; backlist && i < XFASTINT (nframes); i++)
db9f0278
JB
3568 backlist = backlist->next;
3569
3570 if (!backlist)
3571 return Qnil;
44f230aa 3572 if (backlist->nargs == UNEVALLED)
db9f0278
JB
3573 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
3574 else
3575 {
44f230aa 3576 if (backlist->nargs == MANY) /* FIXME: Can this happen? */
db9f0278
JB
3577 tem = *backlist->args;
3578 else
3579 tem = Flist (backlist->nargs, backlist->args);
3580
3581 return Fcons (Qt, Fcons (*backlist->function, tem));
3582 }
3583}
a2ff3819 3584
db9f0278 3585\f
244ed907 3586#if BYTE_MARK_STACK
4ce0541e 3587void
d3da34e0 3588mark_backtrace (void)
4ce0541e
SM
3589{
3590 register struct backtrace *backlist;
f66c7cf8 3591 ptrdiff_t i;
4ce0541e
SM
3592
3593 for (backlist = backtrace_list; backlist; backlist = backlist->next)
3594 {
3595 mark_object (*backlist->function);
3596
44f230aa
SM
3597 if (backlist->nargs == UNEVALLED
3598 || backlist->nargs == MANY) /* FIXME: Can this happen? */
c5101a77 3599 i = 1;
4ce0541e 3600 else
c5101a77
PE
3601 i = backlist->nargs;
3602 while (i--)
4ce0541e
SM
3603 mark_object (backlist->args[i]);
3604 }
3605}
244ed907 3606#endif
4ce0541e 3607
dfcf069d 3608void
d3da34e0 3609syms_of_eval (void)
db9f0278 3610{
29208e82 3611 DEFVAR_INT ("max-specpdl-size", max_specpdl_size,
82fc29a1 3612 doc: /* *Limit on number of Lisp variable bindings and `unwind-protect's.
9f5903bb 3613If Lisp code tries to increase the total number past this amount,
2520dc0c
RS
3614an error is signaled.
3615You can safely use a value considerably larger than the default value,
3616if that proves inconveniently small. However, if you increase it too far,
3617Emacs could run out of memory trying to make the stack bigger. */);
db9f0278 3618
29208e82 3619 DEFVAR_INT ("max-lisp-eval-depth", max_lisp_eval_depth,
9dbc9081 3620 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
2520dc0c
RS
3621
3622This limit serves to catch infinite recursions for you before they cause
9dbc9081
PJ
3623actual stack overflow in C, which would be fatal for Emacs.
3624You can safely make it considerably larger than its default value,
2520dc0c
RS
3625if that proves inconveniently small. However, if you increase it too far,
3626Emacs could overflow the real C stack, and crash. */);
db9f0278 3627
29208e82 3628 DEFVAR_LISP ("quit-flag", Vquit_flag,
9dbc9081 3629 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
42ed718e
RS
3630If the value is t, that means do an ordinary quit.
3631If the value equals `throw-on-input', that means quit by throwing
3632to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
3633Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
3634but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
db9f0278
JB
3635 Vquit_flag = Qnil;
3636
29208e82 3637 DEFVAR_LISP ("inhibit-quit", Vinhibit_quit,
9dbc9081
PJ
3638 doc: /* Non-nil inhibits C-g quitting from happening immediately.
3639Note that `quit-flag' will still be set by typing C-g,
3640so a quit will be signaled as soon as `inhibit-quit' is nil.
3641To prevent this happening, set `quit-flag' to nil
3642before making `inhibit-quit' nil. */);
db9f0278
JB
3643 Vinhibit_quit = Qnil;
3644
cd3520a4
JB
3645 DEFSYM (Qinhibit_quit, "inhibit-quit");
3646 DEFSYM (Qautoload, "autoload");
3647 DEFSYM (Qdebug_on_error, "debug-on-error");
3648 DEFSYM (Qmacro, "macro");
3649 DEFSYM (Qdeclare, "declare");
177c0ea7 3650
db9f0278
JB
3651 /* Note that the process handling also uses Qexit, but we don't want
3652 to staticpro it twice, so we just do it here. */
cd3520a4 3653 DEFSYM (Qexit, "exit");
b9598260 3654
cd3520a4
JB
3655 DEFSYM (Qinteractive, "interactive");
3656 DEFSYM (Qcommandp, "commandp");
3657 DEFSYM (Qdefun, "defun");
3658 DEFSYM (Qand_rest, "&rest");
3659 DEFSYM (Qand_optional, "&optional");
3660 DEFSYM (Qclosure, "closure");
3661 DEFSYM (Qdebug, "debug");
f01cbfdd 3662
29208e82 3663 DEFVAR_LISP ("debug-on-error", Vdebug_on_error,
9dbc9081
PJ
3664 doc: /* *Non-nil means enter debugger if an error is signaled.
3665Does not apply to errors handled by `condition-case' or those
3666matched by `debug-ignored-errors'.
3667If the value is a list, an error only means to enter the debugger
3668if one of its condition symbols appears in the list.
3669When you evaluate an expression interactively, this variable
3670is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
fbbdcf2f
CY
3671The command `toggle-debug-on-error' toggles this.
3672See also the variable `debug-on-quit'. */);
128c0f66 3673 Vdebug_on_error = Qnil;
db9f0278 3674
29208e82 3675 DEFVAR_LISP ("debug-ignored-errors", Vdebug_ignored_errors,
9dbc9081
PJ
3676 doc: /* *List of errors for which the debugger should not be called.
3677Each element may be a condition-name or a regexp that matches error messages.
3678If any element applies to a given error, that error skips the debugger
3679and just returns to top level.
3680This overrides the variable `debug-on-error'.
3681It does not apply to errors handled by `condition-case'. */);
fc950e09
KH
3682 Vdebug_ignored_errors = Qnil;
3683
29208e82 3684 DEFVAR_BOOL ("debug-on-quit", debug_on_quit,
82fc29a1
JB
3685 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
3686Does not apply if quit is handled by a `condition-case'. */);
db9f0278
JB
3687 debug_on_quit = 0;
3688
29208e82 3689 DEFVAR_BOOL ("debug-on-next-call", debug_on_next_call,
9dbc9081 3690 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
db9f0278 3691
29208e82 3692 DEFVAR_BOOL ("debugger-may-continue", debugger_may_continue,
9dbc9081
PJ
3693 doc: /* Non-nil means debugger may continue execution.
3694This is nil when the debugger is called under circumstances where it
3695might not be safe to continue. */);
dac204bc 3696 debugger_may_continue = 1;
556d7314 3697
29208e82 3698 DEFVAR_LISP ("debugger", Vdebugger,
9dbc9081
PJ
3699 doc: /* Function to call to invoke debugger.
3700If due to frame exit, args are `exit' and the value being returned;
3701 this function's value will be returned instead of that.
3702If due to error, args are `error' and a list of the args to `signal'.
3703If due to `apply' or `funcall' entry, one arg, `lambda'.
3704If due to `eval' entry, one arg, t. */);
db9f0278
JB
3705 Vdebugger = Qnil;
3706
29208e82 3707 DEFVAR_LISP ("signal-hook-function", Vsignal_hook_function,
9dbc9081
PJ
3708 doc: /* If non-nil, this is a function for `signal' to call.
3709It receives the same arguments that `signal' was given.
3710The Edebug package uses this to regain control. */);
61ede770
RS
3711 Vsignal_hook_function = Qnil;
3712
29208e82 3713 DEFVAR_LISP ("debug-on-signal", Vdebug_on_signal,
9dbc9081
PJ
3714 doc: /* *Non-nil means call the debugger regardless of condition handlers.
3715Note that `debug-on-error', `debug-on-quit' and friends
3716still determine whether to handle the particular condition. */);
57a6e758 3717 Vdebug_on_signal = Qnil;
61ede770 3718
29208e82 3719 DEFVAR_LISP ("macro-declaration-function", Vmacro_declaration_function,
d6edd563
GM
3720 doc: /* Function to process declarations in a macro definition.
3721The function will be called with two args MACRO and DECL.
3722MACRO is the name of the macro being defined.
3723DECL is a list `(declare ...)' containing the declarations.
3724The value the function returns is not used. */);
3725 Vmacro_declaration_function = Qnil;
3726
b38b1ec0
SM
3727 /* When lexical binding is being used,
3728 vinternal_interpreter_environment is non-nil, and contains an alist
3729 of lexically-bound variable, or (t), indicating an empty
3730 environment. The lisp name of this variable would be
3731 `internal-interpreter-environment' if it weren't hidden.
3732 Every element of this list can be either a cons (VAR . VAL)
3733 specifying a lexical binding, or a single symbol VAR indicating
3734 that this variable should use dynamic scoping. */
cd3520a4 3735 DEFSYM (Qinternal_interpreter_environment, "internal-interpreter-environment");
b38b1ec0
SM
3736 DEFVAR_LISP ("internal-interpreter-environment",
3737 Vinternal_interpreter_environment,
b9598260
SM
3738 doc: /* If non-nil, the current lexical environment of the lisp interpreter.
3739When lexical binding is not being used, this variable is nil.
3740A value of `(t)' indicates an empty environment, otherwise it is an
3741alist of active lexical bindings. */);
3742 Vinternal_interpreter_environment = Qnil;
b38b1ec0
SM
3743 /* Don't export this variable to Elisp, so noone can mess with it
3744 (Just imagine if someone makes it buffer-local). */
3745 Funintern (Qinternal_interpreter_environment, Qnil);
b9598260 3746
cd3520a4 3747 DEFSYM (Vrun_hooks, "run-hooks");
db9f0278
JB
3748
3749 staticpro (&Vautoload_queue);
3750 Vautoload_queue = Qnil;
a2ff3819
GM
3751 staticpro (&Vsignaling_function);
3752 Vsignaling_function = Qnil;
db9f0278
JB
3753
3754 defsubr (&Sor);
3755 defsubr (&Sand);
3756 defsubr (&Sif);
3757 defsubr (&Scond);
3758 defsubr (&Sprogn);
3759 defsubr (&Sprog1);
3760 defsubr (&Sprog2);
3761 defsubr (&Ssetq);
3762 defsubr (&Squote);
3763 defsubr (&Sfunction);
3764 defsubr (&Sdefun);
3765 defsubr (&Sdefmacro);
3766 defsubr (&Sdefvar);
19cebf5a 3767 defsubr (&Sdefvaralias);
db9f0278
JB
3768 defsubr (&Sdefconst);
3769 defsubr (&Suser_variable_p);
3770 defsubr (&Slet);
3771 defsubr (&SletX);
3772 defsubr (&Swhile);
3773 defsubr (&Smacroexpand);
3774 defsubr (&Scatch);
3775 defsubr (&Sthrow);
3776 defsubr (&Sunwind_protect);
3777 defsubr (&Scondition_case);
3778 defsubr (&Ssignal);
3779 defsubr (&Sinteractive_p);
4b664e76 3780 defsubr (&Scalled_interactively_p);
db9f0278
JB
3781 defsubr (&Scommandp);
3782 defsubr (&Sautoload);
3783 defsubr (&Seval);
3784 defsubr (&Sapply);
3785 defsubr (&Sfuncall);
ff936e53
SM
3786 defsubr (&Srun_hooks);
3787 defsubr (&Srun_hook_with_args);
3788 defsubr (&Srun_hook_with_args_until_success);
3789 defsubr (&Srun_hook_with_args_until_failure);
f6d62986 3790 defsubr (&Srun_hook_wrapped);
661c7d6e 3791 defsubr (&Sfetch_bytecode);
db9f0278
JB
3792 defsubr (&Sbacktrace_debug);
3793 defsubr (&Sbacktrace);
3794 defsubr (&Sbacktrace_frame);
4a330052 3795 defsubr (&Sspecial_variable_p);
b9598260 3796 defsubr (&Sfunctionp);
db9f0278 3797}