Commit | Line | Data |
---|---|---|
db9f0278 | 1 | /* Evaluator for GNU Emacs Lisp interpreter. |
1182a7cb DL |
2 | Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000 |
3 | Free Software Foundation, Inc. | |
db9f0278 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
7 | GNU Emacs is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
96277b2d | 9 | the Free Software Foundation; either version 2, or (at your option) |
db9f0278 JB |
10 | any later version. |
11 | ||
12 | GNU Emacs is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
19 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
20 | Boston, MA 02111-1307, USA. */ | |
db9f0278 JB |
21 | |
22 | ||
18160b98 | 23 | #include <config.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" |
db9f0278 JB |
29 | #include <setjmp.h> |
30 | ||
31 | /* This definition is duplicated in alloc.c and keyboard.c */ | |
32 | /* Putting it in lisp.h makes cc bomb out! */ | |
33 | ||
34 | struct backtrace | |
35 | { | |
36 | struct backtrace *next; | |
37 | Lisp_Object *function; | |
38 | Lisp_Object *args; /* Points to vector of args. */ | |
daa37602 JB |
39 | int nargs; /* Length of vector. |
40 | If nargs is UNEVALLED, args points to slot holding | |
41 | list of unevalled args */ | |
db9f0278 JB |
42 | char evalargs; |
43 | /* Nonzero means call value of debugger when done with this operation. */ | |
44 | char debug_on_exit; | |
45 | }; | |
46 | ||
47 | struct backtrace *backtrace_list; | |
48 | ||
82da7701 JB |
49 | /* This structure helps implement the `catch' and `throw' control |
50 | structure. A struct catchtag contains all the information needed | |
51 | to restore the state of the interpreter after a non-local jump. | |
52 | ||
53 | Handlers for error conditions (represented by `struct handler' | |
54 | structures) just point to a catch tag to do the cleanup required | |
55 | for their jumps. | |
56 | ||
57 | catchtag structures are chained together in the C calling stack; | |
58 | the `next' member points to the next outer catchtag. | |
59 | ||
60 | A call like (throw TAG VAL) searches for a catchtag whose `tag' | |
61 | member is TAG, and then unbinds to it. The `val' member is used to | |
62 | hold VAL while the stack is unwound; `val' is returned as the value | |
63 | of the catch form. | |
64 | ||
65 | All the other members are concerned with restoring the interpreter | |
66 | state. */ | |
db9f0278 JB |
67 | struct catchtag |
68 | { | |
69 | Lisp_Object tag; | |
70 | Lisp_Object val; | |
71 | struct catchtag *next; | |
72 | struct gcpro *gcpro; | |
73 | jmp_buf jmp; | |
74 | struct backtrace *backlist; | |
75 | struct handler *handlerlist; | |
76 | int lisp_eval_depth; | |
77 | int pdlcount; | |
78 | int poll_suppress_count; | |
bcf28080 | 79 | struct byte_stack *byte_stack; |
db9f0278 JB |
80 | }; |
81 | ||
82 | struct catchtag *catchlist; | |
83 | ||
15934ffa RS |
84 | #ifdef DEBUG_GCPRO |
85 | /* Count levels of GCPRO to detect failure to UNGCPRO. */ | |
86 | int gcpro_level; | |
87 | #endif | |
88 | ||
db9f0278 | 89 | Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun; |
ad236261 | 90 | Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag; |
db9f0278 JB |
91 | Lisp_Object Qmocklisp_arguments, Vmocklisp_arguments, Qmocklisp; |
92 | Lisp_Object Qand_rest, Qand_optional; | |
93 | Lisp_Object Qdebug_on_error; | |
94 | ||
6e6e9f08 RS |
95 | /* This holds either the symbol `run-hooks' or nil. |
96 | It is nil at an early stage of startup, and when Emacs | |
97 | is shutting down. */ | |
db9f0278 JB |
98 | Lisp_Object Vrun_hooks; |
99 | ||
100 | /* Non-nil means record all fset's and provide's, to be undone | |
101 | if the file being autoloaded is not fully loaded. | |
102 | They are recorded by being consed onto the front of Vautoload_queue: | |
103 | (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */ | |
104 | ||
105 | Lisp_Object Vautoload_queue; | |
106 | ||
107 | /* Current number of specbindings allocated in specpdl. */ | |
108 | int specpdl_size; | |
109 | ||
110 | /* Pointer to beginning of specpdl. */ | |
111 | struct specbinding *specpdl; | |
112 | ||
113 | /* Pointer to first unused element in specpdl. */ | |
114 | struct specbinding *specpdl_ptr; | |
115 | ||
116 | /* Maximum size allowed for specpdl allocation */ | |
117 | int max_specpdl_size; | |
118 | ||
119 | /* Depth in Lisp evaluations and function calls. */ | |
120 | int lisp_eval_depth; | |
121 | ||
122 | /* Maximum allowed depth in Lisp evaluations and function calls. */ | |
123 | int max_lisp_eval_depth; | |
124 | ||
125 | /* Nonzero means enter debugger before next function call */ | |
126 | int debug_on_next_call; | |
127 | ||
556d7314 GM |
128 | /* Non-zero means debuffer may continue. This is zero when the |
129 | debugger is called during redisplay, where it might not be safe to | |
130 | continue the interrupted redisplay. */ | |
131 | ||
132 | int debugger_may_continue; | |
133 | ||
128c0f66 | 134 | /* List of conditions (non-nil atom means all) which cause a backtrace |
4de86b16 | 135 | if an error is handled by the command loop's error handler. */ |
128c0f66 | 136 | Lisp_Object Vstack_trace_on_error; |
db9f0278 | 137 | |
128c0f66 | 138 | /* List of conditions (non-nil atom means all) which enter the debugger |
4de86b16 | 139 | if an error is handled by the command loop's error handler. */ |
128c0f66 | 140 | Lisp_Object Vdebug_on_error; |
db9f0278 | 141 | |
fc950e09 KH |
142 | /* List of conditions and regexps specifying error messages which |
143 | do not enter the debugger even if Vdebug_on_errors says they should. */ | |
144 | Lisp_Object Vdebug_ignored_errors; | |
145 | ||
61ede770 | 146 | /* Non-nil means call the debugger even if the error will be handled. */ |
57a6e758 | 147 | Lisp_Object Vdebug_on_signal; |
61ede770 RS |
148 | |
149 | /* Hook for edebug to use. */ | |
150 | Lisp_Object Vsignal_hook_function; | |
151 | ||
db9f0278 | 152 | /* Nonzero means enter debugger if a quit signal |
128c0f66 | 153 | is handled by the command loop's error handler. */ |
db9f0278 JB |
154 | int debug_on_quit; |
155 | ||
be857679 | 156 | /* The value of num_nonmacro_input_events as of the last time we |
82da7701 | 157 | started to enter the debugger. If we decide to enter the debugger |
be857679 | 158 | again when this is still equal to num_nonmacro_input_events, then we |
82da7701 JB |
159 | know that the debugger itself has an error, and we should just |
160 | signal the error instead of entering an infinite loop of debugger | |
161 | invocations. */ | |
162 | int when_entered_debugger; | |
db9f0278 JB |
163 | |
164 | Lisp_Object Vdebugger; | |
165 | ||
166 | void specbind (), record_unwind_protect (); | |
167 | ||
420e60e6 RS |
168 | Lisp_Object run_hook_with_args (); |
169 | ||
db9f0278 JB |
170 | Lisp_Object funcall_lambda (); |
171 | extern Lisp_Object ml_apply (); /* Apply a mocklisp function to unevaluated argument list */ | |
172 | ||
dfcf069d | 173 | void |
db9f0278 JB |
174 | init_eval_once () |
175 | { | |
176 | specpdl_size = 50; | |
716acfce | 177 | specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding)); |
270e8074 | 178 | specpdl_ptr = specpdl; |
db9f0278 | 179 | max_specpdl_size = 600; |
969f5145 | 180 | max_lisp_eval_depth = 300; |
34d470ba RS |
181 | |
182 | Vrun_hooks = Qnil; | |
db9f0278 JB |
183 | } |
184 | ||
dfcf069d | 185 | void |
db9f0278 JB |
186 | init_eval () |
187 | { | |
188 | specpdl_ptr = specpdl; | |
189 | catchlist = 0; | |
190 | handlerlist = 0; | |
191 | backtrace_list = 0; | |
192 | Vquit_flag = Qnil; | |
193 | debug_on_next_call = 0; | |
194 | lisp_eval_depth = 0; | |
87e21fbd | 195 | #ifdef DEBUG_GCPRO |
15934ffa | 196 | gcpro_level = 0; |
87e21fbd | 197 | #endif |
be857679 | 198 | /* This is less than the initial value of num_nonmacro_input_events. */ |
b5b911f9 | 199 | when_entered_debugger = -1; |
db9f0278 JB |
200 | } |
201 | ||
202 | Lisp_Object | |
203 | call_debugger (arg) | |
204 | Lisp_Object arg; | |
205 | { | |
3648c842 | 206 | int debug_while_redisplaying; |
556d7314 | 207 | int count = specpdl_ptr - specpdl; |
3648c842 GM |
208 | Lisp_Object val; |
209 | ||
db9f0278 JB |
210 | if (lisp_eval_depth + 20 > max_lisp_eval_depth) |
211 | max_lisp_eval_depth = lisp_eval_depth + 20; | |
3648c842 | 212 | |
db9f0278 JB |
213 | if (specpdl_size + 40 > max_specpdl_size) |
214 | max_specpdl_size = specpdl_size + 40; | |
3648c842 | 215 | |
db9f0278 | 216 | debug_on_next_call = 0; |
be857679 | 217 | when_entered_debugger = num_nonmacro_input_events; |
3648c842 GM |
218 | |
219 | /* Resetting redisplaying_p to 0 makes sure that debug output is | |
220 | displayed if the debugger is invoked during redisplay. */ | |
221 | debug_while_redisplaying = redisplaying_p; | |
222 | redisplaying_p = 0; | |
556d7314 GM |
223 | specbind (intern ("debugger-may-continue"), |
224 | debug_while_redisplaying ? Qnil : Qt); | |
3648c842 GM |
225 | |
226 | val = apply1 (Vdebugger, arg); | |
227 | ||
228 | /* Interrupting redisplay and resuming it later is not safe under | |
229 | all circumstances. So, when the debugger returns, abort the | |
230 | interupted redisplay by going back to the top-level. */ | |
231 | if (debug_while_redisplaying) | |
232 | Ftop_level (); | |
233 | ||
556d7314 | 234 | return unbind_to (count, val); |
db9f0278 JB |
235 | } |
236 | ||
dfcf069d | 237 | void |
db9f0278 JB |
238 | do_debug_on_call (code) |
239 | Lisp_Object code; | |
240 | { | |
241 | debug_on_next_call = 0; | |
242 | backtrace_list->debug_on_exit = 1; | |
243 | call_debugger (Fcons (code, Qnil)); | |
244 | } | |
245 | \f | |
246 | /* NOTE!!! Every function that can call EVAL must protect its args | |
247 | and temporaries from garbage collection while it needs them. | |
248 | The definition of `For' shows what you have to do. */ | |
249 | ||
250 | DEFUN ("or", For, Sor, 0, UNEVALLED, 0, | |
251 | "Eval args until one of them yields non-nil, then return that value.\n\ | |
252 | The remaining args are not evalled at all.\n\ | |
253 | If all args return nil, return nil.") | |
254 | (args) | |
255 | Lisp_Object args; | |
256 | { | |
257 | register Lisp_Object val; | |
258 | Lisp_Object args_left; | |
259 | struct gcpro gcpro1; | |
260 | ||
265a9e55 | 261 | if (NILP(args)) |
db9f0278 JB |
262 | return Qnil; |
263 | ||
264 | args_left = args; | |
265 | GCPRO1 (args_left); | |
266 | ||
267 | do | |
268 | { | |
269 | val = Feval (Fcar (args_left)); | |
265a9e55 | 270 | if (!NILP (val)) |
db9f0278 JB |
271 | break; |
272 | args_left = Fcdr (args_left); | |
273 | } | |
265a9e55 | 274 | while (!NILP(args_left)); |
db9f0278 JB |
275 | |
276 | UNGCPRO; | |
277 | return val; | |
278 | } | |
279 | ||
280 | DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0, | |
281 | "Eval args until one of them yields nil, then return nil.\n\ | |
282 | The remaining args are not evalled at all.\n\ | |
283 | If no arg yields nil, return the last arg's value.") | |
284 | (args) | |
285 | Lisp_Object args; | |
286 | { | |
287 | register Lisp_Object val; | |
288 | Lisp_Object args_left; | |
289 | struct gcpro gcpro1; | |
290 | ||
265a9e55 | 291 | if (NILP(args)) |
db9f0278 JB |
292 | return Qt; |
293 | ||
294 | args_left = args; | |
295 | GCPRO1 (args_left); | |
296 | ||
297 | do | |
298 | { | |
299 | val = Feval (Fcar (args_left)); | |
265a9e55 | 300 | if (NILP (val)) |
db9f0278 JB |
301 | break; |
302 | args_left = Fcdr (args_left); | |
303 | } | |
265a9e55 | 304 | while (!NILP(args_left)); |
db9f0278 JB |
305 | |
306 | UNGCPRO; | |
307 | return val; | |
308 | } | |
309 | ||
310 | DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0, | |
1182a7cb | 311 | "If COND yields non-nil, do THEN, else do ELSE...\n\ |
db9f0278 JB |
312 | Returns the value of THEN or the value of the last of the ELSE's.\n\ |
313 | THEN must be one expression, but ELSE... can be zero or more expressions.\n\ | |
314 | If COND yields nil, and there are no ELSE's, the value is nil.") | |
315 | (args) | |
316 | Lisp_Object args; | |
317 | { | |
318 | register Lisp_Object cond; | |
319 | struct gcpro gcpro1; | |
320 | ||
321 | GCPRO1 (args); | |
322 | cond = Feval (Fcar (args)); | |
323 | UNGCPRO; | |
324 | ||
265a9e55 | 325 | if (!NILP (cond)) |
db9f0278 JB |
326 | return Feval (Fcar (Fcdr (args))); |
327 | return Fprogn (Fcdr (Fcdr (args))); | |
328 | } | |
329 | ||
330 | DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0, | |
1182a7cb | 331 | "Try each clause until one succeeds.\n\ |
db9f0278 JB |
332 | Each clause looks like (CONDITION BODY...). CONDITION is evaluated\n\ |
333 | and, if the value is non-nil, this clause succeeds:\n\ | |
334 | then the expressions in BODY are evaluated and the last one's\n\ | |
335 | value is the value of the cond-form.\n\ | |
336 | If no clause succeeds, cond returns nil.\n\ | |
337 | If a clause has one element, as in (CONDITION),\n\ | |
338 | CONDITION's value if non-nil is returned from the cond-form.") | |
339 | (args) | |
340 | Lisp_Object args; | |
341 | { | |
342 | register Lisp_Object clause, val; | |
343 | struct gcpro gcpro1; | |
344 | ||
345 | val = Qnil; | |
346 | GCPRO1 (args); | |
265a9e55 | 347 | while (!NILP (args)) |
db9f0278 JB |
348 | { |
349 | clause = Fcar (args); | |
350 | val = Feval (Fcar (clause)); | |
265a9e55 | 351 | if (!NILP (val)) |
db9f0278 | 352 | { |
03699b14 KR |
353 | if (!EQ (XCDR (clause), Qnil)) |
354 | val = Fprogn (XCDR (clause)); | |
db9f0278 JB |
355 | break; |
356 | } | |
03699b14 | 357 | args = XCDR (args); |
db9f0278 JB |
358 | } |
359 | UNGCPRO; | |
360 | ||
361 | return val; | |
362 | } | |
363 | ||
364 | DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0, | |
1182a7cb | 365 | "Eval BODY forms sequentially and return value of last one.") |
db9f0278 JB |
366 | (args) |
367 | Lisp_Object args; | |
368 | { | |
369 | register Lisp_Object val, tem; | |
370 | Lisp_Object args_left; | |
371 | struct gcpro gcpro1; | |
372 | ||
373 | /* In Mocklisp code, symbols at the front of the progn arglist | |
374 | are to be bound to zero. */ | |
375 | if (!EQ (Vmocklisp_arguments, Qt)) | |
376 | { | |
377 | val = make_number (0); | |
90165123 | 378 | while (!NILP (args) && (tem = Fcar (args), SYMBOLP (tem))) |
db9f0278 JB |
379 | { |
380 | QUIT; | |
381 | specbind (tem, val), args = Fcdr (args); | |
382 | } | |
383 | } | |
384 | ||
265a9e55 | 385 | if (NILP(args)) |
db9f0278 JB |
386 | return Qnil; |
387 | ||
388 | args_left = args; | |
389 | GCPRO1 (args_left); | |
390 | ||
391 | do | |
392 | { | |
393 | val = Feval (Fcar (args_left)); | |
394 | args_left = Fcdr (args_left); | |
395 | } | |
265a9e55 | 396 | while (!NILP(args_left)); |
db9f0278 JB |
397 | |
398 | UNGCPRO; | |
399 | return val; | |
400 | } | |
401 | ||
402 | DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0, | |
1182a7cb | 403 | "Eval FIRST and BODY sequentially; value from FIRST.\n\ |
db9f0278 JB |
404 | The value of FIRST is saved during the evaluation of the remaining args,\n\ |
405 | whose values are discarded.") | |
406 | (args) | |
407 | Lisp_Object args; | |
408 | { | |
409 | Lisp_Object val; | |
410 | register Lisp_Object args_left; | |
411 | struct gcpro gcpro1, gcpro2; | |
412 | register int argnum = 0; | |
413 | ||
265a9e55 | 414 | if (NILP(args)) |
db9f0278 JB |
415 | return Qnil; |
416 | ||
417 | args_left = args; | |
418 | val = Qnil; | |
419 | GCPRO2 (args, val); | |
420 | ||
421 | do | |
422 | { | |
423 | if (!(argnum++)) | |
424 | val = Feval (Fcar (args_left)); | |
425 | else | |
426 | Feval (Fcar (args_left)); | |
427 | args_left = Fcdr (args_left); | |
428 | } | |
265a9e55 | 429 | while (!NILP(args_left)); |
db9f0278 JB |
430 | |
431 | UNGCPRO; | |
432 | return val; | |
433 | } | |
434 | ||
435 | DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0, | |
1182a7cb | 436 | "Eval X, Y and BODY sequentially; value from Y.\n\ |
db9f0278 JB |
437 | The value of Y is saved during the evaluation of the remaining args,\n\ |
438 | whose values are discarded.") | |
439 | (args) | |
440 | Lisp_Object args; | |
441 | { | |
442 | Lisp_Object val; | |
443 | register Lisp_Object args_left; | |
444 | struct gcpro gcpro1, gcpro2; | |
445 | register int argnum = -1; | |
446 | ||
447 | val = Qnil; | |
448 | ||
87d238ba | 449 | if (NILP (args)) |
db9f0278 JB |
450 | return Qnil; |
451 | ||
452 | args_left = args; | |
453 | val = Qnil; | |
454 | GCPRO2 (args, val); | |
455 | ||
456 | do | |
457 | { | |
458 | if (!(argnum++)) | |
459 | val = Feval (Fcar (args_left)); | |
460 | else | |
461 | Feval (Fcar (args_left)); | |
462 | args_left = Fcdr (args_left); | |
463 | } | |
87d238ba | 464 | while (!NILP (args_left)); |
db9f0278 JB |
465 | |
466 | UNGCPRO; | |
467 | return val; | |
468 | } | |
469 | ||
470 | DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0, | |
1182a7cb | 471 | "Set each SYM to the value of its VAL.\n\ |
b0d75191 RS |
472 | The symbols SYM are variables; they are literal (not evaluated).\n\ |
473 | The values VAL are expressions; they are evaluated.\n\ | |
474 | Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.\n\ | |
475 | The second VAL is not computed until after the first SYM is set, and so on;\n\ | |
476 | each VAL can use the new value of variables set earlier in the `setq'.\n\ | |
196e7d3f | 477 | The return value of the `setq' form is the value of the last VAL.") |
db9f0278 JB |
478 | (args) |
479 | Lisp_Object args; | |
480 | { | |
481 | register Lisp_Object args_left; | |
482 | register Lisp_Object val, sym; | |
483 | struct gcpro gcpro1; | |
484 | ||
265a9e55 | 485 | if (NILP(args)) |
db9f0278 JB |
486 | return Qnil; |
487 | ||
488 | args_left = args; | |
489 | GCPRO1 (args); | |
490 | ||
491 | do | |
492 | { | |
493 | val = Feval (Fcar (Fcdr (args_left))); | |
494 | sym = Fcar (args_left); | |
495 | Fset (sym, val); | |
496 | args_left = Fcdr (Fcdr (args_left)); | |
497 | } | |
265a9e55 | 498 | while (!NILP(args_left)); |
db9f0278 JB |
499 | |
500 | UNGCPRO; | |
501 | return val; | |
502 | } | |
503 | ||
504 | DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0, | |
505 | "Return the argument, without evaluating it. `(quote x)' yields `x'.") | |
506 | (args) | |
507 | Lisp_Object args; | |
508 | { | |
509 | return Fcar (args); | |
510 | } | |
511 | ||
512 | DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0, | |
513 | "Like `quote', but preferred for objects which are functions.\n\ | |
514 | In byte compilation, `function' causes its argument to be compiled.\n\ | |
515 | `quote' cannot do that.") | |
516 | (args) | |
517 | Lisp_Object args; | |
518 | { | |
519 | return Fcar (args); | |
520 | } | |
521 | ||
522 | DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0, | |
523 | "Return t if function in which this appears was called interactively.\n\ | |
524 | This means that the function was called with call-interactively (which\n\ | |
525 | includes being called as the binding of a key)\n\ | |
526 | and input is currently coming from the keyboard (not in keyboard macro).") | |
527 | () | |
528 | { | |
529 | register struct backtrace *btp; | |
530 | register Lisp_Object fun; | |
531 | ||
532 | if (!INTERACTIVE) | |
533 | return Qnil; | |
534 | ||
db9f0278 | 535 | btp = backtrace_list; |
daa37602 JB |
536 | |
537 | /* If this isn't a byte-compiled function, there may be a frame at | |
538 | the top for Finteractive_p itself. If so, skip it. */ | |
539 | fun = Findirect_function (*btp->function); | |
0598f773 | 540 | if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p) |
db9f0278 | 541 | btp = btp->next; |
daa37602 JB |
542 | |
543 | /* If we're running an Emacs 18-style byte-compiled function, there | |
544 | may be a frame for Fbytecode. Now, given the strictest | |
545 | definition, this function isn't really being called | |
546 | interactively, but because that's the way Emacs 18 always builds | |
547 | byte-compiled functions, we'll accept it for now. */ | |
548 | if (EQ (*btp->function, Qbytecode)) | |
549 | btp = btp->next; | |
550 | ||
551 | /* If this isn't a byte-compiled function, then we may now be | |
552 | looking at several frames for special forms. Skip past them. */ | |
553 | while (btp && | |
554 | btp->nargs == UNEVALLED) | |
a6e3fa71 JB |
555 | btp = btp->next; |
556 | ||
daa37602 JB |
557 | /* btp now points at the frame of the innermost function that isn't |
558 | a special form, ignoring frames for Finteractive_p and/or | |
559 | Fbytecode at the top. If this frame is for a built-in function | |
560 | (such as load or eval-region) return nil. */ | |
ffd56f97 | 561 | fun = Findirect_function (*btp->function); |
90165123 | 562 | if (SUBRP (fun)) |
db9f0278 JB |
563 | return Qnil; |
564 | /* btp points to the frame of a Lisp function that called interactive-p. | |
565 | Return t if that function was called interactively. */ | |
566 | if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively)) | |
567 | return Qt; | |
568 | return Qnil; | |
569 | } | |
570 | ||
571 | DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0, | |
1182a7cb | 572 | "Define NAME as a function.\n\ |
db9f0278 JB |
573 | The definition is (lambda ARGLIST [DOCSTRING] BODY...).\n\ |
574 | See also the function `interactive'.") | |
575 | (args) | |
576 | Lisp_Object args; | |
577 | { | |
578 | register Lisp_Object fn_name; | |
579 | register Lisp_Object defn; | |
580 | ||
581 | fn_name = Fcar (args); | |
582 | defn = Fcons (Qlambda, Fcdr (args)); | |
265a9e55 | 583 | if (!NILP (Vpurify_flag)) |
db9f0278 JB |
584 | defn = Fpurecopy (defn); |
585 | Ffset (fn_name, defn); | |
2a49b6e5 | 586 | LOADHIST_ATTACH (fn_name); |
db9f0278 JB |
587 | return fn_name; |
588 | } | |
589 | ||
590 | DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0, | |
1182a7cb | 591 | "Define NAME as a macro.\n\ |
db9f0278 JB |
592 | The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).\n\ |
593 | When the macro is called, as in (NAME ARGS...),\n\ | |
594 | the function (lambda ARGLIST BODY...) is applied to\n\ | |
595 | the list ARGS... as it appears in the expression,\n\ | |
596 | and the result should be a form to be evaluated instead of the original.") | |
597 | (args) | |
598 | Lisp_Object args; | |
599 | { | |
600 | register Lisp_Object fn_name; | |
601 | register Lisp_Object defn; | |
602 | ||
603 | fn_name = Fcar (args); | |
604 | defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args))); | |
265a9e55 | 605 | if (!NILP (Vpurify_flag)) |
db9f0278 JB |
606 | defn = Fpurecopy (defn); |
607 | Ffset (fn_name, defn); | |
2a49b6e5 | 608 | LOADHIST_ATTACH (fn_name); |
db9f0278 JB |
609 | return fn_name; |
610 | } | |
611 | ||
612 | DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, | |
1182a7cb | 613 | "Define SYMBOL as a variable.\n\ |
db9f0278 JB |
614 | You are not required to define a variable in order to use it,\n\ |
615 | but the definition can supply documentation and an initial value\n\ | |
616 | in a way that tags can recognize.\n\n\ | |
617 | INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.\n\ | |
06ef7355 RS |
618 | If SYMBOL is buffer-local, its default value is what is set;\n\ |
619 | buffer-local values are not affected.\n\ | |
db9f0278 JB |
620 | INITVALUE and DOCSTRING are optional.\n\ |
621 | If DOCSTRING starts with *, this variable is identified as a user option.\n\ | |
622 | This means that M-x set-variable and M-x edit-options recognize it.\n\ | |
623 | If INITVALUE is missing, SYMBOL's value is not set.") | |
624 | (args) | |
625 | Lisp_Object args; | |
626 | { | |
a42ba017 | 627 | register Lisp_Object sym, tem, tail; |
db9f0278 JB |
628 | |
629 | sym = Fcar (args); | |
a42ba017 RS |
630 | tail = Fcdr (args); |
631 | if (!NILP (Fcdr (Fcdr (tail)))) | |
632 | error ("too many arguments"); | |
633 | ||
634 | if (!NILP (tail)) | |
db9f0278 JB |
635 | { |
636 | tem = Fdefault_boundp (sym); | |
265a9e55 | 637 | if (NILP (tem)) |
db9f0278 JB |
638 | Fset_default (sym, Feval (Fcar (Fcdr (args)))); |
639 | } | |
a42ba017 RS |
640 | tail = Fcdr (Fcdr (args)); |
641 | if (!NILP (Fcar (tail))) | |
db9f0278 | 642 | { |
ca248607 | 643 | tem = Fcar (tail); |
265a9e55 | 644 | if (!NILP (Vpurify_flag)) |
db9f0278 JB |
645 | tem = Fpurecopy (tem); |
646 | Fput (sym, Qvariable_documentation, tem); | |
647 | } | |
2a49b6e5 | 648 | LOADHIST_ATTACH (sym); |
db9f0278 JB |
649 | return sym; |
650 | } | |
651 | ||
652 | DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0, | |
1182a7cb | 653 | "Define SYMBOL as a constant variable.\n\ |
c569512a | 654 | The intent is that neither programs nor users should ever change this value.\n\ |
db9f0278 | 655 | Always sets the value of SYMBOL to the result of evalling INITVALUE.\n\ |
06ef7355 RS |
656 | If SYMBOL is buffer-local, its default value is what is set;\n\ |
657 | buffer-local values are not affected.\n\ | |
701b1ec2 | 658 | DOCSTRING is optional.") |
db9f0278 JB |
659 | (args) |
660 | Lisp_Object args; | |
661 | { | |
662 | register Lisp_Object sym, tem; | |
663 | ||
664 | sym = Fcar (args); | |
a42ba017 RS |
665 | if (!NILP (Fcdr (Fcdr (Fcdr (args))))) |
666 | error ("too many arguments"); | |
667 | ||
1182a7cb DL |
668 | tem = Feval (Fcar (Fcdr (args))); |
669 | if (!NILP (Vpurify_flag)) | |
670 | tem = Fpurecopy (tem); | |
671 | Fset_default (sym, tem); | |
db9f0278 | 672 | tem = Fcar (Fcdr (Fcdr (args))); |
265a9e55 | 673 | if (!NILP (tem)) |
db9f0278 | 674 | { |
265a9e55 | 675 | if (!NILP (Vpurify_flag)) |
db9f0278 JB |
676 | tem = Fpurecopy (tem); |
677 | Fput (sym, Qvariable_documentation, tem); | |
678 | } | |
2a49b6e5 | 679 | LOADHIST_ATTACH (sym); |
db9f0278 JB |
680 | return sym; |
681 | } | |
682 | ||
683 | DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0, | |
684 | "Returns t if VARIABLE is intended to be set and modified by users.\n\ | |
685 | \(The alternative is a variable used internally in a Lisp program.)\n\ | |
686 | Determined by whether the first character of the documentation\n\ | |
caff32a7 DL |
687 | for the variable is `*' or if the variable is customizable (has a non-nil\n\ |
688 | value of any of `custom-type', `custom-loads' or `standard-value'\n\ | |
689 | on its property list).") | |
db9f0278 JB |
690 | (variable) |
691 | Lisp_Object variable; | |
692 | { | |
693 | Lisp_Object documentation; | |
694 | ||
5e78e475 RS |
695 | if (!SYMBOLP (variable)) |
696 | return Qnil; | |
697 | ||
db9f0278 | 698 | documentation = Fget (variable, Qvariable_documentation); |
90165123 | 699 | if (INTEGERP (documentation) && XINT (documentation) < 0) |
db9f0278 | 700 | return Qt; |
65411977 RS |
701 | if (STRINGP (documentation) |
702 | && ((unsigned char) XSTRING (documentation)->data[0] == '*')) | |
703 | return Qt; | |
704 | /* If it is (STRING . INTEGER), a negative integer means a user variable. */ | |
705 | if (CONSP (documentation) | |
03699b14 KR |
706 | && STRINGP (XCAR (documentation)) |
707 | && INTEGERP (XCDR (documentation)) | |
708 | && XINT (XCDR (documentation)) < 0) | |
db9f0278 | 709 | return Qt; |
caff32a7 DL |
710 | /* Customizable? */ |
711 | if ((!NILP (Fget (variable, intern ("custom-type")))) | |
712 | || (!NILP (Fget (variable, intern ("custom-loads")))) | |
713 | || (!NILP (Fget (variable, intern ("standard-value"))))) | |
714 | return Qt; | |
db9f0278 JB |
715 | return Qnil; |
716 | } | |
717 | \f | |
718 | DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0, | |
1182a7cb | 719 | "Bind variables according to VARLIST then eval BODY.\n\ |
db9f0278 JB |
720 | The value of the last form in BODY is returned.\n\ |
721 | Each element of VARLIST is a symbol (which is bound to nil)\n\ | |
722 | or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\ | |
723 | Each VALUEFORM can refer to the symbols already bound by this VARLIST.") | |
724 | (args) | |
725 | Lisp_Object args; | |
726 | { | |
727 | Lisp_Object varlist, val, elt; | |
728 | int count = specpdl_ptr - specpdl; | |
729 | struct gcpro gcpro1, gcpro2, gcpro3; | |
730 | ||
731 | GCPRO3 (args, elt, varlist); | |
732 | ||
733 | varlist = Fcar (args); | |
265a9e55 | 734 | while (!NILP (varlist)) |
db9f0278 JB |
735 | { |
736 | QUIT; | |
737 | elt = Fcar (varlist); | |
90165123 | 738 | if (SYMBOLP (elt)) |
db9f0278 | 739 | specbind (elt, Qnil); |
08564963 JB |
740 | else if (! NILP (Fcdr (Fcdr (elt)))) |
741 | Fsignal (Qerror, | |
742 | Fcons (build_string ("`let' bindings can have only one value-form"), | |
743 | elt)); | |
db9f0278 JB |
744 | else |
745 | { | |
746 | val = Feval (Fcar (Fcdr (elt))); | |
747 | specbind (Fcar (elt), val); | |
748 | } | |
749 | varlist = Fcdr (varlist); | |
750 | } | |
751 | UNGCPRO; | |
752 | val = Fprogn (Fcdr (args)); | |
753 | return unbind_to (count, val); | |
754 | } | |
755 | ||
756 | DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0, | |
1182a7cb | 757 | "Bind variables according to VARLIST then eval BODY.\n\ |
db9f0278 JB |
758 | The value of the last form in BODY is returned.\n\ |
759 | Each element of VARLIST is a symbol (which is bound to nil)\n\ | |
760 | or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\ | |
761 | All the VALUEFORMs are evalled before any symbols are bound.") | |
762 | (args) | |
763 | Lisp_Object args; | |
764 | { | |
765 | Lisp_Object *temps, tem; | |
766 | register Lisp_Object elt, varlist; | |
767 | int count = specpdl_ptr - specpdl; | |
768 | register int argnum; | |
769 | struct gcpro gcpro1, gcpro2; | |
770 | ||
771 | varlist = Fcar (args); | |
772 | ||
773 | /* Make space to hold the values to give the bound variables */ | |
774 | elt = Flength (varlist); | |
775 | temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object)); | |
776 | ||
777 | /* Compute the values and store them in `temps' */ | |
778 | ||
779 | GCPRO2 (args, *temps); | |
780 | gcpro2.nvars = 0; | |
781 | ||
265a9e55 | 782 | for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist)) |
db9f0278 JB |
783 | { |
784 | QUIT; | |
785 | elt = Fcar (varlist); | |
90165123 | 786 | if (SYMBOLP (elt)) |
db9f0278 | 787 | temps [argnum++] = Qnil; |
08564963 JB |
788 | else if (! NILP (Fcdr (Fcdr (elt)))) |
789 | Fsignal (Qerror, | |
790 | Fcons (build_string ("`let' bindings can have only one value-form"), | |
791 | elt)); | |
db9f0278 JB |
792 | else |
793 | temps [argnum++] = Feval (Fcar (Fcdr (elt))); | |
794 | gcpro2.nvars = argnum; | |
795 | } | |
796 | UNGCPRO; | |
797 | ||
798 | varlist = Fcar (args); | |
265a9e55 | 799 | for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist)) |
db9f0278 JB |
800 | { |
801 | elt = Fcar (varlist); | |
802 | tem = temps[argnum++]; | |
90165123 | 803 | if (SYMBOLP (elt)) |
db9f0278 JB |
804 | specbind (elt, tem); |
805 | else | |
806 | specbind (Fcar (elt), tem); | |
807 | } | |
808 | ||
809 | elt = Fprogn (Fcdr (args)); | |
810 | return unbind_to (count, elt); | |
811 | } | |
812 | ||
813 | DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0, | |
1182a7cb | 814 | "If TEST yields non-nil, eval BODY... and repeat.\n\ |
db9f0278 JB |
815 | The order of execution is thus TEST, BODY, TEST, BODY and so on\n\ |
816 | until TEST returns nil.") | |
817 | (args) | |
818 | Lisp_Object args; | |
819 | { | |
820 | Lisp_Object test, body, tem; | |
821 | struct gcpro gcpro1, gcpro2; | |
822 | ||
823 | GCPRO2 (test, body); | |
824 | ||
825 | test = Fcar (args); | |
826 | body = Fcdr (args); | |
e3c24a74 RS |
827 | while (tem = Feval (test), |
828 | (!EQ (Vmocklisp_arguments, Qt) ? XINT (tem) : !NILP (tem))) | |
db9f0278 JB |
829 | { |
830 | QUIT; | |
831 | Fprogn (body); | |
832 | } | |
833 | ||
834 | UNGCPRO; | |
835 | return Qnil; | |
836 | } | |
837 | ||
838 | DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0, | |
839 | "Return result of expanding macros at top level of FORM.\n\ | |
840 | If FORM is not a macro call, it is returned unchanged.\n\ | |
841 | Otherwise, the macro is expanded and the expansion is considered\n\ | |
842 | in place of FORM. When a non-macro-call results, it is returned.\n\n\ | |
843 | The second optional arg ENVIRONMENT species an environment of macro\n\ | |
844 | definitions to shadow the loaded ones for use in file byte-compilation.") | |
79e8bfbf | 845 | (form, environment) |
2e267a2e | 846 | Lisp_Object form; |
79e8bfbf | 847 | Lisp_Object environment; |
db9f0278 | 848 | { |
23d6b5a6 | 849 | /* With cleanups from Hallvard Furuseth. */ |
db9f0278 JB |
850 | register Lisp_Object expander, sym, def, tem; |
851 | ||
852 | while (1) | |
853 | { | |
854 | /* Come back here each time we expand a macro call, | |
855 | in case it expands into another macro call. */ | |
90165123 | 856 | if (!CONSP (form)) |
db9f0278 | 857 | break; |
23d6b5a6 | 858 | /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */ |
03699b14 | 859 | def = sym = XCAR (form); |
23d6b5a6 | 860 | tem = Qnil; |
db9f0278 JB |
861 | /* Trace symbols aliases to other symbols |
862 | until we get a symbol that is not an alias. */ | |
90165123 | 863 | while (SYMBOLP (def)) |
db9f0278 JB |
864 | { |
865 | QUIT; | |
23d6b5a6 | 866 | sym = def; |
79e8bfbf | 867 | tem = Fassq (sym, environment); |
265a9e55 | 868 | if (NILP (tem)) |
db9f0278 JB |
869 | { |
870 | def = XSYMBOL (sym)->function; | |
23d6b5a6 JB |
871 | if (!EQ (def, Qunbound)) |
872 | continue; | |
db9f0278 | 873 | } |
23d6b5a6 | 874 | break; |
db9f0278 | 875 | } |
79e8bfbf | 876 | /* Right now TEM is the result from SYM in ENVIRONMENT, |
db9f0278 | 877 | and if TEM is nil then DEF is SYM's function definition. */ |
265a9e55 | 878 | if (NILP (tem)) |
db9f0278 | 879 | { |
79e8bfbf | 880 | /* SYM is not mentioned in ENVIRONMENT. |
db9f0278 | 881 | Look at its function definition. */ |
90165123 | 882 | if (EQ (def, Qunbound) || !CONSP (def)) |
db9f0278 JB |
883 | /* Not defined or definition not suitable */ |
884 | break; | |
03699b14 | 885 | if (EQ (XCAR (def), Qautoload)) |
db9f0278 JB |
886 | { |
887 | /* Autoloading function: will it be a macro when loaded? */ | |
ee9ee63c | 888 | tem = Fnth (make_number (4), def); |
47ccd8b6 | 889 | if (EQ (tem, Qt) || EQ (tem, Qmacro)) |
ee9ee63c JB |
890 | /* Yes, load it and try again. */ |
891 | { | |
ca20916b RS |
892 | struct gcpro gcpro1; |
893 | GCPRO1 (form); | |
ee9ee63c | 894 | do_autoload (def, sym); |
ca20916b | 895 | UNGCPRO; |
ee9ee63c JB |
896 | continue; |
897 | } | |
898 | else | |
db9f0278 | 899 | break; |
db9f0278 | 900 | } |
03699b14 | 901 | else if (!EQ (XCAR (def), Qmacro)) |
db9f0278 | 902 | break; |
03699b14 | 903 | else expander = XCDR (def); |
db9f0278 JB |
904 | } |
905 | else | |
906 | { | |
03699b14 | 907 | expander = XCDR (tem); |
265a9e55 | 908 | if (NILP (expander)) |
db9f0278 JB |
909 | break; |
910 | } | |
03699b14 | 911 | form = apply1 (expander, XCDR (form)); |
db9f0278 JB |
912 | } |
913 | return form; | |
914 | } | |
915 | \f | |
916 | DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0, | |
1182a7cb | 917 | "Eval BODY allowing nonlocal exits using `throw'.\n\ |
4e306308 RS |
918 | TAG is evalled to get the tag to use; it must not be nil.\n\ |
919 | \n\ | |
920 | Then the BODY is executed.\n\ | |
db9f0278 JB |
921 | Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.\n\ |
922 | If no throw happens, `catch' returns the value of the last BODY form.\n\ | |
923 | If a throw happens, it specifies the value to return from `catch'.") | |
924 | (args) | |
925 | Lisp_Object args; | |
926 | { | |
927 | register Lisp_Object tag; | |
928 | struct gcpro gcpro1; | |
929 | ||
930 | GCPRO1 (args); | |
931 | tag = Feval (Fcar (args)); | |
932 | UNGCPRO; | |
933 | return internal_catch (tag, Fprogn, Fcdr (args)); | |
934 | } | |
935 | ||
936 | /* Set up a catch, then call C function FUNC on argument ARG. | |
937 | FUNC should return a Lisp_Object. | |
938 | This is how catches are done from within C code. */ | |
939 | ||
940 | Lisp_Object | |
941 | internal_catch (tag, func, arg) | |
942 | Lisp_Object tag; | |
943 | Lisp_Object (*func) (); | |
944 | Lisp_Object arg; | |
945 | { | |
946 | /* This structure is made part of the chain `catchlist'. */ | |
947 | struct catchtag c; | |
948 | ||
949 | /* Fill in the components of c, and put it on the list. */ | |
950 | c.next = catchlist; | |
951 | c.tag = tag; | |
952 | c.val = Qnil; | |
953 | c.backlist = backtrace_list; | |
954 | c.handlerlist = handlerlist; | |
955 | c.lisp_eval_depth = lisp_eval_depth; | |
956 | c.pdlcount = specpdl_ptr - specpdl; | |
957 | c.poll_suppress_count = poll_suppress_count; | |
958 | c.gcpro = gcprolist; | |
bcf28080 | 959 | c.byte_stack = byte_stack_list; |
db9f0278 JB |
960 | catchlist = &c; |
961 | ||
962 | /* Call FUNC. */ | |
963 | if (! _setjmp (c.jmp)) | |
964 | c.val = (*func) (arg); | |
965 | ||
966 | /* Throw works by a longjmp that comes right here. */ | |
967 | catchlist = c.next; | |
968 | return c.val; | |
969 | } | |
970 | ||
ba410f40 JB |
971 | /* Unwind the specbind, catch, and handler stacks back to CATCH, and |
972 | jump to that CATCH, returning VALUE as the value of that catch. | |
db9f0278 | 973 | |
ba410f40 JB |
974 | This is the guts Fthrow and Fsignal; they differ only in the way |
975 | they choose the catch tag to throw to. A catch tag for a | |
976 | condition-case form has a TAG of Qnil. | |
db9f0278 | 977 | |
ba410f40 JB |
978 | Before each catch is discarded, unbind all special bindings and |
979 | execute all unwind-protect clauses made above that catch. Unwind | |
980 | the handler stack as we go, so that the proper handlers are in | |
981 | effect for each unwind-protect clause we run. At the end, restore | |
982 | some static info saved in CATCH, and longjmp to the location | |
983 | specified in the | |
984 | ||
985 | This is used for correct unwinding in Fthrow and Fsignal. */ | |
db9f0278 JB |
986 | |
987 | static void | |
ba410f40 | 988 | unwind_to_catch (catch, value) |
db9f0278 | 989 | struct catchtag *catch; |
ba410f40 | 990 | Lisp_Object value; |
db9f0278 JB |
991 | { |
992 | register int last_time; | |
993 | ||
ba410f40 JB |
994 | /* Save the value in the tag. */ |
995 | catch->val = value; | |
996 | ||
82da7701 | 997 | /* Restore the polling-suppression count. */ |
1cdc3155 | 998 | set_poll_suppress_count (catch->poll_suppress_count); |
82da7701 | 999 | |
db9f0278 JB |
1000 | do |
1001 | { | |
1002 | last_time = catchlist == catch; | |
82da7701 JB |
1003 | |
1004 | /* Unwind the specpdl stack, and then restore the proper set of | |
1005 | handlers. */ | |
db9f0278 JB |
1006 | unbind_to (catchlist->pdlcount, Qnil); |
1007 | handlerlist = catchlist->handlerlist; | |
1008 | catchlist = catchlist->next; | |
1009 | } | |
1010 | while (! last_time); | |
1011 | ||
bcf28080 | 1012 | byte_stack_list = catch->byte_stack; |
db9f0278 | 1013 | gcprolist = catch->gcpro; |
15934ffa RS |
1014 | #ifdef DEBUG_GCPRO |
1015 | if (gcprolist != 0) | |
1016 | gcpro_level = gcprolist->level + 1; | |
1017 | else | |
1018 | gcpro_level = 0; | |
1019 | #endif | |
db9f0278 JB |
1020 | backtrace_list = catch->backlist; |
1021 | lisp_eval_depth = catch->lisp_eval_depth; | |
ba410f40 JB |
1022 | |
1023 | _longjmp (catch->jmp, 1); | |
db9f0278 JB |
1024 | } |
1025 | ||
1026 | DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0, | |
1182a7cb | 1027 | "Throw to the catch for TAG and return VALUE from it.\n\ |
db9f0278 | 1028 | Both TAG and VALUE are evalled.") |
79e8bfbf EN |
1029 | (tag, value) |
1030 | register Lisp_Object tag, value; | |
db9f0278 JB |
1031 | { |
1032 | register struct catchtag *c; | |
1033 | ||
1034 | while (1) | |
1035 | { | |
265a9e55 | 1036 | if (!NILP (tag)) |
db9f0278 JB |
1037 | for (c = catchlist; c; c = c->next) |
1038 | { | |
1039 | if (EQ (c->tag, tag)) | |
79e8bfbf | 1040 | unwind_to_catch (c, value); |
db9f0278 | 1041 | } |
79e8bfbf | 1042 | tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil))); |
db9f0278 JB |
1043 | } |
1044 | } | |
1045 | ||
1046 | ||
1047 | DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0, | |
1048 | "Do BODYFORM, protecting with UNWINDFORMS.\n\ | |
db9f0278 JB |
1049 | If BODYFORM completes normally, its value is returned\n\ |
1050 | after executing the UNWINDFORMS.\n\ | |
1051 | If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.") | |
1052 | (args) | |
1053 | Lisp_Object args; | |
1054 | { | |
1055 | Lisp_Object val; | |
1056 | int count = specpdl_ptr - specpdl; | |
1057 | ||
1058 | record_unwind_protect (0, Fcdr (args)); | |
1059 | val = Feval (Fcar (args)); | |
1060 | return unbind_to (count, val); | |
1061 | } | |
1062 | \f | |
1063 | /* Chain of condition handlers currently in effect. | |
1064 | The elements of this chain are contained in the stack frames | |
1065 | of Fcondition_case and internal_condition_case. | |
1066 | When an error is signaled (by calling Fsignal, below), | |
1067 | this chain is searched for an element that applies. */ | |
1068 | ||
1069 | struct handler *handlerlist; | |
1070 | ||
1071 | DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0, | |
1072 | "Regain control when an error is signaled.\n\ | |
db9f0278 JB |
1073 | executes BODYFORM and returns its value if no error happens.\n\ |
1074 | Each element of HANDLERS looks like (CONDITION-NAME BODY...)\n\ | |
1075 | where the BODY is made of Lisp expressions.\n\n\ | |
1076 | A handler is applicable to an error\n\ | |
1077 | if CONDITION-NAME is one of the error's condition names.\n\ | |
1078 | If an error happens, the first applicable handler is run.\n\ | |
1079 | \n\ | |
633357d4 RS |
1080 | The car of a handler may be a list of condition names\n\ |
1081 | instead of a single condition name.\n\ | |
1082 | \n\ | |
db9f0278 JB |
1083 | When a handler handles an error,\n\ |
1084 | control returns to the condition-case and the handler BODY... is executed\n\ | |
1085 | with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).\n\ | |
1086 | VAR may be nil; then you do not get access to the signal information.\n\ | |
1087 | \n\ | |
1088 | The value of the last BODY form is returned from the condition-case.\n\ | |
1089 | See also the function `signal' for more info.") | |
1090 | (args) | |
1091 | Lisp_Object args; | |
1092 | { | |
1093 | Lisp_Object val; | |
1094 | struct catchtag c; | |
1095 | struct handler h; | |
82da7701 | 1096 | register Lisp_Object var, bodyform, handlers; |
db9f0278 | 1097 | |
82da7701 JB |
1098 | var = Fcar (args); |
1099 | bodyform = Fcar (Fcdr (args)); | |
1100 | handlers = Fcdr (Fcdr (args)); | |
1101 | CHECK_SYMBOL (var, 0); | |
1102 | ||
1103 | for (val = handlers; ! NILP (val); val = Fcdr (val)) | |
1104 | { | |
1105 | Lisp_Object tem; | |
1106 | tem = Fcar (val); | |
5f96776a RS |
1107 | if (! (NILP (tem) |
1108 | || (CONSP (tem) | |
03699b14 KR |
1109 | && (SYMBOLP (XCAR (tem)) |
1110 | || CONSP (XCAR (tem)))))) | |
82da7701 JB |
1111 | error ("Invalid condition handler", tem); |
1112 | } | |
db9f0278 JB |
1113 | |
1114 | c.tag = Qnil; | |
1115 | c.val = Qnil; | |
1116 | c.backlist = backtrace_list; | |
1117 | c.handlerlist = handlerlist; | |
1118 | c.lisp_eval_depth = lisp_eval_depth; | |
1119 | c.pdlcount = specpdl_ptr - specpdl; | |
1120 | c.poll_suppress_count = poll_suppress_count; | |
1121 | c.gcpro = gcprolist; | |
bcf28080 | 1122 | c.byte_stack = byte_stack_list; |
db9f0278 JB |
1123 | if (_setjmp (c.jmp)) |
1124 | { | |
265a9e55 | 1125 | if (!NILP (h.var)) |
9d58218c RS |
1126 | specbind (h.var, c.val); |
1127 | val = Fprogn (Fcdr (h.chosen_clause)); | |
82da7701 JB |
1128 | |
1129 | /* Note that this just undoes the binding of h.var; whoever | |
1130 | longjumped to us unwound the stack to c.pdlcount before | |
1131 | throwing. */ | |
db9f0278 JB |
1132 | unbind_to (c.pdlcount, Qnil); |
1133 | return val; | |
1134 | } | |
1135 | c.next = catchlist; | |
1136 | catchlist = &c; | |
db9f0278 | 1137 | |
82da7701 JB |
1138 | h.var = var; |
1139 | h.handler = handlers; | |
db9f0278 | 1140 | h.next = handlerlist; |
db9f0278 JB |
1141 | h.tag = &c; |
1142 | handlerlist = &h; | |
1143 | ||
82da7701 | 1144 | val = Feval (bodyform); |
db9f0278 JB |
1145 | catchlist = c.next; |
1146 | handlerlist = h.next; | |
1147 | return val; | |
1148 | } | |
1149 | ||
f029ca5f RS |
1150 | /* Call the function BFUN with no arguments, catching errors within it |
1151 | according to HANDLERS. If there is an error, call HFUN with | |
1152 | one argument which is the data that describes the error: | |
1153 | (SIGNALNAME . DATA) | |
1154 | ||
1155 | HANDLERS can be a list of conditions to catch. | |
1156 | If HANDLERS is Qt, catch all errors. | |
1157 | If HANDLERS is Qerror, catch all errors | |
1158 | but allow the debugger to run if that is enabled. */ | |
1159 | ||
db9f0278 JB |
1160 | Lisp_Object |
1161 | internal_condition_case (bfun, handlers, hfun) | |
1162 | Lisp_Object (*bfun) (); | |
1163 | Lisp_Object handlers; | |
1164 | Lisp_Object (*hfun) (); | |
1165 | { | |
1166 | Lisp_Object val; | |
1167 | struct catchtag c; | |
1168 | struct handler h; | |
1169 | ||
01591d17 RS |
1170 | /* Since Fsignal resets this to 0, it had better be 0 now |
1171 | or else we have a potential bug. */ | |
1172 | if (interrupt_input_blocked != 0) | |
1173 | abort (); | |
1174 | ||
db9f0278 JB |
1175 | c.tag = Qnil; |
1176 | c.val = Qnil; | |
1177 | c.backlist = backtrace_list; | |
1178 | c.handlerlist = handlerlist; | |
1179 | c.lisp_eval_depth = lisp_eval_depth; | |
1180 | c.pdlcount = specpdl_ptr - specpdl; | |
1181 | c.poll_suppress_count = poll_suppress_count; | |
1182 | c.gcpro = gcprolist; | |
bcf28080 | 1183 | c.byte_stack = byte_stack_list; |
db9f0278 JB |
1184 | if (_setjmp (c.jmp)) |
1185 | { | |
9d58218c | 1186 | return (*hfun) (c.val); |
db9f0278 JB |
1187 | } |
1188 | c.next = catchlist; | |
1189 | catchlist = &c; | |
1190 | h.handler = handlers; | |
1191 | h.var = Qnil; | |
db9f0278 JB |
1192 | h.next = handlerlist; |
1193 | h.tag = &c; | |
1194 | handlerlist = &h; | |
1195 | ||
1196 | val = (*bfun) (); | |
1197 | catchlist = c.next; | |
1198 | handlerlist = h.next; | |
1199 | return val; | |
1200 | } | |
1201 | ||
f029ca5f RS |
1202 | /* Like internal_condition_case but call HFUN with ARG as its argument. */ |
1203 | ||
d227775c RS |
1204 | Lisp_Object |
1205 | internal_condition_case_1 (bfun, arg, handlers, hfun) | |
1206 | Lisp_Object (*bfun) (); | |
1207 | Lisp_Object arg; | |
1208 | Lisp_Object handlers; | |
1209 | Lisp_Object (*hfun) (); | |
1210 | { | |
1211 | Lisp_Object val; | |
1212 | struct catchtag c; | |
1213 | struct handler h; | |
1214 | ||
1215 | c.tag = Qnil; | |
1216 | c.val = Qnil; | |
1217 | c.backlist = backtrace_list; | |
1218 | c.handlerlist = handlerlist; | |
1219 | c.lisp_eval_depth = lisp_eval_depth; | |
1220 | c.pdlcount = specpdl_ptr - specpdl; | |
1221 | c.poll_suppress_count = poll_suppress_count; | |
1222 | c.gcpro = gcprolist; | |
bcf28080 | 1223 | c.byte_stack = byte_stack_list; |
d227775c RS |
1224 | if (_setjmp (c.jmp)) |
1225 | { | |
9d58218c | 1226 | return (*hfun) (c.val); |
d227775c RS |
1227 | } |
1228 | c.next = catchlist; | |
1229 | catchlist = &c; | |
1230 | h.handler = handlers; | |
1231 | h.var = Qnil; | |
1232 | h.next = handlerlist; | |
1233 | h.tag = &c; | |
1234 | handlerlist = &h; | |
1235 | ||
1236 | val = (*bfun) (arg); | |
1237 | catchlist = c.next; | |
1238 | handlerlist = h.next; | |
1239 | return val; | |
1240 | } | |
1241 | \f | |
db9f0278 JB |
1242 | static Lisp_Object find_handler_clause (); |
1243 | ||
1244 | DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, | |
4200e719 | 1245 | "Signal an error. Args are ERROR-SYMBOL and associated DATA.\n\ |
db9f0278 | 1246 | This function does not return.\n\n\ |
4200e719 | 1247 | An error symbol is a symbol with an `error-conditions' property\n\ |
db9f0278 JB |
1248 | that is a list of condition names.\n\ |
1249 | A handler for any of those names will get to handle this signal.\n\ | |
1250 | The symbol `error' should normally be one of them.\n\ | |
1251 | \n\ | |
1252 | DATA should be a list. Its elements are printed as part of the error message.\n\ | |
1253 | If the signal is handled, DATA is made available to the handler.\n\ | |
1254 | See also the function `condition-case'.") | |
4200e719 RS |
1255 | (error_symbol, data) |
1256 | Lisp_Object error_symbol, data; | |
db9f0278 | 1257 | { |
bfa8ca43 AS |
1258 | /* When memory is full, ERROR-SYMBOL is nil, |
1259 | and DATA is (REAL-ERROR-SYMBOL . REAL-DATA). */ | |
db9f0278 JB |
1260 | register struct handler *allhandlers = handlerlist; |
1261 | Lisp_Object conditions; | |
1262 | extern int gc_in_progress; | |
1263 | extern int waiting_for_input; | |
1264 | Lisp_Object debugger_value; | |
c11d3d17 | 1265 | Lisp_Object string; |
1ea9dec4 | 1266 | Lisp_Object real_error_symbol; |
48f8dfa3 | 1267 | extern int display_busy_cursor_p; |
db9f0278 | 1268 | |
db9f0278 JB |
1269 | immediate_quit = 0; |
1270 | if (gc_in_progress || waiting_for_input) | |
1271 | abort (); | |
1272 | ||
1273 | TOTALLY_UNBLOCK_INPUT; | |
1274 | ||
1ea9dec4 RS |
1275 | if (NILP (error_symbol)) |
1276 | real_error_symbol = Fcar (data); | |
1277 | else | |
1278 | real_error_symbol = error_symbol; | |
1279 | ||
48f8dfa3 GM |
1280 | #ifdef HAVE_X_WINDOWS |
1281 | if (display_busy_cursor_p) | |
1282 | Fx_hide_busy_cursor (Qt); | |
1283 | #endif | |
48f8dfa3 | 1284 | |
61ede770 RS |
1285 | /* This hook is used by edebug. */ |
1286 | if (! NILP (Vsignal_hook_function)) | |
f01a9c5b | 1287 | call2 (Vsignal_hook_function, error_symbol, data); |
61ede770 | 1288 | |
1ea9dec4 | 1289 | conditions = Fget (real_error_symbol, Qerror_conditions); |
db9f0278 JB |
1290 | |
1291 | for (; handlerlist; handlerlist = handlerlist->next) | |
1292 | { | |
1293 | register Lisp_Object clause; | |
1294 | clause = find_handler_clause (handlerlist->handler, conditions, | |
4200e719 | 1295 | error_symbol, data, &debugger_value); |
db9f0278 JB |
1296 | |
1297 | #if 0 /* Most callers are not prepared to handle gc if this returns. | |
1298 | So, since this feature is not very useful, take it out. */ | |
1299 | /* If have called debugger and user wants to continue, | |
1300 | just return nil. */ | |
1301 | if (EQ (clause, Qlambda)) | |
1302 | return debugger_value; | |
1303 | #else | |
1304 | if (EQ (clause, Qlambda)) | |
82da7701 | 1305 | { |
690337b7 KH |
1306 | /* We can't return values to code which signaled an error, but we |
1307 | can continue code which has signaled a quit. */ | |
1ea9dec4 | 1308 | if (EQ (real_error_symbol, Qquit)) |
82da7701 JB |
1309 | return Qnil; |
1310 | else | |
d3e6f8be | 1311 | error ("Cannot return from the debugger in an error"); |
82da7701 | 1312 | } |
db9f0278 JB |
1313 | #endif |
1314 | ||
265a9e55 | 1315 | if (!NILP (clause)) |
db9f0278 | 1316 | { |
9d58218c | 1317 | Lisp_Object unwind_data; |
db9f0278 | 1318 | struct handler *h = handlerlist; |
9d58218c | 1319 | |
db9f0278 | 1320 | handlerlist = allhandlers; |
1ea9dec4 RS |
1321 | |
1322 | if (NILP (error_symbol)) | |
1323 | unwind_data = data; | |
9d58218c RS |
1324 | else |
1325 | unwind_data = Fcons (error_symbol, data); | |
1326 | h->chosen_clause = clause; | |
1327 | unwind_to_catch (h->tag, unwind_data); | |
db9f0278 JB |
1328 | } |
1329 | } | |
1330 | ||
1331 | handlerlist = allhandlers; | |
1332 | /* If no handler is present now, try to run the debugger, | |
1333 | and if that fails, throw to top level. */ | |
4200e719 | 1334 | find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value); |
c11d3d17 RS |
1335 | if (catchlist != 0) |
1336 | Fthrow (Qtop_level, Qt); | |
1337 | ||
1ea9dec4 | 1338 | if (! NILP (error_symbol)) |
c11d3d17 RS |
1339 | data = Fcons (error_symbol, data); |
1340 | ||
1341 | string = Ferror_message_string (data); | |
377127ce | 1342 | fatal ("%s", XSTRING (string)->data, 0); |
db9f0278 JB |
1343 | } |
1344 | ||
128c0f66 RM |
1345 | /* Return nonzero iff LIST is a non-nil atom or |
1346 | a list containing one of CONDITIONS. */ | |
1347 | ||
1348 | static int | |
1349 | wants_debugger (list, conditions) | |
1350 | Lisp_Object list, conditions; | |
1351 | { | |
4de86b16 | 1352 | if (NILP (list)) |
128c0f66 RM |
1353 | return 0; |
1354 | if (! CONSP (list)) | |
1355 | return 1; | |
1356 | ||
ab67260b | 1357 | while (CONSP (conditions)) |
128c0f66 | 1358 | { |
ab67260b | 1359 | Lisp_Object this, tail; |
03699b14 KR |
1360 | this = XCAR (conditions); |
1361 | for (tail = list; CONSP (tail); tail = XCDR (tail)) | |
1362 | if (EQ (XCAR (tail), this)) | |
128c0f66 | 1363 | return 1; |
03699b14 | 1364 | conditions = XCDR (conditions); |
128c0f66 | 1365 | } |
ab67260b | 1366 | return 0; |
128c0f66 RM |
1367 | } |
1368 | ||
fc950e09 KH |
1369 | /* Return 1 if an error with condition-symbols CONDITIONS, |
1370 | and described by SIGNAL-DATA, should skip the debugger | |
1371 | according to debugger-ignore-errors. */ | |
1372 | ||
1373 | static int | |
1374 | skip_debugger (conditions, data) | |
1375 | Lisp_Object conditions, data; | |
1376 | { | |
1377 | Lisp_Object tail; | |
1378 | int first_string = 1; | |
1379 | Lisp_Object error_message; | |
1380 | ||
1381 | for (tail = Vdebug_ignored_errors; CONSP (tail); | |
03699b14 | 1382 | tail = XCDR (tail)) |
fc950e09 | 1383 | { |
03699b14 | 1384 | if (STRINGP (XCAR (tail))) |
fc950e09 KH |
1385 | { |
1386 | if (first_string) | |
1387 | { | |
1388 | error_message = Ferror_message_string (data); | |
1389 | first_string = 0; | |
1390 | } | |
03699b14 | 1391 | if (fast_string_match (XCAR (tail), error_message) >= 0) |
fc950e09 KH |
1392 | return 1; |
1393 | } | |
1394 | else | |
1395 | { | |
1396 | Lisp_Object contail; | |
1397 | ||
1398 | for (contail = conditions; CONSP (contail); | |
03699b14 KR |
1399 | contail = XCDR (contail)) |
1400 | if (EQ (XCAR (tail), XCAR (contail))) | |
fc950e09 KH |
1401 | return 1; |
1402 | } | |
1403 | } | |
1404 | ||
1405 | return 0; | |
1406 | } | |
1407 | ||
128c0f66 | 1408 | /* Value of Qlambda means we have called debugger and user has continued. |
1ea9dec4 | 1409 | There are two ways to pass SIG and DATA: |
9b942ebd | 1410 | = SIG is the error symbol, and DATA is the rest of the data. |
1ea9dec4 | 1411 | = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA). |
9b942ebd | 1412 | This is for memory-full errors only. |
1ea9dec4 | 1413 | |
128c0f66 | 1414 | Store value returned from debugger into *DEBUGGER_VALUE_PTR. */ |
db9f0278 JB |
1415 | |
1416 | static Lisp_Object | |
1417 | find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr) | |
1418 | Lisp_Object handlers, conditions, sig, data; | |
1419 | Lisp_Object *debugger_value_ptr; | |
1420 | { | |
1421 | register Lisp_Object h; | |
1422 | register Lisp_Object tem; | |
db9f0278 JB |
1423 | |
1424 | if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */ | |
1425 | return Qt; | |
61ede770 RS |
1426 | /* error is used similarly, but means print an error message |
1427 | and run the debugger if that is enabled. */ | |
1428 | if (EQ (handlers, Qerror) | |
57a6e758 RS |
1429 | || !NILP (Vdebug_on_signal)) /* This says call debugger even if |
1430 | there is a handler. */ | |
db9f0278 | 1431 | { |
61ede770 RS |
1432 | int count = specpdl_ptr - specpdl; |
1433 | int debugger_called = 0; | |
1ea9dec4 | 1434 | Lisp_Object sig_symbol, combined_data; |
9b942ebd RS |
1435 | /* This is set to 1 if we are handling a memory-full error, |
1436 | because these must not run the debugger. | |
1437 | (There is no room in memory to do that!) */ | |
1438 | int no_debugger = 0; | |
1ea9dec4 RS |
1439 | |
1440 | if (NILP (sig)) | |
1441 | { | |
1442 | combined_data = data; | |
1443 | sig_symbol = Fcar (data); | |
9b942ebd | 1444 | no_debugger = 1; |
1ea9dec4 RS |
1445 | } |
1446 | else | |
1447 | { | |
1448 | combined_data = Fcons (sig, data); | |
1449 | sig_symbol = sig; | |
1450 | } | |
61ede770 | 1451 | |
128c0f66 | 1452 | if (wants_debugger (Vstack_trace_on_error, conditions)) |
88817f3b RS |
1453 | { |
1454 | #ifdef __STDC__ | |
1455 | internal_with_output_to_temp_buffer ("*Backtrace*", | |
1456 | (Lisp_Object (*) (Lisp_Object)) Fbacktrace, | |
1457 | Qnil); | |
1458 | #else | |
1459 | internal_with_output_to_temp_buffer ("*Backtrace*", | |
1460 | Fbacktrace, Qnil); | |
1461 | #endif | |
1462 | } | |
9b942ebd RS |
1463 | if (! no_debugger |
1464 | && (EQ (sig_symbol, Qquit) | |
1465 | ? debug_on_quit | |
1466 | : wants_debugger (Vdebug_on_error, conditions)) | |
1ea9dec4 | 1467 | && ! skip_debugger (conditions, combined_data) |
be857679 | 1468 | && when_entered_debugger < num_nonmacro_input_events) |
db9f0278 | 1469 | { |
db9f0278 | 1470 | specbind (Qdebug_on_error, Qnil); |
fc950e09 KH |
1471 | *debugger_value_ptr |
1472 | = call_debugger (Fcons (Qerror, | |
1ea9dec4 | 1473 | Fcons (combined_data, Qnil))); |
61ede770 RS |
1474 | debugger_called = 1; |
1475 | } | |
1476 | /* If there is no handler, return saying whether we ran the debugger. */ | |
1477 | if (EQ (handlers, Qerror)) | |
1478 | { | |
1479 | if (debugger_called) | |
1480 | return unbind_to (count, Qlambda); | |
1481 | return Qt; | |
db9f0278 | 1482 | } |
db9f0278 JB |
1483 | } |
1484 | for (h = handlers; CONSP (h); h = Fcdr (h)) | |
1485 | { | |
5f96776a RS |
1486 | Lisp_Object handler, condit; |
1487 | ||
1488 | handler = Fcar (h); | |
1489 | if (!CONSP (handler)) | |
db9f0278 | 1490 | continue; |
5f96776a RS |
1491 | condit = Fcar (handler); |
1492 | /* Handle a single condition name in handler HANDLER. */ | |
1493 | if (SYMBOLP (condit)) | |
1494 | { | |
1495 | tem = Fmemq (Fcar (handler), conditions); | |
1496 | if (!NILP (tem)) | |
1497 | return handler; | |
1498 | } | |
1499 | /* Handle a list of condition names in handler HANDLER. */ | |
1500 | else if (CONSP (condit)) | |
1501 | { | |
1502 | while (CONSP (condit)) | |
1503 | { | |
1504 | tem = Fmemq (Fcar (condit), conditions); | |
1505 | if (!NILP (tem)) | |
1506 | return handler; | |
03699b14 | 1507 | condit = XCDR (condit); |
5f96776a RS |
1508 | } |
1509 | } | |
db9f0278 JB |
1510 | } |
1511 | return Qnil; | |
1512 | } | |
1513 | ||
1514 | /* dump an error message; called like printf */ | |
1515 | ||
1516 | /* VARARGS 1 */ | |
1517 | void | |
1518 | error (m, a1, a2, a3) | |
1519 | char *m; | |
9125da08 | 1520 | char *a1, *a2, *a3; |
db9f0278 JB |
1521 | { |
1522 | char buf[200]; | |
9125da08 RS |
1523 | int size = 200; |
1524 | int mlen; | |
1525 | char *buffer = buf; | |
1526 | char *args[3]; | |
1527 | int allocated = 0; | |
1528 | Lisp_Object string; | |
1529 | ||
1530 | args[0] = a1; | |
1531 | args[1] = a2; | |
1532 | args[2] = a3; | |
1533 | ||
1534 | mlen = strlen (m); | |
db9f0278 JB |
1535 | |
1536 | while (1) | |
9125da08 | 1537 | { |
955f3ff9 | 1538 | int used = doprnt (buffer, size, m, m + mlen, 3, args); |
9125da08 RS |
1539 | if (used < size) |
1540 | break; | |
1541 | size *= 2; | |
1542 | if (allocated) | |
1543 | buffer = (char *) xrealloc (buffer, size); | |
5ece1728 RS |
1544 | else |
1545 | { | |
1546 | buffer = (char *) xmalloc (size); | |
1547 | allocated = 1; | |
1548 | } | |
9125da08 RS |
1549 | } |
1550 | ||
955f3ff9 | 1551 | string = build_string (buffer); |
9125da08 RS |
1552 | if (allocated) |
1553 | free (buffer); | |
1554 | ||
1555 | Fsignal (Qerror, Fcons (string, Qnil)); | |
db9f0278 JB |
1556 | } |
1557 | \f | |
1558 | DEFUN ("commandp", Fcommandp, Scommandp, 1, 1, 0, | |
1559 | "T if FUNCTION makes provisions for interactive calling.\n\ | |
1560 | This means it contains a description for how to read arguments to give it.\n\ | |
1561 | The value is nil for an invalid function or a symbol with no function\n\ | |
1562 | definition.\n\ | |
1563 | \n\ | |
1564 | Interactively callable functions include strings and vectors (treated\n\ | |
1565 | as keyboard macros), lambda-expressions that contain a top-level call\n\ | |
1566 | to `interactive', autoload definitions made by `autoload' with non-nil\n\ | |
1567 | fourth argument, and some of the built-in functions of Lisp.\n\ | |
1568 | \n\ | |
1569 | Also, a symbol satisfies `commandp' if its function definition does so.") | |
1570 | (function) | |
1571 | Lisp_Object function; | |
1572 | { | |
1573 | register Lisp_Object fun; | |
1574 | register Lisp_Object funcar; | |
db9f0278 JB |
1575 | |
1576 | fun = function; | |
1577 | ||
ffd56f97 JB |
1578 | fun = indirect_function (fun); |
1579 | if (EQ (fun, Qunbound)) | |
1580 | return Qnil; | |
db9f0278 JB |
1581 | |
1582 | /* Emacs primitives are interactive if their DEFUN specifies an | |
1583 | interactive spec. */ | |
90165123 | 1584 | if (SUBRP (fun)) |
db9f0278 JB |
1585 | { |
1586 | if (XSUBR (fun)->prompt) | |
1587 | return Qt; | |
1588 | else | |
1589 | return Qnil; | |
1590 | } | |
1591 | ||
1592 | /* Bytecode objects are interactive if they are long enough to | |
1593 | have an element whose index is COMPILED_INTERACTIVE, which is | |
1594 | where the interactive spec is stored. */ | |
90165123 | 1595 | else if (COMPILEDP (fun)) |
f9b4aacf | 1596 | return ((XVECTOR (fun)->size & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE |
db9f0278 JB |
1597 | ? Qt : Qnil); |
1598 | ||
1599 | /* Strings and vectors are keyboard macros. */ | |
90165123 | 1600 | if (STRINGP (fun) || VECTORP (fun)) |
db9f0278 JB |
1601 | return Qt; |
1602 | ||
1603 | /* Lists may represent commands. */ | |
1604 | if (!CONSP (fun)) | |
1605 | return Qnil; | |
1606 | funcar = Fcar (fun); | |
90165123 | 1607 | if (!SYMBOLP (funcar)) |
db9f0278 JB |
1608 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); |
1609 | if (EQ (funcar, Qlambda)) | |
1610 | return Fassq (Qinteractive, Fcdr (Fcdr (fun))); | |
1611 | if (EQ (funcar, Qmocklisp)) | |
1612 | return Qt; /* All mocklisp functions can be called interactively */ | |
1613 | if (EQ (funcar, Qautoload)) | |
1614 | return Fcar (Fcdr (Fcdr (Fcdr (fun)))); | |
1615 | else | |
1616 | return Qnil; | |
1617 | } | |
1618 | ||
1619 | /* ARGSUSED */ | |
1620 | DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0, | |
1621 | "Define FUNCTION to autoload from FILE.\n\ | |
1622 | FUNCTION is a symbol; FILE is a file name string to pass to `load'.\n\ | |
1623 | Third arg DOCSTRING is documentation for the function.\n\ | |
1624 | Fourth arg INTERACTIVE if non-nil says function can be called interactively.\n\ | |
ee9ee63c JB |
1625 | Fifth arg TYPE indicates the type of the object:\n\ |
1626 | nil or omitted says FUNCTION is a function,\n\ | |
1627 | `keymap' says FUNCTION is really a keymap, and\n\ | |
1628 | `macro' or t says FUNCTION is really a macro.\n\ | |
db9f0278 JB |
1629 | Third through fifth args give info about the real definition.\n\ |
1630 | They default to nil.\n\ | |
1631 | If FUNCTION is already defined other than as an autoload,\n\ | |
1632 | this does nothing and returns nil.") | |
ee9ee63c JB |
1633 | (function, file, docstring, interactive, type) |
1634 | Lisp_Object function, file, docstring, interactive, type; | |
db9f0278 JB |
1635 | { |
1636 | #ifdef NO_ARG_ARRAY | |
1637 | Lisp_Object args[4]; | |
1638 | #endif | |
1639 | ||
1640 | CHECK_SYMBOL (function, 0); | |
1641 | CHECK_STRING (file, 1); | |
1642 | ||
1643 | /* If function is defined and not as an autoload, don't override */ | |
1644 | if (!EQ (XSYMBOL (function)->function, Qunbound) | |
90165123 | 1645 | && !(CONSP (XSYMBOL (function)->function) |
03699b14 | 1646 | && EQ (XCAR (XSYMBOL (function)->function), Qautoload))) |
db9f0278 JB |
1647 | return Qnil; |
1648 | ||
1649 | #ifdef NO_ARG_ARRAY | |
1650 | args[0] = file; | |
1651 | args[1] = docstring; | |
1652 | args[2] = interactive; | |
ee9ee63c | 1653 | args[3] = type; |
db9f0278 JB |
1654 | |
1655 | return Ffset (function, Fcons (Qautoload, Flist (4, &args[0]))); | |
1656 | #else /* NO_ARG_ARRAY */ | |
1657 | return Ffset (function, Fcons (Qautoload, Flist (4, &file))); | |
1658 | #endif /* not NO_ARG_ARRAY */ | |
1659 | } | |
1660 | ||
1661 | Lisp_Object | |
1662 | un_autoload (oldqueue) | |
1663 | Lisp_Object oldqueue; | |
1664 | { | |
1665 | register Lisp_Object queue, first, second; | |
1666 | ||
1667 | /* Queue to unwind is current value of Vautoload_queue. | |
1668 | oldqueue is the shadowed value to leave in Vautoload_queue. */ | |
1669 | queue = Vautoload_queue; | |
1670 | Vautoload_queue = oldqueue; | |
1671 | while (CONSP (queue)) | |
1672 | { | |
1673 | first = Fcar (queue); | |
1674 | second = Fcdr (first); | |
1675 | first = Fcar (first); | |
1676 | if (EQ (second, Qnil)) | |
1677 | Vfeatures = first; | |
1678 | else | |
1679 | Ffset (first, second); | |
1680 | queue = Fcdr (queue); | |
1681 | } | |
1682 | return Qnil; | |
1683 | } | |
1684 | ||
ca20916b RS |
1685 | /* Load an autoloaded function. |
1686 | FUNNAME is the symbol which is the function's name. | |
1687 | FUNDEF is the autoload definition (a list). */ | |
1688 | ||
045ba794 | 1689 | void |
db9f0278 JB |
1690 | do_autoload (fundef, funname) |
1691 | Lisp_Object fundef, funname; | |
1692 | { | |
1693 | int count = specpdl_ptr - specpdl; | |
cb81ac97 | 1694 | Lisp_Object fun, queue, first, second; |
ca20916b | 1695 | struct gcpro gcpro1, gcpro2, gcpro3; |
db9f0278 JB |
1696 | |
1697 | fun = funname; | |
1698 | CHECK_SYMBOL (funname, 0); | |
ca20916b | 1699 | GCPRO3 (fun, funname, fundef); |
db9f0278 | 1700 | |
f87740dc RS |
1701 | /* Preserve the match data. */ |
1702 | record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); | |
1703 | ||
1704 | /* Value saved here is to be restored into Vautoload_queue. */ | |
db9f0278 JB |
1705 | record_unwind_protect (un_autoload, Vautoload_queue); |
1706 | Vautoload_queue = Qt; | |
4aac2302 | 1707 | Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt); |
2a49b6e5 | 1708 | |
f87740dc | 1709 | /* Save the old autoloads, in case we ever do an unload. */ |
2a49b6e5 RS |
1710 | queue = Vautoload_queue; |
1711 | while (CONSP (queue)) | |
1712 | { | |
1713 | first = Fcar (queue); | |
1714 | second = Fcdr (first); | |
1715 | first = Fcar (first); | |
5739ce6b ER |
1716 | |
1717 | /* Note: This test is subtle. The cdr of an autoload-queue entry | |
1718 | may be an atom if the autoload entry was generated by a defalias | |
f87740dc | 1719 | or fset. */ |
5739ce6b | 1720 | if (CONSP (second)) |
03e267c2 | 1721 | Fput (first, Qautoload, (Fcdr (second))); |
5739ce6b | 1722 | |
2a49b6e5 RS |
1723 | queue = Fcdr (queue); |
1724 | } | |
1725 | ||
db9f0278 JB |
1726 | /* Once loading finishes, don't undo it. */ |
1727 | Vautoload_queue = Qt; | |
1728 | unbind_to (count, Qnil); | |
1729 | ||
ffd56f97 JB |
1730 | fun = Findirect_function (fun); |
1731 | ||
76c2b0cc | 1732 | if (!NILP (Fequal (fun, fundef))) |
db9f0278 JB |
1733 | error ("Autoloading failed to define function %s", |
1734 | XSYMBOL (funname)->name->data); | |
ca20916b | 1735 | UNGCPRO; |
db9f0278 JB |
1736 | } |
1737 | \f | |
1738 | DEFUN ("eval", Feval, Seval, 1, 1, 0, | |
1739 | "Evaluate FORM and return its value.") | |
1740 | (form) | |
1741 | Lisp_Object form; | |
1742 | { | |
1743 | Lisp_Object fun, val, original_fun, original_args; | |
1744 | Lisp_Object funcar; | |
1745 | struct backtrace backtrace; | |
1746 | struct gcpro gcpro1, gcpro2, gcpro3; | |
1747 | ||
48f8dfa3 GM |
1748 | /* Since Fsignal resets this to 0, it had better be 0 now |
1749 | or else we have a potential bug. */ | |
1750 | if (interrupt_input_blocked != 0) | |
1751 | abort (); | |
1752 | ||
90165123 | 1753 | if (SYMBOLP (form)) |
db9f0278 JB |
1754 | { |
1755 | if (EQ (Vmocklisp_arguments, Qt)) | |
1756 | return Fsymbol_value (form); | |
1757 | val = Fsymbol_value (form); | |
265a9e55 | 1758 | if (NILP (val)) |
a631e24c | 1759 | XSETFASTINT (val, 0); |
db9f0278 | 1760 | else if (EQ (val, Qt)) |
a631e24c | 1761 | XSETFASTINT (val, 1); |
db9f0278 JB |
1762 | return val; |
1763 | } | |
1764 | if (!CONSP (form)) | |
1765 | return form; | |
1766 | ||
1767 | QUIT; | |
1768 | if (consing_since_gc > gc_cons_threshold) | |
1769 | { | |
1770 | GCPRO1 (form); | |
1771 | Fgarbage_collect (); | |
1772 | UNGCPRO; | |
1773 | } | |
1774 | ||
1775 | if (++lisp_eval_depth > max_lisp_eval_depth) | |
1776 | { | |
1777 | if (max_lisp_eval_depth < 100) | |
1778 | max_lisp_eval_depth = 100; | |
1779 | if (lisp_eval_depth > max_lisp_eval_depth) | |
1780 | error ("Lisp nesting exceeds max-lisp-eval-depth"); | |
1781 | } | |
1782 | ||
1783 | original_fun = Fcar (form); | |
1784 | original_args = Fcdr (form); | |
1785 | ||
1786 | backtrace.next = backtrace_list; | |
1787 | backtrace_list = &backtrace; | |
1788 | backtrace.function = &original_fun; /* This also protects them from gc */ | |
1789 | backtrace.args = &original_args; | |
1790 | backtrace.nargs = UNEVALLED; | |
1791 | backtrace.evalargs = 1; | |
1792 | backtrace.debug_on_exit = 0; | |
1793 | ||
1794 | if (debug_on_next_call) | |
1795 | do_debug_on_call (Qt); | |
1796 | ||
1797 | /* At this point, only original_fun and original_args | |
1798 | have values that will be used below */ | |
1799 | retry: | |
ffd56f97 | 1800 | fun = Findirect_function (original_fun); |
db9f0278 | 1801 | |
90165123 | 1802 | if (SUBRP (fun)) |
db9f0278 JB |
1803 | { |
1804 | Lisp_Object numargs; | |
166c822d | 1805 | Lisp_Object argvals[8]; |
db9f0278 JB |
1806 | Lisp_Object args_left; |
1807 | register int i, maxargs; | |
1808 | ||
1809 | args_left = original_args; | |
1810 | numargs = Flength (args_left); | |
1811 | ||
1812 | if (XINT (numargs) < XSUBR (fun)->min_args || | |
1813 | (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs))) | |
1814 | return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | |
1815 | ||
1816 | if (XSUBR (fun)->max_args == UNEVALLED) | |
1817 | { | |
1818 | backtrace.evalargs = 0; | |
1819 | val = (*XSUBR (fun)->function) (args_left); | |
1820 | goto done; | |
1821 | } | |
1822 | ||
1823 | if (XSUBR (fun)->max_args == MANY) | |
1824 | { | |
1825 | /* Pass a vector of evaluated arguments */ | |
1826 | Lisp_Object *vals; | |
1827 | register int argnum = 0; | |
1828 | ||
1829 | vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object)); | |
1830 | ||
1831 | GCPRO3 (args_left, fun, fun); | |
1832 | gcpro3.var = vals; | |
1833 | gcpro3.nvars = 0; | |
1834 | ||
265a9e55 | 1835 | while (!NILP (args_left)) |
db9f0278 JB |
1836 | { |
1837 | vals[argnum++] = Feval (Fcar (args_left)); | |
1838 | args_left = Fcdr (args_left); | |
1839 | gcpro3.nvars = argnum; | |
1840 | } | |
db9f0278 JB |
1841 | |
1842 | backtrace.args = vals; | |
1843 | backtrace.nargs = XINT (numargs); | |
1844 | ||
1845 | val = (*XSUBR (fun)->function) (XINT (numargs), vals); | |
a6e3fa71 | 1846 | UNGCPRO; |
db9f0278 JB |
1847 | goto done; |
1848 | } | |
1849 | ||
1850 | GCPRO3 (args_left, fun, fun); | |
1851 | gcpro3.var = argvals; | |
1852 | gcpro3.nvars = 0; | |
1853 | ||
1854 | maxargs = XSUBR (fun)->max_args; | |
1855 | for (i = 0; i < maxargs; args_left = Fcdr (args_left)) | |
1856 | { | |
1857 | argvals[i] = Feval (Fcar (args_left)); | |
1858 | gcpro3.nvars = ++i; | |
1859 | } | |
1860 | ||
1861 | UNGCPRO; | |
1862 | ||
1863 | backtrace.args = argvals; | |
1864 | backtrace.nargs = XINT (numargs); | |
1865 | ||
1866 | switch (i) | |
1867 | { | |
1868 | case 0: | |
1869 | val = (*XSUBR (fun)->function) (); | |
1870 | goto done; | |
1871 | case 1: | |
1872 | val = (*XSUBR (fun)->function) (argvals[0]); | |
1873 | goto done; | |
1874 | case 2: | |
1875 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1]); | |
1876 | goto done; | |
1877 | case 3: | |
1878 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1], | |
1879 | argvals[2]); | |
1880 | goto done; | |
1881 | case 4: | |
1882 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1], | |
1883 | argvals[2], argvals[3]); | |
1884 | goto done; | |
1885 | case 5: | |
1886 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], | |
1887 | argvals[3], argvals[4]); | |
1888 | goto done; | |
1889 | case 6: | |
1890 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], | |
1891 | argvals[3], argvals[4], argvals[5]); | |
1892 | goto done; | |
15c65264 RS |
1893 | case 7: |
1894 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], | |
1895 | argvals[3], argvals[4], argvals[5], | |
1896 | argvals[6]); | |
1897 | goto done; | |
db9f0278 | 1898 | |
166c822d KH |
1899 | case 8: |
1900 | val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], | |
1901 | argvals[3], argvals[4], argvals[5], | |
1902 | argvals[6], argvals[7]); | |
1903 | goto done; | |
1904 | ||
db9f0278 | 1905 | default: |
08564963 JB |
1906 | /* Someone has created a subr that takes more arguments than |
1907 | is supported by this code. We need to either rewrite the | |
1908 | subr to use a different argument protocol, or add more | |
1909 | cases to this switch. */ | |
1910 | abort (); | |
db9f0278 JB |
1911 | } |
1912 | } | |
90165123 | 1913 | if (COMPILEDP (fun)) |
db9f0278 JB |
1914 | val = apply_lambda (fun, original_args, 1); |
1915 | else | |
1916 | { | |
1917 | if (!CONSP (fun)) | |
1918 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
1919 | funcar = Fcar (fun); | |
90165123 | 1920 | if (!SYMBOLP (funcar)) |
db9f0278 JB |
1921 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); |
1922 | if (EQ (funcar, Qautoload)) | |
1923 | { | |
1924 | do_autoload (fun, original_fun); | |
1925 | goto retry; | |
1926 | } | |
1927 | if (EQ (funcar, Qmacro)) | |
1928 | val = Feval (apply1 (Fcdr (fun), original_args)); | |
1929 | else if (EQ (funcar, Qlambda)) | |
1930 | val = apply_lambda (fun, original_args, 1); | |
1931 | else if (EQ (funcar, Qmocklisp)) | |
1932 | val = ml_apply (fun, original_args); | |
1933 | else | |
1934 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
1935 | } | |
1936 | done: | |
1937 | if (!EQ (Vmocklisp_arguments, Qt)) | |
1938 | { | |
265a9e55 | 1939 | if (NILP (val)) |
a631e24c | 1940 | XSETFASTINT (val, 0); |
db9f0278 | 1941 | else if (EQ (val, Qt)) |
a631e24c | 1942 | XSETFASTINT (val, 1); |
db9f0278 JB |
1943 | } |
1944 | lisp_eval_depth--; | |
1945 | if (backtrace.debug_on_exit) | |
1946 | val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); | |
1947 | backtrace_list = backtrace.next; | |
1948 | return val; | |
1949 | } | |
1950 | \f | |
1951 | DEFUN ("apply", Fapply, Sapply, 2, MANY, 0, | |
1952 | "Call FUNCTION with our remaining args, using our last arg as list of args.\n\ | |
fd7fe9a1 | 1953 | Then return the value FUNCTION returns.\n\ |
db9f0278 JB |
1954 | Thus, (apply '+ 1 2 '(3 4)) returns 10.") |
1955 | (nargs, args) | |
1956 | int nargs; | |
1957 | Lisp_Object *args; | |
1958 | { | |
1959 | register int i, numargs; | |
1960 | register Lisp_Object spread_arg; | |
1961 | register Lisp_Object *funcall_args; | |
db9f0278 | 1962 | Lisp_Object fun; |
a6e3fa71 | 1963 | struct gcpro gcpro1; |
db9f0278 JB |
1964 | |
1965 | fun = args [0]; | |
1966 | funcall_args = 0; | |
1967 | spread_arg = args [nargs - 1]; | |
1968 | CHECK_LIST (spread_arg, nargs); | |
1969 | ||
1970 | numargs = XINT (Flength (spread_arg)); | |
1971 | ||
1972 | if (numargs == 0) | |
1973 | return Ffuncall (nargs - 1, args); | |
1974 | else if (numargs == 1) | |
1975 | { | |
03699b14 | 1976 | args [nargs - 1] = XCAR (spread_arg); |
db9f0278 JB |
1977 | return Ffuncall (nargs, args); |
1978 | } | |
1979 | ||
a6e3fa71 | 1980 | numargs += nargs - 2; |
db9f0278 | 1981 | |
ffd56f97 JB |
1982 | fun = indirect_function (fun); |
1983 | if (EQ (fun, Qunbound)) | |
db9f0278 | 1984 | { |
ffd56f97 JB |
1985 | /* Let funcall get the error */ |
1986 | fun = args[0]; | |
1987 | goto funcall; | |
db9f0278 JB |
1988 | } |
1989 | ||
90165123 | 1990 | if (SUBRP (fun)) |
db9f0278 JB |
1991 | { |
1992 | if (numargs < XSUBR (fun)->min_args | |
1993 | || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) | |
1994 | goto funcall; /* Let funcall get the error */ | |
1995 | else if (XSUBR (fun)->max_args > numargs) | |
1996 | { | |
1997 | /* Avoid making funcall cons up a yet another new vector of arguments | |
1998 | by explicitly supplying nil's for optional values */ | |
1999 | funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args) | |
2000 | * sizeof (Lisp_Object)); | |
2001 | for (i = numargs; i < XSUBR (fun)->max_args;) | |
2002 | funcall_args[++i] = Qnil; | |
a6e3fa71 JB |
2003 | GCPRO1 (*funcall_args); |
2004 | gcpro1.nvars = 1 + XSUBR (fun)->max_args; | |
db9f0278 JB |
2005 | } |
2006 | } | |
2007 | funcall: | |
2008 | /* We add 1 to numargs because funcall_args includes the | |
2009 | function itself as well as its arguments. */ | |
2010 | if (!funcall_args) | |
a6e3fa71 JB |
2011 | { |
2012 | funcall_args = (Lisp_Object *) alloca ((1 + numargs) | |
2013 | * sizeof (Lisp_Object)); | |
2014 | GCPRO1 (*funcall_args); | |
2015 | gcpro1.nvars = 1 + numargs; | |
2016 | } | |
2017 | ||
db9f0278 JB |
2018 | bcopy (args, funcall_args, nargs * sizeof (Lisp_Object)); |
2019 | /* Spread the last arg we got. Its first element goes in | |
2020 | the slot that it used to occupy, hence this value of I. */ | |
2021 | i = nargs - 1; | |
265a9e55 | 2022 | while (!NILP (spread_arg)) |
db9f0278 | 2023 | { |
03699b14 KR |
2024 | funcall_args [i++] = XCAR (spread_arg); |
2025 | spread_arg = XCDR (spread_arg); | |
db9f0278 | 2026 | } |
a6e3fa71 JB |
2027 | |
2028 | RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); | |
db9f0278 JB |
2029 | } |
2030 | \f | |
ff936e53 SM |
2031 | /* Run hook variables in various ways. */ |
2032 | ||
2033 | enum run_hooks_condition {to_completion, until_success, until_failure}; | |
2034 | ||
2035 | DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 1, MANY, 0, | |
2036 | "Run each hook in HOOKS. Major mode functions use this.\n\ | |
2037 | Each argument should be a symbol, a hook variable.\n\ | |
2038 | These symbols are processed in the order specified.\n\ | |
2039 | If a hook symbol has a non-nil value, that value may be a function\n\ | |
2040 | or a list of functions to be called to run the hook.\n\ | |
2041 | If the value is a function, it is called with no arguments.\n\ | |
2042 | If it is a list, the elements are called, in order, with no arguments.\n\ | |
2043 | \n\ | |
2044 | To make a hook variable buffer-local, use `make-local-hook',\n\ | |
2045 | not `make-local-variable'.") | |
2046 | (nargs, args) | |
2047 | int nargs; | |
2048 | Lisp_Object *args; | |
2049 | { | |
2050 | Lisp_Object hook[1]; | |
2051 | register int i; | |
2052 | ||
2053 | for (i = 0; i < nargs; i++) | |
2054 | { | |
2055 | hook[0] = args[i]; | |
2056 | run_hook_with_args (1, hook, to_completion); | |
2057 | } | |
2058 | ||
2059 | return Qnil; | |
2060 | } | |
2061 | ||
a0d76c27 EN |
2062 | DEFUN ("run-hook-with-args", Frun_hook_with_args, |
2063 | Srun_hook_with_args, 1, MANY, 0, | |
b0b667cb KH |
2064 | "Run HOOK with the specified arguments ARGS.\n\ |
2065 | HOOK should be a symbol, a hook variable. If HOOK has a non-nil\n\ | |
2066 | value, that value may be a function or a list of functions to be\n\ | |
2067 | called to run the hook. If the value is a function, it is called with\n\ | |
2068 | the given arguments and its return value is returned. If it is a list\n\ | |
2069 | of functions, those functions are called, in order,\n\ | |
2070 | with the given arguments ARGS.\n\ | |
2071 | It is best not to depend on the value return by `run-hook-with-args',\n\ | |
2072 | as that may change.\n\ | |
2073 | \n\ | |
ff936e53 SM |
2074 | To make a hook variable buffer-local, use `make-local-hook',\n\ |
2075 | not `make-local-variable'.") | |
2076 | (nargs, args) | |
2077 | int nargs; | |
2078 | Lisp_Object *args; | |
2079 | { | |
2080 | return run_hook_with_args (nargs, args, to_completion); | |
2081 | } | |
2082 | ||
a0d76c27 EN |
2083 | DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, |
2084 | Srun_hook_with_args_until_success, 1, MANY, 0, | |
ff936e53 SM |
2085 | "Run HOOK with the specified arguments ARGS.\n\ |
2086 | HOOK should be a symbol, a hook variable. Its value should\n\ | |
2087 | be a list of functions. We call those functions, one by one,\n\ | |
2088 | passing arguments ARGS to each of them, until one of them\n\ | |
2089 | returns a non-nil value. Then we return that value.\n\ | |
2090 | If all the functions return nil, we return nil.\n\ | |
2091 | \n\ | |
2092 | To make a hook variable buffer-local, use `make-local-hook',\n\ | |
2093 | not `make-local-variable'.") | |
b0b667cb KH |
2094 | (nargs, args) |
2095 | int nargs; | |
2096 | Lisp_Object *args; | |
2097 | { | |
ff936e53 SM |
2098 | return run_hook_with_args (nargs, args, until_success); |
2099 | } | |
2100 | ||
a0d76c27 EN |
2101 | DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, |
2102 | Srun_hook_with_args_until_failure, 1, MANY, 0, | |
ff936e53 SM |
2103 | "Run HOOK with the specified arguments ARGS.\n\ |
2104 | HOOK should be a symbol, a hook variable. Its value should\n\ | |
2105 | be a list of functions. We call those functions, one by one,\n\ | |
2106 | passing arguments ARGS to each of them, until one of them\n\ | |
2107 | returns nil. Then we return nil.\n\ | |
2108 | If all the functions return non-nil, we return non-nil.\n\ | |
2109 | \n\ | |
2110 | To make a hook variable buffer-local, use `make-local-hook',\n\ | |
2111 | not `make-local-variable'.") | |
2112 | (nargs, args) | |
2113 | int nargs; | |
2114 | Lisp_Object *args; | |
2115 | { | |
2116 | return run_hook_with_args (nargs, args, until_failure); | |
2117 | } | |
2118 | ||
c933ea05 RS |
2119 | /* ARGS[0] should be a hook symbol. |
2120 | Call each of the functions in the hook value, passing each of them | |
2121 | as arguments all the rest of ARGS (all NARGS - 1 elements). | |
2122 | COND specifies a condition to test after each call | |
2123 | to decide whether to stop. | |
2124 | The caller (or its caller, etc) must gcpro all of ARGS, | |
2125 | except that it isn't necessary to gcpro ARGS[0]. */ | |
2126 | ||
ff936e53 SM |
2127 | Lisp_Object |
2128 | run_hook_with_args (nargs, args, cond) | |
2129 | int nargs; | |
2130 | Lisp_Object *args; | |
2131 | enum run_hooks_condition cond; | |
2132 | { | |
2133 | Lisp_Object sym, val, ret; | |
fada05d6 KH |
2134 | Lisp_Object globals; |
2135 | struct gcpro gcpro1, gcpro2, gcpro3; | |
b0b667cb | 2136 | |
f029ca5f RS |
2137 | /* If we are dying or still initializing, |
2138 | don't do anything--it would probably crash if we tried. */ | |
2139 | if (NILP (Vrun_hooks)) | |
caff32a7 | 2140 | return Qnil; |
f029ca5f | 2141 | |
b0b667cb | 2142 | sym = args[0]; |
aa681b51 | 2143 | val = find_symbol_value (sym); |
ff936e53 SM |
2144 | ret = (cond == until_failure ? Qt : Qnil); |
2145 | ||
b0b667cb | 2146 | if (EQ (val, Qunbound) || NILP (val)) |
ff936e53 | 2147 | return ret; |
03699b14 | 2148 | else if (!CONSP (val) || EQ (XCAR (val), Qlambda)) |
b0b667cb KH |
2149 | { |
2150 | args[0] = val; | |
2151 | return Ffuncall (nargs, args); | |
2152 | } | |
2153 | else | |
2154 | { | |
fada05d6 KH |
2155 | globals = Qnil; |
2156 | GCPRO3 (sym, val, globals); | |
cb9d21f8 | 2157 | |
ff936e53 SM |
2158 | for (; |
2159 | CONSP (val) && ((cond == to_completion) | |
2160 | || (cond == until_success ? NILP (ret) | |
2161 | : !NILP (ret))); | |
03699b14 | 2162 | val = XCDR (val)) |
b0b667cb | 2163 | { |
03699b14 | 2164 | if (EQ (XCAR (val), Qt)) |
b0b667cb KH |
2165 | { |
2166 | /* t indicates this hook has a local binding; | |
2167 | it means to run the global binding too. */ | |
b0b667cb | 2168 | |
ff936e53 SM |
2169 | for (globals = Fdefault_value (sym); |
2170 | CONSP (globals) && ((cond == to_completion) | |
2171 | || (cond == until_success ? NILP (ret) | |
2172 | : !NILP (ret))); | |
03699b14 | 2173 | globals = XCDR (globals)) |
b0b667cb | 2174 | { |
03699b14 | 2175 | args[0] = XCAR (globals); |
77d92e05 RS |
2176 | /* In a global value, t should not occur. If it does, we |
2177 | must ignore it to avoid an endless loop. */ | |
2178 | if (!EQ (args[0], Qt)) | |
2179 | ret = Ffuncall (nargs, args); | |
b0b667cb KH |
2180 | } |
2181 | } | |
2182 | else | |
2183 | { | |
03699b14 | 2184 | args[0] = XCAR (val); |
ff936e53 | 2185 | ret = Ffuncall (nargs, args); |
b0b667cb KH |
2186 | } |
2187 | } | |
cb9d21f8 RS |
2188 | |
2189 | UNGCPRO; | |
ff936e53 | 2190 | return ret; |
b0b667cb KH |
2191 | } |
2192 | } | |
c933ea05 RS |
2193 | |
2194 | /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual | |
2195 | present value of that symbol. | |
2196 | Call each element of FUNLIST, | |
2197 | passing each of them the rest of ARGS. | |
2198 | The caller (or its caller, etc) must gcpro all of ARGS, | |
2199 | except that it isn't necessary to gcpro ARGS[0]. */ | |
2200 | ||
2201 | Lisp_Object | |
2202 | run_hook_list_with_args (funlist, nargs, args) | |
2203 | Lisp_Object funlist; | |
2204 | int nargs; | |
2205 | Lisp_Object *args; | |
2206 | { | |
2207 | Lisp_Object sym; | |
2208 | Lisp_Object val; | |
fada05d6 KH |
2209 | Lisp_Object globals; |
2210 | struct gcpro gcpro1, gcpro2, gcpro3; | |
c933ea05 RS |
2211 | |
2212 | sym = args[0]; | |
fada05d6 KH |
2213 | globals = Qnil; |
2214 | GCPRO3 (sym, val, globals); | |
c933ea05 | 2215 | |
03699b14 | 2216 | for (val = funlist; CONSP (val); val = XCDR (val)) |
c933ea05 | 2217 | { |
03699b14 | 2218 | if (EQ (XCAR (val), Qt)) |
c933ea05 RS |
2219 | { |
2220 | /* t indicates this hook has a local binding; | |
2221 | it means to run the global binding too. */ | |
c933ea05 RS |
2222 | |
2223 | for (globals = Fdefault_value (sym); | |
2224 | CONSP (globals); | |
03699b14 | 2225 | globals = XCDR (globals)) |
c933ea05 | 2226 | { |
03699b14 | 2227 | args[0] = XCAR (globals); |
77d92e05 RS |
2228 | /* In a global value, t should not occur. If it does, we |
2229 | must ignore it to avoid an endless loop. */ | |
2230 | if (!EQ (args[0], Qt)) | |
2231 | Ffuncall (nargs, args); | |
c933ea05 RS |
2232 | } |
2233 | } | |
2234 | else | |
2235 | { | |
03699b14 | 2236 | args[0] = XCAR (val); |
c933ea05 RS |
2237 | Ffuncall (nargs, args); |
2238 | } | |
2239 | } | |
2240 | UNGCPRO; | |
2241 | return Qnil; | |
2242 | } | |
7d48558f RS |
2243 | |
2244 | /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */ | |
2245 | ||
2246 | void | |
2247 | run_hook_with_args_2 (hook, arg1, arg2) | |
2248 | Lisp_Object hook, arg1, arg2; | |
2249 | { | |
2250 | Lisp_Object temp[3]; | |
2251 | temp[0] = hook; | |
2252 | temp[1] = arg1; | |
2253 | temp[2] = arg2; | |
2254 | ||
2255 | Frun_hook_with_args (3, temp); | |
2256 | } | |
ff936e53 | 2257 | \f |
db9f0278 JB |
2258 | /* Apply fn to arg */ |
2259 | Lisp_Object | |
2260 | apply1 (fn, arg) | |
2261 | Lisp_Object fn, arg; | |
2262 | { | |
a6e3fa71 JB |
2263 | struct gcpro gcpro1; |
2264 | ||
2265 | GCPRO1 (fn); | |
265a9e55 | 2266 | if (NILP (arg)) |
a6e3fa71 JB |
2267 | RETURN_UNGCPRO (Ffuncall (1, &fn)); |
2268 | gcpro1.nvars = 2; | |
db9f0278 JB |
2269 | #ifdef NO_ARG_ARRAY |
2270 | { | |
2271 | Lisp_Object args[2]; | |
2272 | args[0] = fn; | |
2273 | args[1] = arg; | |
a6e3fa71 JB |
2274 | gcpro1.var = args; |
2275 | RETURN_UNGCPRO (Fapply (2, args)); | |
db9f0278 JB |
2276 | } |
2277 | #else /* not NO_ARG_ARRAY */ | |
a6e3fa71 | 2278 | RETURN_UNGCPRO (Fapply (2, &fn)); |
db9f0278 JB |
2279 | #endif /* not NO_ARG_ARRAY */ |
2280 | } | |
2281 | ||
2282 | /* Call function fn on no arguments */ | |
2283 | Lisp_Object | |
2284 | call0 (fn) | |
2285 | Lisp_Object fn; | |
2286 | { | |
a6e3fa71 JB |
2287 | struct gcpro gcpro1; |
2288 | ||
2289 | GCPRO1 (fn); | |
2290 | RETURN_UNGCPRO (Ffuncall (1, &fn)); | |
db9f0278 JB |
2291 | } |
2292 | ||
15285f9f | 2293 | /* Call function fn with 1 argument arg1 */ |
db9f0278 JB |
2294 | /* ARGSUSED */ |
2295 | Lisp_Object | |
15285f9f RS |
2296 | call1 (fn, arg1) |
2297 | Lisp_Object fn, arg1; | |
db9f0278 | 2298 | { |
a6e3fa71 | 2299 | struct gcpro gcpro1; |
db9f0278 | 2300 | #ifdef NO_ARG_ARRAY |
a6e3fa71 JB |
2301 | Lisp_Object args[2]; |
2302 | ||
db9f0278 | 2303 | args[0] = fn; |
15285f9f | 2304 | args[1] = arg1; |
a6e3fa71 JB |
2305 | GCPRO1 (args[0]); |
2306 | gcpro1.nvars = 2; | |
2307 | RETURN_UNGCPRO (Ffuncall (2, args)); | |
db9f0278 | 2308 | #else /* not NO_ARG_ARRAY */ |
a6e3fa71 JB |
2309 | GCPRO1 (fn); |
2310 | gcpro1.nvars = 2; | |
2311 | RETURN_UNGCPRO (Ffuncall (2, &fn)); | |
db9f0278 JB |
2312 | #endif /* not NO_ARG_ARRAY */ |
2313 | } | |
2314 | ||
15285f9f | 2315 | /* Call function fn with 2 arguments arg1, arg2 */ |
db9f0278 JB |
2316 | /* ARGSUSED */ |
2317 | Lisp_Object | |
15285f9f RS |
2318 | call2 (fn, arg1, arg2) |
2319 | Lisp_Object fn, arg1, arg2; | |
db9f0278 | 2320 | { |
a6e3fa71 | 2321 | struct gcpro gcpro1; |
db9f0278 JB |
2322 | #ifdef NO_ARG_ARRAY |
2323 | Lisp_Object args[3]; | |
2324 | args[0] = fn; | |
15285f9f RS |
2325 | args[1] = arg1; |
2326 | args[2] = arg2; | |
a6e3fa71 JB |
2327 | GCPRO1 (args[0]); |
2328 | gcpro1.nvars = 3; | |
2329 | RETURN_UNGCPRO (Ffuncall (3, args)); | |
db9f0278 | 2330 | #else /* not NO_ARG_ARRAY */ |
a6e3fa71 JB |
2331 | GCPRO1 (fn); |
2332 | gcpro1.nvars = 3; | |
2333 | RETURN_UNGCPRO (Ffuncall (3, &fn)); | |
db9f0278 JB |
2334 | #endif /* not NO_ARG_ARRAY */ |
2335 | } | |
2336 | ||
15285f9f | 2337 | /* Call function fn with 3 arguments arg1, arg2, arg3 */ |
db9f0278 JB |
2338 | /* ARGSUSED */ |
2339 | Lisp_Object | |
15285f9f RS |
2340 | call3 (fn, arg1, arg2, arg3) |
2341 | Lisp_Object fn, arg1, arg2, arg3; | |
db9f0278 | 2342 | { |
a6e3fa71 | 2343 | struct gcpro gcpro1; |
db9f0278 JB |
2344 | #ifdef NO_ARG_ARRAY |
2345 | Lisp_Object args[4]; | |
2346 | args[0] = fn; | |
15285f9f RS |
2347 | args[1] = arg1; |
2348 | args[2] = arg2; | |
2349 | args[3] = arg3; | |
a6e3fa71 JB |
2350 | GCPRO1 (args[0]); |
2351 | gcpro1.nvars = 4; | |
2352 | RETURN_UNGCPRO (Ffuncall (4, args)); | |
db9f0278 | 2353 | #else /* not NO_ARG_ARRAY */ |
a6e3fa71 JB |
2354 | GCPRO1 (fn); |
2355 | gcpro1.nvars = 4; | |
2356 | RETURN_UNGCPRO (Ffuncall (4, &fn)); | |
db9f0278 JB |
2357 | #endif /* not NO_ARG_ARRAY */ |
2358 | } | |
2359 | ||
15285f9f | 2360 | /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */ |
a5a44b91 JB |
2361 | /* ARGSUSED */ |
2362 | Lisp_Object | |
15285f9f RS |
2363 | call4 (fn, arg1, arg2, arg3, arg4) |
2364 | Lisp_Object fn, arg1, arg2, arg3, arg4; | |
a5a44b91 JB |
2365 | { |
2366 | struct gcpro gcpro1; | |
2367 | #ifdef NO_ARG_ARRAY | |
2368 | Lisp_Object args[5]; | |
2369 | args[0] = fn; | |
15285f9f RS |
2370 | args[1] = arg1; |
2371 | args[2] = arg2; | |
2372 | args[3] = arg3; | |
2373 | args[4] = arg4; | |
a5a44b91 JB |
2374 | GCPRO1 (args[0]); |
2375 | gcpro1.nvars = 5; | |
2376 | RETURN_UNGCPRO (Ffuncall (5, args)); | |
2377 | #else /* not NO_ARG_ARRAY */ | |
2378 | GCPRO1 (fn); | |
2379 | gcpro1.nvars = 5; | |
2380 | RETURN_UNGCPRO (Ffuncall (5, &fn)); | |
2381 | #endif /* not NO_ARG_ARRAY */ | |
2382 | } | |
2383 | ||
15285f9f RS |
2384 | /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */ |
2385 | /* ARGSUSED */ | |
2386 | Lisp_Object | |
2387 | call5 (fn, arg1, arg2, arg3, arg4, arg5) | |
2388 | Lisp_Object fn, arg1, arg2, arg3, arg4, arg5; | |
2389 | { | |
2390 | struct gcpro gcpro1; | |
2391 | #ifdef NO_ARG_ARRAY | |
2392 | Lisp_Object args[6]; | |
2393 | args[0] = fn; | |
2394 | args[1] = arg1; | |
2395 | args[2] = arg2; | |
2396 | args[3] = arg3; | |
2397 | args[4] = arg4; | |
2398 | args[5] = arg5; | |
2399 | GCPRO1 (args[0]); | |
2400 | gcpro1.nvars = 6; | |
2401 | RETURN_UNGCPRO (Ffuncall (6, args)); | |
2402 | #else /* not NO_ARG_ARRAY */ | |
2403 | GCPRO1 (fn); | |
2404 | gcpro1.nvars = 6; | |
2405 | RETURN_UNGCPRO (Ffuncall (6, &fn)); | |
2406 | #endif /* not NO_ARG_ARRAY */ | |
2407 | } | |
2408 | ||
2409 | /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */ | |
2410 | /* ARGSUSED */ | |
2411 | Lisp_Object | |
2412 | call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6) | |
2413 | Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6; | |
2414 | { | |
2415 | struct gcpro gcpro1; | |
2416 | #ifdef NO_ARG_ARRAY | |
2417 | Lisp_Object args[7]; | |
2418 | args[0] = fn; | |
2419 | args[1] = arg1; | |
2420 | args[2] = arg2; | |
2421 | args[3] = arg3; | |
2422 | args[4] = arg4; | |
2423 | args[5] = arg5; | |
2424 | args[6] = arg6; | |
2425 | GCPRO1 (args[0]); | |
2426 | gcpro1.nvars = 7; | |
2427 | RETURN_UNGCPRO (Ffuncall (7, args)); | |
2428 | #else /* not NO_ARG_ARRAY */ | |
2429 | GCPRO1 (fn); | |
2430 | gcpro1.nvars = 7; | |
2431 | RETURN_UNGCPRO (Ffuncall (7, &fn)); | |
2432 | #endif /* not NO_ARG_ARRAY */ | |
2433 | } | |
2434 | ||
db9f0278 JB |
2435 | DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0, |
2436 | "Call first argument as a function, passing remaining arguments to it.\n\ | |
fd7fe9a1 | 2437 | Return the value that function returns.\n\ |
db9f0278 JB |
2438 | Thus, (funcall 'cons 'x 'y) returns (x . y).") |
2439 | (nargs, args) | |
2440 | int nargs; | |
2441 | Lisp_Object *args; | |
2442 | { | |
2443 | Lisp_Object fun; | |
2444 | Lisp_Object funcar; | |
2445 | int numargs = nargs - 1; | |
2446 | Lisp_Object lisp_numargs; | |
2447 | Lisp_Object val; | |
2448 | struct backtrace backtrace; | |
2449 | register Lisp_Object *internal_args; | |
2450 | register int i; | |
2451 | ||
2452 | QUIT; | |
2453 | if (consing_since_gc > gc_cons_threshold) | |
a6e3fa71 | 2454 | Fgarbage_collect (); |
db9f0278 JB |
2455 | |
2456 | if (++lisp_eval_depth > max_lisp_eval_depth) | |
2457 | { | |
2458 | if (max_lisp_eval_depth < 100) | |
2459 | max_lisp_eval_depth = 100; | |
2460 | if (lisp_eval_depth > max_lisp_eval_depth) | |
2461 | error ("Lisp nesting exceeds max-lisp-eval-depth"); | |
2462 | } | |
2463 | ||
2464 | backtrace.next = backtrace_list; | |
2465 | backtrace_list = &backtrace; | |
2466 | backtrace.function = &args[0]; | |
2467 | backtrace.args = &args[1]; | |
2468 | backtrace.nargs = nargs - 1; | |
2469 | backtrace.evalargs = 0; | |
2470 | backtrace.debug_on_exit = 0; | |
2471 | ||
2472 | if (debug_on_next_call) | |
2473 | do_debug_on_call (Qlambda); | |
2474 | ||
2475 | retry: | |
2476 | ||
2477 | fun = args[0]; | |
ffd56f97 JB |
2478 | |
2479 | fun = Findirect_function (fun); | |
db9f0278 | 2480 | |
90165123 | 2481 | if (SUBRP (fun)) |
db9f0278 JB |
2482 | { |
2483 | if (numargs < XSUBR (fun)->min_args | |
2484 | || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) | |
2485 | { | |
a631e24c | 2486 | XSETFASTINT (lisp_numargs, numargs); |
db9f0278 JB |
2487 | return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil))); |
2488 | } | |
2489 | ||
2490 | if (XSUBR (fun)->max_args == UNEVALLED) | |
2491 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2492 | ||
2493 | if (XSUBR (fun)->max_args == MANY) | |
2494 | { | |
2495 | val = (*XSUBR (fun)->function) (numargs, args + 1); | |
2496 | goto done; | |
2497 | } | |
2498 | ||
2499 | if (XSUBR (fun)->max_args > numargs) | |
2500 | { | |
2501 | internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object)); | |
2502 | bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object)); | |
2503 | for (i = numargs; i < XSUBR (fun)->max_args; i++) | |
2504 | internal_args[i] = Qnil; | |
2505 | } | |
2506 | else | |
2507 | internal_args = args + 1; | |
2508 | switch (XSUBR (fun)->max_args) | |
2509 | { | |
2510 | case 0: | |
2511 | val = (*XSUBR (fun)->function) (); | |
2512 | goto done; | |
2513 | case 1: | |
2514 | val = (*XSUBR (fun)->function) (internal_args[0]); | |
2515 | goto done; | |
2516 | case 2: | |
2517 | val = (*XSUBR (fun)->function) (internal_args[0], | |
2518 | internal_args[1]); | |
2519 | goto done; | |
2520 | case 3: | |
2521 | val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2522 | internal_args[2]); | |
2523 | goto done; | |
2524 | case 4: | |
2525 | val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2526 | internal_args[2], | |
2527 | internal_args[3]); | |
2528 | goto done; | |
2529 | case 5: | |
2530 | val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2531 | internal_args[2], internal_args[3], | |
2532 | internal_args[4]); | |
2533 | goto done; | |
2534 | case 6: | |
2535 | val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2536 | internal_args[2], internal_args[3], | |
2537 | internal_args[4], internal_args[5]); | |
2538 | goto done; | |
15c65264 RS |
2539 | case 7: |
2540 | val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2541 | internal_args[2], internal_args[3], | |
2542 | internal_args[4], internal_args[5], | |
2543 | internal_args[6]); | |
2544 | goto done; | |
db9f0278 | 2545 | |
166c822d KH |
2546 | case 8: |
2547 | val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2548 | internal_args[2], internal_args[3], | |
2549 | internal_args[4], internal_args[5], | |
2550 | internal_args[6], internal_args[7]); | |
2551 | goto done; | |
2552 | ||
db9f0278 | 2553 | default: |
70ee42f7 | 2554 | |
166c822d | 2555 | /* If a subr takes more than 8 arguments without using MANY |
70ee42f7 JB |
2556 | or UNEVALLED, we need to extend this function to support it. |
2557 | Until this is done, there is no way to call the function. */ | |
2558 | abort (); | |
db9f0278 JB |
2559 | } |
2560 | } | |
90165123 | 2561 | if (COMPILEDP (fun)) |
db9f0278 JB |
2562 | val = funcall_lambda (fun, numargs, args + 1); |
2563 | else | |
2564 | { | |
2565 | if (!CONSP (fun)) | |
2566 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2567 | funcar = Fcar (fun); | |
90165123 | 2568 | if (!SYMBOLP (funcar)) |
db9f0278 JB |
2569 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); |
2570 | if (EQ (funcar, Qlambda)) | |
2571 | val = funcall_lambda (fun, numargs, args + 1); | |
2572 | else if (EQ (funcar, Qmocklisp)) | |
2573 | val = ml_apply (fun, Flist (numargs, args + 1)); | |
2574 | else if (EQ (funcar, Qautoload)) | |
2575 | { | |
2576 | do_autoload (fun, args[0]); | |
2577 | goto retry; | |
2578 | } | |
2579 | else | |
2580 | return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2581 | } | |
2582 | done: | |
2583 | lisp_eval_depth--; | |
2584 | if (backtrace.debug_on_exit) | |
2585 | val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); | |
2586 | backtrace_list = backtrace.next; | |
2587 | return val; | |
2588 | } | |
2589 | \f | |
2590 | Lisp_Object | |
2591 | apply_lambda (fun, args, eval_flag) | |
2592 | Lisp_Object fun, args; | |
2593 | int eval_flag; | |
2594 | { | |
2595 | Lisp_Object args_left; | |
2596 | Lisp_Object numargs; | |
2597 | register Lisp_Object *arg_vector; | |
2598 | struct gcpro gcpro1, gcpro2, gcpro3; | |
2599 | register int i; | |
2600 | register Lisp_Object tem; | |
2601 | ||
2602 | numargs = Flength (args); | |
2603 | arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object)); | |
2604 | args_left = args; | |
2605 | ||
2606 | GCPRO3 (*arg_vector, args_left, fun); | |
2607 | gcpro1.nvars = 0; | |
2608 | ||
2609 | for (i = 0; i < XINT (numargs);) | |
2610 | { | |
2611 | tem = Fcar (args_left), args_left = Fcdr (args_left); | |
2612 | if (eval_flag) tem = Feval (tem); | |
2613 | arg_vector[i++] = tem; | |
2614 | gcpro1.nvars = i; | |
2615 | } | |
2616 | ||
2617 | UNGCPRO; | |
2618 | ||
2619 | if (eval_flag) | |
2620 | { | |
2621 | backtrace_list->args = arg_vector; | |
2622 | backtrace_list->nargs = i; | |
2623 | } | |
2624 | backtrace_list->evalargs = 0; | |
2625 | tem = funcall_lambda (fun, XINT (numargs), arg_vector); | |
2626 | ||
2627 | /* Do the debug-on-exit now, while arg_vector still exists. */ | |
2628 | if (backtrace_list->debug_on_exit) | |
2629 | tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil))); | |
2630 | /* Don't do it again when we return to eval. */ | |
2631 | backtrace_list->debug_on_exit = 0; | |
2632 | return tem; | |
2633 | } | |
2634 | ||
2635 | /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR | |
2636 | and return the result of evaluation. | |
2637 | FUN must be either a lambda-expression or a compiled-code object. */ | |
2638 | ||
2639 | Lisp_Object | |
2640 | funcall_lambda (fun, nargs, arg_vector) | |
2641 | Lisp_Object fun; | |
2642 | int nargs; | |
2643 | register Lisp_Object *arg_vector; | |
2644 | { | |
2645 | Lisp_Object val, tem; | |
2646 | register Lisp_Object syms_left; | |
2647 | Lisp_Object numargs; | |
2648 | register Lisp_Object next; | |
2649 | int count = specpdl_ptr - specpdl; | |
2650 | register int i; | |
2651 | int optional = 0, rest = 0; | |
2652 | ||
2653 | specbind (Qmocklisp_arguments, Qt); /* t means NOT mocklisp! */ | |
2654 | ||
a631e24c | 2655 | XSETFASTINT (numargs, nargs); |
db9f0278 | 2656 | |
90165123 | 2657 | if (CONSP (fun)) |
db9f0278 | 2658 | syms_left = Fcar (Fcdr (fun)); |
90165123 | 2659 | else if (COMPILEDP (fun)) |
db9f0278 JB |
2660 | syms_left = XVECTOR (fun)->contents[COMPILED_ARGLIST]; |
2661 | else abort (); | |
2662 | ||
2663 | i = 0; | |
265a9e55 | 2664 | for (; !NILP (syms_left); syms_left = Fcdr (syms_left)) |
db9f0278 JB |
2665 | { |
2666 | QUIT; | |
2667 | next = Fcar (syms_left); | |
90165123 | 2668 | while (!SYMBOLP (next)) |
9ffa21d4 | 2669 | next = Fsignal (Qinvalid_function, Fcons (fun, Qnil)); |
db9f0278 JB |
2670 | if (EQ (next, Qand_rest)) |
2671 | rest = 1; | |
2672 | else if (EQ (next, Qand_optional)) | |
2673 | optional = 1; | |
2674 | else if (rest) | |
2675 | { | |
9ffa21d4 | 2676 | specbind (next, Flist (nargs - i, &arg_vector[i])); |
db9f0278 JB |
2677 | i = nargs; |
2678 | } | |
2679 | else if (i < nargs) | |
2680 | { | |
2681 | tem = arg_vector[i++]; | |
2682 | specbind (next, tem); | |
2683 | } | |
2684 | else if (!optional) | |
2685 | return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | |
2686 | else | |
2687 | specbind (next, Qnil); | |
2688 | } | |
2689 | ||
2690 | if (i < nargs) | |
2691 | return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | |
2692 | ||
90165123 | 2693 | if (CONSP (fun)) |
db9f0278 JB |
2694 | val = Fprogn (Fcdr (Fcdr (fun))); |
2695 | else | |
ca248607 RS |
2696 | { |
2697 | /* If we have not actually read the bytecode string | |
2698 | and constants vector yet, fetch them from the file. */ | |
2699 | if (CONSP (XVECTOR (fun)->contents[COMPILED_BYTECODE])) | |
661c7d6e | 2700 | Ffetch_bytecode (fun); |
ca248607 RS |
2701 | val = Fbyte_code (XVECTOR (fun)->contents[COMPILED_BYTECODE], |
2702 | XVECTOR (fun)->contents[COMPILED_CONSTANTS], | |
2703 | XVECTOR (fun)->contents[COMPILED_STACK_DEPTH]); | |
2704 | } | |
db9f0278 JB |
2705 | return unbind_to (count, val); |
2706 | } | |
661c7d6e KH |
2707 | |
2708 | DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode, | |
2709 | 1, 1, 0, | |
2710 | "If byte-compiled OBJECT is lazy-loaded, fetch it now.") | |
2711 | (object) | |
2712 | Lisp_Object object; | |
2713 | { | |
2714 | Lisp_Object tem; | |
2715 | ||
2716 | if (COMPILEDP (object) | |
2717 | && CONSP (XVECTOR (object)->contents[COMPILED_BYTECODE])) | |
2718 | { | |
2719 | tem = read_doc_string (XVECTOR (object)->contents[COMPILED_BYTECODE]); | |
5bbdb090 RS |
2720 | if (!CONSP (tem)) |
2721 | error ("invalid byte code"); | |
03699b14 KR |
2722 | XVECTOR (object)->contents[COMPILED_BYTECODE] = XCAR (tem); |
2723 | XVECTOR (object)->contents[COMPILED_CONSTANTS] = XCDR (tem); | |
661c7d6e KH |
2724 | } |
2725 | return object; | |
2726 | } | |
db9f0278 JB |
2727 | \f |
2728 | void | |
2729 | grow_specpdl () | |
2730 | { | |
2731 | register int count = specpdl_ptr - specpdl; | |
2732 | if (specpdl_size >= max_specpdl_size) | |
2733 | { | |
2734 | if (max_specpdl_size < 400) | |
2735 | max_specpdl_size = 400; | |
2736 | if (specpdl_size >= max_specpdl_size) | |
2737 | { | |
debee8fe RS |
2738 | if (!NILP (Vdebug_on_error)) |
2739 | /* Leave room for some specpdl in the debugger. */ | |
2740 | max_specpdl_size = specpdl_size + 100; | |
db9f0278 JB |
2741 | Fsignal (Qerror, |
2742 | Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil)); | |
db9f0278 JB |
2743 | } |
2744 | } | |
2745 | specpdl_size *= 2; | |
2746 | if (specpdl_size > max_specpdl_size) | |
2747 | specpdl_size = max_specpdl_size; | |
2748 | specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding)); | |
2749 | specpdl_ptr = specpdl + count; | |
2750 | } | |
2751 | ||
2752 | void | |
2753 | specbind (symbol, value) | |
2754 | Lisp_Object symbol, value; | |
2755 | { | |
db9f0278 JB |
2756 | Lisp_Object ovalue; |
2757 | ||
9ffa21d4 JB |
2758 | CHECK_SYMBOL (symbol, 0); |
2759 | ||
719177b3 RS |
2760 | ovalue = find_symbol_value (symbol); |
2761 | ||
db9f0278 JB |
2762 | if (specpdl_ptr == specpdl + specpdl_size) |
2763 | grow_specpdl (); | |
db9f0278 | 2764 | specpdl_ptr->func = 0; |
719177b3 RS |
2765 | specpdl_ptr->old_value = ovalue; |
2766 | ||
2767 | if (BUFFER_LOCAL_VALUEP (XSYMBOL (symbol)->value) | |
2768 | || SOME_BUFFER_LOCAL_VALUEP (XSYMBOL (symbol)->value) | |
2769 | || BUFFER_OBJFWDP (XSYMBOL (symbol)->value)) | |
2770 | { | |
27a6c729 | 2771 | Lisp_Object current_buffer, binding_buffer; |
719177b3 RS |
2772 | /* For a local variable, record both the symbol and which |
2773 | buffer's value we are saving. */ | |
27a6c729 RS |
2774 | current_buffer = Fcurrent_buffer (); |
2775 | binding_buffer = current_buffer; | |
719177b3 RS |
2776 | /* If the variable is not local in this buffer, |
2777 | we are saving the global value, so restore that. */ | |
27a6c729 RS |
2778 | if (NILP (Flocal_variable_p (symbol, binding_buffer))) |
2779 | binding_buffer = Qnil; | |
2780 | specpdl_ptr->symbol | |
2781 | = Fcons (symbol, Fcons (binding_buffer, current_buffer)); | |
719177b3 RS |
2782 | } |
2783 | else | |
2784 | specpdl_ptr->symbol = symbol; | |
2785 | ||
db9f0278 | 2786 | specpdl_ptr++; |
3d8585a1 | 2787 | if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue)) |
db9f0278 JB |
2788 | store_symval_forwarding (symbol, ovalue, value); |
2789 | else | |
719177b3 | 2790 | set_internal (symbol, value, 0, 1); |
db9f0278 JB |
2791 | } |
2792 | ||
2793 | void | |
2794 | record_unwind_protect (function, arg) | |
1d159538 | 2795 | Lisp_Object (*function) P_ ((Lisp_Object)); |
db9f0278 JB |
2796 | Lisp_Object arg; |
2797 | { | |
2798 | if (specpdl_ptr == specpdl + specpdl_size) | |
2799 | grow_specpdl (); | |
2800 | specpdl_ptr->func = function; | |
2801 | specpdl_ptr->symbol = Qnil; | |
2802 | specpdl_ptr->old_value = arg; | |
2803 | specpdl_ptr++; | |
2804 | } | |
2805 | ||
2806 | Lisp_Object | |
2807 | unbind_to (count, value) | |
2808 | int count; | |
2809 | Lisp_Object value; | |
2810 | { | |
265a9e55 | 2811 | int quitf = !NILP (Vquit_flag); |
db9f0278 JB |
2812 | struct gcpro gcpro1; |
2813 | ||
2814 | GCPRO1 (value); | |
2815 | ||
2816 | Vquit_flag = Qnil; | |
2817 | ||
2818 | while (specpdl_ptr != specpdl + count) | |
2819 | { | |
2820 | --specpdl_ptr; | |
2821 | if (specpdl_ptr->func != 0) | |
2822 | (*specpdl_ptr->func) (specpdl_ptr->old_value); | |
2823 | /* Note that a "binding" of nil is really an unwind protect, | |
719177b3 | 2824 | so in that case the "old value" is a list of forms to evaluate. */ |
265a9e55 | 2825 | else if (NILP (specpdl_ptr->symbol)) |
db9f0278 | 2826 | Fprogn (specpdl_ptr->old_value); |
27a6c729 RS |
2827 | /* If the symbol is a list, it is really |
2828 | (SYMBOL BINDING_BUFFER . CURRENT_BUFFER) | |
2829 | and it indicates we bound a variable that has | |
2830 | buffer-local bindings. */ | |
719177b3 RS |
2831 | else if (CONSP (specpdl_ptr->symbol)) |
2832 | { | |
2833 | Lisp_Object symbol, buffer; | |
2834 | ||
2835 | symbol = XCAR (specpdl_ptr->symbol); | |
27a6c729 | 2836 | buffer = XCAR (XCDR (specpdl_ptr->symbol)); |
719177b3 RS |
2837 | |
2838 | /* Handle restoring a default value. */ | |
2839 | if (NILP (buffer)) | |
2840 | Fset_default (symbol, specpdl_ptr->old_value); | |
2841 | /* Handle restoring a value saved from a live buffer. */ | |
2842 | else | |
2843 | set_internal (symbol, specpdl_ptr->old_value, XBUFFER (buffer), 1); | |
2844 | } | |
db9f0278 | 2845 | else |
719177b3 | 2846 | set_internal (specpdl_ptr->symbol, specpdl_ptr->old_value, 0, 1); |
db9f0278 | 2847 | } |
265a9e55 | 2848 | if (NILP (Vquit_flag) && quitf) Vquit_flag = Qt; |
db9f0278 JB |
2849 | |
2850 | UNGCPRO; | |
2851 | ||
2852 | return value; | |
2853 | } | |
2854 | \f | |
2855 | #if 0 | |
2856 | ||
2857 | /* Get the value of symbol's global binding, even if that binding | |
2858 | is not now dynamically visible. */ | |
2859 | ||
2860 | Lisp_Object | |
2861 | top_level_value (symbol) | |
2862 | Lisp_Object symbol; | |
2863 | { | |
2864 | register struct specbinding *ptr = specpdl; | |
2865 | ||
2866 | CHECK_SYMBOL (symbol, 0); | |
2867 | for (; ptr != specpdl_ptr; ptr++) | |
2868 | { | |
2869 | if (EQ (ptr->symbol, symbol)) | |
2870 | return ptr->old_value; | |
2871 | } | |
2872 | return Fsymbol_value (symbol); | |
2873 | } | |
2874 | ||
2875 | Lisp_Object | |
2876 | top_level_set (symbol, newval) | |
2877 | Lisp_Object symbol, newval; | |
2878 | { | |
2879 | register struct specbinding *ptr = specpdl; | |
2880 | ||
2881 | CHECK_SYMBOL (symbol, 0); | |
2882 | for (; ptr != specpdl_ptr; ptr++) | |
2883 | { | |
2884 | if (EQ (ptr->symbol, symbol)) | |
2885 | { | |
2886 | ptr->old_value = newval; | |
2887 | return newval; | |
2888 | } | |
2889 | } | |
2890 | return Fset (symbol, newval); | |
2891 | } | |
2892 | ||
2893 | #endif /* 0 */ | |
2894 | \f | |
2895 | DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0, | |
2896 | "Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.\n\ | |
2897 | The debugger is entered when that frame exits, if the flag is non-nil.") | |
2898 | (level, flag) | |
2899 | Lisp_Object level, flag; | |
2900 | { | |
2901 | register struct backtrace *backlist = backtrace_list; | |
2902 | register int i; | |
2903 | ||
2904 | CHECK_NUMBER (level, 0); | |
2905 | ||
2906 | for (i = 0; backlist && i < XINT (level); i++) | |
2907 | { | |
2908 | backlist = backlist->next; | |
2909 | } | |
2910 | ||
2911 | if (backlist) | |
265a9e55 | 2912 | backlist->debug_on_exit = !NILP (flag); |
db9f0278 JB |
2913 | |
2914 | return flag; | |
2915 | } | |
2916 | ||
2917 | DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "", | |
2918 | "Print a trace of Lisp function calls currently active.\n\ | |
2919 | Output stream used is value of `standard-output'.") | |
2920 | () | |
2921 | { | |
2922 | register struct backtrace *backlist = backtrace_list; | |
2923 | register int i; | |
2924 | Lisp_Object tail; | |
2925 | Lisp_Object tem; | |
2926 | extern Lisp_Object Vprint_level; | |
2927 | struct gcpro gcpro1; | |
2928 | ||
a631e24c | 2929 | XSETFASTINT (Vprint_level, 3); |
db9f0278 JB |
2930 | |
2931 | tail = Qnil; | |
2932 | GCPRO1 (tail); | |
2933 | ||
2934 | while (backlist) | |
2935 | { | |
2936 | write_string (backlist->debug_on_exit ? "* " : " ", 2); | |
2937 | if (backlist->nargs == UNEVALLED) | |
2938 | { | |
2939 | Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil); | |
b6703b02 | 2940 | write_string ("\n", -1); |
db9f0278 JB |
2941 | } |
2942 | else | |
2943 | { | |
2944 | tem = *backlist->function; | |
2945 | Fprin1 (tem, Qnil); /* This can QUIT */ | |
2946 | write_string ("(", -1); | |
2947 | if (backlist->nargs == MANY) | |
2948 | { | |
2949 | for (tail = *backlist->args, i = 0; | |
265a9e55 | 2950 | !NILP (tail); |
db9f0278 JB |
2951 | tail = Fcdr (tail), i++) |
2952 | { | |
2953 | if (i) write_string (" ", -1); | |
2954 | Fprin1 (Fcar (tail), Qnil); | |
2955 | } | |
2956 | } | |
2957 | else | |
2958 | { | |
2959 | for (i = 0; i < backlist->nargs; i++) | |
2960 | { | |
2961 | if (i) write_string (" ", -1); | |
2962 | Fprin1 (backlist->args[i], Qnil); | |
2963 | } | |
2964 | } | |
b6703b02 | 2965 | write_string (")\n", -1); |
db9f0278 | 2966 | } |
db9f0278 JB |
2967 | backlist = backlist->next; |
2968 | } | |
2969 | ||
2970 | Vprint_level = Qnil; | |
2971 | UNGCPRO; | |
2972 | return Qnil; | |
2973 | } | |
2974 | ||
2975 | DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, "", | |
79e8bfbf | 2976 | "Return the function and arguments NFRAMES up from current execution point.\n\ |
db9f0278 JB |
2977 | If that frame has not evaluated the arguments yet (or is a special form),\n\ |
2978 | the value is (nil FUNCTION ARG-FORMS...).\n\ | |
2979 | If that frame has evaluated its arguments and called its function already,\n\ | |
2980 | the value is (t FUNCTION ARG-VALUES...).\n\ | |
2981 | A &rest arg is represented as the tail of the list ARG-VALUES.\n\ | |
2982 | FUNCTION is whatever was supplied as car of evaluated list,\n\ | |
2983 | or a lambda expression for macro calls.\n\ | |
79e8bfbf | 2984 | If NFRAMES is more than the number of frames, the value is nil.") |
db9f0278 JB |
2985 | (nframes) |
2986 | Lisp_Object nframes; | |
2987 | { | |
2988 | register struct backtrace *backlist = backtrace_list; | |
2989 | register int i; | |
2990 | Lisp_Object tem; | |
2991 | ||
2992 | CHECK_NATNUM (nframes, 0); | |
2993 | ||
2994 | /* Find the frame requested. */ | |
b6703b02 | 2995 | for (i = 0; backlist && i < XFASTINT (nframes); i++) |
db9f0278 JB |
2996 | backlist = backlist->next; |
2997 | ||
2998 | if (!backlist) | |
2999 | return Qnil; | |
3000 | if (backlist->nargs == UNEVALLED) | |
3001 | return Fcons (Qnil, Fcons (*backlist->function, *backlist->args)); | |
3002 | else | |
3003 | { | |
3004 | if (backlist->nargs == MANY) | |
3005 | tem = *backlist->args; | |
3006 | else | |
3007 | tem = Flist (backlist->nargs, backlist->args); | |
3008 | ||
3009 | return Fcons (Qt, Fcons (*backlist->function, tem)); | |
3010 | } | |
3011 | } | |
3012 | \f | |
dfcf069d | 3013 | void |
db9f0278 JB |
3014 | syms_of_eval () |
3015 | { | |
3016 | DEFVAR_INT ("max-specpdl-size", &max_specpdl_size, | |
7eaada67 RS |
3017 | "*Limit on number of Lisp variable bindings & unwind-protects.\n\ |
3018 | If Lisp code tries to make more than this many at once,\n\ | |
3019 | an error is signaled."); | |
db9f0278 JB |
3020 | |
3021 | DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth, | |
7eaada67 | 3022 | "*Limit on depth in `eval', `apply' and `funcall' before error.\n\ |
db9f0278 JB |
3023 | This limit is to catch infinite recursions for you before they cause\n\ |
3024 | actual stack overflow in C, which would be fatal for Emacs.\n\ | |
3025 | You can safely make it considerably larger than its default value,\n\ | |
3026 | if that proves inconveniently small."); | |
3027 | ||
3028 | DEFVAR_LISP ("quit-flag", &Vquit_flag, | |
3029 | "Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.\n\ | |
d0b68896 | 3030 | Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'."); |
db9f0278 JB |
3031 | Vquit_flag = Qnil; |
3032 | ||
3033 | DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit, | |
3034 | "Non-nil inhibits C-g quitting from happening immediately.\n\ | |
3035 | Note that `quit-flag' will still be set by typing C-g,\n\ | |
690337b7 | 3036 | so a quit will be signaled as soon as `inhibit-quit' is nil.\n\ |
db9f0278 JB |
3037 | To prevent this happening, set `quit-flag' to nil\n\ |
3038 | before making `inhibit-quit' nil."); | |
3039 | Vinhibit_quit = Qnil; | |
3040 | ||
ad236261 JB |
3041 | Qinhibit_quit = intern ("inhibit-quit"); |
3042 | staticpro (&Qinhibit_quit); | |
3043 | ||
db9f0278 JB |
3044 | Qautoload = intern ("autoload"); |
3045 | staticpro (&Qautoload); | |
3046 | ||
3047 | Qdebug_on_error = intern ("debug-on-error"); | |
3048 | staticpro (&Qdebug_on_error); | |
3049 | ||
3050 | Qmacro = intern ("macro"); | |
3051 | staticpro (&Qmacro); | |
3052 | ||
3053 | /* Note that the process handling also uses Qexit, but we don't want | |
3054 | to staticpro it twice, so we just do it here. */ | |
3055 | Qexit = intern ("exit"); | |
3056 | staticpro (&Qexit); | |
3057 | ||
3058 | Qinteractive = intern ("interactive"); | |
3059 | staticpro (&Qinteractive); | |
3060 | ||
3061 | Qcommandp = intern ("commandp"); | |
3062 | staticpro (&Qcommandp); | |
3063 | ||
3064 | Qdefun = intern ("defun"); | |
3065 | staticpro (&Qdefun); | |
3066 | ||
3067 | Qand_rest = intern ("&rest"); | |
3068 | staticpro (&Qand_rest); | |
3069 | ||
3070 | Qand_optional = intern ("&optional"); | |
3071 | staticpro (&Qand_optional); | |
3072 | ||
128c0f66 | 3073 | DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error, |
db9f0278 | 3074 | "*Non-nil means automatically display a backtrace buffer\n\ |
128c0f66 RM |
3075 | after any error that is handled by the editor command loop.\n\ |
3076 | If the value is a list, an error only means to display a backtrace\n\ | |
3077 | if one of its condition symbols appears in the list."); | |
3078 | Vstack_trace_on_error = Qnil; | |
db9f0278 | 3079 | |
128c0f66 | 3080 | DEFVAR_LISP ("debug-on-error", &Vdebug_on_error, |
db9f0278 JB |
3081 | "*Non-nil means enter debugger if an error is signaled.\n\ |
3082 | Does not apply to errors handled by `condition-case'.\n\ | |
128c0f66 RM |
3083 | If the value is a list, an error only means to enter the debugger\n\ |
3084 | if one of its condition symbols appears in the list.\n\ | |
db9f0278 | 3085 | See also variable `debug-on-quit'."); |
128c0f66 | 3086 | Vdebug_on_error = Qnil; |
db9f0278 | 3087 | |
fc950e09 KH |
3088 | DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors, |
3089 | "*List of errors for which the debugger should not be called.\n\ | |
3090 | Each element may be a condition-name or a regexp that matches error messages.\n\ | |
3091 | If any element applies to a given error, that error skips the debugger\n\ | |
3092 | and just returns to top level.\n\ | |
3093 | This overrides the variable `debug-on-error'.\n\ | |
3094 | It does not apply to errors handled by `condition-case'."); | |
3095 | Vdebug_ignored_errors = Qnil; | |
3096 | ||
db9f0278 | 3097 | DEFVAR_BOOL ("debug-on-quit", &debug_on_quit, |
d0b68896 | 3098 | "*Non-nil means enter debugger if quit is signaled (C-g, for example).\n\ |
1b7d8239 | 3099 | Does not apply if quit is handled by a `condition-case'."); |
db9f0278 JB |
3100 | debug_on_quit = 0; |
3101 | ||
3102 | DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call, | |
3103 | "Non-nil means enter debugger before next `eval', `apply' or `funcall'."); | |
3104 | ||
556d7314 GM |
3105 | DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue, |
3106 | "Non-nil means debugger may continue execution.\n\ | |
3107 | This is nil when the debugger is called under circumstances where it\n\ | |
3108 | might not be safe to continue."); | |
dac204bc | 3109 | debugger_may_continue = 1; |
556d7314 | 3110 | |
db9f0278 JB |
3111 | DEFVAR_LISP ("debugger", &Vdebugger, |
3112 | "Function to call to invoke debugger.\n\ | |
3113 | If due to frame exit, args are `exit' and the value being returned;\n\ | |
3114 | this function's value will be returned instead of that.\n\ | |
3115 | If due to error, args are `error' and a list of the args to `signal'.\n\ | |
3116 | If due to `apply' or `funcall' entry, one arg, `lambda'.\n\ | |
3117 | If due to `eval' entry, one arg, t."); | |
3118 | Vdebugger = Qnil; | |
3119 | ||
61ede770 RS |
3120 | DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function, |
3121 | "If non-nil, this is a function for `signal' to call.\n\ | |
3122 | It receives the same arguments that `signal' was given.\n\ | |
3123 | The Edebug package uses this to regain control."); | |
3124 | Vsignal_hook_function = Qnil; | |
3125 | ||
db9f0278 JB |
3126 | Qmocklisp_arguments = intern ("mocklisp-arguments"); |
3127 | staticpro (&Qmocklisp_arguments); | |
3128 | DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments, | |
3129 | "While in a mocklisp function, the list of its unevaluated args."); | |
3130 | Vmocklisp_arguments = Qt; | |
3131 | ||
57a6e758 | 3132 | DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal, |
61ede770 RS |
3133 | "*Non-nil means call the debugger regardless of condition handlers.\n\ |
3134 | Note that `debug-on-error', `debug-on-quit' and friends\n\ | |
3135 | still determine whether to handle the particular condition."); | |
57a6e758 | 3136 | Vdebug_on_signal = Qnil; |
61ede770 | 3137 | |
6e6e9f08 RS |
3138 | Vrun_hooks = intern ("run-hooks"); |
3139 | staticpro (&Vrun_hooks); | |
db9f0278 JB |
3140 | |
3141 | staticpro (&Vautoload_queue); | |
3142 | Vautoload_queue = Qnil; | |
3143 | ||
3144 | defsubr (&Sor); | |
3145 | defsubr (&Sand); | |
3146 | defsubr (&Sif); | |
3147 | defsubr (&Scond); | |
3148 | defsubr (&Sprogn); | |
3149 | defsubr (&Sprog1); | |
3150 | defsubr (&Sprog2); | |
3151 | defsubr (&Ssetq); | |
3152 | defsubr (&Squote); | |
3153 | defsubr (&Sfunction); | |
3154 | defsubr (&Sdefun); | |
3155 | defsubr (&Sdefmacro); | |
3156 | defsubr (&Sdefvar); | |
3157 | defsubr (&Sdefconst); | |
3158 | defsubr (&Suser_variable_p); | |
3159 | defsubr (&Slet); | |
3160 | defsubr (&SletX); | |
3161 | defsubr (&Swhile); | |
3162 | defsubr (&Smacroexpand); | |
3163 | defsubr (&Scatch); | |
3164 | defsubr (&Sthrow); | |
3165 | defsubr (&Sunwind_protect); | |
3166 | defsubr (&Scondition_case); | |
3167 | defsubr (&Ssignal); | |
3168 | defsubr (&Sinteractive_p); | |
3169 | defsubr (&Scommandp); | |
3170 | defsubr (&Sautoload); | |
3171 | defsubr (&Seval); | |
3172 | defsubr (&Sapply); | |
3173 | defsubr (&Sfuncall); | |
ff936e53 SM |
3174 | defsubr (&Srun_hooks); |
3175 | defsubr (&Srun_hook_with_args); | |
3176 | defsubr (&Srun_hook_with_args_until_success); | |
3177 | defsubr (&Srun_hook_with_args_until_failure); | |
661c7d6e | 3178 | defsubr (&Sfetch_bytecode); |
db9f0278 JB |
3179 | defsubr (&Sbacktrace_debug); |
3180 | defsubr (&Sbacktrace); | |
3181 | defsubr (&Sbacktrace_frame); | |
3182 | } |