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