0
|
1 /* Evaluator for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985-1987, 1992-1994 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: FSF 19.30 (except for Fsignal), Mule 2.0. */
|
|
23
|
|
24 /* Debugging hack */
|
|
25 int always_gc;
|
|
26
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #ifndef standalone
|
|
32 #include "commands.h"
|
|
33 #endif
|
|
34
|
|
35 #include "symeval.h"
|
|
36 #include "backtrace.h"
|
|
37 #include "bytecode.h"
|
|
38 #include "buffer.h"
|
|
39 #include "console.h"
|
|
40 #include "opaque.h"
|
|
41
|
|
42 struct backtrace *backtrace_list;
|
|
43
|
116
|
44 /* Note you must always fill all of the fields in a backtrace structure
|
|
45 before pushing them on the backtrace_list. The profiling code depends
|
|
46 on this. */
|
|
47
|
|
48 #define PUSH_BACKTRACE(bt) \
|
|
49 do { (bt).next = backtrace_list; backtrace_list = &(bt); } while (0)
|
|
50
|
|
51 #define POP_BACKTRACE(bt) \
|
|
52 do { backtrace_list = (bt).next; } while (0)
|
|
53
|
0
|
54 /* This is the list of current catches (and also condition-cases).
|
|
55 This is a stack: the most recent catch is at the head of the
|
|
56 list. Catches are created by declaring a 'struct catchtag'
|
|
57 locally, filling the .TAG field in with the tag, and doing
|
|
58 a setjmp() on .JMP. Fthrow() will store the value passed
|
|
59 to it in .VAL and longjmp() back to .JMP, back to the function
|
|
60 that established the catch. This will always be either
|
|
61 internal_catch() (catches established internally or through
|
|
62 `catch') or condition_case_1 (condition-cases established
|
|
63 internally or through `condition-case').
|
|
64
|
|
65 The catchtag also records the current position in the
|
|
66 call stack (stored in BACKTRACE_LIST), the current position
|
|
67 in the specpdl stack (used for variable bindings and
|
|
68 unwind-protects), the value of LISP_EVAL_DEPTH, and the
|
|
69 current position in the GCPRO stack. All of these are
|
|
70 restored by Fthrow().
|
|
71 */
|
185
|
72
|
0
|
73 struct catchtag *catchlist;
|
|
74
|
|
75 Lisp_Object Qautoload, Qmacro, Qexit;
|
|
76 Lisp_Object Qinteractive, Qcommandp, Qdefun, Qprogn, Qvalues;
|
|
77 Lisp_Object Vquit_flag, Vinhibit_quit;
|
|
78 Lisp_Object Qand_rest, Qand_optional;
|
|
79 Lisp_Object Qdebug_on_error;
|
|
80 Lisp_Object Qstack_trace_on_error;
|
|
81 Lisp_Object Qdebug_on_signal;
|
|
82 Lisp_Object Qstack_trace_on_signal;
|
|
83 Lisp_Object Qdebugger;
|
|
84 Lisp_Object Qinhibit_quit;
|
|
85 Lisp_Object Qrun_hooks;
|
|
86
|
|
87 Lisp_Object Qsetq;
|
|
88
|
|
89 Lisp_Object Qdisplay_warning;
|
|
90 Lisp_Object Vpending_warnings, Vpending_warnings_tail;
|
|
91
|
|
92 /* Records whether we want errors to occur. This will be a boolean,
|
|
93 nil (errors OK) or t (no errors). If t, an error will cause a
|
|
94 throw to Qunbound_suspended_errors_tag.
|
|
95
|
|
96 See call_with_suspended_errors(). */
|
|
97 Lisp_Object Vcurrent_error_state;
|
|
98
|
|
99 /* Current warning class when warnings occur, or nil for no warnings.
|
|
100 Only meaningful when Vcurrent_error_state is non-nil.
|
|
101 See call_with_suspended_errors(). */
|
|
102 Lisp_Object Vcurrent_warning_class;
|
|
103
|
|
104 /* Special catch tag used in call_with_suspended_errors(). */
|
|
105 Lisp_Object Qunbound_suspended_errors_tag;
|
|
106
|
|
107 /* Non-nil means we're going down, so we better not run any hooks
|
|
108 or do other non-essential stuff. */
|
|
109 int preparing_for_armageddon;
|
|
110
|
|
111 /* Non-nil means record all fset's and provide's, to be undone
|
|
112 if the file being autoloaded is not fully loaded.
|
|
113 They are recorded by being consed onto the front of Vautoload_queue:
|
|
114 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
|
|
115
|
|
116 Lisp_Object Vautoload_queue;
|
|
117
|
|
118 /* Current number of specbindings allocated in specpdl. */
|
|
119 static int specpdl_size;
|
|
120
|
|
121 /* Pointer to beginning of specpdl. */
|
|
122 struct specbinding *specpdl;
|
|
123
|
|
124 /* Pointer to first unused element in specpdl. */
|
|
125 struct specbinding *specpdl_ptr;
|
|
126
|
2
|
127 /* specpdl_ptr - specpdl. Callers outside this file should use
|
0
|
128 * specpdl_depth () function-call */
|
|
129 static int specpdl_depth_counter;
|
|
130
|
|
131 /* Maximum size allowed for specpdl allocation */
|
|
132 int max_specpdl_size;
|
|
133
|
|
134 /* Depth in Lisp evaluations and function calls. */
|
|
135 int lisp_eval_depth;
|
|
136
|
|
137 /* Maximum allowed depth in Lisp evaluations and function calls. */
|
|
138 int max_lisp_eval_depth;
|
|
139
|
|
140 /* Nonzero means enter debugger before next function call */
|
|
141 static int debug_on_next_call;
|
|
142
|
|
143 /* List of conditions (non-nil atom means all) which cause a backtrace
|
|
144 if an error is handled by the command loop's error handler. */
|
|
145 Lisp_Object Vstack_trace_on_error;
|
|
146
|
|
147 /* List of conditions (non-nil atom means all) which enter the debugger
|
|
148 if an error is handled by the command loop's error handler. */
|
|
149 Lisp_Object Vdebug_on_error;
|
|
150
|
163
|
151 /* List of conditions and regexps specifying error messages which
|
|
152 do not enter the debugger even if Vdebug_on_error says they should. */
|
|
153 Lisp_Object Vdebug_ignored_errors;
|
|
154
|
0
|
155 /* List of conditions (non-nil atom means all) which cause a backtrace
|
|
156 if any error is signalled. */
|
|
157 Lisp_Object Vstack_trace_on_signal;
|
|
158
|
|
159 /* List of conditions (non-nil atom means all) which enter the debugger
|
|
160 if any error is signalled. */
|
|
161 Lisp_Object Vdebug_on_signal;
|
|
162
|
|
163 /* Nonzero means enter debugger if a quit signal
|
|
164 is handled by the command loop's error handler.
|
|
165
|
|
166 From lisp, this is a boolean variable and may have the values 0 and 1.
|
|
167 But, eval.c temporarily uses the second bit of this variable to indicate
|
|
168 that a critical_quit is in progress. The second bit is reset immediately
|
|
169 after it is processed in signal_call_debugger(). */
|
|
170 int debug_on_quit;
|
|
171
|
|
172 #if 0 /* FSFmacs */
|
|
173 /* entering_debugger is basically equivalent */
|
|
174 /* The value of num_nonmacro_input_chars as of the last time we
|
|
175 started to enter the debugger. If we decide to enter the debugger
|
|
176 again when this is still equal to num_nonmacro_input_chars, then we
|
|
177 know that the debugger itself has an error, and we should just
|
|
178 signal the error instead of entering an infinite loop of debugger
|
|
179 invocations. */
|
|
180 int when_entered_debugger;
|
|
181 #endif
|
|
182
|
|
183 /* Nonzero means we are trying to enter the debugger.
|
185
|
184 This is to prevent recursive attempts.
|
0
|
185 Cleared by the debugger calling Fbacktrace */
|
|
186 static int entering_debugger;
|
|
187
|
|
188 /* Function to call to invoke the debugger */
|
|
189 Lisp_Object Vdebugger;
|
|
190
|
|
191 /* Chain of condition handlers currently in effect.
|
|
192 The elements of this chain are contained in the stack frames
|
|
193 of Fcondition_case and internal_condition_case.
|
|
194 When an error is signaled (by calling Fsignal, below),
|
|
195 this chain is searched for an element that applies.
|
|
196
|
|
197 Each element of this list is one of the following:
|
|
198
|
|
199 A list of a handler function and possibly args to pass to
|
|
200 the function. This is a handler established with
|
|
201 `call-with-condition-handler' (q.v.).
|
|
202
|
|
203 A list whose car is Qunbound and whose cdr is Qt.
|
|
204 This is a special condition-case handler established
|
|
205 by C code with condition_case_1(). All errors are
|
|
206 trapped; the debugger is not invoked even if
|
|
207 `debug-on-error' was set.
|
|
208
|
|
209 A list whose car is Qunbound and whose cdr is Qerror.
|
|
210 This is a special condition-case handler established
|
|
211 by C code with condition_case_1(). It is like Qt
|
|
212 except that the debugger is invoked normally if it is
|
|
213 called for.
|
|
214
|
|
215 A list whose car is Qunbound and whose cdr is a list
|
|
216 of lists (CONDITION-NAME BODY ...) exactly as in
|
|
217 `condition-case'. This is a normal `condition-case'
|
|
218 handler.
|
|
219
|
|
220 Note that in all cases *except* the first, there is a
|
|
221 corresponding catch, whose TAG is the value of
|
|
222 Vcondition_handlers just after the handler data just
|
|
223 described is pushed onto it. The reason is that
|
|
224 `condition-case' handlers need to throw back to the
|
|
225 place where the handler was installed before invoking
|
|
226 it, while `call-with-condition-handler' handlers are
|
|
227 invoked in the environment that `signal' was invoked
|
|
228 in.
|
|
229 */
|
|
230 static Lisp_Object Vcondition_handlers;
|
|
231
|
|
232 /* Used for error catching purposes by throw_or_bomb_out */
|
|
233 static int throw_level;
|
|
234
|
74
|
235 static Lisp_Object primitive_funcall (lisp_fn_t fn, int nargs,
|
0
|
236 Lisp_Object args[]);
|
|
237
|
|
238
|
|
239 /**********************************************************************/
|
|
240 /* The subr and compiled-function types */
|
|
241 /**********************************************************************/
|
|
242
|
|
243 static void print_subr (Lisp_Object, Lisp_Object, int);
|
|
244 DEFINE_LRECORD_IMPLEMENTATION ("subr", subr,
|
|
245 this_one_is_unmarkable, print_subr, 0, 0, 0,
|
|
246 struct Lisp_Subr);
|
|
247
|
|
248 static void
|
|
249 print_subr (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
250 {
|
|
251 struct Lisp_Subr *subr = XSUBR (obj);
|
|
252
|
|
253 if (print_readably)
|
|
254 error ("printing unreadable object #<subr %s>",
|
|
255 subr_name (subr));
|
|
256
|
|
257 write_c_string (((subr->max_args == UNEVALLED)
|
|
258 ? "#<special-form "
|
|
259 : "#<subr "),
|
|
260 printcharfun);
|
185
|
261
|
0
|
262 write_c_string (subr_name (subr), printcharfun);
|
|
263 write_c_string (((subr->prompt) ? " (interactive)>" : ">"),
|
|
264 printcharfun);
|
|
265 }
|
|
266
|
|
267
|
|
268 static Lisp_Object mark_compiled_function (Lisp_Object,
|
|
269 void (*) (Lisp_Object));
|
|
270 extern void print_compiled_function (Lisp_Object, Lisp_Object, int);
|
|
271 static int compiled_function_equal (Lisp_Object, Lisp_Object, int);
|
|
272 static unsigned long compiled_function_hash (Lisp_Object obj, int depth);
|
|
273 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("compiled-function", compiled_function,
|
|
274 mark_compiled_function,
|
|
275 print_compiled_function, 0,
|
|
276 compiled_function_equal,
|
|
277 compiled_function_hash,
|
|
278 struct Lisp_Compiled_Function);
|
|
279
|
|
280 static Lisp_Object
|
|
281 mark_compiled_function (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
282 {
|
|
283 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (obj);
|
|
284
|
|
285 ((markobj) (b->bytecodes));
|
|
286 ((markobj) (b->arglist));
|
|
287 ((markobj) (b->doc_and_interactive));
|
|
288 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
289 ((markobj) (b->annotated));
|
|
290 #endif
|
|
291 /* tail-recurse on constants */
|
173
|
292 return b->constants;
|
0
|
293 }
|
|
294
|
|
295 static int
|
|
296 compiled_function_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
297 {
|
|
298 struct Lisp_Compiled_Function *b1 = XCOMPILED_FUNCTION (o1);
|
|
299 struct Lisp_Compiled_Function *b2 = XCOMPILED_FUNCTION (o2);
|
|
300 return (b1->flags.documentationp == b2->flags.documentationp
|
|
301 && b1->flags.interactivep == b2->flags.interactivep
|
|
302 && b1->flags.domainp == b2->flags.domainp /* I18N3 */
|
|
303 && internal_equal (b1->bytecodes, b2->bytecodes, depth + 1)
|
|
304 && internal_equal (b1->constants, b2->constants, depth + 1)
|
|
305 && internal_equal (b1->arglist, b2->arglist, depth + 1)
|
185
|
306 && internal_equal (b1->doc_and_interactive,
|
0
|
307 b2->doc_and_interactive, depth + 1));
|
|
308 }
|
|
309
|
|
310 static unsigned long
|
|
311 compiled_function_hash (Lisp_Object obj, int depth)
|
|
312 {
|
|
313 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (obj);
|
|
314 return HASH3 ((b->flags.documentationp << 2) +
|
|
315 (b->flags.interactivep << 1) +
|
|
316 b->flags.domainp,
|
|
317 internal_hash (b->bytecodes, depth + 1),
|
|
318 internal_hash (b->constants, depth + 1));
|
|
319 }
|
|
320
|
|
321
|
|
322 /**********************************************************************/
|
|
323 /* Entering the debugger */
|
|
324 /**********************************************************************/
|
|
325
|
|
326 /* unwind-protect used by call_debugger() to restore the value of
|
|
327 enterring_debugger. (We cannot use specbind() because the
|
|
328 variable is not Lisp-accessible.) */
|
|
329
|
|
330 static Lisp_Object
|
|
331 restore_entering_debugger (Lisp_Object arg)
|
|
332 {
|
179
|
333 entering_debugger = ! NILP (arg);
|
0
|
334 return arg;
|
|
335 }
|
|
336
|
|
337 /* Actually call the debugger. ARG is a list of args that will be
|
|
338 passed to the debugger function, as follows;
|
|
339
|
|
340 If due to frame exit, args are `exit' and the value being returned;
|
|
341 this function's value will be returned instead of that.
|
|
342 If due to error, args are `error' and a list of the args to `signal'.
|
|
343 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
344 If due to `eval' entry, one arg, t.
|
|
345
|
|
346 */
|
|
347
|
|
348 static Lisp_Object
|
|
349 call_debugger_259 (Lisp_Object arg)
|
|
350 {
|
|
351 return apply1 (Vdebugger, arg);
|
|
352 }
|
|
353
|
|
354 /* Call the debugger, doing some encapsulation. We make sure we have
|
|
355 some room on the eval and specpdl stacks, and bind enterring_debugger
|
|
356 to 1 during this call. This is used to trap errors that may occur
|
|
357 when enterring the debugger (e.g. the value of `debugger' is invalid),
|
|
358 so that the debugger will not be recursively entered if debug-on-error
|
|
359 is set. (Otherwise, XEmacs would infinitely recurse, attempting to
|
|
360 enter the debugger.) enterring_debugger gets reset to 0 as soon
|
|
361 as a backtrace is displayed, so that further errors can indeed be
|
|
362 handled normally.
|
|
363
|
|
364 We also establish a catch for 'debugger. If the debugger function
|
|
365 throws to this instead of returning a value, it means that the user
|
|
366 pressed 'c' (pretend like the debugger was never entered). The
|
|
367 function then returns Qunbound. (If the user pressed 'r', for
|
|
368 return a value, then the debugger function returns normally with
|
|
369 this value.)
|
|
370
|
|
371 The difference between 'c' and 'r' is as follows:
|
|
372
|
|
373 debug-on-call:
|
|
374 No difference. The call proceeds as normal.
|
|
375 debug-on-exit:
|
|
376 With 'r', the specified value is returned as the function's
|
|
377 return value. With 'c', the value that would normally be
|
|
378 returned is returned.
|
|
379 signal:
|
|
380 With 'r', the specified value is returned as the return
|
|
381 value of `signal'. (This is the only time that `signal'
|
|
382 can return, instead of making a non-local exit.) With `c',
|
|
383 `signal' will continue looking for handlers as if the
|
|
384 debugger was never entered, and will probably end up
|
|
385 throwing to a handler or to top-level.
|
|
386 */
|
|
387
|
|
388 static Lisp_Object
|
|
389 call_debugger (Lisp_Object arg)
|
|
390 {
|
|
391 int threw;
|
|
392 Lisp_Object val;
|
|
393 int speccount;
|
|
394
|
|
395 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
|
|
396 max_lisp_eval_depth = lisp_eval_depth + 20;
|
|
397 if (specpdl_size + 40 > max_specpdl_size)
|
|
398 max_specpdl_size = specpdl_size + 40;
|
|
399 debug_on_next_call = 0;
|
|
400
|
|
401 speccount = specpdl_depth_counter;
|
185
|
402 record_unwind_protect (restore_entering_debugger,
|
0
|
403 (entering_debugger ? Qt : Qnil));
|
|
404 entering_debugger = 1;
|
|
405 val = internal_catch (Qdebugger, call_debugger_259, arg, &threw);
|
|
406
|
185
|
407 return unbind_to (speccount, ((threw)
|
179
|
408 ? Qunbound /* Not returning a value */
|
|
409 : val));
|
0
|
410 }
|
|
411
|
|
412 /* Called when debug-on-exit behavior is called for. Enter the debugger
|
|
413 with the appropriate args for this. VAL is the exit value that is
|
|
414 about to be returned. */
|
|
415
|
|
416 static Lisp_Object
|
|
417 do_debug_on_exit (Lisp_Object val)
|
|
418 {
|
|
419 /* This is falsified by call_debugger */
|
|
420 Lisp_Object v = call_debugger (list2 (Qexit, val));
|
94
|
421
|
173
|
422 return !UNBOUNDP (v) ? v : val;
|
0
|
423 }
|
|
424
|
|
425 /* Called when debug-on-call behavior is called for. Enter the debugger
|
|
426 with the appropriate args for this. VAL is either t for a call
|
|
427 through `eval' or 'lambda for a call through `funcall'.
|
|
428
|
|
429 #### The differentiation here between EVAL and FUNCALL is bogus.
|
|
430 FUNCALL can be defined as
|
|
431
|
|
432 (defmacro func (fun &rest args)
|
|
433 (cons (eval fun) args))
|
|
434
|
|
435 and should be treated as such.
|
|
436 */
|
|
437
|
|
438 static void
|
|
439 do_debug_on_call (Lisp_Object code)
|
|
440 {
|
|
441 debug_on_next_call = 0;
|
|
442 backtrace_list->debug_on_exit = 1;
|
|
443 call_debugger (list1 (code));
|
|
444 }
|
|
445
|
|
446 /* LIST is the value of one of the variables `debug-on-error',
|
|
447 `debug-on-signal', `stack-trace-on-error', or `stack-trace-on-signal',
|
|
448 and CONDITIONS is the list of error conditions associated with
|
|
449 the error being signalled. This returns non-nil if LIST
|
|
450 matches CONDITIONS. (A nil value for LIST does not match
|
|
451 CONDITIONS. A non-list value for LIST does match CONDITIONS.
|
|
452 A list matches CONDITIONS when one of the symbols in LIST is the
|
|
453 same as one of the symbols in CONDITIONS.) */
|
|
454
|
|
455 static int
|
|
456 wants_debugger (Lisp_Object list, Lisp_Object conditions)
|
|
457 {
|
|
458 if (NILP (list))
|
|
459 return 0;
|
|
460 if (! CONSP (list))
|
|
461 return 1;
|
|
462
|
|
463 while (CONSP (conditions))
|
|
464 {
|
|
465 Lisp_Object this, tail;
|
|
466 this = XCAR (conditions);
|
|
467 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
|
468 if (EQ (XCAR (tail), this))
|
|
469 return 1;
|
|
470 conditions = XCDR (conditions);
|
|
471 }
|
|
472 return 0;
|
|
473 }
|
|
474
|
163
|
475
|
|
476 /* Return 1 if an error with condition-symbols CONDITIONS,
|
|
477 and described by SIGNAL-DATA, should skip the debugger
|
|
478 according to debugger-ignore-errors. */
|
|
479
|
|
480 static int
|
|
481 skip_debugger (Lisp_Object conditions, Lisp_Object data)
|
|
482 {
|
167
|
483 /* This function can GC */
|
163
|
484 Lisp_Object tail;
|
|
485 int first_string = 1;
|
173
|
486 Lisp_Object error_message = Qnil;
|
163
|
487
|
|
488 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
|
|
489 {
|
|
490 if (STRINGP (XCAR (tail)))
|
|
491 {
|
|
492 if (first_string)
|
|
493 {
|
165
|
494 error_message = Ferror_message_string (data);
|
163
|
495 first_string = 0;
|
|
496 }
|
167
|
497 if (fast_lisp_string_match (XCAR (tail), error_message) >= 0)
|
163
|
498 return 1;
|
|
499 }
|
|
500 else
|
|
501 {
|
|
502 Lisp_Object contail;
|
|
503
|
|
504 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
|
167
|
505 if (EQ (XCAR (tail), XCAR (contail)))
|
163
|
506 return 1;
|
|
507 }
|
|
508 }
|
|
509
|
|
510 return 0;
|
|
511 }
|
|
512
|
0
|
513 /* Actually generate a backtrace on STREAM. */
|
|
514
|
|
515 static Lisp_Object
|
|
516 backtrace_259 (Lisp_Object stream)
|
|
517 {
|
173
|
518 return Fbacktrace (stream, Qt);
|
0
|
519 }
|
|
520
|
|
521 /* An error was signalled. Maybe call the debugger, if the `debug-on-error'
|
|
522 etc. variables call for this. CONDITIONS is the list of conditions
|
|
523 associated with the error being signalled. SIG is the actual error
|
|
524 being signalled, and DATA is the associated data (these are exactly
|
|
525 the same as the arguments to `signal'). ACTIVE_HANDLERS is the
|
|
526 list of error handlers that are to be put in place while the debugger
|
|
527 is called. This is generally the remaining handlers that are
|
|
528 outside of the innermost handler trapping this error. This way,
|
|
529 if the same error occurs inside of the debugger, you usually don't get
|
|
530 the debugger entered recursively.
|
|
531
|
|
532 This function returns Qunbound if it didn't call the debugger or if
|
|
533 the user asked (through 'c') that XEmacs should pretend like the
|
|
534 debugger was never entered. Otherwise, it returns the value
|
|
535 that the user specified with `r'. (Note that much of the time,
|
|
536 the user will abort with C-], and we will never have a chance to
|
|
537 return anything at all.)
|
|
538
|
|
539 SIGNAL_VARS_ONLY means we should only look at debug-on-signal
|
|
540 and stack-trace-on-signal to control whether we do anything.
|
|
541 This is so that debug-on-error doesn't make handled errors
|
|
542 cause the debugger to get invoked.
|
|
543
|
|
544 STACK_TRACE_DISPLAYED and DEBUGGER_ENTERED are used so that
|
|
545 those functions aren't done more than once in a single `signal'
|
|
546 session. */
|
|
547
|
|
548 static Lisp_Object
|
|
549 signal_call_debugger (Lisp_Object conditions,
|
|
550 Lisp_Object sig, Lisp_Object data,
|
|
551 Lisp_Object active_handlers,
|
|
552 int signal_vars_only,
|
|
553 int *stack_trace_displayed,
|
|
554 int *debugger_entered)
|
|
555 {
|
|
556 /* This function can GC */
|
|
557 Lisp_Object val = Qunbound;
|
|
558 Lisp_Object all_handlers = Vcondition_handlers;
|
167
|
559 Lisp_Object temp_data = Qnil;
|
0
|
560 int speccount = specpdl_depth_counter;
|
167
|
561 struct gcpro gcpro1, gcpro2;
|
|
562 GCPRO2 (all_handlers, temp_data);
|
0
|
563
|
|
564 Vcondition_handlers = active_handlers;
|
|
565
|
167
|
566 temp_data = Fcons (sig, data); /* needed for skip_debugger */
|
163
|
567
|
|
568 if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only
|
167
|
569 && wants_debugger (Vstack_trace_on_error, conditions)
|
|
570 && !skip_debugger (conditions, temp_data))
|
0
|
571 {
|
|
572 specbind (Qdebug_on_error, Qnil);
|
|
573 specbind (Qstack_trace_on_error, Qnil);
|
|
574 specbind (Qdebug_on_signal, Qnil);
|
|
575 specbind (Qstack_trace_on_signal, Qnil);
|
185
|
576
|
0
|
577 internal_with_output_to_temp_buffer ("*Backtrace*",
|
|
578 backtrace_259,
|
|
579 Qnil,
|
|
580 Qnil);
|
|
581 unbind_to (speccount, Qnil);
|
|
582 *stack_trace_displayed = 1;
|
|
583 }
|
185
|
584
|
0
|
585 if (!entering_debugger && !*debugger_entered && !signal_vars_only
|
|
586 && (EQ (sig, Qquit)
|
|
587 ? debug_on_quit
|
167
|
588 : wants_debugger (Vdebug_on_error, conditions))
|
|
589 && !skip_debugger (conditions, temp_data))
|
0
|
590 {
|
|
591 debug_on_quit &= ~2; /* reset critical bit */
|
|
592 specbind (Qdebug_on_error, Qnil);
|
|
593 specbind (Qstack_trace_on_error, Qnil);
|
|
594 specbind (Qdebug_on_signal, Qnil);
|
|
595 specbind (Qstack_trace_on_signal, Qnil);
|
185
|
596
|
0
|
597 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
|
|
598 *debugger_entered = 1;
|
|
599 }
|
|
600
|
|
601 if (!entering_debugger && !*stack_trace_displayed
|
|
602 && wants_debugger (Vstack_trace_on_signal, conditions))
|
|
603 {
|
|
604 specbind (Qdebug_on_error, Qnil);
|
|
605 specbind (Qstack_trace_on_error, Qnil);
|
|
606 specbind (Qdebug_on_signal, Qnil);
|
|
607 specbind (Qstack_trace_on_signal, Qnil);
|
185
|
608
|
0
|
609 internal_with_output_to_temp_buffer ("*Backtrace*",
|
|
610 backtrace_259,
|
|
611 Qnil,
|
|
612 Qnil);
|
|
613 unbind_to (speccount, Qnil);
|
|
614 *stack_trace_displayed = 1;
|
|
615 }
|
|
616
|
|
617 if (!entering_debugger && !*debugger_entered
|
|
618 && (EQ (sig, Qquit)
|
|
619 ? debug_on_quit
|
|
620 : wants_debugger (Vdebug_on_signal, conditions)))
|
|
621 {
|
|
622 debug_on_quit &= ~2; /* reset critical bit */
|
|
623 specbind (Qdebug_on_error, Qnil);
|
|
624 specbind (Qstack_trace_on_error, Qnil);
|
|
625 specbind (Qdebug_on_signal, Qnil);
|
|
626 specbind (Qstack_trace_on_signal, Qnil);
|
185
|
627
|
0
|
628 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
|
|
629 *debugger_entered = 1;
|
|
630 }
|
|
631
|
|
632 UNGCPRO;
|
|
633 Vcondition_handlers = all_handlers;
|
173
|
634 return unbind_to (speccount, val);
|
0
|
635 }
|
|
636
|
|
637
|
|
638 /**********************************************************************/
|
|
639 /* The basic special forms */
|
|
640 /**********************************************************************/
|
|
641
|
|
642 /* NOTE!!! Every function that can call EVAL must protect its args
|
|
643 and temporaries from garbage collection while it needs them.
|
|
644 The definition of `For' shows what you have to do. */
|
|
645
|
20
|
646 DEFUN ("or", For, 0, UNEVALLED, 0, /*
|
0
|
647 Eval args until one of them yields non-nil, then return that value.
|
|
648 The remaining args are not evalled at all.
|
|
649 If all args return nil, return nil.
|
20
|
650 */
|
|
651 (args))
|
0
|
652 {
|
|
653 /* This function can GC */
|
|
654 REGISTER Lisp_Object val;
|
|
655 Lisp_Object args_left;
|
|
656 struct gcpro gcpro1;
|
|
657
|
|
658 if (NILP (args))
|
|
659 return Qnil;
|
|
660
|
|
661 args_left = args;
|
|
662 GCPRO1 (args_left);
|
|
663
|
|
664 do
|
|
665 {
|
|
666 val = Feval (Fcar (args_left));
|
|
667 if (!NILP (val))
|
|
668 break;
|
|
669 args_left = Fcdr (args_left);
|
|
670 }
|
|
671 while (!NILP (args_left));
|
|
672
|
|
673 UNGCPRO;
|
|
674 return val;
|
|
675 }
|
|
676
|
20
|
677 DEFUN ("and", Fand, 0, UNEVALLED, 0, /*
|
0
|
678 Eval args until one of them yields nil, then return nil.
|
|
679 The remaining args are not evalled at all.
|
|
680 If no arg yields nil, return the last arg's value.
|
20
|
681 */
|
|
682 (args))
|
0
|
683 {
|
|
684 /* This function can GC */
|
|
685 REGISTER Lisp_Object val;
|
|
686 Lisp_Object args_left;
|
|
687 struct gcpro gcpro1;
|
|
688
|
|
689 if (NILP (args))
|
|
690 return Qt;
|
|
691
|
|
692 args_left = args;
|
|
693 GCPRO1 (args_left);
|
|
694
|
|
695 do
|
|
696 {
|
|
697 val = Feval (Fcar (args_left));
|
|
698 if (NILP (val))
|
|
699 break;
|
|
700 args_left = Fcdr (args_left);
|
|
701 }
|
|
702 while (!NILP (args_left));
|
|
703
|
|
704 UNGCPRO;
|
|
705 return val;
|
|
706 }
|
|
707
|
20
|
708 DEFUN ("if", Fif, 2, UNEVALLED, 0, /*
|
0
|
709 (if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...
|
|
710 Returns the value of THEN or the value of the last of the ELSE's.
|
|
711 THEN must be one expression, but ELSE... can be zero or more expressions.
|
|
712 If COND yields nil, and there are no ELSE's, the value is nil.
|
20
|
713 */
|
70
|
714 (args))
|
0
|
715 {
|
|
716 /* This function can GC */
|
|
717 Lisp_Object cond;
|
|
718 struct gcpro gcpro1;
|
|
719
|
|
720 GCPRO1 (args);
|
|
721 cond = Feval (Fcar (args));
|
|
722 UNGCPRO;
|
|
723
|
|
724 if (!NILP (cond))
|
|
725 return Feval (Fcar (Fcdr (args)));
|
|
726 return Fprogn (Fcdr (Fcdr (args)));
|
|
727 }
|
|
728
|
20
|
729 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /*
|
0
|
730 (cond CLAUSES...): try each clause until one succeeds.
|
|
731 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
|
|
732 and, if the value is non-nil, this clause succeeds:
|
|
733 then the expressions in BODY are evaluated and the last one's
|
|
734 value is the value of the cond-form.
|
|
735 If no clause succeeds, cond returns nil.
|
|
736 If a clause has one element, as in (CONDITION),
|
|
737 CONDITION's value if non-nil is returned from the cond-form.
|
20
|
738 */
|
|
739 (args))
|
0
|
740 {
|
|
741 /* This function can GC */
|
|
742 REGISTER Lisp_Object clause, val;
|
|
743 struct gcpro gcpro1;
|
|
744
|
|
745 val = Qnil;
|
|
746 GCPRO1 (args);
|
|
747 while (!NILP (args))
|
|
748 {
|
|
749 clause = Fcar (args);
|
|
750 val = Feval (Fcar (clause));
|
|
751 if (!NILP (val))
|
|
752 {
|
|
753 if (!EQ (XCDR (clause), Qnil))
|
|
754 val = Fprogn (XCDR (clause));
|
|
755 break;
|
|
756 }
|
|
757 args = XCDR (args);
|
|
758 }
|
|
759 UNGCPRO;
|
|
760
|
|
761 return val;
|
|
762 }
|
|
763
|
20
|
764 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /*
|
0
|
765 (progn BODY...): eval BODY forms sequentially and return value of last one.
|
20
|
766 */
|
|
767 (args))
|
0
|
768 {
|
|
769 /* This function can GC */
|
|
770 REGISTER Lisp_Object val;
|
|
771 Lisp_Object args_left;
|
|
772 struct gcpro gcpro1;
|
|
773
|
195
|
774 if (! CONSP (args))
|
0
|
775 return Qnil;
|
|
776
|
|
777 args_left = args;
|
|
778 GCPRO1 (args_left);
|
|
779
|
|
780 do
|
|
781 {
|
195
|
782 val = Feval (XCAR (args_left));
|
|
783 args_left = XCDR (args_left);
|
0
|
784 }
|
195
|
785 while (CONSP (args_left));
|
0
|
786
|
|
787 UNGCPRO;
|
|
788 return val;
|
|
789 }
|
|
790
|
20
|
791 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /*
|
0
|
792 (prog1 FIRST BODY...): eval FIRST and BODY sequentially; value from FIRST.
|
|
793 The value of FIRST is saved during the evaluation of the remaining args,
|
|
794 whose values are discarded.
|
20
|
795 */
|
|
796 (args))
|
0
|
797 {
|
|
798 /* This function can GC */
|
|
799 Lisp_Object val;
|
|
800 REGISTER Lisp_Object args_left;
|
|
801 struct gcpro gcpro1, gcpro2;
|
|
802 REGISTER int argnum = 0;
|
|
803
|
|
804 if (NILP (args))
|
|
805 return Qnil;
|
|
806
|
|
807 args_left = args;
|
|
808 val = Qnil;
|
|
809 GCPRO2 (args, val);
|
|
810
|
|
811 do
|
|
812 {
|
|
813 if (!(argnum++))
|
|
814 val = Feval (Fcar (args_left));
|
|
815 else
|
|
816 Feval (Fcar (args_left));
|
|
817 args_left = Fcdr (args_left);
|
|
818 }
|
|
819 while (!NILP (args_left));
|
|
820
|
|
821 UNGCPRO;
|
|
822 return val;
|
|
823 }
|
|
824
|
20
|
825 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /*
|
0
|
826 (prog2 X Y BODY...): eval X, Y and BODY sequentially; value from Y.
|
|
827 The value of Y is saved during the evaluation of the remaining args,
|
|
828 whose values are discarded.
|
20
|
829 */
|
|
830 (args))
|
0
|
831 {
|
|
832 /* This function can GC */
|
|
833 Lisp_Object val;
|
|
834 REGISTER Lisp_Object args_left;
|
|
835 struct gcpro gcpro1, gcpro2;
|
|
836 REGISTER int argnum = -1;
|
|
837
|
|
838 val = Qnil;
|
|
839
|
|
840 if (NILP (args))
|
|
841 return Qnil;
|
|
842
|
|
843 args_left = args;
|
|
844 val = Qnil;
|
|
845 GCPRO2 (args, val);
|
|
846
|
|
847 do
|
|
848 {
|
|
849 if (!(argnum++))
|
|
850 val = Feval (Fcar (args_left));
|
|
851 else
|
|
852 Feval (Fcar (args_left));
|
|
853 args_left = Fcdr (args_left);
|
|
854 }
|
|
855 while (!NILP (args_left));
|
|
856
|
|
857 UNGCPRO;
|
|
858 return val;
|
|
859 }
|
|
860
|
20
|
861 DEFUN ("let*", FletX, 1, UNEVALLED, 0, /*
|
0
|
862 (let* VARLIST BODY...): bind variables according to VARLIST then eval BODY.
|
|
863 The value of the last form in BODY is returned.
|
|
864 Each element of VARLIST is a symbol (which is bound to nil)
|
|
865 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
866 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
|
20
|
867 */
|
|
868 (args))
|
0
|
869 {
|
|
870 /* This function can GC */
|
|
871 Lisp_Object varlist, val, elt;
|
|
872 int speccount = specpdl_depth_counter;
|
|
873 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
874
|
|
875 GCPRO3 (args, elt, varlist);
|
|
876
|
|
877 varlist = Fcar (args);
|
|
878 while (!NILP (varlist))
|
|
879 {
|
|
880 QUIT;
|
|
881 elt = Fcar (varlist);
|
|
882 if (SYMBOLP (elt))
|
|
883 specbind (elt, Qnil);
|
|
884 else if (! NILP (Fcdr (Fcdr (elt))))
|
|
885 signal_simple_error ("`let' bindings can have only one value-form",
|
|
886 elt);
|
|
887 else
|
|
888 {
|
|
889 val = Feval (Fcar (Fcdr (elt)));
|
|
890 specbind (Fcar (elt), val);
|
|
891 }
|
|
892 varlist = Fcdr (varlist);
|
|
893 }
|
|
894 UNGCPRO;
|
|
895 val = Fprogn (Fcdr (args));
|
|
896 return unbind_to (speccount, val);
|
|
897 }
|
|
898
|
20
|
899 DEFUN ("let", Flet, 1, UNEVALLED, 0, /*
|
0
|
900 (let VARLIST BODY...): bind variables according to VARLIST then eval BODY.
|
|
901 The value of the last form in BODY is returned.
|
|
902 Each element of VARLIST is a symbol (which is bound to nil)
|
|
903 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
904 All the VALUEFORMs are evalled before any symbols are bound.
|
20
|
905 */
|
|
906 (args))
|
0
|
907 {
|
|
908 /* This function can GC */
|
|
909 Lisp_Object *temps, tem;
|
|
910 REGISTER Lisp_Object elt, varlist;
|
|
911 int speccount = specpdl_depth_counter;
|
|
912 REGISTER int argnum;
|
|
913 struct gcpro gcpro1, gcpro2;
|
|
914
|
|
915 varlist = Fcar (args);
|
|
916
|
|
917 /* Make space to hold the values to give the bound variables */
|
|
918 elt = Flength (varlist);
|
185
|
919 temps = alloca_array (Lisp_Object, XINT (elt));
|
0
|
920
|
|
921 /* Compute the values and store them in `temps' */
|
|
922
|
|
923 GCPRO2 (args, *temps);
|
|
924 gcpro2.nvars = 0;
|
|
925
|
|
926 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
|
|
927 {
|
|
928 QUIT;
|
|
929 elt = Fcar (varlist);
|
|
930 if (SYMBOLP (elt))
|
|
931 temps [argnum++] = Qnil;
|
|
932 else if (! NILP (Fcdr (Fcdr (elt))))
|
|
933 signal_simple_error ("`let' bindings can have only one value-form",
|
|
934 elt);
|
|
935 else
|
|
936 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
|
|
937 gcpro2.nvars = argnum;
|
|
938 }
|
|
939 UNGCPRO;
|
|
940
|
|
941 varlist = Fcar (args);
|
|
942 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
|
|
943 {
|
|
944 elt = Fcar (varlist);
|
|
945 tem = temps[argnum++];
|
|
946 if (SYMBOLP (elt))
|
|
947 specbind (elt, tem);
|
|
948 else
|
|
949 specbind (Fcar (elt), tem);
|
|
950 }
|
|
951
|
|
952 elt = Fprogn (Fcdr (args));
|
|
953 return unbind_to (speccount, elt);
|
|
954 }
|
|
955
|
20
|
956 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /*
|
0
|
957 (while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.
|
|
958 The order of execution is thus TEST, BODY, TEST, BODY and so on
|
|
959 until TEST returns nil.
|
20
|
960 */
|
70
|
961 (args))
|
0
|
962 {
|
|
963 /* This function can GC */
|
|
964 Lisp_Object test, body, tem;
|
|
965 struct gcpro gcpro1, gcpro2;
|
|
966
|
|
967 GCPRO2 (test, body);
|
|
968
|
|
969 test = Fcar (args);
|
|
970 body = Fcdr (args);
|
|
971 while (tem = Feval (test), !NILP (tem))
|
|
972 {
|
|
973 QUIT;
|
|
974 Fprogn (body);
|
|
975 }
|
|
976
|
|
977 UNGCPRO;
|
|
978 return Qnil;
|
|
979 }
|
|
980
|
20
|
981 DEFUN ("setq", Fsetq, 0, UNEVALLED, 0, /*
|
0
|
982 (setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.
|
|
983 The symbols SYM are variables; they are literal (not evaluated).
|
|
984 The values VAL are expressions; they are evaluated.
|
|
985 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
|
|
986 The second VAL is not computed until after the first SYM is set, and so on;
|
|
987 each VAL can use the new value of variables set earlier in the `setq'.
|
|
988 The return value of the `setq' form is the value of the last VAL.
|
20
|
989 */
|
|
990 (args))
|
0
|
991 {
|
|
992 /* This function can GC */
|
|
993 REGISTER Lisp_Object args_left;
|
|
994 REGISTER Lisp_Object val, sym;
|
|
995 struct gcpro gcpro1;
|
|
996
|
|
997 if (NILP (args))
|
|
998 return Qnil;
|
|
999
|
195
|
1000 {
|
|
1001 REGISTER int i;
|
|
1002 for (i = 0, val = args ; CONSP (val); val = XCDR (val))
|
|
1003 {
|
|
1004 i++;
|
|
1005 /*
|
|
1006 * uncomment the QUIT if there is some way a circular
|
|
1007 * arglist can get in here. I think Feval or Fapply would
|
|
1008 * spin first and the list would never get here.
|
|
1009 */
|
|
1010 /* QUIT; */
|
|
1011 }
|
|
1012 if (i & 1) /* Odd number of arguments? */
|
|
1013 Fsignal (Qwrong_number_of_arguments, list2 (Qsetq, make_int(i)));
|
|
1014 }
|
0
|
1015
|
|
1016 args_left = args;
|
|
1017 GCPRO1 (args);
|
|
1018
|
|
1019 do
|
|
1020 {
|
195
|
1021 val = Feval (XCAR (XCDR (args_left)));
|
|
1022 sym = XCAR (args_left);
|
0
|
1023 Fset (sym, val);
|
195
|
1024 args_left = XCDR (XCDR (args_left));
|
0
|
1025 }
|
195
|
1026 while (CONSP (args_left));
|
0
|
1027
|
|
1028 UNGCPRO;
|
|
1029 return val;
|
|
1030 }
|
185
|
1031
|
20
|
1032 DEFUN ("quote", Fquote, 1, UNEVALLED, 0, /*
|
0
|
1033 Return the argument, without evaluating it. `(quote x)' yields `x'.
|
20
|
1034 */
|
|
1035 (args))
|
0
|
1036 {
|
|
1037 return Fcar (args);
|
|
1038 }
|
185
|
1039
|
20
|
1040 DEFUN ("function", Ffunction, 1, UNEVALLED, 0, /*
|
0
|
1041 Like `quote', but preferred for objects which are functions.
|
|
1042 In byte compilation, `function' causes its argument to be compiled.
|
|
1043 `quote' cannot do that.
|
20
|
1044 */
|
|
1045 (args))
|
0
|
1046 {
|
|
1047 return Fcar (args);
|
|
1048 }
|
|
1049
|
|
1050
|
|
1051 /**********************************************************************/
|
|
1052 /* Defining functions/variables */
|
|
1053 /**********************************************************************/
|
|
1054
|
20
|
1055 DEFUN ("defun", Fdefun, 2, UNEVALLED, 0, /*
|
0
|
1056 (defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
|
|
1057 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
|
|
1058 See also the function `interactive'.
|
20
|
1059 */
|
|
1060 (args))
|
0
|
1061 {
|
|
1062 /* This function can GC */
|
|
1063 Lisp_Object fn_name;
|
|
1064 Lisp_Object defn;
|
|
1065
|
|
1066 fn_name = Fcar (args);
|
|
1067 defn = Fcons (Qlambda, Fcdr (args));
|
|
1068 if (purify_flag)
|
|
1069 defn = Fpurecopy (defn);
|
|
1070 Ffset (fn_name, defn);
|
|
1071 LOADHIST_ATTACH (fn_name);
|
|
1072 return fn_name;
|
|
1073 }
|
|
1074
|
20
|
1075 DEFUN ("defmacro", Fdefmacro, 2, UNEVALLED, 0, /*
|
0
|
1076 (defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.
|
|
1077 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).
|
|
1078 When the macro is called, as in (NAME ARGS...),
|
|
1079 the function (lambda ARGLIST BODY...) is applied to
|
|
1080 the list ARGS... as it appears in the expression,
|
|
1081 and the result should be a form to be evaluated instead of the original.
|
20
|
1082 */
|
|
1083 (args))
|
0
|
1084 {
|
|
1085 /* This function can GC */
|
|
1086 Lisp_Object fn_name;
|
|
1087 Lisp_Object defn;
|
|
1088
|
|
1089 fn_name = Fcar (args);
|
|
1090 defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args)));
|
|
1091 if (purify_flag)
|
|
1092 defn = Fpurecopy (defn);
|
|
1093 Ffset (fn_name, defn);
|
|
1094 LOADHIST_ATTACH (fn_name);
|
|
1095 return fn_name;
|
|
1096 }
|
|
1097
|
20
|
1098 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /*
|
0
|
1099 (defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.
|
|
1100 You are not required to define a variable in order to use it,
|
|
1101 but the definition can supply documentation and an initial value
|
|
1102 in a way that tags can recognize.
|
|
1103
|
|
1104 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is
|
|
1105 void. (However, when you evaluate a defvar interactively, it acts like a
|
|
1106 defconst: SYMBOL's value is always set regardless of whether it's currently
|
|
1107 void.)
|
|
1108 If SYMBOL is buffer-local, its default value is what is set;
|
|
1109 buffer-local values are not affected.
|
|
1110 INITVALUE and DOCSTRING are optional.
|
|
1111 If DOCSTRING starts with *, this variable is identified as a user option.
|
|
1112 This means that M-x set-variable and M-x edit-options recognize it.
|
|
1113 If INITVALUE is missing, SYMBOL's value is not set.
|
|
1114
|
|
1115 In lisp-interaction-mode defvar is treated as defconst.
|
20
|
1116 */
|
|
1117 (args))
|
0
|
1118 {
|
|
1119 /* This function can GC */
|
|
1120 REGISTER Lisp_Object sym, tem, tail;
|
|
1121
|
|
1122 sym = Fcar (args);
|
|
1123 tail = Fcdr (args);
|
|
1124 if (!NILP (Fcdr (Fcdr (tail))))
|
|
1125 error ("too many arguments");
|
|
1126
|
|
1127 if (!NILP (tail))
|
|
1128 {
|
|
1129 tem = Fdefault_boundp (sym);
|
|
1130 if (NILP (tem))
|
|
1131 Fset_default (sym, Feval (Fcar (Fcdr (args))));
|
|
1132 }
|
|
1133
|
|
1134 #ifdef I18N3
|
|
1135 if (!NILP (Vfile_domain))
|
|
1136 pure_put (sym, Qvariable_domain, Vfile_domain);
|
|
1137 #endif
|
|
1138
|
|
1139 tail = Fcdr (Fcdr (args));
|
|
1140 if (!NILP (Fcar (tail)))
|
|
1141 {
|
|
1142 tem = Fcar (tail);
|
|
1143 #if 0 /* FSFmacs */
|
|
1144 /* #### We should probably do this but it might be dangerous */
|
|
1145 if (purify_flag)
|
|
1146 tem = Fpurecopy (tem);
|
|
1147 Fput (sym, Qvariable_documentation, tem);
|
|
1148 #else
|
|
1149 pure_put (sym, Qvariable_documentation, tem);
|
|
1150 #endif
|
|
1151 }
|
|
1152
|
|
1153 LOADHIST_ATTACH (sym);
|
|
1154 return sym;
|
|
1155 }
|
|
1156
|
20
|
1157 DEFUN ("defconst", Fdefconst, 2, UNEVALLED, 0, /*
|
0
|
1158 (defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant
|
|
1159 variable.
|
|
1160 The intent is that programs do not change this value, but users may.
|
|
1161 Always sets the value of SYMBOL to the result of evalling INITVALUE.
|
|
1162 If SYMBOL is buffer-local, its default value is what is set;
|
|
1163 buffer-local values are not affected.
|
|
1164 DOCSTRING is optional.
|
|
1165 If DOCSTRING starts with *, this variable is identified as a user option.
|
|
1166 This means that M-x set-variable and M-x edit-options recognize it.
|
|
1167
|
|
1168 Note: do not use `defconst' for user options in libraries that are not
|
|
1169 normally loaded, since it is useful for users to be able to specify
|
|
1170 their own values for such variables before loading the library.
|
|
1171 Since `defconst' unconditionally assigns the variable,
|
|
1172 it would override the user's choice.
|
20
|
1173 */
|
|
1174 (args))
|
0
|
1175 {
|
|
1176 /* This function can GC */
|
|
1177 REGISTER Lisp_Object sym, tem;
|
|
1178
|
|
1179 sym = Fcar (args);
|
|
1180 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
|
|
1181 error ("too many arguments");
|
|
1182
|
|
1183 Fset_default (sym, Feval (Fcar (Fcdr (args))));
|
|
1184
|
|
1185 #ifdef I18N3
|
|
1186 if (!NILP (Vfile_domain))
|
|
1187 pure_put (sym, Qvariable_domain, Vfile_domain);
|
|
1188 #endif
|
|
1189
|
|
1190 tem = Fcar (Fcdr (Fcdr (args)));
|
|
1191
|
|
1192 if (!NILP (tem))
|
|
1193 #if 0 /* FSFmacs */
|
|
1194 /* #### We should probably do this but it might be dangerous */
|
|
1195 {
|
|
1196 if (purify_flag)
|
|
1197 tem = Fpurecopy (tem);
|
|
1198 Fput (sym, Qvariable_documentation, tem);
|
|
1199 }
|
|
1200 #else
|
|
1201 pure_put (sym, Qvariable_documentation, tem);
|
|
1202 #endif
|
|
1203
|
|
1204 LOADHIST_ATTACH (sym);
|
|
1205 return sym;
|
|
1206 }
|
|
1207
|
20
|
1208 DEFUN ("user-variable-p", Fuser_variable_p, 1, 1, 0, /*
|
0
|
1209 Return t if VARIABLE is intended to be set and modified by users.
|
|
1210 \(The alternative is a variable used internally in a Lisp program.)
|
|
1211 Determined by whether the first character of the documentation
|
|
1212 for the variable is `*'.
|
20
|
1213 */
|
|
1214 (variable))
|
0
|
1215 {
|
|
1216 Lisp_Object documentation;
|
185
|
1217
|
0
|
1218 documentation = Fget (variable, Qvariable_documentation, Qnil);
|
|
1219 if (INTP (documentation) && XINT (documentation) < 0)
|
|
1220 return Qt;
|
|
1221 if ((STRINGP (documentation)) &&
|
|
1222 (string_byte (XSTRING (documentation), 0) == '*'))
|
|
1223 return Qt;
|
|
1224 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
|
|
1225 if (CONSP (documentation)
|
|
1226 && STRINGP (XCAR (documentation))
|
|
1227 && INTP (XCDR (documentation))
|
|
1228 && XINT (XCDR (documentation)) < 0)
|
|
1229 return Qt;
|
|
1230 return Qnil;
|
185
|
1231 }
|
0
|
1232
|
20
|
1233 DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /*
|
0
|
1234 Return result of expanding macros at top level of FORM.
|
|
1235 If FORM is not a macro call, it is returned unchanged.
|
|
1236 Otherwise, the macro is expanded and the expansion is considered
|
|
1237 in place of FORM. When a non-macro-call results, it is returned.
|
|
1238
|
|
1239 The second optional arg ENVIRONMENT species an environment of macro
|
|
1240 definitions to shadow the loaded ones for use in file byte-compilation.
|
20
|
1241 */
|
|
1242 (form, env))
|
0
|
1243 {
|
|
1244 /* This function can GC */
|
|
1245 /* With cleanups from Hallvard Furuseth. */
|
|
1246 REGISTER Lisp_Object expander, sym, def, tem;
|
|
1247
|
|
1248 while (1)
|
|
1249 {
|
|
1250 /* Come back here each time we expand a macro call,
|
|
1251 in case it expands into another macro call. */
|
|
1252 if (!CONSP (form))
|
|
1253 break;
|
|
1254 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
|
|
1255 def = sym = XCAR (form);
|
|
1256 tem = Qnil;
|
|
1257 /* Trace symbols aliases to other symbols
|
|
1258 until we get a symbol that is not an alias. */
|
|
1259 while (SYMBOLP (def))
|
|
1260 {
|
|
1261 QUIT;
|
|
1262 sym = def;
|
|
1263 tem = Fassq (sym, env);
|
|
1264 if (NILP (tem))
|
|
1265 {
|
|
1266 def = XSYMBOL (sym)->function;
|
|
1267 if (!UNBOUNDP (def))
|
|
1268 continue;
|
|
1269 }
|
|
1270 break;
|
|
1271 }
|
|
1272 /* Right now TEM is the result from SYM in ENV,
|
|
1273 and if TEM is nil then DEF is SYM's function definition. */
|
|
1274 if (NILP (tem))
|
|
1275 {
|
|
1276 /* SYM is not mentioned in ENV.
|
|
1277 Look at its function definition. */
|
|
1278 if (UNBOUNDP (def)
|
|
1279 || !CONSP (def))
|
|
1280 /* Not defined or definition not suitable */
|
|
1281 break;
|
|
1282 if (EQ (XCAR (def), Qautoload))
|
|
1283 {
|
|
1284 /* Autoloading function: will it be a macro when loaded? */
|
|
1285 tem = Felt (def, make_int (4));
|
|
1286 if (EQ (tem, Qt) || EQ (tem, Qmacro))
|
|
1287 {
|
|
1288 /* Yes, load it and try again. */
|
|
1289 do_autoload (def, sym);
|
|
1290 continue;
|
|
1291 }
|
|
1292 else
|
|
1293 break;
|
|
1294 }
|
|
1295 else if (!EQ (XCAR (def), Qmacro))
|
|
1296 break;
|
|
1297 else expander = XCDR (def);
|
|
1298 }
|
|
1299 else
|
|
1300 {
|
|
1301 expander = XCDR (tem);
|
|
1302 if (NILP (expander))
|
|
1303 break;
|
|
1304 }
|
|
1305 form = apply1 (expander, XCDR (form));
|
|
1306 }
|
|
1307 return form;
|
|
1308 }
|
|
1309
|
|
1310
|
|
1311 /**********************************************************************/
|
|
1312 /* Non-local exits */
|
|
1313 /**********************************************************************/
|
|
1314
|
20
|
1315 DEFUN ("catch", Fcatch, 1, UNEVALLED, 0, /*
|
0
|
1316 (catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.
|
|
1317 TAG is evalled to get the tag to use. Then the BODY is executed.
|
|
1318 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
|
|
1319 If no throw happens, `catch' returns the value of the last BODY form.
|
|
1320 If a throw happens, it specifies the value to return from `catch'.
|
20
|
1321 */
|
|
1322 (args))
|
0
|
1323 {
|
|
1324 /* This function can GC */
|
|
1325 Lisp_Object tag;
|
|
1326 struct gcpro gcpro1;
|
|
1327
|
|
1328 GCPRO1 (args);
|
|
1329 tag = Feval (Fcar (args));
|
|
1330 UNGCPRO;
|
|
1331 return internal_catch (tag, Fprogn, Fcdr (args), 0);
|
|
1332 }
|
|
1333
|
|
1334 /* Set up a catch, then call C function FUNC on argument ARG.
|
|
1335 FUNC should return a Lisp_Object.
|
|
1336 This is how catches are done from within C code. */
|
|
1337
|
|
1338 Lisp_Object
|
185
|
1339 internal_catch (Lisp_Object tag,
|
0
|
1340 Lisp_Object (*func) (Lisp_Object arg),
|
|
1341 Lisp_Object arg,
|
|
1342 int *threw)
|
|
1343 {
|
|
1344 /* This structure is made part of the chain `catchlist'. */
|
|
1345 struct catchtag c;
|
|
1346
|
|
1347 /* Fill in the components of c, and put it on the list. */
|
|
1348 c.next = catchlist;
|
|
1349 c.tag = tag;
|
|
1350 c.val = Qnil;
|
|
1351 c.backlist = backtrace_list;
|
|
1352 #if 0 /* FSFmacs */
|
|
1353 /* #### */
|
|
1354 c.handlerlist = handlerlist;
|
|
1355 #endif
|
|
1356 c.lisp_eval_depth = lisp_eval_depth;
|
|
1357 c.pdlcount = specpdl_depth_counter;
|
|
1358 #if 0 /* FSFmacs */
|
|
1359 c.poll_suppress_count = async_timer_suppress_count;
|
|
1360 #endif
|
|
1361 c.gcpro = gcprolist;
|
|
1362 catchlist = &c;
|
|
1363
|
|
1364 /* Call FUNC. */
|
|
1365 if (SETJMP (c.jmp))
|
|
1366 {
|
|
1367 /* Throw works by a longjmp that comes right here. */
|
|
1368 if (threw) *threw = 1;
|
173
|
1369 return c.val;
|
0
|
1370 }
|
|
1371 c.val = (*func) (arg);
|
|
1372 if (threw) *threw = 0;
|
|
1373 catchlist = c.next;
|
173
|
1374 return c.val;
|
0
|
1375 }
|
|
1376
|
|
1377
|
|
1378 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
|
|
1379 jump to that CATCH, returning VALUE as the value of that catch.
|
|
1380
|
|
1381 This is the guts Fthrow and Fsignal; they differ only in the way
|
|
1382 they choose the catch tag to throw to. A catch tag for a
|
|
1383 condition-case form has a TAG of Qnil.
|
|
1384
|
|
1385 Before each catch is discarded, unbind all special bindings and
|
|
1386 execute all unwind-protect clauses made above that catch. Unwind
|
|
1387 the handler stack as we go, so that the proper handlers are in
|
|
1388 effect for each unwind-protect clause we run. At the end, restore
|
|
1389 some static info saved in CATCH, and longjmp to the location
|
|
1390 specified in the
|
|
1391
|
|
1392 This is used for correct unwinding in Fthrow and Fsignal. */
|
|
1393
|
|
1394 static void
|
|
1395 unwind_to_catch (struct catchtag *c, Lisp_Object val)
|
|
1396 {
|
|
1397 #if 0 /* FSFmacs */
|
|
1398 /* #### */
|
203
|
1399 REGISTER int last_time;
|
0
|
1400 #endif
|
|
1401
|
|
1402 /* Unwind the specbind, catch, and handler stacks back to CATCH
|
|
1403 Before each catch is discarded, unbind all special bindings
|
|
1404 and execute all unwind-protect clauses made above that catch.
|
|
1405 At the end, restore some static info saved in CATCH,
|
|
1406 and longjmp to the location specified.
|
|
1407 */
|
|
1408
|
|
1409 /* Save the value somewhere it will be GC'ed.
|
185
|
1410 (Can't overwrite tag slot because an unwind-protect may
|
0
|
1411 want to throw to this same tag, which isn't yet invalid.) */
|
|
1412 c->val = val;
|
|
1413
|
|
1414 #if 0 /* FSFmacs */
|
|
1415 /* Restore the polling-suppression count. */
|
|
1416 set_poll_suppress_count (catch->poll_suppress_count);
|
|
1417 #endif
|
|
1418
|
|
1419 #if 0 /* FSFmacs */
|
|
1420 /* #### FSFmacs has the following loop. Is it more correct? */
|
|
1421 do
|
|
1422 {
|
|
1423 last_time = catchlist == c;
|
|
1424
|
|
1425 /* Unwind the specpdl stack, and then restore the proper set of
|
|
1426 handlers. */
|
|
1427 unbind_to (catchlist->pdlcount, Qnil);
|
|
1428 handlerlist = catchlist->handlerlist;
|
|
1429 catchlist = catchlist->next;
|
|
1430 }
|
|
1431 while (! last_time);
|
|
1432 #else /* Actual XEmacs code */
|
|
1433 /* Unwind the specpdl stack */
|
|
1434 unbind_to (c->pdlcount, Qnil);
|
|
1435 catchlist = c->next;
|
|
1436 #endif
|
|
1437
|
|
1438 gcprolist = c->gcpro;
|
|
1439 backtrace_list = c->backlist;
|
|
1440 lisp_eval_depth = c->lisp_eval_depth;
|
|
1441
|
|
1442 throw_level = 0;
|
|
1443 LONGJMP (c->jmp, 1);
|
185
|
1444 }
|
0
|
1445
|
|
1446 static DOESNT_RETURN
|
|
1447 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p,
|
|
1448 Lisp_Object sig, Lisp_Object data)
|
|
1449 {
|
|
1450 /* die if we recurse more than is reasonable */
|
|
1451 if (++throw_level > 20)
|
|
1452 abort();
|
|
1453
|
|
1454 /* If bomb_out_p is t, this is being called from Fsignal as a
|
|
1455 "last resort" when there is no handler for this error and
|
|
1456 the debugger couldn't be invoked, so we are throwing to
|
|
1457 'top-level. If this tag doesn't exist (happens during the
|
|
1458 initialization stages) we would get in an infinite recursive
|
|
1459 Fsignal/Fthrow loop, so instead we bomb out to the
|
|
1460 really-early-error-handler.
|
|
1461
|
|
1462 Note that in fact the only time that the "last resort"
|
|
1463 occurs is when there's no catch for 'top-level -- the
|
|
1464 'top-level catch and the catch-all error handler are
|
|
1465 established at the same time, in initial_command_loop/
|
|
1466 top_level_1.
|
|
1467
|
185
|
1468 #### Fix this horrifitude!
|
0
|
1469 */
|
185
|
1470
|
0
|
1471 while (1)
|
|
1472 {
|
|
1473 REGISTER struct catchtag *c;
|
|
1474
|
|
1475 #if 0 /* FSFmacs */
|
|
1476 if (!NILP (tag)) /* #### */
|
|
1477 #endif
|
|
1478 for (c = catchlist; c; c = c->next)
|
|
1479 {
|
|
1480 if (EQ (c->tag, tag))
|
|
1481 unwind_to_catch (c, val);
|
|
1482 }
|
|
1483 if (!bomb_out_p)
|
|
1484 tag = Fsignal (Qno_catch, list2 (tag, val));
|
|
1485 else
|
|
1486 call1 (Qreally_early_error_handler, Fcons (sig, data));
|
|
1487 }
|
|
1488
|
|
1489 /* can't happen. who cares? - (Sun's compiler does) */
|
|
1490 /* throw_level--; */
|
|
1491 /* getting tired of compilation warnings */
|
|
1492 /* return Qnil; */
|
|
1493 }
|
|
1494
|
|
1495 /* See above, where CATCHLIST is defined, for a description of how
|
|
1496 Fthrow() works.
|
|
1497
|
|
1498 Fthrow() is also called by Fsignal(), to do a non-local jump
|
|
1499 back to the appropriate condition-case handler after (maybe)
|
|
1500 the debugger is entered. In that case, TAG is the value
|
|
1501 of Vcondition_handlers that was in place just after the
|
|
1502 condition-case handler was set up. The car of this will be
|
|
1503 some data referring to the handler: Its car will be Qunbound
|
|
1504 (thus, this tag can never be generated by Lisp code), and
|
|
1505 its CDR will be the HANDLERS argument to condition_case_1()
|
|
1506 (either Qerror, Qt, or a list of handlers as in `condition-case').
|
|
1507 This works fine because Fthrow() does not care what TAG was
|
|
1508 passed to it: it just looks up the catch list for something
|
|
1509 that is EQ() to TAG. When it finds it, it will longjmp()
|
|
1510 back to the place that established the catch (in this case,
|
|
1511 condition_case_1). See below for more info.
|
|
1512 */
|
|
1513
|
20
|
1514 DEFUN ("throw", Fthrow, 2, 2, 0, /*
|
0
|
1515 (throw TAG VALUE): throw to the catch for TAG and return VALUE from it.
|
|
1516 Both TAG and VALUE are evalled.
|
20
|
1517 */
|
|
1518 (tag, val))
|
0
|
1519 {
|
|
1520 throw_or_bomb_out (tag, val, 0, Qnil, Qnil); /* Doesn't return */
|
|
1521 return Qnil;
|
|
1522 }
|
|
1523
|
20
|
1524 DEFUN ("unwind-protect", Funwind_protect, 1, UNEVALLED, 0, /*
|
0
|
1525 Do BODYFORM, protecting with UNWINDFORMS.
|
|
1526 Usage looks like (unwind-protect BODYFORM UNWINDFORMS...).
|
|
1527 If BODYFORM completes normally, its value is returned
|
|
1528 after executing the UNWINDFORMS.
|
|
1529 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
|
20
|
1530 */
|
|
1531 (args))
|
0
|
1532 {
|
|
1533 /* This function can GC */
|
|
1534 Lisp_Object val;
|
|
1535 int speccount = specpdl_depth_counter;
|
|
1536
|
|
1537 record_unwind_protect (Fprogn, Fcdr (args));
|
|
1538 val = Feval (Fcar (args));
|
|
1539 return unbind_to (speccount, val);
|
|
1540 }
|
|
1541
|
|
1542
|
|
1543 /**********************************************************************/
|
|
1544 /* Signalling and trapping errors */
|
|
1545 /**********************************************************************/
|
|
1546
|
|
1547 static Lisp_Object
|
|
1548 condition_bind_unwind (Lisp_Object loser)
|
|
1549 {
|
|
1550 struct Lisp_Cons *victim;
|
|
1551 /* ((handler-fun . handler-args) ... other handlers) */
|
|
1552 Lisp_Object tem = XCAR (loser);
|
|
1553
|
|
1554 while (CONSP (tem))
|
|
1555 {
|
|
1556 victim = XCONS (tem);
|
|
1557 tem = victim->cdr;
|
|
1558 free_cons (victim);
|
|
1559 }
|
|
1560 victim = XCONS (loser);
|
|
1561
|
|
1562 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */
|
|
1563 Vcondition_handlers = victim->cdr;
|
|
1564
|
|
1565 free_cons (victim);
|
173
|
1566 return Qnil;
|
0
|
1567 }
|
|
1568
|
|
1569 static Lisp_Object
|
|
1570 condition_case_unwind (Lisp_Object loser)
|
|
1571 {
|
|
1572 struct Lisp_Cons *victim;
|
|
1573
|
|
1574 /* ((<unbound> . clauses) ... other handlers */
|
|
1575 victim = XCONS (XCAR (loser));
|
|
1576 free_cons (victim);
|
|
1577
|
|
1578 victim = XCONS (loser);
|
|
1579 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */
|
|
1580 Vcondition_handlers = victim->cdr;
|
|
1581
|
|
1582 free_cons (victim);
|
173
|
1583 return Qnil;
|
0
|
1584 }
|
|
1585
|
|
1586 /* Split out from condition_case_3 so that primitive C callers
|
|
1587 don't have to cons up a lisp handler form to be evaluated. */
|
|
1588
|
|
1589 /* Call a function BFUN of one argument BARG, trapping errors as
|
|
1590 specified by HANDLERS. If no error occurs that is indicated by
|
|
1591 HANDLERS as something to be caught, the return value of this
|
|
1592 function is the return value from BFUN. If such an error does
|
|
1593 occur, HFUN is called, and its return value becomes the
|
|
1594 return value of condition_case_1(). The second argument passed
|
|
1595 to HFUN will always be HARG. The first argument depends on
|
|
1596 HANDLERS:
|
|
1597
|
|
1598 If HANDLERS is Qt, all errors (this includes QUIT, but not
|
|
1599 non-local exits with `throw') cause HFUN to be invoked, and VAL
|
|
1600 (the first argument to HFUN) is a cons (SIG . DATA) of the
|
|
1601 arguments passed to `signal'. The debugger is not invoked even if
|
|
1602 `debug-on-error' was set.
|
|
1603
|
|
1604 A HANDLERS value of Qerror is the same as Qt except that the
|
|
1605 debugger is invoked if `debug-on-error' was set.
|
|
1606
|
|
1607 Otherwise, HANDLERS should be a list of lists (CONDITION-NAME BODY ...)
|
|
1608 exactly as in `condition-case', and errors will be trapped
|
|
1609 as indicated in HANDLERS. VAL (the first argument to HFUN) will
|
|
1610 be a cons whose car is the cons (SIG . DATA) and whose CDR is the
|
|
1611 list (BODY ...) from the appropriate slot in HANDLERS.
|
|
1612
|
|
1613 This function pushes HANDLERS onto the front of Vcondition_handlers
|
|
1614 (actually with a Qunbound marker as well -- see Fthrow() above
|
|
1615 for why), establishes a catch whose tag is this new value of
|
|
1616 Vcondition_handlers, and calls BFUN. When Fsignal() is called,
|
|
1617 it calls Fthrow(), setting TAG to this same new value of
|
|
1618 Vcondition_handlers and setting VAL to the same thing that will
|
|
1619 be passed to HFUN, as above. Fthrow() longjmp()s back to the
|
|
1620 jump point we just established, and we in turn just call the
|
|
1621 HFUN and return its value.
|
|
1622
|
|
1623 For a real condition-case, HFUN will always be
|
|
1624 run_condition_case_handlers() and HARG is the argument VAR
|
|
1625 to condition-case. That function just binds VAR to the cons
|
|
1626 (SIG . DATA) that is the CAR of VAL, and calls the handler
|
|
1627 (BODY ...) that is the CDR of VAL. Note that before calling
|
|
1628 Fthrow(), Fsignal() restored Vcondition_handlers to the value
|
|
1629 it had *before* condition_case_1() was called. This maintains
|
|
1630 consistency (so that the state of things at exit of
|
|
1631 condition_case_1() is the same as at entry), and implies
|
|
1632 that the handler can signal the same error again (possibly
|
|
1633 after processing of its own), without getting in an infinite
|
|
1634 loop. */
|
|
1635
|
|
1636 Lisp_Object
|
|
1637 condition_case_1 (Lisp_Object handlers,
|
|
1638 Lisp_Object (*bfun) (Lisp_Object barg),
|
|
1639 Lisp_Object barg,
|
|
1640 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg),
|
|
1641 Lisp_Object harg)
|
|
1642 {
|
|
1643 int speccount = specpdl_depth_counter;
|
|
1644 struct catchtag c;
|
|
1645 struct gcpro gcpro1;
|
|
1646
|
|
1647 #if 0 /* FSFmacs */
|
|
1648 c.tag = Qnil;
|
|
1649 #else
|
|
1650 /* Do consing now so out-of-memory error happens up front */
|
|
1651 /* (unbound . stuff) is a special condition-case kludge marker
|
|
1652 which is known specially by Fsignal.
|
|
1653 This is an abomination, but to fix it would require either
|
|
1654 making condition_case cons (a union of the conditions of the clauses)
|
|
1655 or changing the byte-compiler output (no thanks). */
|
|
1656 c.tag = noseeum_cons (noseeum_cons (Qunbound, handlers),
|
|
1657 Vcondition_handlers);
|
|
1658 #endif
|
|
1659 c.val = Qnil;
|
|
1660 c.backlist = backtrace_list;
|
|
1661 #if 0 /* FSFmacs */
|
|
1662 /* #### */
|
|
1663 c.handlerlist = handlerlist;
|
|
1664 #endif
|
|
1665 c.lisp_eval_depth = lisp_eval_depth;
|
|
1666 c.pdlcount = specpdl_depth_counter;
|
|
1667 #if 0 /* FSFmacs */
|
|
1668 c.poll_suppress_count = async_timer_suppress_count;
|
|
1669 #endif
|
|
1670 c.gcpro = gcprolist;
|
|
1671 /* #### FSFmacs does the following statement *after* the setjmp(). */
|
|
1672 c.next = catchlist;
|
|
1673
|
|
1674 if (SETJMP (c.jmp))
|
|
1675 {
|
|
1676 /* throw does ungcpro, etc */
|
173
|
1677 return (*hfun) (c.val, harg);
|
0
|
1678 }
|
|
1679
|
|
1680 record_unwind_protect (condition_case_unwind, c.tag);
|
|
1681
|
|
1682 catchlist = &c;
|
|
1683 #if 0 /* FSFmacs */
|
|
1684 h.handler = handlers;
|
|
1685 h.var = Qnil;
|
|
1686 h.next = handlerlist;
|
|
1687 h.tag = &c;
|
|
1688 handlerlist = &h;
|
|
1689 #else
|
|
1690 Vcondition_handlers = c.tag;
|
|
1691 #endif
|
|
1692 GCPRO1 (harg); /* Somebody has to gc-protect */
|
|
1693
|
|
1694 c.val = ((*bfun) (barg));
|
|
1695
|
|
1696 /* The following is *not* true: (ben)
|
|
1697
|
|
1698 ungcpro, restoring catchlist and condition_handlers are actually
|
|
1699 redundant since unbind_to now restores them. But it looks funny not to
|
|
1700 have this code here, and it doesn't cost anything, so I'm leaving it.*/
|
|
1701 UNGCPRO;
|
|
1702 catchlist = c.next;
|
|
1703 Vcondition_handlers = XCDR (c.tag);
|
|
1704
|
173
|
1705 return unbind_to (speccount, c.val);
|
0
|
1706 }
|
|
1707
|
|
1708 static Lisp_Object
|
|
1709 run_condition_case_handlers (Lisp_Object val, Lisp_Object var)
|
|
1710 {
|
|
1711 /* This function can GC */
|
|
1712 #if 0 /* FSFmacs */
|
|
1713 if (!NILP (h.var))
|
|
1714 specbind (h.var, c.val);
|
|
1715 val = Fprogn (Fcdr (h.chosen_clause));
|
185
|
1716
|
0
|
1717 /* Note that this just undoes the binding of h.var; whoever
|
|
1718 longjumped to us unwound the stack to c.pdlcount before
|
|
1719 throwing. */
|
|
1720 unbind_to (c.pdlcount, Qnil);
|
|
1721 return val;
|
|
1722 #else
|
|
1723 int speccount;
|
|
1724
|
|
1725 if (NILP (var))
|
173
|
1726 return Fprogn (Fcdr (val)); /* tailcall */
|
0
|
1727
|
|
1728 speccount = specpdl_depth_counter;
|
|
1729 specbind (var, Fcar (val));
|
|
1730 val = Fprogn (Fcdr (val));
|
|
1731 return unbind_to (speccount, val);
|
|
1732 #endif
|
|
1733 }
|
|
1734
|
|
1735 /* Here for bytecode to call non-consfully. This is exactly like
|
|
1736 condition-case except that it takes three arguments rather
|
|
1737 than a single list of arguments. */
|
|
1738 Lisp_Object
|
185
|
1739 Fcondition_case_3 (Lisp_Object bodyform,
|
0
|
1740 Lisp_Object var, Lisp_Object handlers)
|
|
1741 {
|
|
1742 /* This function can GC */
|
|
1743 Lisp_Object val;
|
|
1744
|
|
1745 CHECK_SYMBOL (var);
|
|
1746
|
|
1747 for (val = handlers; ! NILP (val); val = Fcdr (val))
|
|
1748 {
|
|
1749 Lisp_Object tem;
|
|
1750 tem = Fcar (val);
|
185
|
1751 if ((!NILP (tem))
|
0
|
1752 && (!CONSP (tem)
|
|
1753 || (!SYMBOLP (XCAR (tem)) && !CONSP (XCAR (tem)))))
|
|
1754 signal_simple_error ("Invalid condition handler", tem);
|
|
1755 }
|
|
1756
|
185
|
1757 return condition_case_1 (handlers,
|
0
|
1758 Feval, bodyform,
|
|
1759 run_condition_case_handlers,
|
|
1760 var);
|
|
1761 }
|
|
1762
|
20
|
1763 DEFUN ("condition-case", Fcondition_case, 2, UNEVALLED, 0, /*
|
0
|
1764 Regain control when an error is signalled.
|
|
1765 Usage looks like (condition-case VAR BODYFORM HANDLERS...).
|
|
1766 executes BODYFORM and returns its value if no error happens.
|
|
1767 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
|
|
1768 where the BODY is made of Lisp expressions.
|
|
1769
|
|
1770 A handler is applicable to an error if CONDITION-NAME is one of the
|
|
1771 error's condition names. If an error happens, the first applicable
|
|
1772 handler is run. As a special case, a CONDITION-NAME of t matches
|
|
1773 all errors, even those without the `error' condition name on them
|
|
1774 (e.g. `quit').
|
|
1775
|
|
1776 The car of a handler may be a list of condition names
|
|
1777 instead of a single condition name.
|
|
1778
|
|
1779 When a handler handles an error,
|
|
1780 control returns to the condition-case and the handler BODY... is executed
|
|
1781 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
|
|
1782 VAR may be nil; then you do not get access to the signal information.
|
|
1783
|
|
1784 The value of the last BODY form is returned from the condition-case.
|
|
1785 See also the function `signal' for more info.
|
|
1786
|
|
1787 Note that at the time the condition handler is invoked, the Lisp stack
|
|
1788 and the current catches, condition-cases, and bindings have all been
|
|
1789 popped back to the state they were in just before the call to
|
|
1790 `condition-case'. This means that resignalling the error from
|
|
1791 within the handler will not result in an infinite loop.
|
|
1792
|
|
1793 If you want to establish an error handler that is called with the
|
|
1794 Lisp stack, bindings, etc. as they were when `signal' was called,
|
|
1795 rather than when the handler was set, use `call-with-condition-handler'.
|
20
|
1796 */
|
70
|
1797 (args))
|
0
|
1798 {
|
|
1799 /* This function can GC */
|
|
1800 return Fcondition_case_3 (Fcar (Fcdr (args)),
|
|
1801 Fcar (args),
|
|
1802 Fcdr (Fcdr (args)));
|
185
|
1803 }
|
0
|
1804
|
20
|
1805 DEFUN ("call-with-condition-handler", Fcall_with_condition_handler, 2, MANY, 0, /*
|
0
|
1806 Regain control when an error is signalled, without popping the stack.
|
|
1807 Usage looks like (call-with-condition-handler HANDLER FUNCTION &rest ARGS).
|
|
1808 This function is similar to `condition-case', but the handler is invoked
|
|
1809 with the same environment (Lisp stack, bindings, catches, condition-cases)
|
|
1810 that was current when `signal' was called, rather than when the handler
|
|
1811 was established.
|
|
1812
|
|
1813 HANDLER should be a function of one argument, which is a cons of the args
|
|
1814 (SIG . DATA) that were passed to `signal'. It is invoked whenever
|
|
1815 `signal' is called (this differs from `condition-case', which allows
|
|
1816 you to specify which errors are trapped). If the handler function
|
|
1817 returns, `signal' continues as if the handler were never invoked.
|
|
1818 (It continues to look for handlers established earlier than this one,
|
|
1819 and invokes the standard error-handler if none is found.)
|
20
|
1820 */
|
70
|
1821 (int nargs, Lisp_Object *args)) /* Note! Args side-effected! */
|
0
|
1822 {
|
|
1823 /* This function can GC */
|
|
1824 int speccount = specpdl_depth_counter;
|
|
1825 Lisp_Object tem;
|
|
1826
|
|
1827 /* #### If there were a way to check that args[0] were a function
|
|
1828 which accepted one arg, that should be done here ... */
|
|
1829
|
|
1830 /* (handler-fun . handler-args) */
|
|
1831 tem = noseeum_cons (list1 (args[0]), Vcondition_handlers);
|
|
1832 record_unwind_protect (condition_bind_unwind, tem);
|
|
1833 Vcondition_handlers = tem;
|
|
1834
|
|
1835 /* Caller should have GC-protected args */
|
|
1836 tem = Ffuncall (nargs - 1, args + 1);
|
173
|
1837 return unbind_to (speccount, tem);
|
0
|
1838 }
|
|
1839
|
|
1840 static int
|
|
1841 condition_type_p (Lisp_Object type, Lisp_Object conditions)
|
|
1842 {
|
|
1843 if (EQ (type, Qt))
|
|
1844 /* (condition-case c # (t c)) catches -all- signals
|
|
1845 * Use with caution! */
|
173
|
1846 return 1;
|
0
|
1847 else
|
|
1848 {
|
|
1849 if (SYMBOLP (type))
|
|
1850 {
|
173
|
1851 return !NILP (Fmemq (type, conditions));
|
0
|
1852 }
|
|
1853 else if (CONSP (type))
|
|
1854 {
|
|
1855 while (CONSP (type))
|
|
1856 {
|
|
1857 if (!NILP (Fmemq (Fcar (type), conditions)))
|
|
1858 return 1;
|
|
1859 type = XCDR (type);
|
|
1860 }
|
|
1861 return 0;
|
|
1862 }
|
|
1863 else
|
|
1864 return 0;
|
|
1865 }
|
|
1866 }
|
|
1867
|
|
1868 static Lisp_Object
|
|
1869 return_from_signal (Lisp_Object value)
|
|
1870 {
|
|
1871 #if 1 /* RMS Claims: */
|
|
1872 /* Most callers are not prepared to handle gc if this
|
|
1873 returns. So, since this feature is not very useful,
|
|
1874 take it out. */
|
|
1875 /* Have called debugger; return value to signaller */
|
173
|
1876 return value;
|
0
|
1877 #else /* But the reality is that that stinks, because: */
|
|
1878 /* GACK!!! Really want some way for debug-on-quit errors
|
|
1879 to be continuable!! */
|
|
1880 error ("Returning a value from an error is no longer supported");
|
|
1881 #endif
|
|
1882 }
|
|
1883
|
|
1884 extern int in_display;
|
|
1885 extern int gc_in_progress;
|
|
1886
|
|
1887
|
|
1888 /****************** the workhorse error-signaling function ******************/
|
|
1889
|
|
1890 /* #### This function has not been synched with FSF. It diverges
|
|
1891 significantly. */
|
|
1892
|
|
1893 static Lisp_Object
|
|
1894 signal_1 (Lisp_Object sig, Lisp_Object data)
|
|
1895 {
|
|
1896 /* This function can GC */
|
|
1897 struct gcpro gcpro1, gcpro2;
|
|
1898 Lisp_Object conditions;
|
|
1899 Lisp_Object handlers;
|
|
1900 /* signal_call_debugger() could get called more than once
|
|
1901 (once when a call-with-condition-handler is about to
|
|
1902 be dealt with, and another when a condition-case handler
|
|
1903 is about to be invoked). So make sure the debugger and/or
|
|
1904 stack trace aren't done more than once. */
|
|
1905 int stack_trace_displayed = 0;
|
|
1906 int debugger_entered = 0;
|
|
1907 GCPRO2 (conditions, handlers);
|
|
1908
|
|
1909 if (!initialized)
|
|
1910 {
|
|
1911 /* who knows how much has been initialized? Safest bet is
|
|
1912 just to bomb out immediately. */
|
|
1913 fprintf (stderr, "Error before initialization is complete!\n");
|
|
1914 abort ();
|
|
1915 }
|
|
1916
|
|
1917 if (gc_in_progress || in_display)
|
|
1918 /* This is one of many reasons why you can't run lisp code from redisplay.
|
|
1919 There is no sensible way to handle errors there. */
|
|
1920 abort ();
|
|
1921
|
|
1922 conditions = Fget (sig, Qerror_conditions, Qnil);
|
|
1923
|
|
1924 for (handlers = Vcondition_handlers;
|
|
1925 CONSP (handlers);
|
|
1926 handlers = XCDR (handlers))
|
|
1927 {
|
|
1928 Lisp_Object handler_fun = XCAR (XCAR (handlers));
|
|
1929 Lisp_Object handler_data = XCDR (XCAR (handlers));
|
|
1930 Lisp_Object outer_handlers = XCDR (handlers);
|
|
1931
|
|
1932 if (!UNBOUNDP (handler_fun))
|
|
1933 {
|
|
1934 /* call-with-condition-handler */
|
|
1935 Lisp_Object tem;
|
|
1936 Lisp_Object all_handlers = Vcondition_handlers;
|
|
1937 struct gcpro ngcpro1;
|
|
1938 NGCPRO1 (all_handlers);
|
|
1939 Vcondition_handlers = outer_handlers;
|
|
1940
|
|
1941 tem = signal_call_debugger (conditions, sig, data,
|
|
1942 outer_handlers, 1,
|
|
1943 &stack_trace_displayed,
|
|
1944 &debugger_entered);
|
|
1945 if (!UNBOUNDP (tem))
|
|
1946 RETURN_NUNGCPRO (return_from_signal (tem));
|
|
1947
|
|
1948 tem = Fcons (sig, data);
|
|
1949 if (NILP (handler_data))
|
|
1950 tem = call1 (handler_fun, tem);
|
|
1951 else
|
|
1952 {
|
|
1953 /* (This code won't be used (for now?).) */
|
|
1954 struct gcpro nngcpro1;
|
|
1955 Lisp_Object args[3];
|
|
1956 NNGCPRO1 (args[0]);
|
|
1957 nngcpro1.nvars = 3;
|
|
1958 args[0] = handler_fun;
|
|
1959 args[1] = tem;
|
|
1960 args[2] = handler_data;
|
|
1961 nngcpro1.var = args;
|
|
1962 tem = Fapply (3, args);
|
|
1963 NNUNGCPRO;
|
|
1964 }
|
|
1965 NUNGCPRO;
|
|
1966 #if 0
|
|
1967 if (!EQ (tem, Qsignal))
|
173
|
1968 return return_from_signal (tem);
|
0
|
1969 #endif
|
|
1970 /* If handler didn't throw, try another handler */
|
|
1971 Vcondition_handlers = all_handlers;
|
|
1972 }
|
|
1973
|
|
1974 /* It's a condition-case handler */
|
|
1975
|
185
|
1976 /* t is used by handlers for all conditions, set up by C code.
|
0
|
1977 * debugger is not called even if debug_on_error */
|
|
1978 else if (EQ (handler_data, Qt))
|
|
1979 {
|
|
1980 UNGCPRO;
|
173
|
1981 return Fthrow (handlers, Fcons (sig, data));
|
0
|
1982 }
|
|
1983 /* `error' is used similarly to the way `t' is used, but in
|
|
1984 addition it invokes the debugger if debug_on_error.
|
|
1985 This is normally used for the outer command-loop error
|
|
1986 handler. */
|
|
1987 else if (EQ (handler_data, Qerror))
|
|
1988 {
|
|
1989 Lisp_Object tem = signal_call_debugger (conditions, sig, data,
|
|
1990 outer_handlers, 0,
|
|
1991 &stack_trace_displayed,
|
|
1992 &debugger_entered);
|
|
1993
|
|
1994 UNGCPRO;
|
|
1995 if (!UNBOUNDP (tem))
|
173
|
1996 return return_from_signal (tem);
|
0
|
1997
|
|
1998 tem = Fcons (sig, data);
|
173
|
1999 return Fthrow (handlers, tem);
|
0
|
2000 }
|
|
2001 else
|
|
2002 {
|
|
2003 /* handler established by real (Lisp) condition-case */
|
|
2004 Lisp_Object h;
|
|
2005
|
|
2006 for (h = handler_data; CONSP (h); h = Fcdr (h))
|
|
2007 {
|
|
2008 Lisp_Object clause = Fcar (h);
|
|
2009 Lisp_Object tem = Fcar (clause);
|
|
2010
|
|
2011 if (condition_type_p (tem, conditions))
|
|
2012 {
|
|
2013 tem = signal_call_debugger (conditions, sig, data,
|
|
2014 outer_handlers, 1,
|
|
2015 &stack_trace_displayed,
|
|
2016 &debugger_entered);
|
|
2017 UNGCPRO;
|
|
2018 if (!UNBOUNDP (tem))
|
173
|
2019 return return_from_signal (tem);
|
0
|
2020
|
|
2021 /* Doesn't return */
|
|
2022 tem = Fcons (Fcons (sig, data), Fcdr (clause));
|
173
|
2023 return Fthrow (handlers, tem);
|
0
|
2024 }
|
|
2025 }
|
|
2026 }
|
|
2027 }
|
|
2028
|
|
2029 /* If no handler is present now, try to run the debugger,
|
|
2030 and if that fails, throw to top level.
|
|
2031
|
|
2032 #### The only time that no handler is present is during
|
|
2033 temacs or perhaps very early in XEmacs. In both cases,
|
|
2034 there is no 'top-level catch. (That's why the
|
|
2035 "bomb-out" hack was added.)
|
|
2036
|
185
|
2037 #### Fix this horrifitude!
|
0
|
2038 */
|
|
2039 signal_call_debugger (conditions, sig, data, Qnil, 0,
|
|
2040 &stack_trace_displayed,
|
|
2041 &debugger_entered);
|
|
2042 UNGCPRO;
|
|
2043 throw_or_bomb_out (Qtop_level, Qt, 1, sig, data); /* Doesn't return */
|
|
2044 return Qnil;
|
|
2045 }
|
|
2046
|
|
2047
|
|
2048 /****************** Error functions class 1 ******************/
|
|
2049
|
|
2050 /* Class 1: General functions that signal an error.
|
|
2051 These functions take an error type and a list of associated error
|
|
2052 data. */
|
|
2053
|
|
2054 /* The simplest external error function: it would be called
|
|
2055 signal_continuable_error() in the terminology below, but it's
|
|
2056 Lisp-callable. */
|
|
2057
|
20
|
2058 DEFUN ("signal", Fsignal, 2, 2, 0, /*
|
0
|
2059 Signal a continuable error. Args are ERROR-SYMBOL, and associated DATA.
|
|
2060 An error symbol is a symbol defined using `define-error'.
|
|
2061 DATA should be a list. Its elements are printed as part of the error message.
|
|
2062 If the signal is handled, DATA is made available to the handler.
|
|
2063 See also the function `signal-error', and the functions to handle errors:
|
|
2064 `condition-case' and `call-with-condition-handler'.
|
|
2065
|
|
2066 Note that this function can return, if the debugger is invoked and the
|
|
2067 user invokes the "return from signal" option.
|
20
|
2068 */
|
|
2069 (error_symbol, data))
|
0
|
2070 {
|
|
2071 /* Fsignal() is one of these functions that's called all the time
|
|
2072 with newly-created Lisp objects. We allow this; but we must GC-
|
|
2073 protect the objects because all sorts of weird stuff could
|
|
2074 happen. */
|
|
2075
|
|
2076 struct gcpro gcpro1;
|
|
2077
|
|
2078 GCPRO1 (data);
|
|
2079 if (!NILP (Vcurrent_error_state))
|
|
2080 {
|
|
2081 if (!NILP (Vcurrent_warning_class))
|
|
2082 warn_when_safe_lispobj (Vcurrent_warning_class, Qwarning,
|
|
2083 Fcons (error_symbol, data));
|
|
2084 Fthrow (Qunbound_suspended_errors_tag, Qnil);
|
|
2085 abort (); /* Better not get here! */
|
|
2086 }
|
|
2087 RETURN_UNGCPRO (signal_1 (error_symbol, data));
|
|
2088 }
|
|
2089
|
|
2090 /* Signal a non-continuable error. */
|
|
2091
|
|
2092 DOESNT_RETURN
|
|
2093 signal_error (Lisp_Object sig, Lisp_Object data)
|
|
2094 {
|
|
2095 for (;;)
|
|
2096 Fsignal (sig, data);
|
|
2097 }
|
|
2098
|
|
2099 static Lisp_Object
|
|
2100 call_with_suspended_errors_1 (Lisp_Object opaque_arg)
|
|
2101 {
|
|
2102 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg);
|
173
|
2103 return primitive_funcall ((lisp_fn_t) get_opaque_ptr (kludgy_args[0]),
|
|
2104 XINT (kludgy_args[1]), kludgy_args + 2);
|
0
|
2105 }
|
|
2106
|
|
2107 static Lisp_Object
|
|
2108 restore_current_warning_class (Lisp_Object warning_class)
|
|
2109 {
|
|
2110 Vcurrent_warning_class = warning_class;
|
|
2111 return Qnil;
|
|
2112 }
|
|
2113
|
|
2114 static Lisp_Object
|
|
2115 restore_current_error_state (Lisp_Object error_state)
|
|
2116 {
|
|
2117 Vcurrent_error_state = error_state;
|
|
2118 return Qnil;
|
|
2119 }
|
|
2120
|
|
2121 /* Many functions would like to do one of three things if an error
|
|
2122 occurs:
|
|
2123
|
|
2124 (1) signal the error, as usual.
|
|
2125 (2) silently fail and return some error value.
|
|
2126 (3) do as (2) but issue a warning in the process.
|
|
2127
|
|
2128 Currently there's lots of stuff that passes an Error_behavior
|
|
2129 value and calls maybe_signal_error() and other such functions.
|
|
2130 This approach is inherently error-prone and broken. A much
|
|
2131 more robust and easier approach is to use call_with_suspended_errors().
|
|
2132 Wrap this around any function in which you might want errors
|
|
2133 to not be errors.
|
|
2134 */
|
|
2135
|
|
2136 Lisp_Object
|
179
|
2137 call_with_suspended_errors (lisp_fn_t fun, volatile Lisp_Object retval,
|
0
|
2138 Lisp_Object class, Error_behavior errb,
|
|
2139 int nargs, ...)
|
|
2140 {
|
|
2141 va_list vargs;
|
|
2142 int speccount;
|
|
2143 Lisp_Object kludgy_args[22];
|
|
2144 Lisp_Object *args = kludgy_args + 2;
|
|
2145 int i;
|
|
2146 Lisp_Object no_error;
|
|
2147
|
|
2148 assert (SYMBOLP (class)); /* sanity-check */
|
|
2149 assert (!NILP (class));
|
|
2150 assert (nargs >= 0 && nargs < 20);
|
|
2151
|
|
2152 /* ERROR_ME means don't trap errors. (However, if errors are
|
|
2153 already trapped, we leave them trapped.)
|
|
2154
|
|
2155 Otherwise, we trap errors, and trap warnings if ERROR_ME_WARN.
|
|
2156
|
|
2157 If ERROR_ME_NOT, it causes no warnings even if warnings
|
|
2158 were previously enabled. However, we never change the
|
|
2159 warning class from one to another. */
|
|
2160 if (!ERRB_EQ (errb, ERROR_ME))
|
|
2161 {
|
|
2162 if (ERRB_EQ (errb, ERROR_ME_NOT)) /* person wants no warnings */
|
|
2163 class = Qnil;
|
|
2164 errb = ERROR_ME_NOT;
|
|
2165 no_error = Qt;
|
|
2166 }
|
|
2167 else
|
|
2168 no_error = Qnil;
|
185
|
2169
|
0
|
2170 va_start (vargs, nargs);
|
|
2171 for (i = 0; i < nargs; i++)
|
|
2172 args[i] = va_arg (vargs, Lisp_Object);
|
|
2173 va_end (vargs);
|
|
2174
|
|
2175 /* If error-checking is not disabled, just call the function.
|
|
2176 It's important not to override disabled error-checking with
|
|
2177 enabled error-checking. */
|
185
|
2178
|
0
|
2179 if (ERRB_EQ (errb, ERROR_ME))
|
|
2180 return primitive_funcall (fun, nargs, args);
|
|
2181
|
|
2182 speccount = specpdl_depth ();
|
|
2183 if (NILP (class) || NILP (Vcurrent_warning_class))
|
|
2184 {
|
|
2185 /* If we're currently calling for no warnings, then make it so.
|
|
2186 If we're currently calling for warnings and we weren't
|
|
2187 previously, then set our warning class; otherwise, leave
|
|
2188 the existing one alone. */
|
|
2189 record_unwind_protect (restore_current_warning_class,
|
|
2190 Vcurrent_warning_class);
|
|
2191 Vcurrent_warning_class = class;
|
|
2192 }
|
|
2193 if (!EQ (Vcurrent_error_state, no_error))
|
|
2194 {
|
|
2195 record_unwind_protect (restore_current_error_state,
|
|
2196 Vcurrent_error_state);
|
|
2197 Vcurrent_error_state = no_error;
|
|
2198 }
|
|
2199
|
|
2200 {
|
|
2201 int threw;
|
|
2202 Lisp_Object the_retval;
|
|
2203 Lisp_Object opaque1 = make_opaque_ptr (kludgy_args);
|
|
2204 Lisp_Object opaque2 = make_opaque_ptr ((void *) fun);
|
|
2205 struct gcpro gcpro1, gcpro2;
|
|
2206
|
|
2207 GCPRO2 (opaque1, opaque2);
|
|
2208 kludgy_args[0] = opaque2;
|
|
2209 kludgy_args[1] = make_int (nargs);
|
|
2210 the_retval = internal_catch (Qunbound_suspended_errors_tag,
|
|
2211 call_with_suspended_errors_1,
|
|
2212 opaque1, &threw);
|
|
2213 free_opaque_ptr (opaque1);
|
|
2214 free_opaque_ptr (opaque2);
|
|
2215 UNGCPRO;
|
|
2216 /* Use the returned value except in non-local exit, when
|
|
2217 RETVAL applies. */
|
|
2218 if (!threw)
|
|
2219 retval = the_retval;
|
|
2220 return unbind_to (speccount, retval);
|
|
2221 }
|
|
2222 }
|
|
2223
|
|
2224 /* Signal a non-continuable error or display a warning or do nothing,
|
|
2225 according to ERRB. CLASS is the class of warning and should
|
|
2226 refer to what sort of operation is being done (e.g. Qtoolbar,
|
|
2227 Qresource, etc.). */
|
|
2228
|
|
2229 void
|
|
2230 maybe_signal_error (Lisp_Object sig, Lisp_Object data, Lisp_Object class,
|
|
2231 Error_behavior errb)
|
|
2232 {
|
|
2233 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2234 return;
|
|
2235 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2236 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2237 else
|
|
2238 for (;;)
|
|
2239 Fsignal (sig, data);
|
|
2240 }
|
|
2241
|
|
2242 /* Signal a continuable error or display a warning or do nothing,
|
|
2243 according to ERRB. */
|
|
2244
|
|
2245 Lisp_Object
|
|
2246 maybe_signal_continuable_error (Lisp_Object sig, Lisp_Object data,
|
|
2247 Lisp_Object class, Error_behavior errb)
|
|
2248 {
|
|
2249 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2250 return Qnil;
|
|
2251 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2252 {
|
|
2253 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2254 return Qnil;
|
|
2255 }
|
|
2256 else
|
|
2257 return Fsignal (sig, data);
|
|
2258 }
|
|
2259
|
|
2260
|
|
2261 /****************** Error functions class 2 ******************/
|
|
2262
|
|
2263 /* Class 2: Printf-like functions that signal an error.
|
|
2264 These functions signal an error of type Qerror, whose data
|
|
2265 is a single string, created using the arguments. */
|
|
2266
|
|
2267 /* dump an error message; called like printf */
|
|
2268
|
|
2269 DOESNT_RETURN
|
|
2270 error (CONST char *fmt, ...)
|
|
2271 {
|
|
2272 Lisp_Object obj;
|
|
2273 va_list args;
|
|
2274
|
|
2275 va_start (args, fmt);
|
|
2276 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2277 args);
|
|
2278 va_end (args);
|
|
2279
|
|
2280 /* Fsignal GC-protects its args */
|
|
2281 signal_error (Qerror, list1 (obj));
|
|
2282 }
|
|
2283
|
|
2284 void
|
|
2285 maybe_error (Lisp_Object class, Error_behavior errb, CONST char *fmt, ...)
|
|
2286 {
|
|
2287 Lisp_Object obj;
|
|
2288 va_list args;
|
|
2289
|
|
2290 /* Optimization: */
|
|
2291 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2292 return;
|
|
2293
|
|
2294 va_start (args, fmt);
|
|
2295 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2296 args);
|
|
2297 va_end (args);
|
|
2298
|
|
2299 /* Fsignal GC-protects its args */
|
|
2300 maybe_signal_error (Qerror, list1 (obj), class, errb);
|
|
2301 }
|
|
2302
|
|
2303 Lisp_Object
|
|
2304 continuable_error (CONST char *fmt, ...)
|
|
2305 {
|
|
2306 Lisp_Object obj;
|
|
2307 va_list args;
|
|
2308
|
|
2309 va_start (args, fmt);
|
|
2310 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2311 args);
|
|
2312 va_end (args);
|
|
2313
|
|
2314 /* Fsignal GC-protects its args */
|
|
2315 return Fsignal (Qerror, list1 (obj));
|
|
2316 }
|
|
2317
|
|
2318 Lisp_Object
|
|
2319 maybe_continuable_error (Lisp_Object class, Error_behavior errb,
|
|
2320 CONST char *fmt, ...)
|
|
2321 {
|
|
2322 Lisp_Object obj;
|
|
2323 va_list args;
|
|
2324
|
|
2325 /* Optimization: */
|
|
2326 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2327 return Qnil;
|
|
2328
|
|
2329 va_start (args, fmt);
|
|
2330 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2331 args);
|
|
2332 va_end (args);
|
|
2333
|
|
2334 /* Fsignal GC-protects its args */
|
|
2335 return maybe_signal_continuable_error (Qerror, list1 (obj), class, errb);
|
|
2336 }
|
|
2337
|
|
2338
|
|
2339 /****************** Error functions class 3 ******************/
|
|
2340
|
|
2341 /* Class 3: Signal an error with a string and an associated object.
|
|
2342 These functions signal an error of type Qerror, whose data
|
|
2343 is two objects, a string and a related Lisp object (usually the object
|
|
2344 where the error is occurring). */
|
|
2345
|
|
2346 DOESNT_RETURN
|
|
2347 signal_simple_error (CONST char *reason, Lisp_Object frob)
|
|
2348 {
|
|
2349 signal_error (Qerror, list2 (build_translated_string (reason), frob));
|
|
2350 }
|
|
2351
|
|
2352 void
|
|
2353 maybe_signal_simple_error (CONST char *reason, Lisp_Object frob,
|
|
2354 Lisp_Object class, Error_behavior errb)
|
|
2355 {
|
|
2356 /* Optimization: */
|
|
2357 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2358 return;
|
|
2359 maybe_signal_error (Qerror, list2 (build_translated_string (reason), frob),
|
|
2360 class, errb);
|
|
2361 }
|
|
2362
|
|
2363 Lisp_Object
|
|
2364 signal_simple_continuable_error (CONST char *reason, Lisp_Object frob)
|
|
2365 {
|
|
2366 return Fsignal (Qerror, list2 (build_translated_string (reason), frob));
|
|
2367 }
|
|
2368
|
|
2369 Lisp_Object
|
|
2370 maybe_signal_simple_continuable_error (CONST char *reason, Lisp_Object frob,
|
|
2371 Lisp_Object class, Error_behavior errb)
|
|
2372 {
|
|
2373 /* Optimization: */
|
|
2374 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2375 return Qnil;
|
|
2376 return maybe_signal_continuable_error
|
|
2377 (Qerror, list2 (build_translated_string (reason),
|
|
2378 frob), class, errb);
|
185
|
2379 }
|
0
|
2380
|
|
2381
|
|
2382 /****************** Error functions class 4 ******************/
|
|
2383
|
|
2384 /* Class 4: Printf-like functions that signal an error.
|
|
2385 These functions signal an error of type Qerror, whose data
|
|
2386 is a two objects, a string (created using the arguments) and a
|
|
2387 Lisp object.
|
|
2388 */
|
|
2389
|
|
2390 DOESNT_RETURN
|
|
2391 error_with_frob (Lisp_Object frob, CONST char *fmt, ...)
|
|
2392 {
|
|
2393 Lisp_Object obj;
|
|
2394 va_list args;
|
|
2395
|
|
2396 va_start (args, fmt);
|
|
2397 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2398 args);
|
|
2399 va_end (args);
|
|
2400
|
|
2401 /* Fsignal GC-protects its args */
|
|
2402 signal_error (Qerror, list2 (obj, frob));
|
|
2403 }
|
|
2404
|
|
2405 void
|
|
2406 maybe_error_with_frob (Lisp_Object frob, Lisp_Object class,
|
|
2407 Error_behavior errb, CONST char *fmt, ...)
|
|
2408 {
|
|
2409 Lisp_Object obj;
|
|
2410 va_list args;
|
|
2411
|
|
2412 /* Optimization: */
|
|
2413 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2414 return;
|
|
2415
|
|
2416 va_start (args, fmt);
|
|
2417 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2418 args);
|
|
2419 va_end (args);
|
|
2420
|
|
2421 /* Fsignal GC-protects its args */
|
|
2422 maybe_signal_error (Qerror, list2 (obj, frob), class, errb);
|
|
2423 }
|
|
2424
|
|
2425 Lisp_Object
|
|
2426 continuable_error_with_frob (Lisp_Object frob, CONST char *fmt, ...)
|
|
2427 {
|
|
2428 Lisp_Object obj;
|
|
2429 va_list args;
|
|
2430
|
|
2431 va_start (args, fmt);
|
|
2432 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2433 args);
|
|
2434 va_end (args);
|
|
2435
|
|
2436 /* Fsignal GC-protects its args */
|
|
2437 return Fsignal (Qerror, list2 (obj, frob));
|
|
2438 }
|
|
2439
|
|
2440 Lisp_Object
|
|
2441 maybe_continuable_error_with_frob (Lisp_Object frob, Lisp_Object class,
|
|
2442 Error_behavior errb, CONST char *fmt, ...)
|
|
2443 {
|
|
2444 Lisp_Object obj;
|
|
2445 va_list args;
|
|
2446
|
|
2447 /* Optimization: */
|
|
2448 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2449 return Qnil;
|
|
2450
|
|
2451 va_start (args, fmt);
|
|
2452 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2453 args);
|
|
2454 va_end (args);
|
|
2455
|
|
2456 /* Fsignal GC-protects its args */
|
|
2457 return maybe_signal_continuable_error (Qerror, list2 (obj, frob),
|
|
2458 class, errb);
|
|
2459 }
|
|
2460
|
|
2461
|
|
2462 /****************** Error functions class 5 ******************/
|
|
2463
|
|
2464 /* Class 5: Signal an error with a string and two associated objects.
|
|
2465 These functions signal an error of type Qerror, whose data
|
|
2466 is three objects, a string and two related Lisp objects. */
|
|
2467
|
|
2468 DOESNT_RETURN
|
|
2469 signal_simple_error_2 (CONST char *reason,
|
|
2470 Lisp_Object frob0, Lisp_Object frob1)
|
|
2471 {
|
|
2472 signal_error (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2473 frob1));
|
|
2474 }
|
|
2475
|
|
2476 void
|
|
2477 maybe_signal_simple_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2478 Lisp_Object frob1, Lisp_Object class,
|
|
2479 Error_behavior errb)
|
|
2480 {
|
|
2481 /* Optimization: */
|
|
2482 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2483 return;
|
|
2484 maybe_signal_error (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2485 frob1), class, errb);
|
|
2486 }
|
|
2487
|
|
2488
|
|
2489 Lisp_Object
|
|
2490 signal_simple_continuable_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2491 Lisp_Object frob1)
|
|
2492 {
|
|
2493 return Fsignal (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2494 frob1));
|
|
2495 }
|
|
2496
|
|
2497 Lisp_Object
|
|
2498 maybe_signal_simple_continuable_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2499 Lisp_Object frob1, Lisp_Object class,
|
|
2500 Error_behavior errb)
|
|
2501 {
|
|
2502 /* Optimization: */
|
|
2503 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2504 return Qnil;
|
|
2505 return maybe_signal_continuable_error
|
|
2506 (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2507 frob1),
|
|
2508 class, errb);
|
|
2509 }
|
|
2510
|
|
2511
|
|
2512 /* This is what the QUIT macro calls to signal a quit */
|
|
2513 void
|
|
2514 signal_quit (void)
|
|
2515 {
|
|
2516 /* This function can GC */
|
|
2517 if (EQ (Vquit_flag, Qcritical))
|
|
2518 debug_on_quit |= 2; /* set critical bit. */
|
185
|
2519 Vquit_flag = Qnil;
|
0
|
2520 /* note that this is continuable. */
|
|
2521 Fsignal (Qquit, Qnil);
|
|
2522 }
|
|
2523
|
|
2524
|
|
2525 /**********************************************************************/
|
|
2526 /* User commands */
|
|
2527 /**********************************************************************/
|
|
2528
|
20
|
2529 DEFUN ("commandp", Fcommandp, 1, 1, 0, /*
|
0
|
2530 T if FUNCTION makes provisions for interactive calling.
|
|
2531 This means it contains a description for how to read arguments to give it.
|
|
2532 The value is nil for an invalid function or a symbol with no function
|
|
2533 definition.
|
|
2534
|
|
2535 Interactively callable functions include
|
|
2536
|
|
2537 -- strings and vectors (treated as keyboard macros)
|
|
2538 -- lambda-expressions that contain a top-level call to `interactive'
|
|
2539 -- autoload definitions made by `autoload' with non-nil fourth argument
|
|
2540 (i.e. the interactive flag)
|
|
2541 -- compiled-function objects with a non-nil `compiled-function-interactive'
|
|
2542 value
|
|
2543 -- subrs (built-in functions) that are interactively callable
|
|
2544
|
|
2545 Also, a symbol satisfies `commandp' if its function definition does so.
|
20
|
2546 */
|
|
2547 (function))
|
0
|
2548 {
|
|
2549 REGISTER Lisp_Object fun;
|
|
2550 REGISTER Lisp_Object funcar;
|
|
2551
|
|
2552 fun = function;
|
|
2553
|
|
2554 fun = indirect_function (fun, 0);
|
|
2555 if (UNBOUNDP (fun))
|
|
2556 return Qnil;
|
|
2557
|
|
2558 /* Emacs primitives are interactive if their DEFUN specifies an
|
|
2559 interactive spec. */
|
|
2560 if (SUBRP (fun))
|
149
|
2561 return XSUBR (fun)->prompt ? Qt : Qnil;
|
|
2562
|
|
2563 if (COMPILED_FUNCTIONP (fun))
|
|
2564 return XCOMPILED_FUNCTION (fun)->flags.interactivep ? Qt : Qnil;
|
0
|
2565
|
|
2566 /* Strings and vectors are keyboard macros. */
|
|
2567 if (VECTORP (fun) || STRINGP (fun))
|
|
2568 return Qt;
|
|
2569
|
|
2570 /* Lists may represent commands. */
|
|
2571 if (!CONSP (fun))
|
|
2572 return Qnil;
|
|
2573 funcar = Fcar (fun);
|
|
2574 if (!SYMBOLP (funcar))
|
|
2575 return Fsignal (Qinvalid_function, list1 (fun));
|
|
2576 if (EQ (funcar, Qlambda))
|
|
2577 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
|
|
2578 if (EQ (funcar, Qautoload))
|
|
2579 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
|
|
2580 else
|
|
2581 return Qnil;
|
|
2582 }
|
|
2583
|
20
|
2584 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /*
|
0
|
2585 Execute CMD as an editor command.
|
|
2586 CMD must be an object that satisfies the `commandp' predicate.
|
|
2587 Optional second arg RECORD-FLAG is as in `call-interactively'.
|
|
2588 The argument KEYS specifies the value to use instead of (this-command-keys)
|
|
2589 when reading the arguments.
|
20
|
2590 */
|
|
2591 (cmd, record, keys))
|
0
|
2592 {
|
|
2593 /* This function can GC */
|
|
2594 Lisp_Object prefixarg;
|
|
2595 Lisp_Object final = cmd;
|
|
2596 struct backtrace backtrace;
|
|
2597 struct console *con = XCONSOLE (Vselected_console);
|
|
2598
|
|
2599 prefixarg = con->prefix_arg;
|
|
2600 con->prefix_arg = Qnil;
|
|
2601 Vcurrent_prefix_arg = prefixarg;
|
|
2602 debug_on_next_call = 0; /* #### from FSFmacs; correct? */
|
|
2603
|
|
2604 if (SYMBOLP (cmd) && !NILP (Fget (cmd, Qdisabled, Qnil)))
|
|
2605 return run_hook (Vdisabled_command_hook);
|
|
2606
|
|
2607 for (;;)
|
|
2608 {
|
|
2609 final = indirect_function (cmd, 1);
|
|
2610 if (CONSP (final) && EQ (Fcar (final), Qautoload))
|
|
2611 do_autoload (final, cmd);
|
|
2612 else
|
|
2613 break;
|
|
2614 }
|
|
2615
|
|
2616 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final))
|
|
2617 {
|
|
2618 #ifdef EMACS_BTL
|
|
2619 backtrace.id_number = 0;
|
|
2620 #endif
|
|
2621 backtrace.function = &Qcall_interactively;
|
|
2622 backtrace.args = &cmd;
|
|
2623 backtrace.nargs = 1;
|
|
2624 backtrace.evalargs = 0;
|
|
2625 backtrace.pdlcount = specpdl_depth ();
|
|
2626 backtrace.debug_on_exit = 0;
|
116
|
2627 PUSH_BACKTRACE (backtrace);
|
0
|
2628
|
|
2629 final = Fcall_interactively (cmd, record, keys);
|
|
2630
|
116
|
2631 POP_BACKTRACE (backtrace);
|
173
|
2632 return final;
|
0
|
2633 }
|
|
2634 else if (STRINGP (final) || VECTORP (final))
|
|
2635 {
|
|
2636 return Fexecute_kbd_macro (final, prefixarg);
|
|
2637 }
|
|
2638 else
|
|
2639 {
|
|
2640 Fsignal (Qwrong_type_argument,
|
|
2641 Fcons (Qcommandp,
|
|
2642 ((EQ (cmd, final))
|
|
2643 ? list1 (cmd)
|
|
2644 : list2 (cmd, final))));
|
|
2645 return Qnil;
|
|
2646 }
|
|
2647 }
|
|
2648
|
20
|
2649 DEFUN ("interactive-p", Finteractive_p, 0, 0, 0, /*
|
0
|
2650 Return t if function in which this appears was called interactively.
|
|
2651 This means that the function was called with call-interactively (which
|
|
2652 includes being called as the binding of a key)
|
|
2653 and input is currently coming from the keyboard (not in keyboard macro).
|
20
|
2654 */
|
|
2655 ())
|
0
|
2656 {
|
|
2657 REGISTER struct backtrace *btp;
|
|
2658 REGISTER Lisp_Object fun;
|
|
2659
|
|
2660 if (!INTERACTIVE)
|
|
2661 return Qnil;
|
|
2662
|
|
2663 /* Unless the object was compiled, skip the frame of interactive-p itself
|
|
2664 (if interpreted) or the frame of byte-code (if called from a compiled
|
|
2665 function). Note that *btp->function may be a symbol pointing at a
|
|
2666 compiled function. */
|
|
2667 btp = backtrace_list;
|
|
2668
|
|
2669 #if 0 /* FSFmacs */
|
|
2670
|
|
2671 /* #### FSFmacs does the following instead. I can't figure
|
|
2672 out which one is more correct. */
|
|
2673 /* If this isn't a byte-compiled function, there may be a frame at
|
|
2674 the top for Finteractive_p itself. If so, skip it. */
|
|
2675 fun = Findirect_function (*btp->function);
|
|
2676 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p)
|
|
2677 btp = btp->next;
|
|
2678
|
|
2679 /* If we're running an Emacs 18-style byte-compiled function, there
|
|
2680 may be a frame for Fbyte_code. Now, given the strictest
|
|
2681 definition, this function isn't really being called
|
|
2682 interactively, but because that's the way Emacs 18 always builds
|
|
2683 byte-compiled functions, we'll accept it for now. */
|
|
2684 if (EQ (*btp->function, Qbyte_code))
|
|
2685 btp = btp->next;
|
|
2686
|
|
2687 /* If this isn't a byte-compiled function, then we may now be
|
|
2688 looking at several frames for special forms. Skip past them. */
|
185
|
2689 while (btp &&
|
0
|
2690 btp->nargs == UNEVALLED)
|
|
2691 btp = btp->next;
|
|
2692
|
|
2693 #else
|
|
2694
|
|
2695 if (! (COMPILED_FUNCTIONP (Findirect_function (*btp->function))))
|
|
2696 btp = btp->next;
|
|
2697 for (;
|
|
2698 btp && (btp->nargs == UNEVALLED
|
|
2699 || EQ (*btp->function, Qbyte_code));
|
|
2700 btp = btp->next)
|
|
2701 {}
|
|
2702 /* btp now points at the frame of the innermost function
|
|
2703 that DOES eval its args.
|
|
2704 If it is a built-in function (such as load or eval-region)
|
|
2705 return nil. */
|
|
2706 /* Beats me why this is necessary, but it is */
|
|
2707 if (btp && EQ (*btp->function, Qcall_interactively))
|
|
2708 return Qt;
|
|
2709
|
|
2710 #endif
|
|
2711
|
|
2712 fun = Findirect_function (*btp->function);
|
|
2713 if (SUBRP (fun))
|
|
2714 return Qnil;
|
|
2715 /* btp points to the frame of a Lisp function that called interactive-p.
|
|
2716 Return t if that function was called interactively. */
|
|
2717 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
|
|
2718 return Qt;
|
|
2719 return Qnil;
|
|
2720 }
|
|
2721
|
|
2722
|
|
2723 /**********************************************************************/
|
|
2724 /* Autoloading */
|
|
2725 /**********************************************************************/
|
|
2726
|
20
|
2727 DEFUN ("autoload", Fautoload, 2, 5, 0, /*
|
0
|
2728 Define FUNCTION to autoload from FILE.
|
|
2729 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
|
|
2730 Third arg DOCSTRING is documentation for the function.
|
|
2731 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
|
|
2732 Fifth arg TYPE indicates the type of the object:
|
|
2733 nil or omitted says FUNCTION is a function,
|
|
2734 `keymap' says FUNCTION is really a keymap, and
|
|
2735 `macro' or t says FUNCTION is really a macro.
|
|
2736 Third through fifth args give info about the real definition.
|
|
2737 They default to nil.
|
|
2738 If FUNCTION is already defined other than as an autoload,
|
|
2739 this does nothing and returns nil.
|
20
|
2740 */
|
|
2741 (function, file, docstring, interactive, type))
|
0
|
2742 {
|
|
2743 /* This function can GC */
|
|
2744 CHECK_SYMBOL (function);
|
|
2745 CHECK_STRING (file);
|
|
2746
|
|
2747 /* If function is defined and not as an autoload, don't override */
|
|
2748 if (!UNBOUNDP (XSYMBOL (function)->function)
|
|
2749 && !(CONSP (XSYMBOL (function)->function)
|
|
2750 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
|
|
2751 return Qnil;
|
|
2752
|
|
2753 if (purify_flag)
|
|
2754 {
|
|
2755 /* Attempt to avoid consing identical (string=) pure strings. */
|
|
2756 file = Fsymbol_name (Fintern (file, Qnil));
|
|
2757 }
|
|
2758
|
185
|
2759 return Ffset (function,
|
0
|
2760 Fpurecopy (Fcons (Qautoload, list4 (file,
|
|
2761 docstring,
|
|
2762 interactive,
|
|
2763 type))));
|
|
2764 }
|
|
2765
|
|
2766 Lisp_Object
|
|
2767 un_autoload (Lisp_Object oldqueue)
|
|
2768 {
|
|
2769 /* This function can GC */
|
|
2770 REGISTER Lisp_Object queue, first, second;
|
|
2771
|
|
2772 /* Queue to unwind is current value of Vautoload_queue.
|
|
2773 oldqueue is the shadowed value to leave in Vautoload_queue. */
|
|
2774 queue = Vautoload_queue;
|
|
2775 Vautoload_queue = oldqueue;
|
|
2776 while (CONSP (queue))
|
|
2777 {
|
|
2778 first = Fcar (queue);
|
|
2779 second = Fcdr (first);
|
|
2780 first = Fcar (first);
|
|
2781 if (NILP (second))
|
|
2782 Vfeatures = first;
|
|
2783 else
|
|
2784 Ffset (first, second);
|
|
2785 queue = Fcdr (queue);
|
|
2786 }
|
|
2787 return Qnil;
|
|
2788 }
|
|
2789
|
|
2790 void
|
185
|
2791 do_autoload (Lisp_Object fundef,
|
0
|
2792 Lisp_Object funname)
|
|
2793 {
|
|
2794 /* This function can GC */
|
|
2795 int speccount = specpdl_depth_counter;
|
|
2796 Lisp_Object fun = funname;
|
|
2797 struct gcpro gcpro1, gcpro2;
|
|
2798
|
|
2799 CHECK_SYMBOL (funname);
|
|
2800 GCPRO2 (fun, funname);
|
|
2801
|
|
2802 /* Value saved here is to be restored into Vautoload_queue */
|
|
2803 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
2804 Vautoload_queue = Qt;
|
|
2805 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil,
|
|
2806 Qnil);
|
|
2807
|
|
2808 {
|
|
2809 Lisp_Object queue = Vautoload_queue;
|
|
2810
|
|
2811 /* Save the old autoloads, in case we ever do an unload. */
|
|
2812 queue = Vautoload_queue;
|
|
2813 while (CONSP (queue))
|
|
2814 {
|
|
2815 Lisp_Object first = Fcar (queue);
|
|
2816 Lisp_Object second = Fcdr (first);
|
|
2817
|
|
2818 first = Fcar (first);
|
|
2819
|
|
2820 /* Note: This test is subtle. The cdr of an autoload-queue entry
|
|
2821 may be an atom if the autoload entry was generated by a defalias
|
|
2822 or fset. */
|
|
2823 if (CONSP (second))
|
|
2824 Fput (first, Qautoload, (Fcdr (second)));
|
|
2825
|
|
2826 queue = Fcdr (queue);
|
|
2827 }
|
|
2828 }
|
|
2829
|
|
2830 /* Once loading finishes, don't undo it. */
|
|
2831 Vautoload_queue = Qt;
|
|
2832 unbind_to (speccount, Qnil);
|
|
2833
|
|
2834 fun = indirect_function (fun, 0);
|
|
2835
|
|
2836 #if 0 /* FSFmacs */
|
|
2837 if (!NILP (Fequal (fun, fundef)))
|
|
2838 #else
|
|
2839 if (UNBOUNDP (fun)
|
|
2840 || (CONSP (fun)
|
|
2841 && EQ (XCAR (fun), Qautoload)))
|
|
2842 #endif
|
|
2843 error ("Autoloading failed to define function %s",
|
|
2844 string_data (XSYMBOL (funname)->name));
|
|
2845 UNGCPRO;
|
|
2846 }
|
|
2847
|
|
2848
|
|
2849 /**********************************************************************/
|
|
2850 /* eval, funcall, apply */
|
|
2851 /**********************************************************************/
|
|
2852
|
185
|
2853 static Lisp_Object funcall_lambda (Lisp_Object fun,
|
0
|
2854 int nargs, Lisp_Object args[]);
|
185
|
2855 static Lisp_Object apply_lambda (Lisp_Object fun,
|
0
|
2856 int nargs, Lisp_Object args);
|
|
2857 static Lisp_Object funcall_subr (struct Lisp_Subr *sub, Lisp_Object args[]);
|
|
2858
|
|
2859 static int in_warnings;
|
|
2860
|
|
2861 static Lisp_Object
|
|
2862 in_warnings_restore (Lisp_Object minimus)
|
|
2863 {
|
|
2864 in_warnings = 0;
|
|
2865 return Qnil;
|
|
2866 }
|
|
2867
|
195
|
2868 #define inline_funcall_subr(rv, subr, av) \
|
|
2869 do { \
|
|
2870 switch (subr->max_args) { \
|
|
2871 case 0: rv = (subr_function(subr))(); \
|
|
2872 break; \
|
|
2873 case 1: rv = (subr_function(subr))(av[0]); \
|
|
2874 break; \
|
|
2875 case 2: rv = (subr_function(subr))(av[0], av[1]); \
|
|
2876 break; \
|
|
2877 case 3: rv = (subr_function(subr))(av[0], av[1], av[2]); \
|
|
2878 break; \
|
|
2879 case 4: rv = (subr_function(subr))(av[0], av[1], av[2], av[3]); \
|
|
2880 break; \
|
|
2881 case 5: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4]); \
|
|
2882 break; \
|
|
2883 case 6: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2884 av[5]); \
|
|
2885 break; \
|
|
2886 case 7: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2887 av[5], av[6]); \
|
|
2888 break; \
|
|
2889 case 8: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2890 av[5], av[6], av[7]); \
|
|
2891 break; \
|
|
2892 case 9: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2893 av[5], av[6], av[7], av[8]); \
|
|
2894 break; \
|
|
2895 case 10: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2896 av[5], av[6], av[7], av[8], av[9]); \
|
|
2897 break; \
|
|
2898 case 11: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2899 av[5], av[6], av[7], av[8], av[9], \
|
|
2900 av[10]); \
|
|
2901 break; \
|
|
2902 case 12: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2903 av[5], av[6], av[7], av[8], av[9], \
|
|
2904 av[10], av[11]); \
|
|
2905 break; \
|
|
2906 } \
|
|
2907 } while (0)
|
0
|
2908
|
20
|
2909 DEFUN ("eval", Feval, 1, 1, 0, /*
|
0
|
2910 Evaluate FORM and return its value.
|
20
|
2911 */
|
|
2912 (form))
|
0
|
2913 {
|
|
2914 /* This function can GC */
|
|
2915 Lisp_Object fun, val, original_fun, original_args;
|
|
2916 int nargs;
|
|
2917 struct backtrace backtrace;
|
|
2918
|
|
2919 /* I think this is a pretty safe place to call Lisp code, don't you? */
|
|
2920 while (!in_warnings && !NILP (Vpending_warnings))
|
|
2921 {
|
|
2922 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
2923 int speccount = specpdl_depth ();
|
|
2924 Lisp_Object this_warning_cons, this_warning, class, level, messij;
|
|
2925
|
|
2926 record_unwind_protect (in_warnings_restore, Qnil);
|
|
2927 in_warnings = 1;
|
|
2928 this_warning_cons = Vpending_warnings;
|
|
2929 this_warning = XCAR (this_warning_cons);
|
|
2930 /* in case an error occurs in the warn function, at least
|
|
2931 it won't happen infinitely */
|
|
2932 Vpending_warnings = XCDR (Vpending_warnings);
|
|
2933 free_cons (XCONS (this_warning_cons));
|
|
2934 class = XCAR (this_warning);
|
|
2935 level = XCAR (XCDR (this_warning));
|
|
2936 messij = XCAR (XCDR (XCDR (this_warning)));
|
|
2937 free_list (this_warning);
|
185
|
2938
|
0
|
2939 if (NILP (Vpending_warnings))
|
|
2940 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary,
|
|
2941 but safer */
|
|
2942
|
|
2943 GCPRO4 (form, class, level, messij);
|
|
2944 if (!STRINGP (messij))
|
|
2945 messij = Fprin1_to_string (messij, Qnil);
|
|
2946 call3 (Qdisplay_warning, class, messij, level);
|
|
2947 UNGCPRO;
|
|
2948 unbind_to (speccount, Qnil);
|
|
2949 }
|
|
2950
|
|
2951 if (!CONSP (form))
|
|
2952 {
|
|
2953 if (!SYMBOLP (form))
|
|
2954 return form;
|
|
2955
|
|
2956 val = Fsymbol_value (form);
|
|
2957
|
|
2958 return val;
|
|
2959 }
|
|
2960
|
|
2961 QUIT;
|
|
2962 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
2963 {
|
|
2964 struct gcpro gcpro1;
|
|
2965 GCPRO1 (form);
|
|
2966 garbage_collect_1 ();
|
|
2967 UNGCPRO;
|
|
2968 }
|
|
2969
|
|
2970 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
2971 {
|
|
2972 if (max_lisp_eval_depth < 100)
|
|
2973 max_lisp_eval_depth = 100;
|
|
2974 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
2975 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
2976 }
|
|
2977
|
195
|
2978 /*
|
|
2979 * At this point we know that `form' is a Lisp_Cons so we can safely
|
|
2980 * use XCAR and XCDR.
|
|
2981 */
|
|
2982 original_fun = XCAR (form);
|
|
2983 original_args = XCDR (form);
|
|
2984
|
|
2985 /*
|
|
2986 * Formerly we used a call to Flength here, but that is slow and
|
|
2987 * wasteful due to type checking, stack push/pop and initialization.
|
|
2988 * We know we're dealing with a cons, so open code it for speed.
|
|
2989 *
|
|
2990 * We call QUIT in the loop so that a circular arg list won't lock
|
|
2991 * up the editor.
|
|
2992 */
|
|
2993 for (nargs = 0, val = original_args ; CONSP (val) ; val = XCDR (val))
|
|
2994 {
|
|
2995 nargs++;
|
|
2996 QUIT;
|
|
2997 }
|
|
2998 if (! NILP (val))
|
|
2999 signal_simple_error ("Argument list must be nil-terminated",
|
|
3000 original_args);
|
0
|
3001
|
|
3002 #ifdef EMACS_BTL
|
|
3003 backtrace.id_number = 0;
|
|
3004 #endif
|
|
3005 backtrace.pdlcount = specpdl_depth_counter;
|
|
3006 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
3007 backtrace.args = &original_args;
|
|
3008 backtrace.nargs = UNEVALLED;
|
|
3009 backtrace.evalargs = 1;
|
|
3010 backtrace.debug_on_exit = 0;
|
116
|
3011 PUSH_BACKTRACE (backtrace);
|
0
|
3012
|
|
3013 if (debug_on_next_call)
|
|
3014 do_debug_on_call (Qt);
|
|
3015
|
|
3016 /* At this point, only original_fun and original_args
|
|
3017 have values that will be used below */
|
|
3018 retry:
|
|
3019 fun = indirect_function (original_fun, 1);
|
|
3020
|
|
3021 if (SUBRP (fun))
|
|
3022 {
|
|
3023 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3024 int max_args = subr->max_args;
|
|
3025 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
3026 Lisp_Object args_left;
|
|
3027 REGISTER int i;
|
|
3028
|
|
3029 args_left = original_args;
|
|
3030
|
|
3031 if (nargs < subr->min_args
|
|
3032 || (max_args >= 0 && max_args < nargs))
|
|
3033 {
|
185
|
3034 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3035 list2 (fun, make_int (nargs)));
|
|
3036 }
|
|
3037
|
|
3038 if (max_args == UNEVALLED)
|
|
3039 {
|
|
3040 backtrace.evalargs = 0;
|
|
3041 val = ((subr_function (subr)) (args_left));
|
|
3042 }
|
|
3043
|
|
3044 else if (max_args == MANY)
|
|
3045 {
|
|
3046 /* Pass a vector of evaluated arguments */
|
|
3047 Lisp_Object *vals;
|
|
3048 REGISTER int argnum;
|
|
3049 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3050
|
185
|
3051 vals = alloca_array (Lisp_Object, nargs);
|
0
|
3052
|
|
3053 GCPRO3 (args_left, fun, vals[0]);
|
|
3054 gcpro3.nvars = 0;
|
|
3055
|
|
3056 argnum = 0;
|
195
|
3057 while (CONSP (args_left))
|
0
|
3058 {
|
195
|
3059 vals[argnum++] = Feval (XCAR (args_left));
|
|
3060 args_left = XCDR (args_left);
|
0
|
3061 gcpro3.nvars = argnum;
|
|
3062 }
|
|
3063
|
|
3064 backtrace.args = vals;
|
|
3065 backtrace.nargs = nargs;
|
|
3066
|
74
|
3067 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
|
|
3068 (nargs, vals);
|
0
|
3069
|
|
3070 /* Have to duplicate this code because if the
|
|
3071 * debugger is called it must be in a scope in
|
|
3072 * which the `alloca'-ed data in vals is still valid.
|
|
3073 * (And GC-protected.)
|
|
3074 */
|
|
3075 lisp_eval_depth--;
|
|
3076 if (backtrace.debug_on_exit)
|
|
3077 val = do_debug_on_exit (val);
|
116
|
3078 POP_BACKTRACE (backtrace);
|
0
|
3079 UNGCPRO;
|
173
|
3080 return val;
|
0
|
3081 }
|
|
3082
|
|
3083 else
|
|
3084 {
|
|
3085 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3086
|
|
3087 GCPRO3 (args_left, fun, fun);
|
|
3088 gcpro3.var = argvals;
|
|
3089 gcpro3.nvars = 0;
|
|
3090
|
195
|
3091 for (i = 0; i < nargs; args_left = XCDR (args_left))
|
0
|
3092 {
|
195
|
3093 argvals[i] = Feval (XCAR (args_left));
|
0
|
3094 gcpro3.nvars = ++i;
|
|
3095 }
|
185
|
3096
|
0
|
3097 UNGCPRO;
|
185
|
3098
|
195
|
3099 /* i == nargs at this point */
|
|
3100 for (; i < max_args; i++)
|
0
|
3101 argvals[i] = Qnil;
|
|
3102
|
|
3103 backtrace.args = argvals;
|
|
3104 backtrace.nargs = nargs;
|
|
3105
|
195
|
3106 /* val = funcall_subr (subr, argvals); */
|
|
3107 inline_funcall_subr(val, subr, argvals);
|
0
|
3108 }
|
|
3109 }
|
|
3110 else if (COMPILED_FUNCTIONP (fun))
|
|
3111 val = apply_lambda (fun, nargs, original_args);
|
|
3112 else
|
|
3113 {
|
|
3114 Lisp_Object funcar;
|
|
3115
|
|
3116 if (!CONSP (fun))
|
|
3117 goto invalid_function;
|
195
|
3118 funcar = XCAR (fun);
|
0
|
3119 if (!SYMBOLP (funcar))
|
|
3120 goto invalid_function;
|
|
3121 if (EQ (funcar, Qautoload))
|
|
3122 {
|
|
3123 do_autoload (fun, original_fun);
|
|
3124 goto retry;
|
|
3125 }
|
|
3126 if (EQ (funcar, Qmacro))
|
195
|
3127 val = Feval (apply1 (XCDR (fun), original_args));
|
0
|
3128 else if (EQ (funcar, Qlambda))
|
|
3129 val = apply_lambda (fun, nargs, original_args);
|
|
3130 else
|
|
3131 {
|
|
3132 invalid_function:
|
|
3133 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3134 }
|
|
3135 }
|
|
3136
|
|
3137 lisp_eval_depth--;
|
|
3138 if (backtrace.debug_on_exit)
|
|
3139 val = do_debug_on_exit (val);
|
116
|
3140 POP_BACKTRACE (backtrace);
|
173
|
3141 return val;
|
0
|
3142 }
|
|
3143
|
|
3144
|
|
3145 Lisp_Object
|
|
3146 funcall_recording_as (Lisp_Object recorded_as, int nargs,
|
|
3147 Lisp_Object *args)
|
|
3148 {
|
|
3149 /* This function can GC */
|
|
3150 Lisp_Object fun;
|
|
3151 Lisp_Object val;
|
|
3152 struct backtrace backtrace;
|
|
3153 REGISTER int i;
|
|
3154
|
|
3155 QUIT;
|
|
3156 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
3157 /* Callers should gcpro lexpr args */
|
|
3158 garbage_collect_1 ();
|
|
3159
|
|
3160 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3161 {
|
|
3162 if (max_lisp_eval_depth < 100)
|
|
3163 max_lisp_eval_depth = 100;
|
|
3164 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
3165 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
3166 }
|
|
3167
|
|
3168 /* Count number of arguments to function */
|
|
3169 nargs = nargs - 1;
|
|
3170
|
|
3171 #ifdef EMACS_BTL
|
|
3172 backtrace.id_number = 0;
|
|
3173 #endif
|
|
3174 backtrace.pdlcount = specpdl_depth_counter;
|
|
3175 backtrace.function = &args[0];
|
|
3176 backtrace.args = &args[1];
|
|
3177 backtrace.nargs = nargs;
|
|
3178 backtrace.evalargs = 0;
|
|
3179 backtrace.debug_on_exit = 0;
|
116
|
3180 PUSH_BACKTRACE (backtrace);
|
0
|
3181
|
|
3182 if (debug_on_next_call)
|
|
3183 do_debug_on_call (Qlambda);
|
|
3184
|
|
3185 retry:
|
|
3186
|
|
3187 fun = args[0];
|
|
3188
|
|
3189 #ifdef EMACS_BTL
|
|
3190 {
|
|
3191 extern int emacs_btl_elisp_only_p;
|
|
3192 extern int btl_symbol_id_number ();
|
|
3193 if (emacs_btl_elisp_only_p)
|
|
3194 backtrace.id_number = btl_symbol_id_number (fun);
|
|
3195 }
|
|
3196 #endif
|
|
3197
|
|
3198 if (SYMBOLP (fun))
|
|
3199 fun = indirect_function (fun, 1);
|
|
3200
|
|
3201 if (SUBRP (fun))
|
|
3202 {
|
|
3203 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3204 int max_args = subr->max_args;
|
|
3205
|
|
3206 if (max_args == UNEVALLED)
|
|
3207 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3208
|
|
3209 if (nargs < subr->min_args
|
|
3210 || (max_args >= 0 && max_args < nargs))
|
|
3211 {
|
185
|
3212 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3213 list2 (fun, make_int (nargs)));
|
|
3214 }
|
|
3215
|
|
3216 if (max_args == MANY)
|
|
3217 {
|
74
|
3218 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
|
|
3219 (nargs, args + 1);
|
0
|
3220 }
|
|
3221
|
|
3222 else if (max_args > nargs)
|
|
3223 {
|
|
3224 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
3225
|
|
3226 /* Default optionals to nil */
|
|
3227 for (i = 0; i < nargs; i++)
|
|
3228 argvals[i] = args[i + 1];
|
|
3229 for (i = nargs; i < max_args; i++)
|
|
3230 argvals[i] = Qnil;
|
|
3231
|
195
|
3232 /* val = funcall_subr (subr, argvals); */
|
|
3233 inline_funcall_subr(val, subr, argvals);
|
0
|
3234 }
|
|
3235 else
|
195
|
3236 /* val = funcall_subr (subr, args + 1); */
|
|
3237 inline_funcall_subr(val, subr, (&args[1]));
|
0
|
3238 }
|
|
3239 else if (COMPILED_FUNCTIONP (fun))
|
|
3240 val = funcall_lambda (fun, nargs, args + 1);
|
|
3241 else if (!CONSP (fun))
|
|
3242 {
|
|
3243 invalid_function:
|
|
3244 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3245 }
|
|
3246 else
|
|
3247 {
|
195
|
3248 /* `fun' is a Lisp_Cons so XCAR is safe */
|
|
3249 Lisp_Object funcar = XCAR (fun);
|
0
|
3250
|
|
3251 if (!SYMBOLP (funcar))
|
|
3252 goto invalid_function;
|
|
3253 if (EQ (funcar, Qlambda))
|
|
3254 val = funcall_lambda (fun, nargs, args + 1);
|
|
3255 else if (EQ (funcar, Qautoload))
|
|
3256 {
|
|
3257 do_autoload (fun, args[0]);
|
|
3258 goto retry;
|
|
3259 }
|
|
3260 else
|
|
3261 {
|
|
3262 goto invalid_function;
|
|
3263 }
|
|
3264 }
|
|
3265 lisp_eval_depth--;
|
|
3266 if (backtrace.debug_on_exit)
|
|
3267 val = do_debug_on_exit (val);
|
116
|
3268 POP_BACKTRACE (backtrace);
|
0
|
3269 return val;
|
|
3270 }
|
|
3271
|
20
|
3272 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
|
0
|
3273 Call first argument as a function, passing remaining arguments to it.
|
|
3274 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
20
|
3275 */
|
|
3276 (int nargs, Lisp_Object *args))
|
0
|
3277 {
|
|
3278 return funcall_recording_as (args[0], nargs, args);
|
|
3279 }
|
|
3280
|
20
|
3281 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
|
0
|
3282 Return the number of arguments a function may be called with. The
|
|
3283 function may be any form that can be passed to `funcall', any special
|
|
3284 form, or any macro.
|
20
|
3285 */
|
|
3286 (function))
|
0
|
3287 {
|
|
3288 Lisp_Object orig_function = function;
|
|
3289 Lisp_Object arglist;
|
|
3290 int argcount;
|
|
3291
|
|
3292 retry:
|
|
3293
|
|
3294 if (SYMBOLP (function))
|
|
3295 function = indirect_function (function, 1);
|
|
3296
|
|
3297 if (SUBRP (function))
|
|
3298 return Fsubr_min_args (function);
|
|
3299 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3300 {
|
|
3301 invalid_function:
|
|
3302 return Fsignal (Qinvalid_function, list1 (function));
|
|
3303 }
|
|
3304
|
|
3305 if (CONSP (function))
|
|
3306 {
|
|
3307 Lisp_Object funcar = Fcar (function);
|
|
3308
|
|
3309 if (!SYMBOLP (funcar))
|
|
3310 goto invalid_function;
|
|
3311 if (EQ (funcar, Qmacro))
|
|
3312 {
|
|
3313 function = Fcdr (function);
|
|
3314 goto retry;
|
|
3315 }
|
|
3316 if (EQ (funcar, Qautoload))
|
|
3317 {
|
|
3318 do_autoload (function, orig_function);
|
|
3319 goto retry;
|
|
3320 }
|
|
3321 if (EQ (funcar, Qlambda))
|
|
3322 arglist = Fcar (Fcdr (function));
|
|
3323 else
|
|
3324 goto invalid_function;
|
|
3325 }
|
|
3326 else
|
|
3327 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3328
|
|
3329 argcount = 0;
|
|
3330 while (!NILP (arglist))
|
|
3331 {
|
|
3332 QUIT;
|
|
3333 if (EQ (Fcar (arglist), Qand_optional)
|
|
3334 || EQ (Fcar (arglist), Qand_rest))
|
|
3335 break;
|
|
3336 argcount++;
|
|
3337 arglist = Fcdr (arglist);
|
|
3338 }
|
|
3339
|
|
3340 return make_int (argcount);
|
|
3341 }
|
|
3342
|
20
|
3343 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
|
0
|
3344 Return the number of arguments a function may be called with. If the
|
|
3345 function takes an arbitrary number of arguments or is a built-in
|
|
3346 special form, nil is returned. The function may be any form that can
|
|
3347 be passed to `funcall', any special form, or any macro.
|
20
|
3348 */
|
|
3349 (function))
|
0
|
3350 {
|
|
3351 Lisp_Object orig_function = function;
|
|
3352 Lisp_Object arglist;
|
|
3353 int argcount;
|
|
3354
|
|
3355 retry:
|
|
3356
|
|
3357 if (SYMBOLP (function))
|
|
3358 function = indirect_function (function, 1);
|
|
3359
|
|
3360 if (SUBRP (function))
|
|
3361 return Fsubr_max_args (function);
|
|
3362 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3363 {
|
|
3364 invalid_function:
|
|
3365 return Fsignal (Qinvalid_function, list1 (function));
|
|
3366 }
|
|
3367
|
|
3368 if (CONSP (function))
|
|
3369 {
|
|
3370 Lisp_Object funcar = Fcar (function);
|
|
3371
|
|
3372 if (!SYMBOLP (funcar))
|
|
3373 goto invalid_function;
|
|
3374 if (EQ (funcar, Qmacro))
|
|
3375 {
|
|
3376 function = Fcdr (function);
|
|
3377 goto retry;
|
|
3378 }
|
|
3379 if (EQ (funcar, Qautoload))
|
|
3380 {
|
|
3381 do_autoload (function, orig_function);
|
|
3382 goto retry;
|
|
3383 }
|
|
3384 if (EQ (funcar, Qlambda))
|
|
3385 arglist = Fcar (Fcdr (function));
|
|
3386 else
|
|
3387 goto invalid_function;
|
|
3388 }
|
|
3389 else
|
|
3390 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3391
|
|
3392 argcount = 0;
|
|
3393 while (!NILP (arglist))
|
|
3394 {
|
|
3395 QUIT;
|
|
3396 if (EQ (Fcar (arglist), Qand_optional))
|
|
3397 {
|
|
3398 arglist = Fcdr (arglist);
|
|
3399 continue;
|
|
3400 }
|
|
3401 if (EQ (Fcar (arglist), Qand_rest))
|
|
3402 return Qnil;
|
|
3403 argcount++;
|
|
3404 arglist = Fcdr (arglist);
|
|
3405 }
|
|
3406
|
|
3407 return make_int (argcount);
|
|
3408 }
|
|
3409
|
|
3410
|
20
|
3411 DEFUN ("apply", Fapply, 2, MANY, 0, /*
|
0
|
3412 Call FUNCTION with our remaining args, using our last arg as list of args.
|
|
3413 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
20
|
3414 */
|
|
3415 (int nargs, Lisp_Object *args))
|
0
|
3416 {
|
|
3417 /* This function can GC */
|
|
3418 Lisp_Object fun = args[0];
|
195
|
3419 Lisp_Object spread_arg = args [nargs - 1], p;
|
0
|
3420 int numargs;
|
|
3421 int funcall_nargs;
|
|
3422
|
|
3423 CHECK_LIST (spread_arg);
|
185
|
3424
|
195
|
3425 /*
|
|
3426 * Formerly we used a call to Flength here, but that is slow and
|
|
3427 * wasteful due to type checking, stack push/pop and initialization.
|
|
3428 * We know we're dealing with a cons, so open code it for speed.
|
|
3429 *
|
|
3430 * We call QUIT in the loop so that a circular arg list won't lock
|
|
3431 * up the editor.
|
|
3432 */
|
|
3433 for (numargs = 0, p = spread_arg ; CONSP (p) ; p = XCDR (p))
|
|
3434 {
|
|
3435 numargs++;
|
|
3436 QUIT;
|
|
3437 }
|
|
3438 if (! NILP (p))
|
|
3439 signal_simple_error ("Argument list must be nil-terminated", spread_arg);
|
0
|
3440
|
|
3441 if (numargs == 0)
|
|
3442 /* (apply foo 0 1 '()) */
|
|
3443 return Ffuncall (nargs - 1, args);
|
|
3444 else if (numargs == 1)
|
|
3445 {
|
|
3446 /* (apply foo 0 1 '(2)) */
|
|
3447 args [nargs - 1] = XCAR (spread_arg);
|
|
3448 return Ffuncall (nargs, args);
|
|
3449 }
|
|
3450
|
|
3451 /* -1 for function, -1 for spread arg */
|
|
3452 numargs = nargs - 2 + numargs;
|
|
3453 /* +1 for function */
|
|
3454 funcall_nargs = 1 + numargs;
|
|
3455
|
|
3456 if (SYMBOLP (fun))
|
|
3457 fun = indirect_function (fun, 0);
|
|
3458 if (UNBOUNDP (fun))
|
|
3459 {
|
|
3460 /* Let funcall get the error */
|
|
3461 fun = args[0];
|
|
3462 }
|
|
3463 else if (SUBRP (fun))
|
|
3464 {
|
|
3465 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3466 int max_args = subr->max_args;
|
|
3467
|
|
3468 if (numargs < subr->min_args
|
|
3469 || (max_args >= 0 && max_args < numargs))
|
|
3470 {
|
|
3471 /* Let funcall get the error */
|
|
3472 }
|
|
3473 else if (max_args > numargs)
|
|
3474 {
|
|
3475 /* Avoid having funcall cons up yet another new vector of arguments
|
|
3476 by explicitly supplying nil's for optional values */
|
|
3477 funcall_nargs += (max_args - numargs);
|
|
3478 }
|
|
3479 }
|
|
3480 {
|
|
3481 REGISTER int i;
|
185
|
3482 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs);
|
0
|
3483 struct gcpro gcpro1;
|
|
3484
|
|
3485 GCPRO1 (*funcall_args);
|
|
3486 gcpro1.nvars = funcall_nargs;
|
|
3487
|
|
3488 /* Copy in the unspread args */
|
|
3489 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object));
|
|
3490 /* Spread the last arg we got. Its first element goes in
|
|
3491 the slot that it used to occupy, hence this value of I. */
|
185
|
3492 for (i = nargs - 1;
|
0
|
3493 !NILP (spread_arg); /* i < 1 + numargs */
|
|
3494 i++, spread_arg = XCDR (spread_arg))
|
|
3495 {
|
|
3496 funcall_args [i] = XCAR (spread_arg);
|
|
3497 }
|
|
3498 /* Supply nil for optional args (to subrs) */
|
|
3499 for (; i < funcall_nargs; i++)
|
|
3500 funcall_args[i] = Qnil;
|
|
3501
|
|
3502
|
|
3503 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
|
|
3504 }
|
|
3505 }
|
|
3506
|
|
3507
|
74
|
3508 /* Define proper types and argument lists simultaneously */
|
|
3509 #define PRIMITIVE_FUNCALL(n) ((Lisp_Object (*) (PRIMITIVE_FUNCALL_##n)
|
|
3510 #define PRIMITIVE_FUNCALL_0 void)) (fn)) (
|
|
3511 #define PRIMITIVE_FUNCALL_1 Lisp_Object)) (fn)) (args[0]
|
|
3512 #define PRIMITIVE_FUNCALL_2 Lisp_Object, PRIMITIVE_FUNCALL_1, args[1]
|
|
3513 #define PRIMITIVE_FUNCALL_3 Lisp_Object, PRIMITIVE_FUNCALL_2, args[2]
|
|
3514 #define PRIMITIVE_FUNCALL_4 Lisp_Object, PRIMITIVE_FUNCALL_3, args[3]
|
|
3515 #define PRIMITIVE_FUNCALL_5 Lisp_Object, PRIMITIVE_FUNCALL_4, args[4]
|
|
3516 #define PRIMITIVE_FUNCALL_6 Lisp_Object, PRIMITIVE_FUNCALL_5, args[5]
|
|
3517 #define PRIMITIVE_FUNCALL_7 Lisp_Object, PRIMITIVE_FUNCALL_6, args[6]
|
|
3518 #define PRIMITIVE_FUNCALL_8 Lisp_Object, PRIMITIVE_FUNCALL_7, args[7]
|
|
3519 #define PRIMITIVE_FUNCALL_9 Lisp_Object, PRIMITIVE_FUNCALL_8, args[8]
|
|
3520 #define PRIMITIVE_FUNCALL_10 Lisp_Object, PRIMITIVE_FUNCALL_9, args[9]
|
|
3521 #define PRIMITIVE_FUNCALL_11 Lisp_Object, PRIMITIVE_FUNCALL_10, args[10]
|
|
3522 #define PRIMITIVE_FUNCALL_12 Lisp_Object, PRIMITIVE_FUNCALL_11, args[11]
|
|
3523
|
0
|
3524 static Lisp_Object
|
74
|
3525 primitive_funcall (lisp_fn_t fn, int nargs, Lisp_Object args[])
|
0
|
3526 {
|
|
3527 switch (nargs)
|
|
3528 {
|
74
|
3529 case 0: return PRIMITIVE_FUNCALL(0);
|
|
3530 case 1: return PRIMITIVE_FUNCALL(1);
|
|
3531 case 2: return PRIMITIVE_FUNCALL(2);
|
|
3532 case 3: return PRIMITIVE_FUNCALL(3);
|
|
3533 case 4: return PRIMITIVE_FUNCALL(4);
|
|
3534 case 5: return PRIMITIVE_FUNCALL(5);
|
|
3535 case 6: return PRIMITIVE_FUNCALL(6);
|
|
3536 case 7: return PRIMITIVE_FUNCALL(7);
|
|
3537 case 8: return PRIMITIVE_FUNCALL(8);
|
|
3538 case 9: return PRIMITIVE_FUNCALL(9);
|
|
3539 case 10: return PRIMITIVE_FUNCALL(10);
|
|
3540 case 11: return PRIMITIVE_FUNCALL(11);
|
|
3541 case 12: return PRIMITIVE_FUNCALL(12);
|
0
|
3542 }
|
74
|
3543
|
|
3544 /* Someone has created a subr that takes more arguments than is
|
|
3545 supported by this code. We need to either rewrite the subr to
|
|
3546 use a different argument protocol, or add more cases to this
|
|
3547 switch. */
|
|
3548 abort ();
|
0
|
3549 return Qnil; /* suppress compiler warning */
|
|
3550 }
|
|
3551
|
|
3552 static Lisp_Object
|
|
3553 funcall_subr (struct Lisp_Subr *subr, Lisp_Object args[])
|
|
3554 {
|
|
3555 return primitive_funcall (subr_function (subr), subr->max_args, args);
|
|
3556 }
|
|
3557
|
|
3558 /* FSFmacs has an extra arg EVAL_FLAG. If false, some of
|
|
3559 the statements below are not done. But it's always true
|
|
3560 in all the calls to apply_lambda(). */
|
|
3561
|
|
3562 static Lisp_Object
|
|
3563 apply_lambda (Lisp_Object fun, int numargs, Lisp_Object unevalled_args)
|
|
3564 {
|
|
3565 /* This function can GC */
|
|
3566 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3567 REGISTER int i;
|
|
3568 REGISTER Lisp_Object tem;
|
185
|
3569 REGISTER Lisp_Object *arg_vector = alloca_array (Lisp_Object, numargs);
|
0
|
3570
|
|
3571 GCPRO3 (*arg_vector, unevalled_args, fun);
|
|
3572 gcpro1.nvars = 0;
|
|
3573
|
|
3574 for (i = 0; i < numargs;)
|
|
3575 {
|
195
|
3576 /*
|
|
3577 * unevalled_args is always a normal list, or Feval would have
|
|
3578 * rejected it, so use XCAR and XCDR.
|
|
3579 */
|
|
3580 tem = XCAR (unevalled_args), unevalled_args = XCDR (unevalled_args);
|
0
|
3581 tem = Feval (tem);
|
|
3582 arg_vector[i++] = tem;
|
|
3583 gcpro1.nvars = i;
|
|
3584 }
|
|
3585
|
|
3586 UNGCPRO;
|
|
3587
|
|
3588 backtrace_list->args = arg_vector;
|
|
3589 backtrace_list->nargs = i;
|
|
3590 backtrace_list->evalargs = 0;
|
|
3591 tem = funcall_lambda (fun, numargs, arg_vector);
|
|
3592
|
|
3593 /* Do the debug-on-exit now, while arg_vector still exists. */
|
|
3594 if (backtrace_list->debug_on_exit)
|
|
3595 tem = do_debug_on_exit (tem);
|
|
3596 /* Don't do it again when we return to eval. */
|
|
3597 backtrace_list->debug_on_exit = 0;
|
173
|
3598 return tem;
|
0
|
3599 }
|
|
3600
|
|
3601 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
|
|
3602 and return the result of evaluation.
|
|
3603 FUN must be either a lambda-expression or a compiled-code object. */
|
|
3604
|
|
3605 static Lisp_Object
|
|
3606 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object arg_vector[])
|
|
3607 {
|
|
3608 /* This function can GC */
|
|
3609 Lisp_Object val, tem;
|
|
3610 REGISTER Lisp_Object syms_left;
|
|
3611 REGISTER Lisp_Object next;
|
|
3612 int speccount = specpdl_depth_counter;
|
|
3613 REGISTER int i;
|
|
3614 int optional = 0, rest = 0;
|
|
3615
|
|
3616 if (CONSP (fun))
|
195
|
3617 syms_left = Fcar (XCDR (fun));
|
0
|
3618 else if (COMPILED_FUNCTIONP (fun))
|
|
3619 syms_left = XCOMPILED_FUNCTION (fun)->arglist;
|
|
3620 else abort ();
|
|
3621
|
|
3622 i = 0;
|
195
|
3623 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
|
0
|
3624 {
|
|
3625 QUIT;
|
195
|
3626 next = XCAR (syms_left);
|
0
|
3627 if (!SYMBOLP (next))
|
|
3628 signal_error (Qinvalid_function, list1 (fun));
|
|
3629 if (EQ (next, Qand_rest))
|
|
3630 rest = 1;
|
|
3631 else if (EQ (next, Qand_optional))
|
|
3632 optional = 1;
|
|
3633 else if (rest)
|
|
3634 {
|
|
3635 specbind (next, Flist (nargs - i, &arg_vector[i]));
|
|
3636 i = nargs;
|
|
3637 }
|
|
3638 else if (i < nargs)
|
|
3639 {
|
|
3640 tem = arg_vector[i++];
|
|
3641 specbind (next, tem);
|
|
3642 }
|
|
3643 else if (!optional)
|
185
|
3644 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3645 list2 (fun, make_int (nargs)));
|
|
3646 else
|
|
3647 specbind (next, Qnil);
|
|
3648 }
|
|
3649
|
|
3650 if (i < nargs)
|
185
|
3651 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3652 list2 (fun, make_int (nargs)));
|
|
3653
|
|
3654 if (CONSP (fun))
|
195
|
3655 val = Fprogn (Fcdr (XCDR (fun)));
|
0
|
3656 else
|
|
3657 {
|
|
3658 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
3659 /* If we have not actually read the bytecode string
|
|
3660 and constants vector yet, fetch them from the file. */
|
|
3661 if (CONSP (b->bytecodes))
|
|
3662 Ffetch_bytecode (fun);
|
|
3663 val = Fbyte_code (b->bytecodes,
|
|
3664 b->constants,
|
|
3665 make_int (b->maxdepth));
|
|
3666 }
|
|
3667 return unbind_to (speccount, val);
|
|
3668 }
|
|
3669
|
20
|
3670 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /*
|
0
|
3671 If byte-compiled OBJECT is lazy-loaded, fetch it now.
|
20
|
3672 */
|
|
3673 (object))
|
0
|
3674 {
|
|
3675 Lisp_Object tem;
|
|
3676
|
|
3677 if (COMPILED_FUNCTIONP (object)
|
|
3678 && CONSP (XCOMPILED_FUNCTION (object)->bytecodes))
|
|
3679 {
|
|
3680 tem = read_doc_string (XCOMPILED_FUNCTION (object)->bytecodes);
|
|
3681 if (!CONSP (tem))
|
|
3682 signal_simple_error ("invalid lazy-loaded byte code", tem);
|
70
|
3683 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
3684 if (XCOMPILED_FUNCTION (object)->flags.ebolified
|
|
3685 && VECTORP (XCDR (tem)))
|
|
3686 ebolify_bytecode_constants (XCDR (tem));
|
0
|
3687 /* VERY IMPORTANT to purecopy here!!!!!
|
|
3688 See load_force_doc_string_unwind. */
|
|
3689 XCOMPILED_FUNCTION (object)->bytecodes = Fpurecopy (XCAR (tem));
|
|
3690 XCOMPILED_FUNCTION (object)->constants = Fpurecopy (XCDR (tem));
|
|
3691 }
|
|
3692 return object;
|
|
3693 }
|
|
3694
|
|
3695
|
|
3696 /**********************************************************************/
|
|
3697 /* Run hook variables in various ways. */
|
|
3698 /**********************************************************************/
|
|
3699
|
20
|
3700 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
|
0
|
3701 Run each hook in HOOKS. Major mode functions use this.
|
|
3702 Each argument should be a symbol, a hook variable.
|
|
3703 These symbols are processed in the order specified.
|
|
3704 If a hook symbol has a non-nil value, that value may be a function
|
|
3705 or a list of functions to be called to run the hook.
|
|
3706 If the value is a function, it is called with no arguments.
|
|
3707 If it is a list, the elements are called, in order, with no arguments.
|
|
3708
|
|
3709 To make a hook variable buffer-local, use `make-local-hook',
|
|
3710 not `make-local-variable'.
|
20
|
3711 */
|
|
3712 (int nargs, Lisp_Object *args))
|
0
|
3713 {
|
|
3714 REGISTER int i;
|
|
3715
|
|
3716 for (i = 0; i < nargs; i++)
|
187
|
3717 run_hook_with_args (1, args + i, RUN_HOOKS_TO_COMPLETION);
|
0
|
3718
|
|
3719 return Qnil;
|
|
3720 }
|
185
|
3721
|
20
|
3722 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /*
|
0
|
3723 Run HOOK with the specified arguments ARGS.
|
|
3724 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
3725 value, that value may be a function or a list of functions to be
|
|
3726 called to run the hook. If the value is a function, it is called with
|
|
3727 the given arguments and its return value is returned. If it is a list
|
|
3728 of functions, those functions are called, in order,
|
|
3729 with the given arguments ARGS.
|
|
3730 It is best not to depend on the value return by `run-hook-with-args',
|
|
3731 as that may change.
|
|
3732
|
|
3733 To make a hook variable buffer-local, use `make-local-hook',
|
|
3734 not `make-local-variable'.
|
20
|
3735 */
|
|
3736 (int nargs, Lisp_Object *args))
|
0
|
3737 {
|
|
3738 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
|
|
3739 }
|
|
3740
|
20
|
3741 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /*
|
0
|
3742 Run HOOK with the specified arguments ARGS.
|
|
3743 HOOK should be a symbol, a hook variable. Its value should
|
|
3744 be a list of functions. We call those functions, one by one,
|
|
3745 passing arguments ARGS to each of them, until one of them
|
|
3746 returns a non-nil value. Then we return that value.
|
|
3747 If all the functions return nil, we return nil.
|
|
3748
|
|
3749 To make a hook variable buffer-local, use `make-local-hook',
|
|
3750 not `make-local-variable'.
|
20
|
3751 */
|
|
3752 (int nargs, Lisp_Object *args))
|
0
|
3753 {
|
|
3754 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
|
|
3755 }
|
|
3756
|
20
|
3757 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /*
|
0
|
3758 Run HOOK with the specified arguments ARGS.
|
|
3759 HOOK should be a symbol, a hook variable. Its value should
|
|
3760 be a list of functions. We call those functions, one by one,
|
|
3761 passing arguments ARGS to each of them, until one of them
|
|
3762 returns nil. Then we return nil.
|
|
3763 If all the functions return non-nil, we return non-nil.
|
|
3764
|
|
3765 To make a hook variable buffer-local, use `make-local-hook',
|
|
3766 not `make-local-variable'.
|
20
|
3767 */
|
|
3768 (int nargs, Lisp_Object *args))
|
0
|
3769 {
|
|
3770 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
|
|
3771 }
|
|
3772
|
|
3773 /* ARGS[0] should be a hook symbol.
|
|
3774 Call each of the functions in the hook value, passing each of them
|
|
3775 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
3776 COND specifies a condition to test after each call
|
|
3777 to decide whether to stop.
|
|
3778 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3779 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3780
|
|
3781 Lisp_Object
|
|
3782 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
|
|
3783 enum run_hooks_condition cond)
|
|
3784 {
|
|
3785 Lisp_Object sym, val, ret;
|
|
3786 struct gcpro gcpro1, gcpro2;
|
|
3787
|
|
3788 if (!initialized || preparing_for_armageddon)
|
|
3789 /* We need to bail out of here pronto. */
|
|
3790 return Qnil;
|
|
3791
|
|
3792 /* Whenever gc_in_progress is true, preparing_for_armageddon
|
|
3793 will also be true unless something is really hosed. */
|
|
3794 assert (!gc_in_progress);
|
|
3795
|
|
3796 sym = args[0];
|
|
3797 val = symbol_value_in_buffer (sym, make_buffer (buf));
|
|
3798 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
3799
|
|
3800 if (UNBOUNDP (val) || NILP (val))
|
|
3801 return ret;
|
|
3802 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
|
3803 {
|
|
3804 args[0] = val;
|
|
3805 return Ffuncall (nargs, args);
|
|
3806 }
|
|
3807 else
|
|
3808 {
|
|
3809 GCPRO2 (sym, val);
|
|
3810
|
|
3811 for (;
|
|
3812 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3813 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
|
|
3814 : !NILP (ret)));
|
|
3815 val = XCDR (val))
|
|
3816 {
|
|
3817 if (EQ (XCAR (val), Qt))
|
|
3818 {
|
|
3819 /* t indicates this hook has a local binding;
|
|
3820 it means to run the global binding too. */
|
|
3821 Lisp_Object globals;
|
|
3822
|
|
3823 for (globals = Fdefault_value (sym);
|
|
3824 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3825 || (cond == RUN_HOOKS_UNTIL_SUCCESS
|
|
3826 ? NILP (ret)
|
|
3827 : !NILP (ret)));
|
|
3828 globals = XCDR (globals))
|
|
3829 {
|
|
3830 args[0] = XCAR (globals);
|
|
3831 /* In a global value, t should not occur. If it does, we
|
|
3832 must ignore it to avoid an endless loop. */
|
|
3833 if (!EQ (args[0], Qt))
|
|
3834 ret = Ffuncall (nargs, args);
|
|
3835 }
|
|
3836 }
|
|
3837 else
|
|
3838 {
|
|
3839 args[0] = XCAR (val);
|
|
3840 ret = Ffuncall (nargs, args);
|
|
3841 }
|
|
3842 }
|
|
3843
|
|
3844 UNGCPRO;
|
|
3845 return ret;
|
|
3846 }
|
|
3847 }
|
|
3848
|
|
3849 Lisp_Object
|
|
3850 run_hook_with_args (int nargs, Lisp_Object *args,
|
|
3851 enum run_hooks_condition cond)
|
|
3852 {
|
|
3853 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond);
|
|
3854 }
|
|
3855
|
|
3856 #if 0
|
|
3857
|
|
3858 /* From FSF 19.30, not currently used */
|
|
3859
|
|
3860 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
3861 present value of that symbol.
|
|
3862 Call each element of FUNLIST,
|
|
3863 passing each of them the rest of ARGS.
|
|
3864 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3865 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3866
|
|
3867 Lisp_Object
|
|
3868 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
|
|
3869 {
|
|
3870 Lisp_Object sym;
|
|
3871 Lisp_Object val;
|
|
3872 struct gcpro gcpro1, gcpro2;
|
|
3873
|
|
3874 sym = args[0];
|
|
3875 GCPRO2 (sym, val);
|
|
3876
|
|
3877 for (val = funlist; CONSP (val); val = XCDR (val))
|
|
3878 {
|
|
3879 if (EQ (XCAR (val), Qt))
|
|
3880 {
|
|
3881 /* t indicates this hook has a local binding;
|
|
3882 it means to run the global binding too. */
|
|
3883 Lisp_Object globals;
|
|
3884
|
|
3885 for (globals = Fdefault_value (sym);
|
|
3886 CONSP (globals);
|
|
3887 globals = XCDR (globals))
|
|
3888 {
|
|
3889 args[0] = XCAR (globals);
|
|
3890 /* In a global value, t should not occur. If it does, we
|
|
3891 must ignore it to avoid an endless loop. */
|
|
3892 if (!EQ (args[0], Qt))
|
|
3893 Ffuncall (nargs, args);
|
|
3894 }
|
|
3895 }
|
|
3896 else
|
|
3897 {
|
|
3898 args[0] = XCAR (val);
|
|
3899 Ffuncall (nargs, args);
|
|
3900 }
|
|
3901 }
|
|
3902 UNGCPRO;
|
|
3903 return Qnil;
|
|
3904 }
|
|
3905
|
|
3906 #endif /* 0 */
|
|
3907
|
|
3908 void
|
|
3909 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...)
|
|
3910 {
|
|
3911 /* This function can GC */
|
|
3912 struct gcpro gcpro1;
|
|
3913 int i;
|
|
3914 va_list vargs;
|
185
|
3915 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
0
|
3916
|
|
3917 va_start (vargs, nargs);
|
|
3918 funcall_args[0] = hook_var;
|
|
3919 for (i = 0; i < nargs; i++)
|
|
3920 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3921 va_end (vargs);
|
|
3922
|
|
3923 GCPRO1 (*funcall_args);
|
|
3924 gcpro1.nvars = nargs + 1;
|
|
3925 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION);
|
|
3926 UNGCPRO;
|
|
3927 }
|
|
3928
|
|
3929 void
|
|
3930 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var,
|
|
3931 int nargs, ...)
|
|
3932 {
|
|
3933 /* This function can GC */
|
|
3934 struct gcpro gcpro1;
|
|
3935 int i;
|
|
3936 va_list vargs;
|
185
|
3937 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
0
|
3938
|
|
3939 va_start (vargs, nargs);
|
|
3940 funcall_args[0] = hook_var;
|
|
3941 for (i = 0; i < nargs; i++)
|
|
3942 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3943 va_end (vargs);
|
|
3944
|
|
3945 GCPRO1 (*funcall_args);
|
|
3946 gcpro1.nvars = nargs + 1;
|
|
3947 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args,
|
|
3948 RUN_HOOKS_TO_COMPLETION);
|
|
3949 UNGCPRO;
|
|
3950 }
|
|
3951
|
|
3952 Lisp_Object
|
|
3953 run_hook (Lisp_Object hook)
|
|
3954 {
|
|
3955 Frun_hooks (1, &hook);
|
|
3956 return Qnil;
|
|
3957 }
|
|
3958
|
|
3959
|
|
3960 /**********************************************************************/
|
|
3961 /* Front-ends to eval, funcall, apply */
|
|
3962 /**********************************************************************/
|
|
3963
|
|
3964 /* Apply fn to arg */
|
|
3965 Lisp_Object
|
|
3966 apply1 (Lisp_Object fn, Lisp_Object arg)
|
|
3967 {
|
|
3968 /* This function can GC */
|
|
3969 struct gcpro gcpro1;
|
|
3970 Lisp_Object args[2];
|
|
3971
|
|
3972 if (NILP (arg))
|
173
|
3973 return Ffuncall (1, &fn);
|
0
|
3974 GCPRO1 (args[0]);
|
|
3975 gcpro1.nvars = 2;
|
|
3976 args[0] = fn;
|
|
3977 args[1] = arg;
|
|
3978 RETURN_UNGCPRO (Fapply (2, args));
|
|
3979 }
|
|
3980
|
|
3981 /* Call function fn on no arguments */
|
|
3982 Lisp_Object
|
|
3983 call0 (Lisp_Object fn)
|
|
3984 {
|
|
3985 /* This function can GC */
|
|
3986 struct gcpro gcpro1;
|
|
3987
|
|
3988 GCPRO1 (fn);
|
|
3989 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
3990 }
|
|
3991
|
|
3992 /* Call function fn with argument arg0 */
|
|
3993 Lisp_Object
|
|
3994 call1 (Lisp_Object fn,
|
|
3995 Lisp_Object arg0)
|
|
3996 {
|
|
3997 /* This function can GC */
|
|
3998 struct gcpro gcpro1;
|
185
|
3999 Lisp_Object args[2];
|
0
|
4000 args[0] = fn;
|
|
4001 args[1] = arg0;
|
|
4002 GCPRO1 (args[0]);
|
|
4003 gcpro1.nvars = 2;
|
|
4004 RETURN_UNGCPRO (Ffuncall (2, args));
|
|
4005 }
|
|
4006
|
|
4007 /* Call function fn with arguments arg0, arg1 */
|
|
4008 Lisp_Object
|
|
4009 call2 (Lisp_Object fn,
|
|
4010 Lisp_Object arg0, Lisp_Object arg1)
|
|
4011 {
|
|
4012 /* This function can GC */
|
|
4013 struct gcpro gcpro1;
|
|
4014 Lisp_Object args[3];
|
|
4015 args[0] = fn;
|
|
4016 args[1] = arg0;
|
|
4017 args[2] = arg1;
|
|
4018 GCPRO1 (args[0]);
|
|
4019 gcpro1.nvars = 3;
|
|
4020 RETURN_UNGCPRO (Ffuncall (3, args));
|
|
4021 }
|
|
4022
|
|
4023 /* Call function fn with arguments arg0, arg1, arg2 */
|
|
4024 Lisp_Object
|
|
4025 call3 (Lisp_Object fn,
|
|
4026 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4027 {
|
|
4028 /* This function can GC */
|
|
4029 struct gcpro gcpro1;
|
|
4030 Lisp_Object args[4];
|
|
4031 args[0] = fn;
|
|
4032 args[1] = arg0;
|
|
4033 args[2] = arg1;
|
|
4034 args[3] = arg2;
|
|
4035 GCPRO1 (args[0]);
|
|
4036 gcpro1.nvars = 4;
|
|
4037 RETURN_UNGCPRO (Ffuncall (4, args));
|
|
4038 }
|
|
4039
|
|
4040 /* Call function fn with arguments arg0, arg1, arg2, arg3 */
|
|
4041 Lisp_Object
|
|
4042 call4 (Lisp_Object fn,
|
|
4043 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4044 Lisp_Object arg3)
|
|
4045 {
|
|
4046 /* This function can GC */
|
|
4047 struct gcpro gcpro1;
|
|
4048 Lisp_Object args[5];
|
|
4049 args[0] = fn;
|
|
4050 args[1] = arg0;
|
|
4051 args[2] = arg1;
|
|
4052 args[3] = arg2;
|
|
4053 args[4] = arg3;
|
|
4054 GCPRO1 (args[0]);
|
|
4055 gcpro1.nvars = 5;
|
|
4056 RETURN_UNGCPRO (Ffuncall (5, args));
|
|
4057 }
|
|
4058
|
|
4059 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */
|
|
4060 Lisp_Object
|
|
4061 call5 (Lisp_Object fn,
|
185
|
4062 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4063 Lisp_Object arg3, Lisp_Object arg4)
|
|
4064 {
|
|
4065 /* This function can GC */
|
|
4066 struct gcpro gcpro1;
|
|
4067 Lisp_Object args[6];
|
|
4068 args[0] = fn;
|
|
4069 args[1] = arg0;
|
|
4070 args[2] = arg1;
|
|
4071 args[3] = arg2;
|
|
4072 args[4] = arg3;
|
|
4073 args[5] = arg4;
|
|
4074 GCPRO1 (args[0]);
|
|
4075 gcpro1.nvars = 6;
|
|
4076 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
4077 }
|
|
4078
|
|
4079 Lisp_Object
|
|
4080 call6 (Lisp_Object fn,
|
185
|
4081 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4082 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4083 {
|
|
4084 /* This function can GC */
|
|
4085 struct gcpro gcpro1;
|
|
4086 Lisp_Object args[7];
|
|
4087 args[0] = fn;
|
|
4088 args[1] = arg0;
|
|
4089 args[2] = arg1;
|
|
4090 args[3] = arg2;
|
|
4091 args[4] = arg3;
|
|
4092 args[5] = arg4;
|
|
4093 args[6] = arg5;
|
|
4094 GCPRO1 (args[0]);
|
|
4095 gcpro1.nvars = 7;
|
|
4096 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
4097 }
|
|
4098
|
|
4099 Lisp_Object
|
|
4100 call7 (Lisp_Object fn,
|
185
|
4101 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4102 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4103 Lisp_Object arg6)
|
|
4104 {
|
|
4105 /* This function can GC */
|
|
4106 struct gcpro gcpro1;
|
|
4107 Lisp_Object args[8];
|
|
4108 args[0] = fn;
|
|
4109 args[1] = arg0;
|
|
4110 args[2] = arg1;
|
|
4111 args[3] = arg2;
|
|
4112 args[4] = arg3;
|
|
4113 args[5] = arg4;
|
|
4114 args[6] = arg5;
|
|
4115 args[7] = arg6;
|
|
4116 GCPRO1 (args[0]);
|
|
4117 gcpro1.nvars = 8;
|
|
4118 RETURN_UNGCPRO (Ffuncall (8, args));
|
|
4119 }
|
|
4120
|
|
4121 Lisp_Object
|
|
4122 call8 (Lisp_Object fn,
|
185
|
4123 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4124 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4125 Lisp_Object arg6, Lisp_Object arg7)
|
|
4126 {
|
|
4127 /* This function can GC */
|
|
4128 struct gcpro gcpro1;
|
|
4129 Lisp_Object args[9];
|
|
4130 args[0] = fn;
|
|
4131 args[1] = arg0;
|
|
4132 args[2] = arg1;
|
|
4133 args[3] = arg2;
|
|
4134 args[4] = arg3;
|
|
4135 args[5] = arg4;
|
|
4136 args[6] = arg5;
|
|
4137 args[7] = arg6;
|
|
4138 args[8] = arg7;
|
|
4139 GCPRO1 (args[0]);
|
|
4140 gcpro1.nvars = 9;
|
|
4141 RETURN_UNGCPRO (Ffuncall (9, args));
|
|
4142 }
|
|
4143
|
|
4144 Lisp_Object
|
|
4145 call0_in_buffer (struct buffer *buf, Lisp_Object fn)
|
|
4146 {
|
|
4147 int speccount = specpdl_depth ();
|
|
4148 Lisp_Object val;
|
|
4149
|
|
4150 if (current_buffer != buf)
|
|
4151 {
|
|
4152 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4153 set_buffer_internal (buf);
|
|
4154 }
|
|
4155 val = call0 (fn);
|
|
4156 unbind_to (speccount, Qnil);
|
|
4157 return val;
|
|
4158 }
|
|
4159
|
|
4160 Lisp_Object
|
|
4161 call1_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4162 Lisp_Object arg0)
|
|
4163 {
|
|
4164 int speccount = specpdl_depth ();
|
|
4165 Lisp_Object val;
|
|
4166
|
|
4167 if (current_buffer != buf)
|
|
4168 {
|
|
4169 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4170 set_buffer_internal (buf);
|
|
4171 }
|
|
4172 val = call1 (fn, arg0);
|
|
4173 unbind_to (speccount, Qnil);
|
|
4174 return val;
|
|
4175 }
|
|
4176
|
|
4177 Lisp_Object
|
|
4178 call2_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4179 Lisp_Object arg0, Lisp_Object arg1)
|
|
4180 {
|
|
4181 int speccount = specpdl_depth ();
|
|
4182 Lisp_Object val;
|
|
4183
|
|
4184 if (current_buffer != buf)
|
|
4185 {
|
|
4186 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4187 set_buffer_internal (buf);
|
|
4188 }
|
|
4189 val = call2 (fn, arg0, arg1);
|
|
4190 unbind_to (speccount, Qnil);
|
|
4191 return val;
|
|
4192 }
|
|
4193
|
|
4194 Lisp_Object
|
|
4195 call3_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4196 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4197 {
|
|
4198 int speccount = specpdl_depth ();
|
|
4199 Lisp_Object val;
|
|
4200
|
|
4201 if (current_buffer != buf)
|
|
4202 {
|
|
4203 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4204 set_buffer_internal (buf);
|
|
4205 }
|
|
4206 val = call3 (fn, arg0, arg1, arg2);
|
|
4207 unbind_to (speccount, Qnil);
|
|
4208 return val;
|
|
4209 }
|
|
4210
|
|
4211 Lisp_Object
|
|
4212 call4_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4213 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4214 Lisp_Object arg3)
|
|
4215 {
|
|
4216 int speccount = specpdl_depth ();
|
|
4217 Lisp_Object val;
|
|
4218
|
|
4219 if (current_buffer != buf)
|
|
4220 {
|
|
4221 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4222 set_buffer_internal (buf);
|
|
4223 }
|
|
4224 val = call4 (fn, arg0, arg1, arg2, arg3);
|
|
4225 unbind_to (speccount, Qnil);
|
|
4226 return val;
|
|
4227 }
|
|
4228
|
|
4229 Lisp_Object
|
|
4230 call5_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4231 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4232 Lisp_Object arg3, Lisp_Object arg4)
|
|
4233 {
|
|
4234 int speccount = specpdl_depth ();
|
|
4235 Lisp_Object val;
|
|
4236
|
|
4237 if (current_buffer != buf)
|
|
4238 {
|
|
4239 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4240 set_buffer_internal (buf);
|
|
4241 }
|
|
4242 val = call5 (fn, arg0, arg1, arg2, arg3, arg4);
|
|
4243 unbind_to (speccount, Qnil);
|
|
4244 return val;
|
|
4245 }
|
|
4246
|
|
4247 Lisp_Object
|
|
4248 call6_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4249 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4250 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4251 {
|
|
4252 int speccount = specpdl_depth ();
|
|
4253 Lisp_Object val;
|
|
4254
|
|
4255 if (current_buffer != buf)
|
|
4256 {
|
|
4257 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4258 set_buffer_internal (buf);
|
|
4259 }
|
|
4260 val = call6 (fn, arg0, arg1, arg2, arg3, arg4, arg5);
|
|
4261 unbind_to (speccount, Qnil);
|
|
4262 return val;
|
|
4263 }
|
|
4264
|
|
4265 Lisp_Object
|
|
4266 eval_in_buffer (struct buffer *buf, Lisp_Object form)
|
|
4267 {
|
|
4268 int speccount = specpdl_depth ();
|
|
4269 Lisp_Object val;
|
|
4270
|
|
4271 if (current_buffer != buf)
|
|
4272 {
|
|
4273 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4274 set_buffer_internal (buf);
|
|
4275 }
|
|
4276 val = Feval (form);
|
|
4277 unbind_to (speccount, Qnil);
|
|
4278 return val;
|
|
4279 }
|
|
4280
|
|
4281
|
|
4282 /***** Error-catching front-ends to eval, funcall, apply */
|
|
4283
|
|
4284 /* Call function fn on no arguments, with condition handler */
|
|
4285 Lisp_Object
|
|
4286 call0_with_handler (Lisp_Object handler, Lisp_Object fn)
|
|
4287 {
|
|
4288 /* This function can GC */
|
|
4289 struct gcpro gcpro1;
|
|
4290 Lisp_Object args[2];
|
|
4291 args[0] = handler;
|
|
4292 args[1] = fn;
|
|
4293 GCPRO1 (args[0]);
|
|
4294 gcpro1.nvars = 2;
|
|
4295 RETURN_UNGCPRO (Fcall_with_condition_handler (2, args));
|
|
4296 }
|
|
4297
|
|
4298 /* Call function fn with argument arg0, with condition handler */
|
|
4299 Lisp_Object
|
|
4300 call1_with_handler (Lisp_Object handler, Lisp_Object fn,
|
|
4301 Lisp_Object arg0)
|
|
4302 {
|
|
4303 /* This function can GC */
|
|
4304 struct gcpro gcpro1;
|
|
4305 Lisp_Object args[3];
|
|
4306 args[0] = handler;
|
|
4307 args[1] = fn;
|
|
4308 args[2] = arg0;
|
|
4309 GCPRO1 (args[0]);
|
|
4310 gcpro1.nvars = 3;
|
|
4311 RETURN_UNGCPRO (Fcall_with_condition_handler (3, args));
|
|
4312 }
|
|
4313
|
|
4314
|
|
4315 /* The following functions provide you with error-trapping versions
|
|
4316 of the various front-ends above. They take an additional
|
|
4317 "warning_string" argument; if non-zero, a warning with this
|
|
4318 string and the actual error that occurred will be displayed
|
|
4319 in the *Warnings* buffer if an error occurs. In all cases,
|
|
4320 QUIT is inhibited while these functions are running, and if
|
|
4321 an error occurs, Qunbound is returned instead of the normal
|
|
4322 return value.
|
|
4323 */
|
|
4324
|
185
|
4325 /* #### This stuff needs to catch throws as well. We need to
|
0
|
4326 improve internal_catch() so it can take a "catch anything"
|
|
4327 argument similar to Qt or Qerror for condition_case_1(). */
|
|
4328
|
|
4329 static Lisp_Object
|
|
4330 caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4331 {
|
|
4332 if (!NILP (errordata))
|
|
4333 {
|
|
4334 Lisp_Object args[2];
|
185
|
4335
|
0
|
4336 if (!NILP (arg))
|
|
4337 {
|
|
4338 char *str = (char *) get_opaque_ptr (arg);
|
|
4339 args[0] = build_string (str);
|
|
4340 }
|
|
4341 else
|
|
4342 args[0] = build_string ("error");
|
|
4343 /* #### This should call
|
|
4344 (with-output-to-string (display-error errordata))
|
|
4345 but that stuff is all in Lisp currently. */
|
|
4346 args[1] = errordata;
|
|
4347 warn_when_safe_lispobj
|
|
4348 (Qerror, Qwarning,
|
|
4349 emacs_doprnt_string_lisp ((CONST Bufbyte *) "%s: %s",
|
|
4350 Qnil, -1, 2, args));
|
|
4351 }
|
|
4352 return Qunbound;
|
|
4353 }
|
|
4354
|
|
4355 static Lisp_Object
|
|
4356 allow_quit_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4357 {
|
|
4358 if (CONSP (errordata) && EQ (XCAR (errordata), Qquit))
|
|
4359 return Fsignal (Qquit, XCDR (errordata));
|
|
4360 return caught_a_squirmer (errordata, arg);
|
|
4361 }
|
|
4362
|
|
4363 static Lisp_Object
|
|
4364 safe_run_hook_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4365 {
|
|
4366 Lisp_Object hook = Fcar (arg);
|
|
4367 arg = Fcdr (arg);
|
|
4368 /* Clear out the hook. */
|
|
4369 Fset (hook, Qnil);
|
|
4370 return caught_a_squirmer (errordata, arg);
|
|
4371 }
|
|
4372
|
|
4373 static Lisp_Object
|
|
4374 allow_quit_safe_run_hook_caught_a_squirmer (Lisp_Object errordata,
|
|
4375 Lisp_Object arg)
|
|
4376 {
|
|
4377 Lisp_Object hook = Fcar (arg);
|
|
4378 arg = Fcdr (arg);
|
|
4379 if (!CONSP (errordata) || !EQ (XCAR (errordata), Qquit))
|
|
4380 /* Clear out the hook. */
|
|
4381 Fset (hook, Qnil);
|
|
4382 return allow_quit_caught_a_squirmer (errordata, arg);
|
|
4383 }
|
|
4384
|
|
4385 static Lisp_Object
|
|
4386 catch_them_squirmers_eval_in_buffer (Lisp_Object cons)
|
|
4387 {
|
|
4388 return eval_in_buffer (XBUFFER (XCAR (cons)), XCDR (cons));
|
|
4389 }
|
|
4390
|
|
4391 Lisp_Object
|
|
4392 eval_in_buffer_trapping_errors (CONST char *warning_string,
|
|
4393 struct buffer *buf, Lisp_Object form)
|
|
4394 {
|
|
4395 int speccount = specpdl_depth ();
|
|
4396 Lisp_Object tem;
|
|
4397 Lisp_Object buffer = Qnil;
|
|
4398 Lisp_Object cons;
|
|
4399 Lisp_Object opaque;
|
|
4400 struct gcpro gcpro1, gcpro2;
|
|
4401
|
|
4402 XSETBUFFER (buffer, buf);
|
|
4403
|
|
4404 specbind (Qinhibit_quit, Qt);
|
|
4405 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4406
|
|
4407 cons = noseeum_cons (buffer, form);
|
|
4408 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4409 GCPRO2 (cons, opaque);
|
|
4410 /* Qerror not Qt, so you can get a backtrace */
|
|
4411 tem = condition_case_1 (Qerror,
|
|
4412 catch_them_squirmers_eval_in_buffer, cons,
|
|
4413 caught_a_squirmer, opaque);
|
|
4414 free_cons (XCONS (cons));
|
|
4415 if (OPAQUEP (opaque))
|
|
4416 free_opaque_ptr (opaque);
|
|
4417 UNGCPRO;
|
185
|
4418
|
0
|
4419 /* gc_currently_forbidden = 0; */
|
|
4420 return unbind_to (speccount, tem);
|
|
4421 }
|
|
4422
|
|
4423 static Lisp_Object
|
|
4424 catch_them_squirmers_run_hook (Lisp_Object hook_symbol)
|
|
4425 {
|
|
4426 /* This function can GC */
|
|
4427 run_hook (hook_symbol);
|
|
4428 return Qnil;
|
|
4429 }
|
|
4430
|
|
4431 Lisp_Object
|
|
4432 run_hook_trapping_errors (CONST char *warning_string, Lisp_Object hook_symbol)
|
|
4433 {
|
|
4434 int speccount = specpdl_depth ();
|
|
4435 Lisp_Object tem;
|
|
4436 Lisp_Object opaque;
|
|
4437 struct gcpro gcpro1;
|
|
4438
|
|
4439 if (!initialized || preparing_for_armageddon)
|
|
4440 return Qnil;
|
|
4441 tem = find_symbol_value (hook_symbol);
|
|
4442 if (NILP (tem) || UNBOUNDP (tem))
|
|
4443 return Qnil;
|
|
4444
|
|
4445 specbind (Qinhibit_quit, Qt);
|
|
4446
|
|
4447 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4448 GCPRO1 (opaque);
|
|
4449 /* Qerror not Qt, so you can get a backtrace */
|
|
4450 tem = condition_case_1 (Qerror,
|
|
4451 catch_them_squirmers_run_hook, hook_symbol,
|
|
4452 caught_a_squirmer, opaque);
|
|
4453 if (OPAQUEP (opaque))
|
|
4454 free_opaque_ptr (opaque);
|
|
4455 UNGCPRO;
|
|
4456
|
|
4457 return unbind_to (speccount, tem);
|
|
4458 }
|
|
4459
|
|
4460 /* Same as run_hook_trapping_errors() but also set the hook to nil
|
|
4461 if an error occurs. */
|
|
4462
|
|
4463 Lisp_Object
|
|
4464 safe_run_hook_trapping_errors (CONST char *warning_string,
|
|
4465 Lisp_Object hook_symbol,
|
|
4466 int allow_quit)
|
|
4467 {
|
|
4468 int speccount = specpdl_depth ();
|
|
4469 Lisp_Object tem;
|
|
4470 Lisp_Object cons = Qnil;
|
|
4471 struct gcpro gcpro1;
|
|
4472
|
|
4473 if (!initialized || preparing_for_armageddon)
|
|
4474 return Qnil;
|
|
4475 tem = find_symbol_value (hook_symbol);
|
|
4476 if (NILP (tem) || UNBOUNDP (tem))
|
|
4477 return Qnil;
|
|
4478
|
|
4479 if (!allow_quit)
|
|
4480 specbind (Qinhibit_quit, Qt);
|
|
4481
|
185
|
4482 cons = noseeum_cons (hook_symbol,
|
0
|
4483 warning_string ? make_opaque_ptr (warning_string)
|
|
4484 : Qnil);
|
|
4485 GCPRO1 (cons);
|
|
4486 /* Qerror not Qt, so you can get a backtrace */
|
|
4487 tem = condition_case_1 (Qerror,
|
|
4488 catch_them_squirmers_run_hook,
|
|
4489 hook_symbol,
|
|
4490 allow_quit ?
|
|
4491 allow_quit_safe_run_hook_caught_a_squirmer :
|
|
4492 safe_run_hook_caught_a_squirmer,
|
|
4493 cons);
|
|
4494 if (OPAQUEP (XCDR (cons)))
|
|
4495 free_opaque_ptr (XCDR (cons));
|
|
4496 free_cons (XCONS (cons));
|
|
4497 UNGCPRO;
|
|
4498
|
|
4499 return unbind_to (speccount, tem);
|
|
4500 }
|
|
4501
|
|
4502 static Lisp_Object
|
|
4503 catch_them_squirmers_call0 (Lisp_Object function)
|
|
4504 {
|
|
4505 /* This function can GC */
|
|
4506 return call0 (function);
|
|
4507 }
|
|
4508
|
|
4509 Lisp_Object
|
|
4510 call0_trapping_errors (CONST char *warning_string, Lisp_Object function)
|
|
4511 {
|
|
4512 int speccount = specpdl_depth ();
|
|
4513 Lisp_Object tem;
|
|
4514 Lisp_Object opaque = Qnil;
|
|
4515 struct gcpro gcpro1, gcpro2;
|
|
4516
|
|
4517 if (SYMBOLP (function))
|
|
4518 {
|
|
4519 tem = XSYMBOL (function)->function;
|
|
4520 if (NILP (tem) || UNBOUNDP (tem))
|
173
|
4521 return Qnil;
|
0
|
4522 }
|
|
4523
|
|
4524 GCPRO2 (opaque, function);
|
|
4525 specbind (Qinhibit_quit, Qt);
|
|
4526 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4527
|
|
4528 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4529 /* Qerror not Qt, so you can get a backtrace */
|
|
4530 tem = condition_case_1 (Qerror,
|
|
4531 catch_them_squirmers_call0, function,
|
|
4532 caught_a_squirmer, opaque);
|
|
4533 if (OPAQUEP (opaque))
|
|
4534 free_opaque_ptr (opaque);
|
|
4535 UNGCPRO;
|
|
4536
|
|
4537 /* gc_currently_forbidden = 0; */
|
|
4538 return unbind_to (speccount, tem);
|
|
4539 }
|
|
4540
|
|
4541 static Lisp_Object
|
|
4542 catch_them_squirmers_call1 (Lisp_Object cons)
|
|
4543 {
|
|
4544 /* This function can GC */
|
|
4545 return call1 (XCAR (cons), XCDR (cons));
|
|
4546 }
|
|
4547
|
|
4548 static Lisp_Object
|
|
4549 catch_them_squirmers_call2 (Lisp_Object cons)
|
|
4550 {
|
|
4551 /* This function can GC */
|
|
4552 return call2 (XCAR (cons), XCAR (XCDR (cons)), XCAR (XCDR (XCDR (cons))));
|
|
4553 }
|
|
4554
|
|
4555 Lisp_Object
|
|
4556 call1_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4557 Lisp_Object object)
|
|
4558 {
|
|
4559 int speccount = specpdl_depth ();
|
|
4560 Lisp_Object tem;
|
|
4561 Lisp_Object cons = Qnil;
|
|
4562 Lisp_Object opaque = Qnil;
|
|
4563 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4564
|
|
4565 if (SYMBOLP (function))
|
|
4566 {
|
|
4567 tem = XSYMBOL (function)->function;
|
|
4568 if (NILP (tem) || UNBOUNDP (tem))
|
173
|
4569 return Qnil;
|
0
|
4570 }
|
|
4571
|
|
4572 GCPRO4 (cons, opaque, function, object);
|
|
4573
|
|
4574 specbind (Qinhibit_quit, Qt);
|
|
4575 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4576
|
|
4577 cons = noseeum_cons (function, object);
|
|
4578 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4579 /* Qerror not Qt, so you can get a backtrace */
|
|
4580 tem = condition_case_1 (Qerror,
|
|
4581 catch_them_squirmers_call1, cons,
|
|
4582 caught_a_squirmer, opaque);
|
|
4583 if (OPAQUEP (opaque))
|
|
4584 free_opaque_ptr (opaque);
|
|
4585 free_cons (XCONS (cons));
|
|
4586 UNGCPRO;
|
185
|
4587
|
0
|
4588 /* gc_currently_forbidden = 0; */
|
|
4589 return unbind_to (speccount, tem);
|
|
4590 }
|
|
4591
|
|
4592 Lisp_Object
|
|
4593 call2_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4594 Lisp_Object object1, Lisp_Object object2)
|
|
4595 {
|
|
4596 int speccount = specpdl_depth ();
|
|
4597 Lisp_Object tem;
|
|
4598 Lisp_Object cons = Qnil;
|
|
4599 Lisp_Object opaque = Qnil;
|
|
4600 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4601
|
|
4602 if (SYMBOLP (function))
|
|
4603 {
|
|
4604 tem = XSYMBOL (function)->function;
|
|
4605 if (NILP (tem) || UNBOUNDP (tem))
|
173
|
4606 return Qnil;
|
0
|
4607 }
|
|
4608
|
|
4609 GCPRO5 (cons, opaque, function, object1, object2);
|
|
4610 specbind (Qinhibit_quit, Qt);
|
|
4611 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4612
|
|
4613 cons = list3 (function, object1, object2);
|
|
4614 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4615 /* Qerror not Qt, so you can get a backtrace */
|
|
4616 tem = condition_case_1 (Qerror,
|
|
4617 catch_them_squirmers_call2, cons,
|
|
4618 caught_a_squirmer, opaque);
|
|
4619 if (OPAQUEP (opaque))
|
|
4620 free_opaque_ptr (opaque);
|
|
4621 free_list (cons);
|
|
4622 UNGCPRO;
|
|
4623
|
|
4624 /* gc_currently_forbidden = 0; */
|
|
4625 return unbind_to (speccount, tem);
|
|
4626 }
|
|
4627
|
|
4628
|
|
4629 /**********************************************************************/
|
|
4630 /* The special binding stack */
|
|
4631 /**********************************************************************/
|
|
4632
|
2
|
4633 #define min_max_specpdl_size 400
|
|
4634
|
0
|
4635 static void
|
|
4636 grow_specpdl (void)
|
|
4637 {
|
|
4638 if (specpdl_size >= max_specpdl_size)
|
|
4639 {
|
2
|
4640 if (max_specpdl_size < min_max_specpdl_size)
|
|
4641 max_specpdl_size = min_max_specpdl_size;
|
0
|
4642 if (specpdl_size >= max_specpdl_size)
|
|
4643 {
|
|
4644 if (!NILP (Vdebug_on_error) || !NILP (Vdebug_on_signal))
|
|
4645 /* Leave room for some specpdl in the debugger. */
|
|
4646 max_specpdl_size = specpdl_size + 100;
|
|
4647 continuable_error
|
|
4648 ("Variable binding depth exceeds max-specpdl-size");
|
|
4649 }
|
|
4650 }
|
|
4651 specpdl_size *= 2;
|
|
4652 if (specpdl_size > max_specpdl_size)
|
|
4653 specpdl_size = max_specpdl_size;
|
185
|
4654 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size);
|
0
|
4655 specpdl_ptr = specpdl + specpdl_depth_counter;
|
|
4656 }
|
|
4657
|
|
4658
|
|
4659 /* Handle unbinding buffer-local variables */
|
|
4660 static Lisp_Object
|
|
4661 specbind_unwind_local (Lisp_Object ovalue)
|
|
4662 {
|
|
4663 Lisp_Object current = Fcurrent_buffer ();
|
|
4664 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4665 struct Lisp_Cons *victim = XCONS (ovalue);
|
|
4666 Lisp_Object buf = get_buffer (victim->car, 0);
|
|
4667 ovalue = victim->cdr;
|
|
4668
|
|
4669 free_cons (victim);
|
|
4670
|
|
4671 if (NILP (buf))
|
|
4672 {
|
|
4673 /* Deleted buffer -- do nothing */
|
|
4674 }
|
|
4675 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0)
|
|
4676 {
|
|
4677 /* Was buffer-local when binding was made, now no longer is.
|
|
4678 * (kill-local-variable can do this.)
|
|
4679 * Do nothing in this case.
|
|
4680 */
|
|
4681 }
|
|
4682 else if (EQ (buf, current))
|
|
4683 Fset (symbol, ovalue);
|
|
4684 else
|
|
4685 {
|
|
4686 /* Urk! Somebody switched buffers */
|
|
4687 struct gcpro gcpro1;
|
|
4688 GCPRO1 (current);
|
|
4689 Fset_buffer (buf);
|
|
4690 Fset (symbol, ovalue);
|
|
4691 Fset_buffer (current);
|
|
4692 UNGCPRO;
|
|
4693 }
|
173
|
4694 return symbol;
|
0
|
4695 }
|
|
4696
|
|
4697 static Lisp_Object
|
|
4698 specbind_unwind_wasnt_local (Lisp_Object buffer)
|
|
4699 {
|
|
4700 Lisp_Object current = Fcurrent_buffer ();
|
|
4701 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4702
|
|
4703 buffer = get_buffer (buffer, 0);
|
|
4704 if (NILP (buffer))
|
|
4705 {
|
|
4706 /* Deleted buffer -- do nothing */
|
|
4707 }
|
|
4708 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0)
|
|
4709 {
|
|
4710 /* Was buffer-local when binding was made, now no longer is.
|
|
4711 * (kill-local-variable can do this.)
|
|
4712 * Do nothing in this case.
|
|
4713 */
|
|
4714 }
|
|
4715 else if (EQ (buffer, current))
|
|
4716 Fkill_local_variable (symbol);
|
|
4717 else
|
|
4718 {
|
|
4719 /* Urk! Somebody switched buffers */
|
|
4720 struct gcpro gcpro1;
|
|
4721 GCPRO1 (current);
|
|
4722 Fset_buffer (buffer);
|
|
4723 Fkill_local_variable (symbol);
|
|
4724 Fset_buffer (current);
|
|
4725 UNGCPRO;
|
|
4726 }
|
173
|
4727 return symbol;
|
0
|
4728 }
|
|
4729
|
|
4730
|
|
4731 /* Don't want to include buffer.h just for this */
|
|
4732 extern struct buffer *current_buffer;
|
|
4733
|
|
4734 void
|
|
4735 specbind (Lisp_Object symbol, Lisp_Object value)
|
|
4736 {
|
|
4737 int buffer_local;
|
|
4738
|
|
4739 CHECK_SYMBOL (symbol);
|
|
4740
|
|
4741 if (specpdl_depth_counter >= specpdl_size)
|
|
4742 grow_specpdl ();
|
|
4743
|
|
4744 buffer_local = symbol_value_buffer_local_info (symbol, current_buffer);
|
|
4745 if (buffer_local == 0)
|
|
4746 {
|
|
4747 specpdl_ptr->old_value = find_symbol_value (symbol);
|
|
4748 specpdl_ptr->func = 0; /* Handled specially by unbind_to */
|
|
4749 }
|
|
4750 else if (buffer_local > 0)
|
|
4751 {
|
|
4752 /* Already buffer-local */
|
|
4753 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (),
|
|
4754 find_symbol_value (symbol));
|
|
4755 specpdl_ptr->func = specbind_unwind_local;
|
|
4756 }
|
|
4757 else
|
|
4758 {
|
|
4759 /* About to become buffer-local */
|
|
4760 specpdl_ptr->old_value = Fcurrent_buffer ();
|
|
4761 specpdl_ptr->func = specbind_unwind_wasnt_local;
|
|
4762 }
|
185
|
4763
|
0
|
4764 specpdl_ptr->symbol = symbol;
|
|
4765 specpdl_ptr++;
|
|
4766 specpdl_depth_counter++;
|
|
4767
|
|
4768 Fset (symbol, value);
|
|
4769 }
|
|
4770
|
|
4771 void
|
|
4772 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
|
|
4773 Lisp_Object arg)
|
|
4774 {
|
|
4775 if (specpdl_depth_counter >= specpdl_size)
|
|
4776 grow_specpdl ();
|
|
4777 specpdl_ptr->func = function;
|
|
4778 specpdl_ptr->symbol = Qnil;
|
|
4779 specpdl_ptr->old_value = arg;
|
|
4780 specpdl_ptr++;
|
|
4781 specpdl_depth_counter++;
|
|
4782 }
|
|
4783
|
|
4784 extern int check_sigio (void);
|
|
4785
|
|
4786 Lisp_Object
|
|
4787 unbind_to (int count, Lisp_Object value)
|
|
4788 {
|
|
4789 int quitf;
|
|
4790 struct gcpro gcpro1;
|
|
4791
|
|
4792 GCPRO1 (value);
|
|
4793
|
|
4794 check_quit (); /* make Vquit_flag accurate */
|
|
4795 quitf = !NILP (Vquit_flag);
|
|
4796 Vquit_flag = Qnil;
|
|
4797
|
|
4798 while (specpdl_depth_counter != count)
|
|
4799 {
|
|
4800 Lisp_Object ovalue;
|
|
4801 --specpdl_ptr;
|
|
4802 --specpdl_depth_counter;
|
|
4803
|
|
4804 ovalue = specpdl_ptr->old_value;
|
|
4805 if (specpdl_ptr->func != 0)
|
|
4806 /* An unwind-protect */
|
|
4807 (*specpdl_ptr->func) (ovalue);
|
|
4808 else
|
|
4809 Fset (specpdl_ptr->symbol, ovalue);
|
|
4810
|
|
4811 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
|
|
4812 /* There should never be anything here for us to remove.
|
|
4813 If so, it indicates a logic error in Emacs. Catches
|
|
4814 should get removed when a throw or signal occurs, or
|
|
4815 when a catch or condition-case exits normally. But
|
|
4816 it's too dangerous to just remove this code. --ben */
|
|
4817
|
|
4818 /* Furthermore, this code is not in FSFmacs!!!
|
|
4819 Braino on mly's part? */
|
|
4820 /* If we're unwound past the pdlcount of a catch frame,
|
|
4821 that catch can't possibly still be valid. */
|
|
4822 while (catchlist && catchlist->pdlcount > specpdl_depth_counter)
|
|
4823 {
|
|
4824 catchlist = catchlist->next;
|
|
4825 /* Don't mess with gcprolist, backtrace_list here */
|
|
4826 }
|
|
4827 #endif
|
|
4828 }
|
|
4829 if (quitf)
|
|
4830 Vquit_flag = Qt;
|
|
4831
|
|
4832 UNGCPRO;
|
|
4833
|
173
|
4834 return value;
|
0
|
4835 }
|
|
4836
|
|
4837
|
|
4838 int
|
|
4839 specpdl_depth (void)
|
|
4840 {
|
173
|
4841 return specpdl_depth_counter;
|
0
|
4842 }
|
|
4843
|
|
4844
|
|
4845 /* Get the value of symbol's global binding, even if that binding is
|
|
4846 not now dynamically visible. May return Qunbound or magic values. */
|
|
4847
|
|
4848 Lisp_Object
|
|
4849 top_level_value (Lisp_Object symbol)
|
|
4850 {
|
|
4851 REGISTER struct specbinding *ptr = specpdl;
|
|
4852
|
|
4853 CHECK_SYMBOL (symbol);
|
|
4854 for (; ptr != specpdl_ptr; ptr++)
|
|
4855 {
|
|
4856 if (EQ (ptr->symbol, symbol))
|
|
4857 return ptr->old_value;
|
|
4858 }
|
|
4859 return XSYMBOL (symbol)->value;
|
|
4860 }
|
|
4861
|
|
4862 #if 0
|
|
4863
|
|
4864 Lisp_Object
|
|
4865 top_level_set (Lisp_Object symbol, Lisp_Object newval)
|
|
4866 {
|
|
4867 REGISTER struct specbinding *ptr = specpdl;
|
|
4868
|
|
4869 CHECK_SYMBOL (symbol);
|
|
4870 for (; ptr != specpdl_ptr; ptr++)
|
|
4871 {
|
|
4872 if (EQ (ptr->symbol, symbol))
|
|
4873 {
|
|
4874 ptr->old_value = newval;
|
|
4875 return newval;
|
|
4876 }
|
|
4877 }
|
|
4878 return Fset (symbol, newval);
|
185
|
4879 }
|
0
|
4880
|
|
4881 #endif /* 0 */
|
|
4882
|
|
4883
|
|
4884 /**********************************************************************/
|
|
4885 /* Backtraces */
|
|
4886 /**********************************************************************/
|
|
4887
|
20
|
4888 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
|
0
|
4889 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
4890 The debugger is entered when that frame exits, if the flag is non-nil.
|
20
|
4891 */
|
|
4892 (level, flag))
|
0
|
4893 {
|
|
4894 REGISTER struct backtrace *backlist = backtrace_list;
|
|
4895 REGISTER int i;
|
|
4896
|
|
4897 CHECK_INT (level);
|
|
4898
|
|
4899 for (i = 0; backlist && i < XINT (level); i++)
|
|
4900 {
|
|
4901 backlist = backlist->next;
|
|
4902 }
|
|
4903
|
|
4904 if (backlist)
|
|
4905 backlist->debug_on_exit = !NILP (flag);
|
|
4906
|
|
4907 return flag;
|
|
4908 }
|
|
4909
|
|
4910 static void
|
|
4911 backtrace_specials (int speccount, int speclimit, Lisp_Object stream)
|
|
4912 {
|
|
4913 int printing_bindings = 0;
|
|
4914
|
|
4915 for (; speccount > speclimit; speccount--)
|
|
4916 {
|
|
4917 if (specpdl[speccount - 1].func == 0
|
|
4918 || specpdl[speccount - 1].func == specbind_unwind_local
|
|
4919 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local)
|
|
4920 {
|
|
4921 write_c_string (((!printing_bindings) ? " # bind (" : " "),
|
|
4922 stream);
|
|
4923 Fprin1 (specpdl[speccount - 1].symbol, stream);
|
|
4924 printing_bindings = 1;
|
|
4925 }
|
|
4926 else
|
|
4927 {
|
|
4928 if (printing_bindings) write_c_string (")\n", stream);
|
|
4929 write_c_string (" # (unwind-protect ...)\n", stream);
|
|
4930 printing_bindings = 0;
|
|
4931 }
|
|
4932 }
|
|
4933 if (printing_bindings) write_c_string (")\n", stream);
|
|
4934 }
|
|
4935
|
20
|
4936 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /*
|
0
|
4937 Print a trace of Lisp function calls currently active.
|
|
4938 Option arg STREAM specifies the output stream to send the backtrace to,
|
|
4939 and defaults to the value of `standard-output'. Optional second arg
|
|
4940 DETAILED means show places where currently active variable bindings,
|
|
4941 catches, condition-cases, and unwind-protects were made as well as
|
185
|
4942 function calls.
|
20
|
4943 */
|
|
4944 (stream, detailed))
|
0
|
4945 {
|
|
4946 struct backtrace *backlist = backtrace_list;
|
|
4947 struct catchtag *catches = catchlist;
|
|
4948 int speccount = specpdl_depth_counter;
|
|
4949
|
|
4950 int old_nl = print_escape_newlines;
|
|
4951 int old_pr = print_readably;
|
|
4952 Lisp_Object old_level = Vprint_level;
|
|
4953 Lisp_Object oiq = Vinhibit_quit;
|
|
4954 struct gcpro gcpro1, gcpro2;
|
|
4955
|
|
4956 /* We can't allow quits in here because that could cause the values
|
|
4957 of print_readably and print_escape_newlines to get screwed up.
|
|
4958 Normally we would use a record_unwind_protect but that would
|
|
4959 screw up the functioning of this function. */
|
|
4960 Vinhibit_quit = Qt;
|
|
4961
|
|
4962 entering_debugger = 0;
|
|
4963
|
|
4964 Vprint_level = make_int (3);
|
|
4965 print_readably = 0;
|
|
4966 print_escape_newlines = 1;
|
|
4967
|
|
4968 GCPRO2 (stream, old_level);
|
|
4969
|
|
4970 if (NILP (stream))
|
|
4971 stream = Vstandard_output;
|
|
4972 if (!noninteractive && (NILP (stream) || EQ (stream, Qt)))
|
|
4973 stream = Fselected_frame (Qnil);
|
|
4974
|
|
4975 for (;;)
|
|
4976 {
|
|
4977 if (!NILP (detailed) && catches && catches->backlist == backlist)
|
|
4978 {
|
|
4979 int catchpdl = catches->pdlcount;
|
|
4980 if (specpdl[catchpdl].func == condition_case_unwind
|
|
4981 && speccount > catchpdl)
|
|
4982 /* This is a condition-case catchpoint */
|
|
4983 catchpdl = catchpdl + 1;
|
185
|
4984
|
0
|
4985 backtrace_specials (speccount, catchpdl, stream);
|
|
4986
|
|
4987 speccount = catches->pdlcount;
|
|
4988 if (catchpdl == speccount)
|
|
4989 {
|
|
4990 write_c_string (" # (catch ", stream);
|
|
4991 Fprin1 (catches->tag, stream);
|
|
4992 write_c_string (" ...)\n", stream);
|
|
4993 }
|
|
4994 else
|
|
4995 {
|
|
4996 write_c_string (" # (condition-case ... . ", stream);
|
|
4997 Fprin1 (Fcdr (Fcar (catches->tag)), stream);
|
|
4998 write_c_string (")\n", stream);
|
|
4999 }
|
|
5000 catches = catches->next;
|
|
5001 }
|
|
5002 else if (!backlist)
|
|
5003 break;
|
|
5004 else
|
|
5005 {
|
|
5006 if (!NILP (detailed) && backlist->pdlcount < speccount)
|
|
5007 {
|
|
5008 backtrace_specials (speccount, backlist->pdlcount, stream);
|
|
5009 speccount = backlist->pdlcount;
|
|
5010 }
|
|
5011 write_c_string (((backlist->debug_on_exit) ? "* " : " "),
|
|
5012 stream);
|
|
5013 if (backlist->nargs == UNEVALLED)
|
|
5014 {
|
|
5015 Fprin1 (Fcons (*backlist->function, *backlist->args), stream);
|
|
5016 write_c_string ("\n", stream); /* from FSFmacs 19.30 */
|
|
5017 }
|
|
5018 else
|
|
5019 {
|
|
5020 Lisp_Object tem = *backlist->function;
|
|
5021 Fprin1 (tem, stream); /* This can QUIT */
|
|
5022 write_c_string ("(", stream);
|
|
5023 if (backlist->nargs == MANY)
|
|
5024 {
|
|
5025 int i;
|
|
5026 Lisp_Object tail = Qnil;
|
|
5027 struct gcpro ngcpro1;
|
|
5028
|
|
5029 NGCPRO1 (tail);
|
|
5030 for (tail = *backlist->args, i = 0;
|
|
5031 !NILP (tail);
|
|
5032 tail = Fcdr (tail), i++)
|
|
5033 {
|
|
5034 if (i != 0) write_c_string (" ", stream);
|
|
5035 Fprin1 (Fcar (tail), stream);
|
|
5036 }
|
|
5037 NUNGCPRO;
|
|
5038 }
|
|
5039 else
|
|
5040 {
|
|
5041 int i;
|
|
5042 for (i = 0; i < backlist->nargs; i++)
|
|
5043 {
|
|
5044 if (i != 0) write_c_string (" ", stream);
|
|
5045 Fprin1 (backlist->args[i], stream);
|
|
5046 }
|
|
5047 }
|
|
5048 }
|
|
5049 write_c_string (")\n", stream);
|
|
5050 backlist = backlist->next;
|
|
5051 }
|
|
5052 }
|
|
5053 Vprint_level = old_level;
|
|
5054 print_readably = old_pr;
|
|
5055 print_escape_newlines = old_nl;
|
|
5056 UNGCPRO;
|
|
5057 Vinhibit_quit = oiq;
|
|
5058 return Qnil;
|
|
5059 }
|
|
5060
|
|
5061
|
20
|
5062 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, "", /*
|
0
|
5063 Return the function and arguments N frames up from current execution point.
|
|
5064 If that frame has not evaluated the arguments yet (or is a special form),
|
|
5065 the value is (nil FUNCTION ARG-FORMS...).
|
|
5066 If that frame has evaluated its arguments and called its function already,
|
|
5067 the value is (t FUNCTION ARG-VALUES...).
|
|
5068 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
5069 FUNCTION is whatever was supplied as car of evaluated list,
|
|
5070 or a lambda expression for macro calls.
|
|
5071 If N is more than the number of frames, the value is nil.
|
20
|
5072 */
|
|
5073 (nframes))
|
0
|
5074 {
|
|
5075 REGISTER struct backtrace *backlist = backtrace_list;
|
|
5076 REGISTER int i;
|
|
5077 Lisp_Object tem;
|
|
5078
|
|
5079 CHECK_NATNUM (nframes);
|
|
5080
|
|
5081 /* Find the frame requested. */
|
|
5082 for (i = XINT (nframes); backlist && (i-- > 0);)
|
|
5083 backlist = backlist->next;
|
|
5084
|
|
5085 if (!backlist)
|
|
5086 return Qnil;
|
|
5087 if (backlist->nargs == UNEVALLED)
|
|
5088 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
|
|
5089 else
|
|
5090 {
|
|
5091 if (backlist->nargs == MANY)
|
|
5092 tem = *backlist->args;
|
|
5093 else
|
|
5094 tem = Flist (backlist->nargs, backlist->args);
|
|
5095
|
|
5096 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
5097 }
|
|
5098 }
|
|
5099
|
|
5100
|
|
5101 /**********************************************************************/
|
|
5102 /* Warnings */
|
|
5103 /**********************************************************************/
|
|
5104
|
|
5105 void
|
|
5106 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level,
|
|
5107 Lisp_Object obj)
|
|
5108 {
|
|
5109 obj = list1 (list3 (class, level, obj));
|
|
5110 if (NILP (Vpending_warnings))
|
|
5111 Vpending_warnings = Vpending_warnings_tail = obj;
|
|
5112 else
|
|
5113 {
|
|
5114 Fsetcdr (Vpending_warnings_tail, obj);
|
|
5115 Vpending_warnings_tail = obj;
|
|
5116 }
|
|
5117 }
|
|
5118
|
|
5119 /* #### This should probably accept Lisp objects; but then we have
|
|
5120 to make sure that Feval() isn't called, since it might not be safe.
|
|
5121
|
|
5122 An alternative approach is to just pass some non-string type of
|
|
5123 Lisp Object to warn_when_safe_lispobj(); `prin1-to-string' will
|
|
5124 automatically be called when it is safe to do so. */
|
|
5125
|
|
5126 void
|
|
5127 warn_when_safe (Lisp_Object class, Lisp_Object level, CONST char *fmt, ...)
|
|
5128 {
|
|
5129 Lisp_Object obj;
|
|
5130 va_list args;
|
|
5131
|
|
5132 va_start (args, fmt);
|
|
5133 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt),
|
|
5134 Qnil, -1, args);
|
|
5135 va_end (args);
|
|
5136
|
|
5137 warn_when_safe_lispobj (class, level, obj);
|
|
5138 }
|
|
5139
|
|
5140
|
|
5141
|
|
5142
|
|
5143 /**********************************************************************/
|
|
5144 /* Initialization */
|
|
5145 /**********************************************************************/
|
|
5146
|
|
5147 void
|
|
5148 syms_of_eval (void)
|
|
5149 {
|
|
5150 defsymbol (&Qinhibit_quit, "inhibit-quit");
|
|
5151 defsymbol (&Qautoload, "autoload");
|
|
5152 defsymbol (&Qdebug_on_error, "debug-on-error");
|
|
5153 defsymbol (&Qstack_trace_on_error, "stack-trace-on-error");
|
|
5154 defsymbol (&Qdebug_on_signal, "debug-on-signal");
|
|
5155 defsymbol (&Qstack_trace_on_signal, "stack-trace-on-signal");
|
|
5156 defsymbol (&Qdebugger, "debugger");
|
|
5157 defsymbol (&Qmacro, "macro");
|
|
5158 defsymbol (&Qand_rest, "&rest");
|
|
5159 defsymbol (&Qand_optional, "&optional");
|
|
5160 /* Note that the process code also uses Qexit */
|
|
5161 defsymbol (&Qexit, "exit");
|
|
5162 defsymbol (&Qsetq, "setq");
|
|
5163 defsymbol (&Qinteractive, "interactive");
|
|
5164 defsymbol (&Qcommandp, "commandp");
|
|
5165 defsymbol (&Qdefun, "defun");
|
|
5166 defsymbol (&Qprogn, "progn");
|
|
5167 defsymbol (&Qvalues, "values");
|
|
5168 defsymbol (&Qdisplay_warning, "display-warning");
|
|
5169 defsymbol (&Qrun_hooks, "run-hooks");
|
|
5170
|
20
|
5171 DEFSUBR (For);
|
|
5172 DEFSUBR (Fand);
|
|
5173 DEFSUBR (Fif);
|
|
5174 DEFSUBR (Fcond);
|
|
5175 DEFSUBR (Fprogn);
|
|
5176 DEFSUBR (Fprog1);
|
|
5177 DEFSUBR (Fprog2);
|
|
5178 DEFSUBR (Fsetq);
|
|
5179 DEFSUBR (Fquote);
|
|
5180 DEFSUBR (Ffunction);
|
|
5181 DEFSUBR (Fdefun);
|
|
5182 DEFSUBR (Fdefmacro);
|
|
5183 DEFSUBR (Fdefvar);
|
|
5184 DEFSUBR (Fdefconst);
|
|
5185 DEFSUBR (Fuser_variable_p);
|
|
5186 DEFSUBR (Flet);
|
|
5187 DEFSUBR (FletX);
|
|
5188 DEFSUBR (Fwhile);
|
|
5189 DEFSUBR (Fmacroexpand_internal);
|
|
5190 DEFSUBR (Fcatch);
|
|
5191 DEFSUBR (Fthrow);
|
|
5192 DEFSUBR (Funwind_protect);
|
|
5193 DEFSUBR (Fcondition_case);
|
|
5194 DEFSUBR (Fcall_with_condition_handler);
|
|
5195 DEFSUBR (Fsignal);
|
|
5196 DEFSUBR (Finteractive_p);
|
|
5197 DEFSUBR (Fcommandp);
|
|
5198 DEFSUBR (Fcommand_execute);
|
|
5199 DEFSUBR (Fautoload);
|
|
5200 DEFSUBR (Feval);
|
|
5201 DEFSUBR (Fapply);
|
|
5202 DEFSUBR (Ffuncall);
|
|
5203 DEFSUBR (Ffunction_min_args);
|
|
5204 DEFSUBR (Ffunction_max_args);
|
|
5205 DEFSUBR (Frun_hooks);
|
|
5206 DEFSUBR (Frun_hook_with_args);
|
|
5207 DEFSUBR (Frun_hook_with_args_until_success);
|
|
5208 DEFSUBR (Frun_hook_with_args_until_failure);
|
|
5209 DEFSUBR (Ffetch_bytecode);
|
|
5210 DEFSUBR (Fbacktrace_debug);
|
|
5211 DEFSUBR (Fbacktrace);
|
|
5212 DEFSUBR (Fbacktrace_frame);
|
0
|
5213 }
|
|
5214
|
|
5215 void
|
|
5216 reinit_eval (void)
|
|
5217 {
|
|
5218 specpdl_ptr = specpdl;
|
|
5219 specpdl_depth_counter = 0;
|
|
5220 catchlist = 0;
|
|
5221 Vcondition_handlers = Qnil;
|
|
5222 backtrace_list = 0;
|
|
5223 Vquit_flag = Qnil;
|
|
5224 debug_on_next_call = 0;
|
|
5225 lisp_eval_depth = 0;
|
|
5226 entering_debugger = 0;
|
|
5227 }
|
|
5228
|
|
5229 void
|
|
5230 vars_of_eval (void)
|
|
5231 {
|
|
5232 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /*
|
|
5233 Limit on number of Lisp variable bindings & unwind-protects before error.
|
|
5234 */ );
|
|
5235
|
|
5236 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /*
|
|
5237 Limit on depth in `eval', `apply' and `funcall' before error.
|
|
5238 This limit is to catch infinite recursions for you before they cause
|
|
5239 actual stack overflow in C, which would be fatal for Emacs.
|
|
5240 You can safely make it considerably larger than its default value,
|
|
5241 if that proves inconveniently small.
|
|
5242 */ );
|
|
5243
|
|
5244 DEFVAR_LISP ("quit-flag", &Vquit_flag /*
|
|
5245 Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
|
|
5246 Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'.
|
|
5247 */ );
|
|
5248 Vquit_flag = Qnil;
|
|
5249
|
|
5250 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /*
|
|
5251 Non-nil inhibits C-g quitting from happening immediately.
|
|
5252 Note that `quit-flag' will still be set by typing C-g,
|
|
5253 so a quit will be signalled as soon as `inhibit-quit' is nil.
|
|
5254 To prevent this happening, set `quit-flag' to nil
|
|
5255 before making `inhibit-quit' nil. The value of `inhibit-quit' is
|
|
5256 ignored if a critical quit is requested by typing control-shift-G in
|
|
5257 an X frame.
|
|
5258 */ );
|
|
5259 Vinhibit_quit = Qnil;
|
|
5260
|
|
5261 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /*
|
|
5262 *Non-nil means automatically display a backtrace buffer
|
|
5263 after any error that is not handled by a `condition-case'.
|
|
5264 If the value is a list, an error only means to display a backtrace
|
|
5265 if one of its condition symbols appears in the list.
|
|
5266 See also variable `stack-trace-on-signal'.
|
|
5267 */ );
|
|
5268 Vstack_trace_on_error = Qnil;
|
|
5269
|
|
5270 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /*
|
|
5271 *Non-nil means automatically display a backtrace buffer
|
|
5272 after any error that is signalled, whether or not it is handled by
|
|
5273 a `condition-case'.
|
|
5274 If the value is a list, an error only means to display a backtrace
|
|
5275 if one of its condition symbols appears in the list.
|
|
5276 See also variable `stack-trace-on-error'.
|
|
5277 */ );
|
|
5278 Vstack_trace_on_signal = Qnil;
|
|
5279
|
163
|
5280 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors /*
|
|
5281 *List of errors for which the debugger should not be called.
|
|
5282 Each element may be a condition-name or a regexp that matches error messages.
|
|
5283 If any element applies to a given error, that error skips the debugger
|
|
5284 and just returns to top level.
|
|
5285 This overrides the variable `debug-on-error'.
|
|
5286 It does not apply to errors handled by `condition-case'.
|
|
5287 */ );
|
|
5288 Vdebug_ignored_errors = Qnil;
|
|
5289
|
0
|
5290 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
|
|
5291 *Non-nil means enter debugger if an unhandled error is signalled.
|
|
5292 The debugger will not be entered if the error is handled by
|
|
5293 a `condition-case'.
|
|
5294 If the value is a list, an error only means to enter the debugger
|
|
5295 if one of its condition symbols appears in the list.
|
181
|
5296 This variable is overridden by `debug-ignored-errors'.
|
0
|
5297 See also variables `debug-on-quit' and `debug-on-signal'.
|
|
5298 */ );
|
|
5299 Vdebug_on_error = Qnil;
|
|
5300
|
|
5301 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /*
|
|
5302 *Non-nil means enter debugger if an error is signalled.
|
|
5303 The debugger will be entered whether or not the error is handled by
|
|
5304 a `condition-case'.
|
|
5305 If the value is a list, an error only means to enter the debugger
|
|
5306 if one of its condition symbols appears in the list.
|
|
5307 See also variable `debug-on-quit'.
|
|
5308 */ );
|
|
5309 Vdebug_on_signal = Qnil;
|
|
5310
|
|
5311 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /*
|
|
5312 *Non-nil means enter debugger if quit is signalled (C-G, for example).
|
|
5313 Does not apply if quit is handled by a `condition-case'. Entering the
|
|
5314 debugger can also be achieved at any time (for X11 console) by typing
|
|
5315 control-shift-G to signal a critical quit.
|
|
5316 */ );
|
|
5317 debug_on_quit = 0;
|
|
5318
|
|
5319 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /*
|
|
5320 Non-nil means enter debugger before next `eval', `apply' or `funcall'.
|
|
5321 */ );
|
|
5322
|
|
5323 DEFVAR_LISP ("debugger", &Vdebugger /*
|
|
5324 Function to call to invoke debugger.
|
|
5325 If due to frame exit, args are `exit' and the value being returned;
|
|
5326 this function's value will be returned instead of that.
|
|
5327 If due to error, args are `error' and a list of the args to `signal'.
|
|
5328 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
5329 If due to `eval' entry, one arg, t.
|
|
5330 */ );
|
|
5331 Vdebugger = Qnil;
|
|
5332
|
|
5333 preparing_for_armageddon = 0;
|
|
5334
|
|
5335 staticpro (&Vpending_warnings);
|
|
5336 Vpending_warnings = Qnil;
|
|
5337 Vpending_warnings_tail = Qnil; /* no need to protect this */
|
|
5338
|
|
5339 in_warnings = 0;
|
|
5340
|
|
5341 staticpro (&Vautoload_queue);
|
|
5342 Vautoload_queue = Qnil;
|
|
5343
|
|
5344 staticpro (&Vcondition_handlers);
|
|
5345
|
|
5346 staticpro (&Vcurrent_warning_class);
|
|
5347 Vcurrent_warning_class = Qnil;
|
|
5348
|
|
5349 staticpro (&Vcurrent_error_state);
|
|
5350 Vcurrent_error_state = Qnil; /* errors as normal */
|
|
5351
|
|
5352 Qunbound_suspended_errors_tag = make_opaque_long (0);
|
|
5353 staticpro (&Qunbound_suspended_errors_tag);
|
|
5354
|
|
5355 specpdl_size = 50;
|
|
5356 specpdl_depth_counter = 0;
|
185
|
5357 specpdl = xnew_array (struct specbinding, specpdl_size);
|
0
|
5358 /* XEmacs change: increase these values. */
|
|
5359 max_specpdl_size = 3000;
|
|
5360 max_lisp_eval_depth = 500;
|
|
5361 throw_level = 0;
|
|
5362
|
|
5363 reinit_eval ();
|
|
5364 }
|