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