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