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