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);
|
223
|
2859 #if 0 /* #### Not called anymore */
|
0
|
2860 static Lisp_Object funcall_subr (struct Lisp_Subr *sub, Lisp_Object args[]);
|
223
|
2861 #endif
|
0
|
2862
|
|
2863 static int in_warnings;
|
|
2864
|
|
2865 static Lisp_Object
|
|
2866 in_warnings_restore (Lisp_Object minimus)
|
|
2867 {
|
|
2868 in_warnings = 0;
|
|
2869 return Qnil;
|
|
2870 }
|
|
2871
|
195
|
2872 #define inline_funcall_subr(rv, subr, av) \
|
|
2873 do { \
|
|
2874 switch (subr->max_args) { \
|
|
2875 case 0: rv = (subr_function(subr))(); \
|
|
2876 break; \
|
|
2877 case 1: rv = (subr_function(subr))(av[0]); \
|
|
2878 break; \
|
|
2879 case 2: rv = (subr_function(subr))(av[0], av[1]); \
|
|
2880 break; \
|
|
2881 case 3: rv = (subr_function(subr))(av[0], av[1], av[2]); \
|
|
2882 break; \
|
|
2883 case 4: rv = (subr_function(subr))(av[0], av[1], av[2], av[3]); \
|
|
2884 break; \
|
|
2885 case 5: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4]); \
|
|
2886 break; \
|
|
2887 case 6: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2888 av[5]); \
|
|
2889 break; \
|
|
2890 case 7: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2891 av[5], av[6]); \
|
|
2892 break; \
|
|
2893 case 8: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2894 av[5], av[6], av[7]); \
|
|
2895 break; \
|
|
2896 case 9: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2897 av[5], av[6], av[7], av[8]); \
|
|
2898 break; \
|
|
2899 case 10: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2900 av[5], av[6], av[7], av[8], av[9]); \
|
|
2901 break; \
|
|
2902 case 11: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2903 av[5], av[6], av[7], av[8], av[9], \
|
|
2904 av[10]); \
|
|
2905 break; \
|
|
2906 case 12: rv = (subr_function(subr))(av[0], av[1], av[2], av[3], av[4], \
|
|
2907 av[5], av[6], av[7], av[8], av[9], \
|
|
2908 av[10], av[11]); \
|
|
2909 break; \
|
|
2910 } \
|
|
2911 } while (0)
|
0
|
2912
|
20
|
2913 DEFUN ("eval", Feval, 1, 1, 0, /*
|
0
|
2914 Evaluate FORM and return its value.
|
20
|
2915 */
|
|
2916 (form))
|
0
|
2917 {
|
|
2918 /* This function can GC */
|
|
2919 Lisp_Object fun, val, original_fun, original_args;
|
|
2920 int nargs;
|
|
2921 struct backtrace backtrace;
|
|
2922
|
|
2923 /* I think this is a pretty safe place to call Lisp code, don't you? */
|
|
2924 while (!in_warnings && !NILP (Vpending_warnings))
|
|
2925 {
|
|
2926 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
2927 int speccount = specpdl_depth ();
|
|
2928 Lisp_Object this_warning_cons, this_warning, class, level, messij;
|
|
2929
|
|
2930 record_unwind_protect (in_warnings_restore, Qnil);
|
|
2931 in_warnings = 1;
|
|
2932 this_warning_cons = Vpending_warnings;
|
|
2933 this_warning = XCAR (this_warning_cons);
|
|
2934 /* in case an error occurs in the warn function, at least
|
|
2935 it won't happen infinitely */
|
|
2936 Vpending_warnings = XCDR (Vpending_warnings);
|
|
2937 free_cons (XCONS (this_warning_cons));
|
|
2938 class = XCAR (this_warning);
|
|
2939 level = XCAR (XCDR (this_warning));
|
|
2940 messij = XCAR (XCDR (XCDR (this_warning)));
|
|
2941 free_list (this_warning);
|
185
|
2942
|
0
|
2943 if (NILP (Vpending_warnings))
|
|
2944 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary,
|
|
2945 but safer */
|
|
2946
|
|
2947 GCPRO4 (form, class, level, messij);
|
|
2948 if (!STRINGP (messij))
|
|
2949 messij = Fprin1_to_string (messij, Qnil);
|
|
2950 call3 (Qdisplay_warning, class, messij, level);
|
|
2951 UNGCPRO;
|
|
2952 unbind_to (speccount, Qnil);
|
|
2953 }
|
|
2954
|
|
2955 if (!CONSP (form))
|
|
2956 {
|
|
2957 if (!SYMBOLP (form))
|
|
2958 return form;
|
|
2959
|
|
2960 val = Fsymbol_value (form);
|
|
2961
|
|
2962 return val;
|
|
2963 }
|
|
2964
|
|
2965 QUIT;
|
|
2966 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
2967 {
|
|
2968 struct gcpro gcpro1;
|
|
2969 GCPRO1 (form);
|
|
2970 garbage_collect_1 ();
|
|
2971 UNGCPRO;
|
|
2972 }
|
|
2973
|
|
2974 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
2975 {
|
|
2976 if (max_lisp_eval_depth < 100)
|
|
2977 max_lisp_eval_depth = 100;
|
|
2978 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
2979 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
2980 }
|
|
2981
|
195
|
2982 /*
|
|
2983 * At this point we know that `form' is a Lisp_Cons so we can safely
|
|
2984 * use XCAR and XCDR.
|
|
2985 */
|
|
2986 original_fun = XCAR (form);
|
|
2987 original_args = XCDR (form);
|
|
2988
|
|
2989 /*
|
|
2990 * Formerly we used a call to Flength here, but that is slow and
|
|
2991 * wasteful due to type checking, stack push/pop and initialization.
|
|
2992 * We know we're dealing with a cons, so open code it for speed.
|
|
2993 *
|
|
2994 * We call QUIT in the loop so that a circular arg list won't lock
|
|
2995 * up the editor.
|
|
2996 */
|
|
2997 for (nargs = 0, val = original_args ; CONSP (val) ; val = XCDR (val))
|
|
2998 {
|
|
2999 nargs++;
|
|
3000 QUIT;
|
|
3001 }
|
|
3002 if (! NILP (val))
|
|
3003 signal_simple_error ("Argument list must be nil-terminated",
|
|
3004 original_args);
|
0
|
3005
|
|
3006 #ifdef EMACS_BTL
|
|
3007 backtrace.id_number = 0;
|
|
3008 #endif
|
|
3009 backtrace.pdlcount = specpdl_depth_counter;
|
|
3010 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
3011 backtrace.args = &original_args;
|
|
3012 backtrace.nargs = UNEVALLED;
|
|
3013 backtrace.evalargs = 1;
|
|
3014 backtrace.debug_on_exit = 0;
|
116
|
3015 PUSH_BACKTRACE (backtrace);
|
0
|
3016
|
|
3017 if (debug_on_next_call)
|
|
3018 do_debug_on_call (Qt);
|
|
3019
|
|
3020 /* At this point, only original_fun and original_args
|
|
3021 have values that will be used below */
|
|
3022 retry:
|
|
3023 fun = indirect_function (original_fun, 1);
|
|
3024
|
|
3025 if (SUBRP (fun))
|
|
3026 {
|
|
3027 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3028 int max_args = subr->max_args;
|
|
3029 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
3030 Lisp_Object args_left;
|
|
3031 REGISTER int i;
|
|
3032
|
|
3033 args_left = original_args;
|
|
3034
|
|
3035 if (nargs < subr->min_args
|
|
3036 || (max_args >= 0 && max_args < nargs))
|
|
3037 {
|
185
|
3038 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3039 list2 (fun, make_int (nargs)));
|
|
3040 }
|
|
3041
|
|
3042 if (max_args == UNEVALLED)
|
|
3043 {
|
|
3044 backtrace.evalargs = 0;
|
|
3045 val = ((subr_function (subr)) (args_left));
|
|
3046 }
|
|
3047
|
|
3048 else if (max_args == MANY)
|
|
3049 {
|
|
3050 /* Pass a vector of evaluated arguments */
|
|
3051 Lisp_Object *vals;
|
|
3052 REGISTER int argnum;
|
|
3053 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3054
|
185
|
3055 vals = alloca_array (Lisp_Object, nargs);
|
0
|
3056
|
|
3057 GCPRO3 (args_left, fun, vals[0]);
|
|
3058 gcpro3.nvars = 0;
|
|
3059
|
|
3060 argnum = 0;
|
195
|
3061 while (CONSP (args_left))
|
0
|
3062 {
|
195
|
3063 vals[argnum++] = Feval (XCAR (args_left));
|
|
3064 args_left = XCDR (args_left);
|
0
|
3065 gcpro3.nvars = argnum;
|
|
3066 }
|
|
3067
|
|
3068 backtrace.args = vals;
|
|
3069 backtrace.nargs = nargs;
|
|
3070
|
74
|
3071 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
|
|
3072 (nargs, vals);
|
0
|
3073
|
|
3074 /* Have to duplicate this code because if the
|
|
3075 * debugger is called it must be in a scope in
|
|
3076 * which the `alloca'-ed data in vals is still valid.
|
|
3077 * (And GC-protected.)
|
|
3078 */
|
|
3079 lisp_eval_depth--;
|
|
3080 if (backtrace.debug_on_exit)
|
|
3081 val = do_debug_on_exit (val);
|
116
|
3082 POP_BACKTRACE (backtrace);
|
0
|
3083 UNGCPRO;
|
173
|
3084 return val;
|
0
|
3085 }
|
|
3086
|
|
3087 else
|
|
3088 {
|
|
3089 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3090
|
|
3091 GCPRO3 (args_left, fun, fun);
|
|
3092 gcpro3.var = argvals;
|
|
3093 gcpro3.nvars = 0;
|
|
3094
|
195
|
3095 for (i = 0; i < nargs; args_left = XCDR (args_left))
|
0
|
3096 {
|
195
|
3097 argvals[i] = Feval (XCAR (args_left));
|
0
|
3098 gcpro3.nvars = ++i;
|
|
3099 }
|
185
|
3100
|
0
|
3101 UNGCPRO;
|
185
|
3102
|
195
|
3103 /* i == nargs at this point */
|
|
3104 for (; i < max_args; i++)
|
0
|
3105 argvals[i] = Qnil;
|
|
3106
|
|
3107 backtrace.args = argvals;
|
|
3108 backtrace.nargs = nargs;
|
|
3109
|
195
|
3110 /* val = funcall_subr (subr, argvals); */
|
|
3111 inline_funcall_subr(val, subr, argvals);
|
0
|
3112 }
|
|
3113 }
|
|
3114 else if (COMPILED_FUNCTIONP (fun))
|
|
3115 val = apply_lambda (fun, nargs, original_args);
|
|
3116 else
|
|
3117 {
|
|
3118 Lisp_Object funcar;
|
|
3119
|
|
3120 if (!CONSP (fun))
|
|
3121 goto invalid_function;
|
195
|
3122 funcar = XCAR (fun);
|
0
|
3123 if (!SYMBOLP (funcar))
|
|
3124 goto invalid_function;
|
|
3125 if (EQ (funcar, Qautoload))
|
|
3126 {
|
|
3127 do_autoload (fun, original_fun);
|
|
3128 goto retry;
|
|
3129 }
|
|
3130 if (EQ (funcar, Qmacro))
|
195
|
3131 val = Feval (apply1 (XCDR (fun), original_args));
|
0
|
3132 else if (EQ (funcar, Qlambda))
|
|
3133 val = apply_lambda (fun, nargs, original_args);
|
|
3134 else
|
|
3135 {
|
|
3136 invalid_function:
|
|
3137 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3138 }
|
|
3139 }
|
|
3140
|
|
3141 lisp_eval_depth--;
|
|
3142 if (backtrace.debug_on_exit)
|
|
3143 val = do_debug_on_exit (val);
|
116
|
3144 POP_BACKTRACE (backtrace);
|
173
|
3145 return val;
|
0
|
3146 }
|
|
3147
|
|
3148
|
|
3149 Lisp_Object
|
|
3150 funcall_recording_as (Lisp_Object recorded_as, int nargs,
|
|
3151 Lisp_Object *args)
|
|
3152 {
|
|
3153 /* This function can GC */
|
|
3154 Lisp_Object fun;
|
|
3155 Lisp_Object val;
|
|
3156 struct backtrace backtrace;
|
|
3157 REGISTER int i;
|
|
3158
|
|
3159 QUIT;
|
|
3160 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
3161 /* Callers should gcpro lexpr args */
|
|
3162 garbage_collect_1 ();
|
|
3163
|
|
3164 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
3165 {
|
|
3166 if (max_lisp_eval_depth < 100)
|
|
3167 max_lisp_eval_depth = 100;
|
|
3168 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
3169 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
3170 }
|
|
3171
|
|
3172 /* Count number of arguments to function */
|
|
3173 nargs = nargs - 1;
|
|
3174
|
|
3175 #ifdef EMACS_BTL
|
|
3176 backtrace.id_number = 0;
|
|
3177 #endif
|
|
3178 backtrace.pdlcount = specpdl_depth_counter;
|
|
3179 backtrace.function = &args[0];
|
|
3180 backtrace.args = &args[1];
|
|
3181 backtrace.nargs = nargs;
|
|
3182 backtrace.evalargs = 0;
|
|
3183 backtrace.debug_on_exit = 0;
|
116
|
3184 PUSH_BACKTRACE (backtrace);
|
0
|
3185
|
|
3186 if (debug_on_next_call)
|
|
3187 do_debug_on_call (Qlambda);
|
|
3188
|
|
3189 retry:
|
|
3190
|
|
3191 fun = args[0];
|
|
3192
|
|
3193 #ifdef EMACS_BTL
|
|
3194 {
|
|
3195 extern int emacs_btl_elisp_only_p;
|
|
3196 extern int btl_symbol_id_number ();
|
|
3197 if (emacs_btl_elisp_only_p)
|
|
3198 backtrace.id_number = btl_symbol_id_number (fun);
|
|
3199 }
|
|
3200 #endif
|
|
3201
|
|
3202 if (SYMBOLP (fun))
|
|
3203 fun = indirect_function (fun, 1);
|
|
3204
|
|
3205 if (SUBRP (fun))
|
|
3206 {
|
|
3207 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3208 int max_args = subr->max_args;
|
|
3209
|
|
3210 if (max_args == UNEVALLED)
|
|
3211 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3212
|
|
3213 if (nargs < subr->min_args
|
|
3214 || (max_args >= 0 && max_args < nargs))
|
|
3215 {
|
185
|
3216 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3217 list2 (fun, make_int (nargs)));
|
|
3218 }
|
|
3219
|
|
3220 if (max_args == MANY)
|
|
3221 {
|
74
|
3222 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
|
|
3223 (nargs, args + 1);
|
0
|
3224 }
|
|
3225
|
|
3226 else if (max_args > nargs)
|
|
3227 {
|
|
3228 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
3229
|
|
3230 /* Default optionals to nil */
|
|
3231 for (i = 0; i < nargs; i++)
|
|
3232 argvals[i] = args[i + 1];
|
|
3233 for (i = nargs; i < max_args; i++)
|
|
3234 argvals[i] = Qnil;
|
|
3235
|
195
|
3236 /* val = funcall_subr (subr, argvals); */
|
|
3237 inline_funcall_subr(val, subr, argvals);
|
0
|
3238 }
|
|
3239 else
|
195
|
3240 /* val = funcall_subr (subr, args + 1); */
|
|
3241 inline_funcall_subr(val, subr, (&args[1]));
|
0
|
3242 }
|
|
3243 else if (COMPILED_FUNCTIONP (fun))
|
|
3244 val = funcall_lambda (fun, nargs, args + 1);
|
|
3245 else if (!CONSP (fun))
|
|
3246 {
|
|
3247 invalid_function:
|
|
3248 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3249 }
|
|
3250 else
|
|
3251 {
|
195
|
3252 /* `fun' is a Lisp_Cons so XCAR is safe */
|
|
3253 Lisp_Object funcar = XCAR (fun);
|
0
|
3254
|
|
3255 if (!SYMBOLP (funcar))
|
|
3256 goto invalid_function;
|
|
3257 if (EQ (funcar, Qlambda))
|
|
3258 val = funcall_lambda (fun, nargs, args + 1);
|
|
3259 else if (EQ (funcar, Qautoload))
|
|
3260 {
|
|
3261 do_autoload (fun, args[0]);
|
|
3262 goto retry;
|
|
3263 }
|
|
3264 else
|
|
3265 {
|
|
3266 goto invalid_function;
|
|
3267 }
|
|
3268 }
|
|
3269 lisp_eval_depth--;
|
|
3270 if (backtrace.debug_on_exit)
|
|
3271 val = do_debug_on_exit (val);
|
116
|
3272 POP_BACKTRACE (backtrace);
|
0
|
3273 return val;
|
|
3274 }
|
|
3275
|
20
|
3276 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
|
0
|
3277 Call first argument as a function, passing remaining arguments to it.
|
|
3278 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
20
|
3279 */
|
|
3280 (int nargs, Lisp_Object *args))
|
0
|
3281 {
|
|
3282 return funcall_recording_as (args[0], nargs, args);
|
|
3283 }
|
|
3284
|
20
|
3285 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
|
0
|
3286 Return the number of arguments a function may be called with. The
|
|
3287 function may be any form that can be passed to `funcall', any special
|
|
3288 form, or any macro.
|
20
|
3289 */
|
|
3290 (function))
|
0
|
3291 {
|
|
3292 Lisp_Object orig_function = function;
|
|
3293 Lisp_Object arglist;
|
|
3294 int argcount;
|
|
3295
|
|
3296 retry:
|
|
3297
|
|
3298 if (SYMBOLP (function))
|
|
3299 function = indirect_function (function, 1);
|
|
3300
|
|
3301 if (SUBRP (function))
|
|
3302 return Fsubr_min_args (function);
|
|
3303 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3304 {
|
|
3305 invalid_function:
|
|
3306 return Fsignal (Qinvalid_function, list1 (function));
|
|
3307 }
|
|
3308
|
|
3309 if (CONSP (function))
|
|
3310 {
|
|
3311 Lisp_Object funcar = Fcar (function);
|
|
3312
|
|
3313 if (!SYMBOLP (funcar))
|
|
3314 goto invalid_function;
|
|
3315 if (EQ (funcar, Qmacro))
|
|
3316 {
|
|
3317 function = Fcdr (function);
|
|
3318 goto retry;
|
|
3319 }
|
|
3320 if (EQ (funcar, Qautoload))
|
|
3321 {
|
|
3322 do_autoload (function, orig_function);
|
|
3323 goto retry;
|
|
3324 }
|
|
3325 if (EQ (funcar, Qlambda))
|
|
3326 arglist = Fcar (Fcdr (function));
|
|
3327 else
|
|
3328 goto invalid_function;
|
|
3329 }
|
|
3330 else
|
|
3331 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3332
|
|
3333 argcount = 0;
|
|
3334 while (!NILP (arglist))
|
|
3335 {
|
|
3336 QUIT;
|
|
3337 if (EQ (Fcar (arglist), Qand_optional)
|
|
3338 || EQ (Fcar (arglist), Qand_rest))
|
|
3339 break;
|
|
3340 argcount++;
|
|
3341 arglist = Fcdr (arglist);
|
|
3342 }
|
|
3343
|
|
3344 return make_int (argcount);
|
|
3345 }
|
|
3346
|
20
|
3347 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
|
0
|
3348 Return the number of arguments a function may be called with. If the
|
|
3349 function takes an arbitrary number of arguments or is a built-in
|
|
3350 special form, nil is returned. The function may be any form that can
|
|
3351 be passed to `funcall', any special form, or any macro.
|
20
|
3352 */
|
|
3353 (function))
|
0
|
3354 {
|
|
3355 Lisp_Object orig_function = function;
|
|
3356 Lisp_Object arglist;
|
|
3357 int argcount;
|
|
3358
|
|
3359 retry:
|
|
3360
|
|
3361 if (SYMBOLP (function))
|
|
3362 function = indirect_function (function, 1);
|
|
3363
|
|
3364 if (SUBRP (function))
|
|
3365 return Fsubr_max_args (function);
|
|
3366 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3367 {
|
|
3368 invalid_function:
|
|
3369 return Fsignal (Qinvalid_function, list1 (function));
|
|
3370 }
|
|
3371
|
|
3372 if (CONSP (function))
|
|
3373 {
|
|
3374 Lisp_Object funcar = Fcar (function);
|
|
3375
|
|
3376 if (!SYMBOLP (funcar))
|
|
3377 goto invalid_function;
|
|
3378 if (EQ (funcar, Qmacro))
|
|
3379 {
|
|
3380 function = Fcdr (function);
|
|
3381 goto retry;
|
|
3382 }
|
|
3383 if (EQ (funcar, Qautoload))
|
|
3384 {
|
|
3385 do_autoload (function, orig_function);
|
|
3386 goto retry;
|
|
3387 }
|
|
3388 if (EQ (funcar, Qlambda))
|
|
3389 arglist = Fcar (Fcdr (function));
|
|
3390 else
|
|
3391 goto invalid_function;
|
|
3392 }
|
|
3393 else
|
|
3394 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3395
|
|
3396 argcount = 0;
|
|
3397 while (!NILP (arglist))
|
|
3398 {
|
|
3399 QUIT;
|
|
3400 if (EQ (Fcar (arglist), Qand_optional))
|
|
3401 {
|
|
3402 arglist = Fcdr (arglist);
|
|
3403 continue;
|
|
3404 }
|
|
3405 if (EQ (Fcar (arglist), Qand_rest))
|
|
3406 return Qnil;
|
|
3407 argcount++;
|
|
3408 arglist = Fcdr (arglist);
|
|
3409 }
|
|
3410
|
|
3411 return make_int (argcount);
|
|
3412 }
|
|
3413
|
|
3414
|
20
|
3415 DEFUN ("apply", Fapply, 2, MANY, 0, /*
|
0
|
3416 Call FUNCTION with our remaining args, using our last arg as list of args.
|
|
3417 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
20
|
3418 */
|
|
3419 (int nargs, Lisp_Object *args))
|
0
|
3420 {
|
|
3421 /* This function can GC */
|
|
3422 Lisp_Object fun = args[0];
|
195
|
3423 Lisp_Object spread_arg = args [nargs - 1], p;
|
0
|
3424 int numargs;
|
|
3425 int funcall_nargs;
|
|
3426
|
|
3427 CHECK_LIST (spread_arg);
|
185
|
3428
|
195
|
3429 /*
|
|
3430 * Formerly we used a call to Flength here, but that is slow and
|
|
3431 * wasteful due to type checking, stack push/pop and initialization.
|
|
3432 * We know we're dealing with a cons, so open code it for speed.
|
|
3433 *
|
|
3434 * We call QUIT in the loop so that a circular arg list won't lock
|
|
3435 * up the editor.
|
|
3436 */
|
|
3437 for (numargs = 0, p = spread_arg ; CONSP (p) ; p = XCDR (p))
|
|
3438 {
|
|
3439 numargs++;
|
|
3440 QUIT;
|
|
3441 }
|
|
3442 if (! NILP (p))
|
|
3443 signal_simple_error ("Argument list must be nil-terminated", spread_arg);
|
0
|
3444
|
|
3445 if (numargs == 0)
|
|
3446 /* (apply foo 0 1 '()) */
|
|
3447 return Ffuncall (nargs - 1, args);
|
|
3448 else if (numargs == 1)
|
|
3449 {
|
|
3450 /* (apply foo 0 1 '(2)) */
|
|
3451 args [nargs - 1] = XCAR (spread_arg);
|
|
3452 return Ffuncall (nargs, args);
|
|
3453 }
|
|
3454
|
|
3455 /* -1 for function, -1 for spread arg */
|
|
3456 numargs = nargs - 2 + numargs;
|
|
3457 /* +1 for function */
|
|
3458 funcall_nargs = 1 + numargs;
|
|
3459
|
|
3460 if (SYMBOLP (fun))
|
|
3461 fun = indirect_function (fun, 0);
|
|
3462 if (UNBOUNDP (fun))
|
|
3463 {
|
|
3464 /* Let funcall get the error */
|
|
3465 fun = args[0];
|
|
3466 }
|
|
3467 else if (SUBRP (fun))
|
|
3468 {
|
|
3469 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3470 int max_args = subr->max_args;
|
|
3471
|
|
3472 if (numargs < subr->min_args
|
|
3473 || (max_args >= 0 && max_args < numargs))
|
|
3474 {
|
|
3475 /* Let funcall get the error */
|
|
3476 }
|
|
3477 else if (max_args > numargs)
|
|
3478 {
|
|
3479 /* Avoid having funcall cons up yet another new vector of arguments
|
|
3480 by explicitly supplying nil's for optional values */
|
|
3481 funcall_nargs += (max_args - numargs);
|
|
3482 }
|
|
3483 }
|
|
3484 {
|
|
3485 REGISTER int i;
|
185
|
3486 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs);
|
0
|
3487 struct gcpro gcpro1;
|
|
3488
|
|
3489 GCPRO1 (*funcall_args);
|
|
3490 gcpro1.nvars = funcall_nargs;
|
|
3491
|
|
3492 /* Copy in the unspread args */
|
|
3493 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object));
|
|
3494 /* Spread the last arg we got. Its first element goes in
|
|
3495 the slot that it used to occupy, hence this value of I. */
|
185
|
3496 for (i = nargs - 1;
|
0
|
3497 !NILP (spread_arg); /* i < 1 + numargs */
|
|
3498 i++, spread_arg = XCDR (spread_arg))
|
|
3499 {
|
|
3500 funcall_args [i] = XCAR (spread_arg);
|
|
3501 }
|
|
3502 /* Supply nil for optional args (to subrs) */
|
|
3503 for (; i < funcall_nargs; i++)
|
|
3504 funcall_args[i] = Qnil;
|
|
3505
|
|
3506
|
|
3507 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
|
|
3508 }
|
|
3509 }
|
|
3510
|
|
3511
|
74
|
3512 /* Define proper types and argument lists simultaneously */
|
|
3513 #define PRIMITIVE_FUNCALL(n) ((Lisp_Object (*) (PRIMITIVE_FUNCALL_##n)
|
|
3514 #define PRIMITIVE_FUNCALL_0 void)) (fn)) (
|
|
3515 #define PRIMITIVE_FUNCALL_1 Lisp_Object)) (fn)) (args[0]
|
|
3516 #define PRIMITIVE_FUNCALL_2 Lisp_Object, PRIMITIVE_FUNCALL_1, args[1]
|
|
3517 #define PRIMITIVE_FUNCALL_3 Lisp_Object, PRIMITIVE_FUNCALL_2, args[2]
|
|
3518 #define PRIMITIVE_FUNCALL_4 Lisp_Object, PRIMITIVE_FUNCALL_3, args[3]
|
|
3519 #define PRIMITIVE_FUNCALL_5 Lisp_Object, PRIMITIVE_FUNCALL_4, args[4]
|
|
3520 #define PRIMITIVE_FUNCALL_6 Lisp_Object, PRIMITIVE_FUNCALL_5, args[5]
|
|
3521 #define PRIMITIVE_FUNCALL_7 Lisp_Object, PRIMITIVE_FUNCALL_6, args[6]
|
|
3522 #define PRIMITIVE_FUNCALL_8 Lisp_Object, PRIMITIVE_FUNCALL_7, args[7]
|
|
3523 #define PRIMITIVE_FUNCALL_9 Lisp_Object, PRIMITIVE_FUNCALL_8, args[8]
|
|
3524 #define PRIMITIVE_FUNCALL_10 Lisp_Object, PRIMITIVE_FUNCALL_9, args[9]
|
|
3525 #define PRIMITIVE_FUNCALL_11 Lisp_Object, PRIMITIVE_FUNCALL_10, args[10]
|
|
3526 #define PRIMITIVE_FUNCALL_12 Lisp_Object, PRIMITIVE_FUNCALL_11, args[11]
|
|
3527
|
0
|
3528 static Lisp_Object
|
74
|
3529 primitive_funcall (lisp_fn_t fn, int nargs, Lisp_Object args[])
|
0
|
3530 {
|
|
3531 switch (nargs)
|
|
3532 {
|
74
|
3533 case 0: return PRIMITIVE_FUNCALL(0);
|
|
3534 case 1: return PRIMITIVE_FUNCALL(1);
|
|
3535 case 2: return PRIMITIVE_FUNCALL(2);
|
|
3536 case 3: return PRIMITIVE_FUNCALL(3);
|
|
3537 case 4: return PRIMITIVE_FUNCALL(4);
|
|
3538 case 5: return PRIMITIVE_FUNCALL(5);
|
|
3539 case 6: return PRIMITIVE_FUNCALL(6);
|
|
3540 case 7: return PRIMITIVE_FUNCALL(7);
|
|
3541 case 8: return PRIMITIVE_FUNCALL(8);
|
|
3542 case 9: return PRIMITIVE_FUNCALL(9);
|
|
3543 case 10: return PRIMITIVE_FUNCALL(10);
|
|
3544 case 11: return PRIMITIVE_FUNCALL(11);
|
|
3545 case 12: return PRIMITIVE_FUNCALL(12);
|
0
|
3546 }
|
74
|
3547
|
|
3548 /* Someone has created a subr that takes more arguments than is
|
|
3549 supported by this code. We need to either rewrite the subr to
|
|
3550 use a different argument protocol, or add more cases to this
|
|
3551 switch. */
|
|
3552 abort ();
|
0
|
3553 return Qnil; /* suppress compiler warning */
|
|
3554 }
|
|
3555
|
223
|
3556 #if 0 /* #### Not called anymore */
|
0
|
3557 static Lisp_Object
|
|
3558 funcall_subr (struct Lisp_Subr *subr, Lisp_Object args[])
|
|
3559 {
|
|
3560 return primitive_funcall (subr_function (subr), subr->max_args, args);
|
|
3561 }
|
223
|
3562 #endif
|
0
|
3563
|
|
3564 /* FSFmacs has an extra arg EVAL_FLAG. If false, some of
|
|
3565 the statements below are not done. But it's always true
|
|
3566 in all the calls to apply_lambda(). */
|
|
3567
|
|
3568 static Lisp_Object
|
|
3569 apply_lambda (Lisp_Object fun, int numargs, Lisp_Object unevalled_args)
|
|
3570 {
|
|
3571 /* This function can GC */
|
|
3572 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3573 REGISTER int i;
|
|
3574 REGISTER Lisp_Object tem;
|
185
|
3575 REGISTER Lisp_Object *arg_vector = alloca_array (Lisp_Object, numargs);
|
0
|
3576
|
|
3577 GCPRO3 (*arg_vector, unevalled_args, fun);
|
|
3578 gcpro1.nvars = 0;
|
|
3579
|
|
3580 for (i = 0; i < numargs;)
|
|
3581 {
|
195
|
3582 /*
|
|
3583 * unevalled_args is always a normal list, or Feval would have
|
|
3584 * rejected it, so use XCAR and XCDR.
|
|
3585 */
|
|
3586 tem = XCAR (unevalled_args), unevalled_args = XCDR (unevalled_args);
|
0
|
3587 tem = Feval (tem);
|
|
3588 arg_vector[i++] = tem;
|
|
3589 gcpro1.nvars = i;
|
|
3590 }
|
|
3591
|
|
3592 UNGCPRO;
|
|
3593
|
|
3594 backtrace_list->args = arg_vector;
|
|
3595 backtrace_list->nargs = i;
|
|
3596 backtrace_list->evalargs = 0;
|
|
3597 tem = funcall_lambda (fun, numargs, arg_vector);
|
|
3598
|
|
3599 /* Do the debug-on-exit now, while arg_vector still exists. */
|
|
3600 if (backtrace_list->debug_on_exit)
|
|
3601 tem = do_debug_on_exit (tem);
|
|
3602 /* Don't do it again when we return to eval. */
|
|
3603 backtrace_list->debug_on_exit = 0;
|
173
|
3604 return tem;
|
0
|
3605 }
|
|
3606
|
|
3607 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
|
|
3608 and return the result of evaluation.
|
|
3609 FUN must be either a lambda-expression or a compiled-code object. */
|
|
3610
|
|
3611 static Lisp_Object
|
|
3612 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object arg_vector[])
|
|
3613 {
|
|
3614 /* This function can GC */
|
|
3615 Lisp_Object val, tem;
|
|
3616 REGISTER Lisp_Object syms_left;
|
|
3617 REGISTER Lisp_Object next;
|
|
3618 int speccount = specpdl_depth_counter;
|
|
3619 REGISTER int i;
|
|
3620 int optional = 0, rest = 0;
|
|
3621
|
|
3622 if (CONSP (fun))
|
195
|
3623 syms_left = Fcar (XCDR (fun));
|
0
|
3624 else if (COMPILED_FUNCTIONP (fun))
|
|
3625 syms_left = XCOMPILED_FUNCTION (fun)->arglist;
|
|
3626 else abort ();
|
|
3627
|
|
3628 i = 0;
|
195
|
3629 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
|
0
|
3630 {
|
|
3631 QUIT;
|
195
|
3632 next = XCAR (syms_left);
|
0
|
3633 if (!SYMBOLP (next))
|
|
3634 signal_error (Qinvalid_function, list1 (fun));
|
|
3635 if (EQ (next, Qand_rest))
|
|
3636 rest = 1;
|
|
3637 else if (EQ (next, Qand_optional))
|
|
3638 optional = 1;
|
|
3639 else if (rest)
|
|
3640 {
|
|
3641 specbind (next, Flist (nargs - i, &arg_vector[i]));
|
|
3642 i = nargs;
|
|
3643 }
|
|
3644 else if (i < nargs)
|
|
3645 {
|
|
3646 tem = arg_vector[i++];
|
|
3647 specbind (next, tem);
|
|
3648 }
|
|
3649 else if (!optional)
|
185
|
3650 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3651 list2 (fun, make_int (nargs)));
|
|
3652 else
|
|
3653 specbind (next, Qnil);
|
|
3654 }
|
|
3655
|
|
3656 if (i < nargs)
|
185
|
3657 return Fsignal (Qwrong_number_of_arguments,
|
0
|
3658 list2 (fun, make_int (nargs)));
|
|
3659
|
|
3660 if (CONSP (fun))
|
195
|
3661 val = Fprogn (Fcdr (XCDR (fun)));
|
0
|
3662 else
|
|
3663 {
|
|
3664 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
3665 /* If we have not actually read the bytecode string
|
|
3666 and constants vector yet, fetch them from the file. */
|
|
3667 if (CONSP (b->bytecodes))
|
|
3668 Ffetch_bytecode (fun);
|
|
3669 val = Fbyte_code (b->bytecodes,
|
|
3670 b->constants,
|
|
3671 make_int (b->maxdepth));
|
|
3672 }
|
|
3673 return unbind_to (speccount, val);
|
|
3674 }
|
|
3675
|
20
|
3676 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /*
|
0
|
3677 If byte-compiled OBJECT is lazy-loaded, fetch it now.
|
20
|
3678 */
|
|
3679 (object))
|
0
|
3680 {
|
|
3681 Lisp_Object tem;
|
|
3682
|
|
3683 if (COMPILED_FUNCTIONP (object)
|
|
3684 && CONSP (XCOMPILED_FUNCTION (object)->bytecodes))
|
|
3685 {
|
|
3686 tem = read_doc_string (XCOMPILED_FUNCTION (object)->bytecodes);
|
|
3687 if (!CONSP (tem))
|
|
3688 signal_simple_error ("invalid lazy-loaded byte code", tem);
|
70
|
3689 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
3690 if (XCOMPILED_FUNCTION (object)->flags.ebolified
|
|
3691 && VECTORP (XCDR (tem)))
|
|
3692 ebolify_bytecode_constants (XCDR (tem));
|
0
|
3693 /* VERY IMPORTANT to purecopy here!!!!!
|
|
3694 See load_force_doc_string_unwind. */
|
|
3695 XCOMPILED_FUNCTION (object)->bytecodes = Fpurecopy (XCAR (tem));
|
|
3696 XCOMPILED_FUNCTION (object)->constants = Fpurecopy (XCDR (tem));
|
|
3697 }
|
|
3698 return object;
|
|
3699 }
|
|
3700
|
|
3701
|
|
3702 /**********************************************************************/
|
|
3703 /* Run hook variables in various ways. */
|
|
3704 /**********************************************************************/
|
|
3705
|
20
|
3706 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
|
0
|
3707 Run each hook in HOOKS. Major mode functions use this.
|
|
3708 Each argument should be a symbol, a hook variable.
|
|
3709 These symbols are processed in the order specified.
|
|
3710 If a hook symbol has a non-nil value, that value may be a function
|
|
3711 or a list of functions to be called to run the hook.
|
|
3712 If the value is a function, it is called with no arguments.
|
|
3713 If it is a list, the elements are called, in order, with no arguments.
|
|
3714
|
|
3715 To make a hook variable buffer-local, use `make-local-hook',
|
|
3716 not `make-local-variable'.
|
20
|
3717 */
|
|
3718 (int nargs, Lisp_Object *args))
|
0
|
3719 {
|
|
3720 REGISTER int i;
|
|
3721
|
|
3722 for (i = 0; i < nargs; i++)
|
187
|
3723 run_hook_with_args (1, args + i, RUN_HOOKS_TO_COMPLETION);
|
0
|
3724
|
|
3725 return Qnil;
|
|
3726 }
|
185
|
3727
|
20
|
3728 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /*
|
0
|
3729 Run HOOK with the specified arguments ARGS.
|
|
3730 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
3731 value, that value may be a function or a list of functions to be
|
|
3732 called to run the hook. If the value is a function, it is called with
|
|
3733 the given arguments and its return value is returned. If it is a list
|
|
3734 of functions, those functions are called, in order,
|
|
3735 with the given arguments ARGS.
|
|
3736 It is best not to depend on the value return by `run-hook-with-args',
|
|
3737 as that may change.
|
|
3738
|
|
3739 To make a hook variable buffer-local, use `make-local-hook',
|
|
3740 not `make-local-variable'.
|
20
|
3741 */
|
|
3742 (int nargs, Lisp_Object *args))
|
0
|
3743 {
|
|
3744 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
|
|
3745 }
|
|
3746
|
20
|
3747 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /*
|
0
|
3748 Run HOOK with the specified arguments ARGS.
|
|
3749 HOOK should be a symbol, a hook variable. Its value should
|
|
3750 be a list of functions. We call those functions, one by one,
|
|
3751 passing arguments ARGS to each of them, until one of them
|
|
3752 returns a non-nil value. Then we return that value.
|
|
3753 If all the functions return nil, we return nil.
|
|
3754
|
|
3755 To make a hook variable buffer-local, use `make-local-hook',
|
|
3756 not `make-local-variable'.
|
20
|
3757 */
|
|
3758 (int nargs, Lisp_Object *args))
|
0
|
3759 {
|
|
3760 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
|
|
3761 }
|
|
3762
|
20
|
3763 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /*
|
0
|
3764 Run HOOK with the specified arguments ARGS.
|
|
3765 HOOK should be a symbol, a hook variable. Its value should
|
|
3766 be a list of functions. We call those functions, one by one,
|
|
3767 passing arguments ARGS to each of them, until one of them
|
|
3768 returns nil. Then we return nil.
|
|
3769 If all the functions return non-nil, we return non-nil.
|
|
3770
|
|
3771 To make a hook variable buffer-local, use `make-local-hook',
|
|
3772 not `make-local-variable'.
|
20
|
3773 */
|
|
3774 (int nargs, Lisp_Object *args))
|
0
|
3775 {
|
|
3776 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
|
|
3777 }
|
|
3778
|
|
3779 /* ARGS[0] should be a hook symbol.
|
|
3780 Call each of the functions in the hook value, passing each of them
|
|
3781 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
3782 COND specifies a condition to test after each call
|
|
3783 to decide whether to stop.
|
|
3784 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3785 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3786
|
|
3787 Lisp_Object
|
|
3788 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
|
|
3789 enum run_hooks_condition cond)
|
|
3790 {
|
|
3791 Lisp_Object sym, val, ret;
|
|
3792 struct gcpro gcpro1, gcpro2;
|
|
3793
|
|
3794 if (!initialized || preparing_for_armageddon)
|
|
3795 /* We need to bail out of here pronto. */
|
|
3796 return Qnil;
|
|
3797
|
|
3798 /* Whenever gc_in_progress is true, preparing_for_armageddon
|
|
3799 will also be true unless something is really hosed. */
|
|
3800 assert (!gc_in_progress);
|
|
3801
|
|
3802 sym = args[0];
|
|
3803 val = symbol_value_in_buffer (sym, make_buffer (buf));
|
|
3804 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
3805
|
|
3806 if (UNBOUNDP (val) || NILP (val))
|
|
3807 return ret;
|
|
3808 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
|
3809 {
|
|
3810 args[0] = val;
|
|
3811 return Ffuncall (nargs, args);
|
|
3812 }
|
|
3813 else
|
|
3814 {
|
|
3815 GCPRO2 (sym, val);
|
|
3816
|
|
3817 for (;
|
|
3818 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3819 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
|
|
3820 : !NILP (ret)));
|
|
3821 val = XCDR (val))
|
|
3822 {
|
|
3823 if (EQ (XCAR (val), Qt))
|
|
3824 {
|
|
3825 /* t indicates this hook has a local binding;
|
|
3826 it means to run the global binding too. */
|
|
3827 Lisp_Object globals;
|
|
3828
|
|
3829 for (globals = Fdefault_value (sym);
|
|
3830 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3831 || (cond == RUN_HOOKS_UNTIL_SUCCESS
|
|
3832 ? NILP (ret)
|
|
3833 : !NILP (ret)));
|
|
3834 globals = XCDR (globals))
|
|
3835 {
|
|
3836 args[0] = XCAR (globals);
|
|
3837 /* In a global value, t should not occur. If it does, we
|
|
3838 must ignore it to avoid an endless loop. */
|
|
3839 if (!EQ (args[0], Qt))
|
|
3840 ret = Ffuncall (nargs, args);
|
|
3841 }
|
|
3842 }
|
|
3843 else
|
|
3844 {
|
|
3845 args[0] = XCAR (val);
|
|
3846 ret = Ffuncall (nargs, args);
|
|
3847 }
|
|
3848 }
|
|
3849
|
|
3850 UNGCPRO;
|
|
3851 return ret;
|
|
3852 }
|
|
3853 }
|
|
3854
|
|
3855 Lisp_Object
|
|
3856 run_hook_with_args (int nargs, Lisp_Object *args,
|
|
3857 enum run_hooks_condition cond)
|
|
3858 {
|
|
3859 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond);
|
|
3860 }
|
|
3861
|
|
3862 #if 0
|
|
3863
|
|
3864 /* From FSF 19.30, not currently used */
|
|
3865
|
|
3866 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
3867 present value of that symbol.
|
|
3868 Call each element of FUNLIST,
|
|
3869 passing each of them the rest of ARGS.
|
|
3870 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3871 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3872
|
|
3873 Lisp_Object
|
|
3874 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
|
|
3875 {
|
|
3876 Lisp_Object sym;
|
|
3877 Lisp_Object val;
|
|
3878 struct gcpro gcpro1, gcpro2;
|
|
3879
|
|
3880 sym = args[0];
|
|
3881 GCPRO2 (sym, val);
|
|
3882
|
|
3883 for (val = funlist; CONSP (val); val = XCDR (val))
|
|
3884 {
|
|
3885 if (EQ (XCAR (val), Qt))
|
|
3886 {
|
|
3887 /* t indicates this hook has a local binding;
|
|
3888 it means to run the global binding too. */
|
|
3889 Lisp_Object globals;
|
|
3890
|
|
3891 for (globals = Fdefault_value (sym);
|
|
3892 CONSP (globals);
|
|
3893 globals = XCDR (globals))
|
|
3894 {
|
|
3895 args[0] = XCAR (globals);
|
|
3896 /* In a global value, t should not occur. If it does, we
|
|
3897 must ignore it to avoid an endless loop. */
|
|
3898 if (!EQ (args[0], Qt))
|
|
3899 Ffuncall (nargs, args);
|
|
3900 }
|
|
3901 }
|
|
3902 else
|
|
3903 {
|
|
3904 args[0] = XCAR (val);
|
|
3905 Ffuncall (nargs, args);
|
|
3906 }
|
|
3907 }
|
|
3908 UNGCPRO;
|
|
3909 return Qnil;
|
|
3910 }
|
|
3911
|
|
3912 #endif /* 0 */
|
|
3913
|
|
3914 void
|
|
3915 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...)
|
|
3916 {
|
|
3917 /* This function can GC */
|
|
3918 struct gcpro gcpro1;
|
|
3919 int i;
|
|
3920 va_list vargs;
|
185
|
3921 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
0
|
3922
|
|
3923 va_start (vargs, nargs);
|
|
3924 funcall_args[0] = hook_var;
|
|
3925 for (i = 0; i < nargs; i++)
|
|
3926 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3927 va_end (vargs);
|
|
3928
|
|
3929 GCPRO1 (*funcall_args);
|
|
3930 gcpro1.nvars = nargs + 1;
|
|
3931 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION);
|
|
3932 UNGCPRO;
|
|
3933 }
|
|
3934
|
|
3935 void
|
|
3936 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var,
|
|
3937 int nargs, ...)
|
|
3938 {
|
|
3939 /* This function can GC */
|
|
3940 struct gcpro gcpro1;
|
|
3941 int i;
|
|
3942 va_list vargs;
|
185
|
3943 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs);
|
0
|
3944
|
|
3945 va_start (vargs, nargs);
|
|
3946 funcall_args[0] = hook_var;
|
|
3947 for (i = 0; i < nargs; i++)
|
|
3948 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3949 va_end (vargs);
|
|
3950
|
|
3951 GCPRO1 (*funcall_args);
|
|
3952 gcpro1.nvars = nargs + 1;
|
|
3953 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args,
|
|
3954 RUN_HOOKS_TO_COMPLETION);
|
|
3955 UNGCPRO;
|
|
3956 }
|
|
3957
|
|
3958 Lisp_Object
|
|
3959 run_hook (Lisp_Object hook)
|
|
3960 {
|
|
3961 Frun_hooks (1, &hook);
|
|
3962 return Qnil;
|
|
3963 }
|
|
3964
|
|
3965
|
|
3966 /**********************************************************************/
|
|
3967 /* Front-ends to eval, funcall, apply */
|
|
3968 /**********************************************************************/
|
|
3969
|
|
3970 /* Apply fn to arg */
|
|
3971 Lisp_Object
|
|
3972 apply1 (Lisp_Object fn, Lisp_Object arg)
|
|
3973 {
|
|
3974 /* This function can GC */
|
|
3975 struct gcpro gcpro1;
|
|
3976 Lisp_Object args[2];
|
|
3977
|
|
3978 if (NILP (arg))
|
173
|
3979 return Ffuncall (1, &fn);
|
0
|
3980 GCPRO1 (args[0]);
|
|
3981 gcpro1.nvars = 2;
|
|
3982 args[0] = fn;
|
|
3983 args[1] = arg;
|
|
3984 RETURN_UNGCPRO (Fapply (2, args));
|
|
3985 }
|
|
3986
|
|
3987 /* Call function fn on no arguments */
|
|
3988 Lisp_Object
|
|
3989 call0 (Lisp_Object fn)
|
|
3990 {
|
|
3991 /* This function can GC */
|
|
3992 struct gcpro gcpro1;
|
|
3993
|
|
3994 GCPRO1 (fn);
|
|
3995 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
3996 }
|
|
3997
|
|
3998 /* Call function fn with argument arg0 */
|
|
3999 Lisp_Object
|
|
4000 call1 (Lisp_Object fn,
|
|
4001 Lisp_Object arg0)
|
|
4002 {
|
|
4003 /* This function can GC */
|
|
4004 struct gcpro gcpro1;
|
185
|
4005 Lisp_Object args[2];
|
0
|
4006 args[0] = fn;
|
|
4007 args[1] = arg0;
|
|
4008 GCPRO1 (args[0]);
|
|
4009 gcpro1.nvars = 2;
|
|
4010 RETURN_UNGCPRO (Ffuncall (2, args));
|
|
4011 }
|
|
4012
|
|
4013 /* Call function fn with arguments arg0, arg1 */
|
|
4014 Lisp_Object
|
|
4015 call2 (Lisp_Object fn,
|
|
4016 Lisp_Object arg0, Lisp_Object arg1)
|
|
4017 {
|
|
4018 /* This function can GC */
|
|
4019 struct gcpro gcpro1;
|
|
4020 Lisp_Object args[3];
|
|
4021 args[0] = fn;
|
|
4022 args[1] = arg0;
|
|
4023 args[2] = arg1;
|
|
4024 GCPRO1 (args[0]);
|
|
4025 gcpro1.nvars = 3;
|
|
4026 RETURN_UNGCPRO (Ffuncall (3, args));
|
|
4027 }
|
|
4028
|
|
4029 /* Call function fn with arguments arg0, arg1, arg2 */
|
|
4030 Lisp_Object
|
|
4031 call3 (Lisp_Object fn,
|
|
4032 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4033 {
|
|
4034 /* This function can GC */
|
|
4035 struct gcpro gcpro1;
|
|
4036 Lisp_Object args[4];
|
|
4037 args[0] = fn;
|
|
4038 args[1] = arg0;
|
|
4039 args[2] = arg1;
|
|
4040 args[3] = arg2;
|
|
4041 GCPRO1 (args[0]);
|
|
4042 gcpro1.nvars = 4;
|
|
4043 RETURN_UNGCPRO (Ffuncall (4, args));
|
|
4044 }
|
|
4045
|
|
4046 /* Call function fn with arguments arg0, arg1, arg2, arg3 */
|
|
4047 Lisp_Object
|
|
4048 call4 (Lisp_Object fn,
|
|
4049 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4050 Lisp_Object arg3)
|
|
4051 {
|
|
4052 /* This function can GC */
|
|
4053 struct gcpro gcpro1;
|
|
4054 Lisp_Object args[5];
|
|
4055 args[0] = fn;
|
|
4056 args[1] = arg0;
|
|
4057 args[2] = arg1;
|
|
4058 args[3] = arg2;
|
|
4059 args[4] = arg3;
|
|
4060 GCPRO1 (args[0]);
|
|
4061 gcpro1.nvars = 5;
|
|
4062 RETURN_UNGCPRO (Ffuncall (5, args));
|
|
4063 }
|
|
4064
|
|
4065 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */
|
|
4066 Lisp_Object
|
|
4067 call5 (Lisp_Object fn,
|
185
|
4068 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4069 Lisp_Object arg3, Lisp_Object arg4)
|
|
4070 {
|
|
4071 /* This function can GC */
|
|
4072 struct gcpro gcpro1;
|
|
4073 Lisp_Object args[6];
|
|
4074 args[0] = fn;
|
|
4075 args[1] = arg0;
|
|
4076 args[2] = arg1;
|
|
4077 args[3] = arg2;
|
|
4078 args[4] = arg3;
|
|
4079 args[5] = arg4;
|
|
4080 GCPRO1 (args[0]);
|
|
4081 gcpro1.nvars = 6;
|
|
4082 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
4083 }
|
|
4084
|
|
4085 Lisp_Object
|
|
4086 call6 (Lisp_Object fn,
|
185
|
4087 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4088 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4089 {
|
|
4090 /* This function can GC */
|
|
4091 struct gcpro gcpro1;
|
|
4092 Lisp_Object args[7];
|
|
4093 args[0] = fn;
|
|
4094 args[1] = arg0;
|
|
4095 args[2] = arg1;
|
|
4096 args[3] = arg2;
|
|
4097 args[4] = arg3;
|
|
4098 args[5] = arg4;
|
|
4099 args[6] = arg5;
|
|
4100 GCPRO1 (args[0]);
|
|
4101 gcpro1.nvars = 7;
|
|
4102 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
4103 }
|
|
4104
|
|
4105 Lisp_Object
|
|
4106 call7 (Lisp_Object fn,
|
185
|
4107 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4108 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4109 Lisp_Object arg6)
|
|
4110 {
|
|
4111 /* This function can GC */
|
|
4112 struct gcpro gcpro1;
|
|
4113 Lisp_Object args[8];
|
|
4114 args[0] = fn;
|
|
4115 args[1] = arg0;
|
|
4116 args[2] = arg1;
|
|
4117 args[3] = arg2;
|
|
4118 args[4] = arg3;
|
|
4119 args[5] = arg4;
|
|
4120 args[6] = arg5;
|
|
4121 args[7] = arg6;
|
|
4122 GCPRO1 (args[0]);
|
|
4123 gcpro1.nvars = 8;
|
|
4124 RETURN_UNGCPRO (Ffuncall (8, args));
|
|
4125 }
|
|
4126
|
|
4127 Lisp_Object
|
|
4128 call8 (Lisp_Object fn,
|
185
|
4129 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
0
|
4130 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4131 Lisp_Object arg6, Lisp_Object arg7)
|
|
4132 {
|
|
4133 /* This function can GC */
|
|
4134 struct gcpro gcpro1;
|
|
4135 Lisp_Object args[9];
|
|
4136 args[0] = fn;
|
|
4137 args[1] = arg0;
|
|
4138 args[2] = arg1;
|
|
4139 args[3] = arg2;
|
|
4140 args[4] = arg3;
|
|
4141 args[5] = arg4;
|
|
4142 args[6] = arg5;
|
|
4143 args[7] = arg6;
|
|
4144 args[8] = arg7;
|
|
4145 GCPRO1 (args[0]);
|
|
4146 gcpro1.nvars = 9;
|
|
4147 RETURN_UNGCPRO (Ffuncall (9, args));
|
|
4148 }
|
|
4149
|
|
4150 Lisp_Object
|
|
4151 call0_in_buffer (struct buffer *buf, Lisp_Object fn)
|
|
4152 {
|
|
4153 int speccount = specpdl_depth ();
|
|
4154 Lisp_Object val;
|
|
4155
|
|
4156 if (current_buffer != buf)
|
|
4157 {
|
|
4158 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4159 set_buffer_internal (buf);
|
|
4160 }
|
|
4161 val = call0 (fn);
|
|
4162 unbind_to (speccount, Qnil);
|
|
4163 return val;
|
|
4164 }
|
|
4165
|
|
4166 Lisp_Object
|
|
4167 call1_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4168 Lisp_Object arg0)
|
|
4169 {
|
|
4170 int speccount = specpdl_depth ();
|
|
4171 Lisp_Object val;
|
|
4172
|
|
4173 if (current_buffer != buf)
|
|
4174 {
|
|
4175 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4176 set_buffer_internal (buf);
|
|
4177 }
|
|
4178 val = call1 (fn, arg0);
|
|
4179 unbind_to (speccount, Qnil);
|
|
4180 return val;
|
|
4181 }
|
|
4182
|
|
4183 Lisp_Object
|
|
4184 call2_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4185 Lisp_Object arg0, Lisp_Object arg1)
|
|
4186 {
|
|
4187 int speccount = specpdl_depth ();
|
|
4188 Lisp_Object val;
|
|
4189
|
|
4190 if (current_buffer != buf)
|
|
4191 {
|
|
4192 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4193 set_buffer_internal (buf);
|
|
4194 }
|
|
4195 val = call2 (fn, arg0, arg1);
|
|
4196 unbind_to (speccount, Qnil);
|
|
4197 return val;
|
|
4198 }
|
|
4199
|
|
4200 Lisp_Object
|
|
4201 call3_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4202 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4203 {
|
|
4204 int speccount = specpdl_depth ();
|
|
4205 Lisp_Object val;
|
|
4206
|
|
4207 if (current_buffer != buf)
|
|
4208 {
|
|
4209 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4210 set_buffer_internal (buf);
|
|
4211 }
|
|
4212 val = call3 (fn, arg0, arg1, arg2);
|
|
4213 unbind_to (speccount, Qnil);
|
|
4214 return val;
|
|
4215 }
|
|
4216
|
|
4217 Lisp_Object
|
|
4218 call4_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4219 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4220 Lisp_Object arg3)
|
|
4221 {
|
|
4222 int speccount = specpdl_depth ();
|
|
4223 Lisp_Object val;
|
|
4224
|
|
4225 if (current_buffer != buf)
|
|
4226 {
|
|
4227 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4228 set_buffer_internal (buf);
|
|
4229 }
|
|
4230 val = call4 (fn, arg0, arg1, arg2, arg3);
|
|
4231 unbind_to (speccount, Qnil);
|
|
4232 return val;
|
|
4233 }
|
|
4234
|
|
4235 Lisp_Object
|
|
4236 call5_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4237 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4238 Lisp_Object arg3, Lisp_Object arg4)
|
|
4239 {
|
|
4240 int speccount = specpdl_depth ();
|
|
4241 Lisp_Object val;
|
|
4242
|
|
4243 if (current_buffer != buf)
|
|
4244 {
|
|
4245 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4246 set_buffer_internal (buf);
|
|
4247 }
|
|
4248 val = call5 (fn, arg0, arg1, arg2, arg3, arg4);
|
|
4249 unbind_to (speccount, Qnil);
|
|
4250 return val;
|
|
4251 }
|
|
4252
|
|
4253 Lisp_Object
|
|
4254 call6_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4255 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4256 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4257 {
|
|
4258 int speccount = specpdl_depth ();
|
|
4259 Lisp_Object val;
|
|
4260
|
|
4261 if (current_buffer != buf)
|
|
4262 {
|
|
4263 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4264 set_buffer_internal (buf);
|
|
4265 }
|
|
4266 val = call6 (fn, arg0, arg1, arg2, arg3, arg4, arg5);
|
|
4267 unbind_to (speccount, Qnil);
|
|
4268 return val;
|
|
4269 }
|
|
4270
|
|
4271 Lisp_Object
|
|
4272 eval_in_buffer (struct buffer *buf, Lisp_Object form)
|
|
4273 {
|
|
4274 int speccount = specpdl_depth ();
|
|
4275 Lisp_Object val;
|
|
4276
|
|
4277 if (current_buffer != buf)
|
|
4278 {
|
|
4279 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4280 set_buffer_internal (buf);
|
|
4281 }
|
|
4282 val = Feval (form);
|
|
4283 unbind_to (speccount, Qnil);
|
|
4284 return val;
|
|
4285 }
|
|
4286
|
|
4287
|
|
4288 /***** Error-catching front-ends to eval, funcall, apply */
|
|
4289
|
|
4290 /* Call function fn on no arguments, with condition handler */
|
|
4291 Lisp_Object
|
|
4292 call0_with_handler (Lisp_Object handler, Lisp_Object fn)
|
|
4293 {
|
|
4294 /* This function can GC */
|
|
4295 struct gcpro gcpro1;
|
|
4296 Lisp_Object args[2];
|
|
4297 args[0] = handler;
|
|
4298 args[1] = fn;
|
|
4299 GCPRO1 (args[0]);
|
|
4300 gcpro1.nvars = 2;
|
|
4301 RETURN_UNGCPRO (Fcall_with_condition_handler (2, args));
|
|
4302 }
|
|
4303
|
|
4304 /* Call function fn with argument arg0, with condition handler */
|
|
4305 Lisp_Object
|
|
4306 call1_with_handler (Lisp_Object handler, Lisp_Object fn,
|
|
4307 Lisp_Object arg0)
|
|
4308 {
|
|
4309 /* This function can GC */
|
|
4310 struct gcpro gcpro1;
|
|
4311 Lisp_Object args[3];
|
|
4312 args[0] = handler;
|
|
4313 args[1] = fn;
|
|
4314 args[2] = arg0;
|
|
4315 GCPRO1 (args[0]);
|
|
4316 gcpro1.nvars = 3;
|
|
4317 RETURN_UNGCPRO (Fcall_with_condition_handler (3, args));
|
|
4318 }
|
|
4319
|
|
4320
|
|
4321 /* The following functions provide you with error-trapping versions
|
|
4322 of the various front-ends above. They take an additional
|
|
4323 "warning_string" argument; if non-zero, a warning with this
|
|
4324 string and the actual error that occurred will be displayed
|
|
4325 in the *Warnings* buffer if an error occurs. In all cases,
|
|
4326 QUIT is inhibited while these functions are running, and if
|
|
4327 an error occurs, Qunbound is returned instead of the normal
|
|
4328 return value.
|
|
4329 */
|
|
4330
|
185
|
4331 /* #### This stuff needs to catch throws as well. We need to
|
0
|
4332 improve internal_catch() so it can take a "catch anything"
|
|
4333 argument similar to Qt or Qerror for condition_case_1(). */
|
|
4334
|
|
4335 static Lisp_Object
|
|
4336 caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4337 {
|
|
4338 if (!NILP (errordata))
|
|
4339 {
|
|
4340 Lisp_Object args[2];
|
185
|
4341
|
0
|
4342 if (!NILP (arg))
|
|
4343 {
|
|
4344 char *str = (char *) get_opaque_ptr (arg);
|
|
4345 args[0] = build_string (str);
|
|
4346 }
|
|
4347 else
|
|
4348 args[0] = build_string ("error");
|
|
4349 /* #### This should call
|
|
4350 (with-output-to-string (display-error errordata))
|
|
4351 but that stuff is all in Lisp currently. */
|
|
4352 args[1] = errordata;
|
|
4353 warn_when_safe_lispobj
|
|
4354 (Qerror, Qwarning,
|
|
4355 emacs_doprnt_string_lisp ((CONST Bufbyte *) "%s: %s",
|
|
4356 Qnil, -1, 2, args));
|
|
4357 }
|
|
4358 return Qunbound;
|
|
4359 }
|
|
4360
|
|
4361 static Lisp_Object
|
|
4362 allow_quit_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4363 {
|
|
4364 if (CONSP (errordata) && EQ (XCAR (errordata), Qquit))
|
|
4365 return Fsignal (Qquit, XCDR (errordata));
|
|
4366 return caught_a_squirmer (errordata, arg);
|
|
4367 }
|
|
4368
|
|
4369 static Lisp_Object
|
|
4370 safe_run_hook_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4371 {
|
|
4372 Lisp_Object hook = Fcar (arg);
|
|
4373 arg = Fcdr (arg);
|
|
4374 /* Clear out the hook. */
|
|
4375 Fset (hook, Qnil);
|
|
4376 return caught_a_squirmer (errordata, arg);
|
|
4377 }
|
|
4378
|
|
4379 static Lisp_Object
|
|
4380 allow_quit_safe_run_hook_caught_a_squirmer (Lisp_Object errordata,
|
|
4381 Lisp_Object arg)
|
|
4382 {
|
|
4383 Lisp_Object hook = Fcar (arg);
|
|
4384 arg = Fcdr (arg);
|
|
4385 if (!CONSP (errordata) || !EQ (XCAR (errordata), Qquit))
|
|
4386 /* Clear out the hook. */
|
|
4387 Fset (hook, Qnil);
|
|
4388 return allow_quit_caught_a_squirmer (errordata, arg);
|
|
4389 }
|
|
4390
|
|
4391 static Lisp_Object
|
|
4392 catch_them_squirmers_eval_in_buffer (Lisp_Object cons)
|
|
4393 {
|
|
4394 return eval_in_buffer (XBUFFER (XCAR (cons)), XCDR (cons));
|
|
4395 }
|
|
4396
|
|
4397 Lisp_Object
|
|
4398 eval_in_buffer_trapping_errors (CONST char *warning_string,
|
|
4399 struct buffer *buf, Lisp_Object form)
|
|
4400 {
|
|
4401 int speccount = specpdl_depth ();
|
|
4402 Lisp_Object tem;
|
|
4403 Lisp_Object buffer = Qnil;
|
|
4404 Lisp_Object cons;
|
|
4405 Lisp_Object opaque;
|
|
4406 struct gcpro gcpro1, gcpro2;
|
|
4407
|
|
4408 XSETBUFFER (buffer, buf);
|
|
4409
|
|
4410 specbind (Qinhibit_quit, Qt);
|
|
4411 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4412
|
|
4413 cons = noseeum_cons (buffer, form);
|
|
4414 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4415 GCPRO2 (cons, opaque);
|
|
4416 /* Qerror not Qt, so you can get a backtrace */
|
|
4417 tem = condition_case_1 (Qerror,
|
|
4418 catch_them_squirmers_eval_in_buffer, cons,
|
|
4419 caught_a_squirmer, opaque);
|
|
4420 free_cons (XCONS (cons));
|
|
4421 if (OPAQUEP (opaque))
|
|
4422 free_opaque_ptr (opaque);
|
|
4423 UNGCPRO;
|
185
|
4424
|
0
|
4425 /* gc_currently_forbidden = 0; */
|
|
4426 return unbind_to (speccount, tem);
|
|
4427 }
|
|
4428
|
|
4429 static Lisp_Object
|
|
4430 catch_them_squirmers_run_hook (Lisp_Object hook_symbol)
|
|
4431 {
|
|
4432 /* This function can GC */
|
|
4433 run_hook (hook_symbol);
|
|
4434 return Qnil;
|
|
4435 }
|
|
4436
|
|
4437 Lisp_Object
|
|
4438 run_hook_trapping_errors (CONST char *warning_string, Lisp_Object hook_symbol)
|
|
4439 {
|
|
4440 int speccount = specpdl_depth ();
|
|
4441 Lisp_Object tem;
|
|
4442 Lisp_Object opaque;
|
|
4443 struct gcpro gcpro1;
|
|
4444
|
|
4445 if (!initialized || preparing_for_armageddon)
|
|
4446 return Qnil;
|
|
4447 tem = find_symbol_value (hook_symbol);
|
|
4448 if (NILP (tem) || UNBOUNDP (tem))
|
|
4449 return Qnil;
|
|
4450
|
|
4451 specbind (Qinhibit_quit, Qt);
|
|
4452
|
|
4453 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4454 GCPRO1 (opaque);
|
|
4455 /* Qerror not Qt, so you can get a backtrace */
|
|
4456 tem = condition_case_1 (Qerror,
|
|
4457 catch_them_squirmers_run_hook, hook_symbol,
|
|
4458 caught_a_squirmer, opaque);
|
|
4459 if (OPAQUEP (opaque))
|
|
4460 free_opaque_ptr (opaque);
|
|
4461 UNGCPRO;
|
|
4462
|
|
4463 return unbind_to (speccount, tem);
|
|
4464 }
|
|
4465
|
|
4466 /* Same as run_hook_trapping_errors() but also set the hook to nil
|
|
4467 if an error occurs. */
|
|
4468
|
|
4469 Lisp_Object
|
|
4470 safe_run_hook_trapping_errors (CONST char *warning_string,
|
|
4471 Lisp_Object hook_symbol,
|
|
4472 int allow_quit)
|
|
4473 {
|
|
4474 int speccount = specpdl_depth ();
|
|
4475 Lisp_Object tem;
|
|
4476 Lisp_Object cons = Qnil;
|
|
4477 struct gcpro gcpro1;
|
|
4478
|
|
4479 if (!initialized || preparing_for_armageddon)
|
|
4480 return Qnil;
|
|
4481 tem = find_symbol_value (hook_symbol);
|
|
4482 if (NILP (tem) || UNBOUNDP (tem))
|
|
4483 return Qnil;
|
|
4484
|
|
4485 if (!allow_quit)
|
|
4486 specbind (Qinhibit_quit, Qt);
|
|
4487
|
185
|
4488 cons = noseeum_cons (hook_symbol,
|
0
|
4489 warning_string ? make_opaque_ptr (warning_string)
|
|
4490 : Qnil);
|
|
4491 GCPRO1 (cons);
|
|
4492 /* Qerror not Qt, so you can get a backtrace */
|
|
4493 tem = condition_case_1 (Qerror,
|
|
4494 catch_them_squirmers_run_hook,
|
|
4495 hook_symbol,
|
|
4496 allow_quit ?
|
|
4497 allow_quit_safe_run_hook_caught_a_squirmer :
|
|
4498 safe_run_hook_caught_a_squirmer,
|
|
4499 cons);
|
|
4500 if (OPAQUEP (XCDR (cons)))
|
|
4501 free_opaque_ptr (XCDR (cons));
|
|
4502 free_cons (XCONS (cons));
|
|
4503 UNGCPRO;
|
|
4504
|
|
4505 return unbind_to (speccount, tem);
|
|
4506 }
|
|
4507
|
|
4508 static Lisp_Object
|
|
4509 catch_them_squirmers_call0 (Lisp_Object function)
|
|
4510 {
|
|
4511 /* This function can GC */
|
|
4512 return call0 (function);
|
|
4513 }
|
|
4514
|
|
4515 Lisp_Object
|
|
4516 call0_trapping_errors (CONST char *warning_string, Lisp_Object function)
|
|
4517 {
|
|
4518 int speccount = specpdl_depth ();
|
|
4519 Lisp_Object tem;
|
|
4520 Lisp_Object opaque = Qnil;
|
|
4521 struct gcpro gcpro1, gcpro2;
|
|
4522
|
|
4523 if (SYMBOLP (function))
|
|
4524 {
|
|
4525 tem = XSYMBOL (function)->function;
|
|
4526 if (NILP (tem) || UNBOUNDP (tem))
|
173
|
4527 return Qnil;
|
0
|
4528 }
|
|
4529
|
|
4530 GCPRO2 (opaque, function);
|
|
4531 specbind (Qinhibit_quit, Qt);
|
|
4532 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4533
|
|
4534 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4535 /* Qerror not Qt, so you can get a backtrace */
|
|
4536 tem = condition_case_1 (Qerror,
|
|
4537 catch_them_squirmers_call0, function,
|
|
4538 caught_a_squirmer, opaque);
|
|
4539 if (OPAQUEP (opaque))
|
|
4540 free_opaque_ptr (opaque);
|
|
4541 UNGCPRO;
|
|
4542
|
|
4543 /* gc_currently_forbidden = 0; */
|
|
4544 return unbind_to (speccount, tem);
|
|
4545 }
|
|
4546
|
|
4547 static Lisp_Object
|
|
4548 catch_them_squirmers_call1 (Lisp_Object cons)
|
|
4549 {
|
|
4550 /* This function can GC */
|
|
4551 return call1 (XCAR (cons), XCDR (cons));
|
|
4552 }
|
|
4553
|
|
4554 static Lisp_Object
|
|
4555 catch_them_squirmers_call2 (Lisp_Object cons)
|
|
4556 {
|
|
4557 /* This function can GC */
|
|
4558 return call2 (XCAR (cons), XCAR (XCDR (cons)), XCAR (XCDR (XCDR (cons))));
|
|
4559 }
|
|
4560
|
|
4561 Lisp_Object
|
|
4562 call1_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4563 Lisp_Object object)
|
|
4564 {
|
|
4565 int speccount = specpdl_depth ();
|
|
4566 Lisp_Object tem;
|
|
4567 Lisp_Object cons = Qnil;
|
|
4568 Lisp_Object opaque = Qnil;
|
|
4569 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4570
|
|
4571 if (SYMBOLP (function))
|
|
4572 {
|
|
4573 tem = XSYMBOL (function)->function;
|
|
4574 if (NILP (tem) || UNBOUNDP (tem))
|
173
|
4575 return Qnil;
|
0
|
4576 }
|
|
4577
|
|
4578 GCPRO4 (cons, opaque, function, object);
|
|
4579
|
|
4580 specbind (Qinhibit_quit, Qt);
|
|
4581 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4582
|
|
4583 cons = noseeum_cons (function, object);
|
|
4584 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4585 /* Qerror not Qt, so you can get a backtrace */
|
|
4586 tem = condition_case_1 (Qerror,
|
|
4587 catch_them_squirmers_call1, cons,
|
|
4588 caught_a_squirmer, opaque);
|
|
4589 if (OPAQUEP (opaque))
|
|
4590 free_opaque_ptr (opaque);
|
|
4591 free_cons (XCONS (cons));
|
|
4592 UNGCPRO;
|
185
|
4593
|
0
|
4594 /* gc_currently_forbidden = 0; */
|
|
4595 return unbind_to (speccount, tem);
|
|
4596 }
|
|
4597
|
|
4598 Lisp_Object
|
|
4599 call2_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4600 Lisp_Object object1, Lisp_Object object2)
|
|
4601 {
|
|
4602 int speccount = specpdl_depth ();
|
|
4603 Lisp_Object tem;
|
|
4604 Lisp_Object cons = Qnil;
|
|
4605 Lisp_Object opaque = Qnil;
|
|
4606 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4607
|
|
4608 if (SYMBOLP (function))
|
|
4609 {
|
|
4610 tem = XSYMBOL (function)->function;
|
|
4611 if (NILP (tem) || UNBOUNDP (tem))
|
173
|
4612 return Qnil;
|
0
|
4613 }
|
|
4614
|
|
4615 GCPRO5 (cons, opaque, function, object1, object2);
|
|
4616 specbind (Qinhibit_quit, Qt);
|
|
4617 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4618
|
|
4619 cons = list3 (function, object1, object2);
|
|
4620 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4621 /* Qerror not Qt, so you can get a backtrace */
|
|
4622 tem = condition_case_1 (Qerror,
|
|
4623 catch_them_squirmers_call2, cons,
|
|
4624 caught_a_squirmer, opaque);
|
|
4625 if (OPAQUEP (opaque))
|
|
4626 free_opaque_ptr (opaque);
|
|
4627 free_list (cons);
|
|
4628 UNGCPRO;
|
|
4629
|
|
4630 /* gc_currently_forbidden = 0; */
|
|
4631 return unbind_to (speccount, tem);
|
|
4632 }
|
|
4633
|
|
4634
|
|
4635 /**********************************************************************/
|
|
4636 /* The special binding stack */
|
|
4637 /**********************************************************************/
|
|
4638
|
2
|
4639 #define min_max_specpdl_size 400
|
|
4640
|
0
|
4641 static void
|
|
4642 grow_specpdl (void)
|
|
4643 {
|
|
4644 if (specpdl_size >= max_specpdl_size)
|
|
4645 {
|
2
|
4646 if (max_specpdl_size < min_max_specpdl_size)
|
|
4647 max_specpdl_size = min_max_specpdl_size;
|
0
|
4648 if (specpdl_size >= max_specpdl_size)
|
|
4649 {
|
|
4650 if (!NILP (Vdebug_on_error) || !NILP (Vdebug_on_signal))
|
|
4651 /* Leave room for some specpdl in the debugger. */
|
|
4652 max_specpdl_size = specpdl_size + 100;
|
|
4653 continuable_error
|
|
4654 ("Variable binding depth exceeds max-specpdl-size");
|
|
4655 }
|
|
4656 }
|
|
4657 specpdl_size *= 2;
|
|
4658 if (specpdl_size > max_specpdl_size)
|
|
4659 specpdl_size = max_specpdl_size;
|
185
|
4660 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size);
|
0
|
4661 specpdl_ptr = specpdl + specpdl_depth_counter;
|
|
4662 }
|
|
4663
|
|
4664
|
|
4665 /* Handle unbinding buffer-local variables */
|
|
4666 static Lisp_Object
|
|
4667 specbind_unwind_local (Lisp_Object ovalue)
|
|
4668 {
|
|
4669 Lisp_Object current = Fcurrent_buffer ();
|
|
4670 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4671 struct Lisp_Cons *victim = XCONS (ovalue);
|
|
4672 Lisp_Object buf = get_buffer (victim->car, 0);
|
|
4673 ovalue = victim->cdr;
|
|
4674
|
|
4675 free_cons (victim);
|
|
4676
|
|
4677 if (NILP (buf))
|
|
4678 {
|
|
4679 /* Deleted buffer -- do nothing */
|
|
4680 }
|
|
4681 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0)
|
|
4682 {
|
|
4683 /* Was buffer-local when binding was made, now no longer is.
|
|
4684 * (kill-local-variable can do this.)
|
|
4685 * Do nothing in this case.
|
|
4686 */
|
|
4687 }
|
|
4688 else if (EQ (buf, current))
|
|
4689 Fset (symbol, ovalue);
|
|
4690 else
|
|
4691 {
|
|
4692 /* Urk! Somebody switched buffers */
|
|
4693 struct gcpro gcpro1;
|
|
4694 GCPRO1 (current);
|
|
4695 Fset_buffer (buf);
|
|
4696 Fset (symbol, ovalue);
|
|
4697 Fset_buffer (current);
|
|
4698 UNGCPRO;
|
|
4699 }
|
173
|
4700 return symbol;
|
0
|
4701 }
|
|
4702
|
|
4703 static Lisp_Object
|
|
4704 specbind_unwind_wasnt_local (Lisp_Object buffer)
|
|
4705 {
|
|
4706 Lisp_Object current = Fcurrent_buffer ();
|
|
4707 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4708
|
|
4709 buffer = get_buffer (buffer, 0);
|
|
4710 if (NILP (buffer))
|
|
4711 {
|
|
4712 /* Deleted buffer -- do nothing */
|
|
4713 }
|
|
4714 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0)
|
|
4715 {
|
|
4716 /* Was buffer-local when binding was made, now no longer is.
|
|
4717 * (kill-local-variable can do this.)
|
|
4718 * Do nothing in this case.
|
|
4719 */
|
|
4720 }
|
|
4721 else if (EQ (buffer, current))
|
|
4722 Fkill_local_variable (symbol);
|
|
4723 else
|
|
4724 {
|
|
4725 /* Urk! Somebody switched buffers */
|
|
4726 struct gcpro gcpro1;
|
|
4727 GCPRO1 (current);
|
|
4728 Fset_buffer (buffer);
|
|
4729 Fkill_local_variable (symbol);
|
|
4730 Fset_buffer (current);
|
|
4731 UNGCPRO;
|
|
4732 }
|
173
|
4733 return symbol;
|
0
|
4734 }
|
|
4735
|
|
4736
|
|
4737 /* Don't want to include buffer.h just for this */
|
|
4738 extern struct buffer *current_buffer;
|
|
4739
|
|
4740 void
|
|
4741 specbind (Lisp_Object symbol, Lisp_Object value)
|
|
4742 {
|
|
4743 int buffer_local;
|
|
4744
|
|
4745 CHECK_SYMBOL (symbol);
|
|
4746
|
|
4747 if (specpdl_depth_counter >= specpdl_size)
|
|
4748 grow_specpdl ();
|
|
4749
|
|
4750 buffer_local = symbol_value_buffer_local_info (symbol, current_buffer);
|
|
4751 if (buffer_local == 0)
|
|
4752 {
|
|
4753 specpdl_ptr->old_value = find_symbol_value (symbol);
|
|
4754 specpdl_ptr->func = 0; /* Handled specially by unbind_to */
|
|
4755 }
|
|
4756 else if (buffer_local > 0)
|
|
4757 {
|
|
4758 /* Already buffer-local */
|
|
4759 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (),
|
|
4760 find_symbol_value (symbol));
|
|
4761 specpdl_ptr->func = specbind_unwind_local;
|
|
4762 }
|
|
4763 else
|
|
4764 {
|
|
4765 /* About to become buffer-local */
|
|
4766 specpdl_ptr->old_value = Fcurrent_buffer ();
|
|
4767 specpdl_ptr->func = specbind_unwind_wasnt_local;
|
|
4768 }
|
185
|
4769
|
0
|
4770 specpdl_ptr->symbol = symbol;
|
|
4771 specpdl_ptr++;
|
|
4772 specpdl_depth_counter++;
|
|
4773
|
|
4774 Fset (symbol, value);
|
|
4775 }
|
|
4776
|
|
4777 void
|
|
4778 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
|
|
4779 Lisp_Object arg)
|
|
4780 {
|
|
4781 if (specpdl_depth_counter >= specpdl_size)
|
|
4782 grow_specpdl ();
|
|
4783 specpdl_ptr->func = function;
|
|
4784 specpdl_ptr->symbol = Qnil;
|
|
4785 specpdl_ptr->old_value = arg;
|
|
4786 specpdl_ptr++;
|
|
4787 specpdl_depth_counter++;
|
|
4788 }
|
|
4789
|
|
4790 extern int check_sigio (void);
|
|
4791
|
|
4792 Lisp_Object
|
|
4793 unbind_to (int count, Lisp_Object value)
|
|
4794 {
|
|
4795 int quitf;
|
|
4796 struct gcpro gcpro1;
|
|
4797
|
|
4798 GCPRO1 (value);
|
|
4799
|
|
4800 check_quit (); /* make Vquit_flag accurate */
|
|
4801 quitf = !NILP (Vquit_flag);
|
|
4802 Vquit_flag = Qnil;
|
|
4803
|
|
4804 while (specpdl_depth_counter != count)
|
|
4805 {
|
|
4806 Lisp_Object ovalue;
|
|
4807 --specpdl_ptr;
|
|
4808 --specpdl_depth_counter;
|
|
4809
|
|
4810 ovalue = specpdl_ptr->old_value;
|
|
4811 if (specpdl_ptr->func != 0)
|
|
4812 /* An unwind-protect */
|
|
4813 (*specpdl_ptr->func) (ovalue);
|
|
4814 else
|
|
4815 Fset (specpdl_ptr->symbol, ovalue);
|
|
4816
|
|
4817 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
|
|
4818 /* There should never be anything here for us to remove.
|
|
4819 If so, it indicates a logic error in Emacs. Catches
|
|
4820 should get removed when a throw or signal occurs, or
|
|
4821 when a catch or condition-case exits normally. But
|
|
4822 it's too dangerous to just remove this code. --ben */
|
|
4823
|
|
4824 /* Furthermore, this code is not in FSFmacs!!!
|
|
4825 Braino on mly's part? */
|
|
4826 /* If we're unwound past the pdlcount of a catch frame,
|
|
4827 that catch can't possibly still be valid. */
|
|
4828 while (catchlist && catchlist->pdlcount > specpdl_depth_counter)
|
|
4829 {
|
|
4830 catchlist = catchlist->next;
|
|
4831 /* Don't mess with gcprolist, backtrace_list here */
|
|
4832 }
|
|
4833 #endif
|
|
4834 }
|
|
4835 if (quitf)
|
|
4836 Vquit_flag = Qt;
|
|
4837
|
|
4838 UNGCPRO;
|
|
4839
|
173
|
4840 return value;
|
0
|
4841 }
|
|
4842
|
|
4843
|
|
4844 int
|
|
4845 specpdl_depth (void)
|
|
4846 {
|
173
|
4847 return specpdl_depth_counter;
|
0
|
4848 }
|
|
4849
|
|
4850
|
|
4851 /* Get the value of symbol's global binding, even if that binding is
|
|
4852 not now dynamically visible. May return Qunbound or magic values. */
|
|
4853
|
|
4854 Lisp_Object
|
|
4855 top_level_value (Lisp_Object symbol)
|
|
4856 {
|
|
4857 REGISTER struct specbinding *ptr = specpdl;
|
|
4858
|
|
4859 CHECK_SYMBOL (symbol);
|
|
4860 for (; ptr != specpdl_ptr; ptr++)
|
|
4861 {
|
|
4862 if (EQ (ptr->symbol, symbol))
|
|
4863 return ptr->old_value;
|
|
4864 }
|
|
4865 return XSYMBOL (symbol)->value;
|
|
4866 }
|
|
4867
|
|
4868 #if 0
|
|
4869
|
|
4870 Lisp_Object
|
|
4871 top_level_set (Lisp_Object symbol, Lisp_Object newval)
|
|
4872 {
|
|
4873 REGISTER struct specbinding *ptr = specpdl;
|
|
4874
|
|
4875 CHECK_SYMBOL (symbol);
|
|
4876 for (; ptr != specpdl_ptr; ptr++)
|
|
4877 {
|
|
4878 if (EQ (ptr->symbol, symbol))
|
|
4879 {
|
|
4880 ptr->old_value = newval;
|
|
4881 return newval;
|
|
4882 }
|
|
4883 }
|
|
4884 return Fset (symbol, newval);
|
185
|
4885 }
|
0
|
4886
|
|
4887 #endif /* 0 */
|
|
4888
|
|
4889
|
|
4890 /**********************************************************************/
|
|
4891 /* Backtraces */
|
|
4892 /**********************************************************************/
|
|
4893
|
20
|
4894 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
|
0
|
4895 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
4896 The debugger is entered when that frame exits, if the flag is non-nil.
|
20
|
4897 */
|
|
4898 (level, flag))
|
0
|
4899 {
|
|
4900 REGISTER struct backtrace *backlist = backtrace_list;
|
|
4901 REGISTER int i;
|
|
4902
|
|
4903 CHECK_INT (level);
|
|
4904
|
|
4905 for (i = 0; backlist && i < XINT (level); i++)
|
|
4906 {
|
|
4907 backlist = backlist->next;
|
|
4908 }
|
|
4909
|
|
4910 if (backlist)
|
|
4911 backlist->debug_on_exit = !NILP (flag);
|
|
4912
|
|
4913 return flag;
|
|
4914 }
|
|
4915
|
|
4916 static void
|
|
4917 backtrace_specials (int speccount, int speclimit, Lisp_Object stream)
|
|
4918 {
|
|
4919 int printing_bindings = 0;
|
|
4920
|
|
4921 for (; speccount > speclimit; speccount--)
|
|
4922 {
|
|
4923 if (specpdl[speccount - 1].func == 0
|
|
4924 || specpdl[speccount - 1].func == specbind_unwind_local
|
|
4925 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local)
|
|
4926 {
|
|
4927 write_c_string (((!printing_bindings) ? " # bind (" : " "),
|
|
4928 stream);
|
|
4929 Fprin1 (specpdl[speccount - 1].symbol, stream);
|
|
4930 printing_bindings = 1;
|
|
4931 }
|
|
4932 else
|
|
4933 {
|
|
4934 if (printing_bindings) write_c_string (")\n", stream);
|
|
4935 write_c_string (" # (unwind-protect ...)\n", stream);
|
|
4936 printing_bindings = 0;
|
|
4937 }
|
|
4938 }
|
|
4939 if (printing_bindings) write_c_string (")\n", stream);
|
|
4940 }
|
|
4941
|
20
|
4942 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /*
|
0
|
4943 Print a trace of Lisp function calls currently active.
|
|
4944 Option arg STREAM specifies the output stream to send the backtrace to,
|
|
4945 and defaults to the value of `standard-output'. Optional second arg
|
|
4946 DETAILED means show places where currently active variable bindings,
|
|
4947 catches, condition-cases, and unwind-protects were made as well as
|
185
|
4948 function calls.
|
20
|
4949 */
|
|
4950 (stream, detailed))
|
0
|
4951 {
|
|
4952 struct backtrace *backlist = backtrace_list;
|
|
4953 struct catchtag *catches = catchlist;
|
|
4954 int speccount = specpdl_depth_counter;
|
|
4955
|
|
4956 int old_nl = print_escape_newlines;
|
|
4957 int old_pr = print_readably;
|
|
4958 Lisp_Object old_level = Vprint_level;
|
|
4959 Lisp_Object oiq = Vinhibit_quit;
|
|
4960 struct gcpro gcpro1, gcpro2;
|
|
4961
|
|
4962 /* We can't allow quits in here because that could cause the values
|
|
4963 of print_readably and print_escape_newlines to get screwed up.
|
|
4964 Normally we would use a record_unwind_protect but that would
|
|
4965 screw up the functioning of this function. */
|
|
4966 Vinhibit_quit = Qt;
|
|
4967
|
|
4968 entering_debugger = 0;
|
|
4969
|
|
4970 Vprint_level = make_int (3);
|
|
4971 print_readably = 0;
|
|
4972 print_escape_newlines = 1;
|
|
4973
|
|
4974 GCPRO2 (stream, old_level);
|
|
4975
|
|
4976 if (NILP (stream))
|
|
4977 stream = Vstandard_output;
|
|
4978 if (!noninteractive && (NILP (stream) || EQ (stream, Qt)))
|
|
4979 stream = Fselected_frame (Qnil);
|
|
4980
|
|
4981 for (;;)
|
|
4982 {
|
|
4983 if (!NILP (detailed) && catches && catches->backlist == backlist)
|
|
4984 {
|
|
4985 int catchpdl = catches->pdlcount;
|
|
4986 if (specpdl[catchpdl].func == condition_case_unwind
|
|
4987 && speccount > catchpdl)
|
|
4988 /* This is a condition-case catchpoint */
|
|
4989 catchpdl = catchpdl + 1;
|
185
|
4990
|
0
|
4991 backtrace_specials (speccount, catchpdl, stream);
|
|
4992
|
|
4993 speccount = catches->pdlcount;
|
|
4994 if (catchpdl == speccount)
|
|
4995 {
|
|
4996 write_c_string (" # (catch ", stream);
|
|
4997 Fprin1 (catches->tag, stream);
|
|
4998 write_c_string (" ...)\n", stream);
|
|
4999 }
|
|
5000 else
|
|
5001 {
|
|
5002 write_c_string (" # (condition-case ... . ", stream);
|
|
5003 Fprin1 (Fcdr (Fcar (catches->tag)), stream);
|
|
5004 write_c_string (")\n", stream);
|
|
5005 }
|
|
5006 catches = catches->next;
|
|
5007 }
|
|
5008 else if (!backlist)
|
|
5009 break;
|
|
5010 else
|
|
5011 {
|
|
5012 if (!NILP (detailed) && backlist->pdlcount < speccount)
|
|
5013 {
|
|
5014 backtrace_specials (speccount, backlist->pdlcount, stream);
|
|
5015 speccount = backlist->pdlcount;
|
|
5016 }
|
|
5017 write_c_string (((backlist->debug_on_exit) ? "* " : " "),
|
|
5018 stream);
|
|
5019 if (backlist->nargs == UNEVALLED)
|
|
5020 {
|
|
5021 Fprin1 (Fcons (*backlist->function, *backlist->args), stream);
|
|
5022 write_c_string ("\n", stream); /* from FSFmacs 19.30 */
|
|
5023 }
|
|
5024 else
|
|
5025 {
|
|
5026 Lisp_Object tem = *backlist->function;
|
|
5027 Fprin1 (tem, stream); /* This can QUIT */
|
|
5028 write_c_string ("(", stream);
|
|
5029 if (backlist->nargs == MANY)
|
|
5030 {
|
|
5031 int i;
|
|
5032 Lisp_Object tail = Qnil;
|
|
5033 struct gcpro ngcpro1;
|
|
5034
|
|
5035 NGCPRO1 (tail);
|
|
5036 for (tail = *backlist->args, i = 0;
|
|
5037 !NILP (tail);
|
|
5038 tail = Fcdr (tail), i++)
|
|
5039 {
|
|
5040 if (i != 0) write_c_string (" ", stream);
|
|
5041 Fprin1 (Fcar (tail), stream);
|
|
5042 }
|
|
5043 NUNGCPRO;
|
|
5044 }
|
|
5045 else
|
|
5046 {
|
|
5047 int i;
|
|
5048 for (i = 0; i < backlist->nargs; i++)
|
|
5049 {
|
|
5050 if (i != 0) write_c_string (" ", stream);
|
|
5051 Fprin1 (backlist->args[i], stream);
|
|
5052 }
|
|
5053 }
|
|
5054 }
|
|
5055 write_c_string (")\n", stream);
|
|
5056 backlist = backlist->next;
|
|
5057 }
|
|
5058 }
|
|
5059 Vprint_level = old_level;
|
|
5060 print_readably = old_pr;
|
|
5061 print_escape_newlines = old_nl;
|
|
5062 UNGCPRO;
|
|
5063 Vinhibit_quit = oiq;
|
|
5064 return Qnil;
|
|
5065 }
|
|
5066
|
|
5067
|
20
|
5068 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, "", /*
|
0
|
5069 Return the function and arguments N frames up from current execution point.
|
|
5070 If that frame has not evaluated the arguments yet (or is a special form),
|
|
5071 the value is (nil FUNCTION ARG-FORMS...).
|
|
5072 If that frame has evaluated its arguments and called its function already,
|
|
5073 the value is (t FUNCTION ARG-VALUES...).
|
|
5074 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
5075 FUNCTION is whatever was supplied as car of evaluated list,
|
|
5076 or a lambda expression for macro calls.
|
|
5077 If N is more than the number of frames, the value is nil.
|
20
|
5078 */
|
|
5079 (nframes))
|
0
|
5080 {
|
|
5081 REGISTER struct backtrace *backlist = backtrace_list;
|
|
5082 REGISTER int i;
|
|
5083 Lisp_Object tem;
|
|
5084
|
|
5085 CHECK_NATNUM (nframes);
|
|
5086
|
|
5087 /* Find the frame requested. */
|
|
5088 for (i = XINT (nframes); backlist && (i-- > 0);)
|
|
5089 backlist = backlist->next;
|
|
5090
|
|
5091 if (!backlist)
|
|
5092 return Qnil;
|
|
5093 if (backlist->nargs == UNEVALLED)
|
|
5094 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
|
|
5095 else
|
|
5096 {
|
|
5097 if (backlist->nargs == MANY)
|
|
5098 tem = *backlist->args;
|
|
5099 else
|
|
5100 tem = Flist (backlist->nargs, backlist->args);
|
|
5101
|
|
5102 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
5103 }
|
|
5104 }
|
|
5105
|
|
5106
|
|
5107 /**********************************************************************/
|
|
5108 /* Warnings */
|
|
5109 /**********************************************************************/
|
|
5110
|
|
5111 void
|
|
5112 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level,
|
|
5113 Lisp_Object obj)
|
|
5114 {
|
|
5115 obj = list1 (list3 (class, level, obj));
|
|
5116 if (NILP (Vpending_warnings))
|
|
5117 Vpending_warnings = Vpending_warnings_tail = obj;
|
|
5118 else
|
|
5119 {
|
|
5120 Fsetcdr (Vpending_warnings_tail, obj);
|
|
5121 Vpending_warnings_tail = obj;
|
|
5122 }
|
|
5123 }
|
|
5124
|
|
5125 /* #### This should probably accept Lisp objects; but then we have
|
|
5126 to make sure that Feval() isn't called, since it might not be safe.
|
|
5127
|
|
5128 An alternative approach is to just pass some non-string type of
|
|
5129 Lisp Object to warn_when_safe_lispobj(); `prin1-to-string' will
|
|
5130 automatically be called when it is safe to do so. */
|
|
5131
|
|
5132 void
|
|
5133 warn_when_safe (Lisp_Object class, Lisp_Object level, CONST char *fmt, ...)
|
|
5134 {
|
|
5135 Lisp_Object obj;
|
|
5136 va_list args;
|
|
5137
|
|
5138 va_start (args, fmt);
|
|
5139 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt),
|
|
5140 Qnil, -1, args);
|
|
5141 va_end (args);
|
|
5142
|
|
5143 warn_when_safe_lispobj (class, level, obj);
|
|
5144 }
|
|
5145
|
|
5146
|
|
5147
|
|
5148
|
|
5149 /**********************************************************************/
|
|
5150 /* Initialization */
|
|
5151 /**********************************************************************/
|
|
5152
|
|
5153 void
|
|
5154 syms_of_eval (void)
|
|
5155 {
|
|
5156 defsymbol (&Qinhibit_quit, "inhibit-quit");
|
|
5157 defsymbol (&Qautoload, "autoload");
|
|
5158 defsymbol (&Qdebug_on_error, "debug-on-error");
|
|
5159 defsymbol (&Qstack_trace_on_error, "stack-trace-on-error");
|
|
5160 defsymbol (&Qdebug_on_signal, "debug-on-signal");
|
|
5161 defsymbol (&Qstack_trace_on_signal, "stack-trace-on-signal");
|
|
5162 defsymbol (&Qdebugger, "debugger");
|
|
5163 defsymbol (&Qmacro, "macro");
|
|
5164 defsymbol (&Qand_rest, "&rest");
|
|
5165 defsymbol (&Qand_optional, "&optional");
|
|
5166 /* Note that the process code also uses Qexit */
|
|
5167 defsymbol (&Qexit, "exit");
|
|
5168 defsymbol (&Qsetq, "setq");
|
|
5169 defsymbol (&Qinteractive, "interactive");
|
|
5170 defsymbol (&Qcommandp, "commandp");
|
|
5171 defsymbol (&Qdefun, "defun");
|
|
5172 defsymbol (&Qprogn, "progn");
|
|
5173 defsymbol (&Qvalues, "values");
|
|
5174 defsymbol (&Qdisplay_warning, "display-warning");
|
|
5175 defsymbol (&Qrun_hooks, "run-hooks");
|
|
5176
|
20
|
5177 DEFSUBR (For);
|
|
5178 DEFSUBR (Fand);
|
|
5179 DEFSUBR (Fif);
|
|
5180 DEFSUBR (Fcond);
|
|
5181 DEFSUBR (Fprogn);
|
|
5182 DEFSUBR (Fprog1);
|
|
5183 DEFSUBR (Fprog2);
|
|
5184 DEFSUBR (Fsetq);
|
|
5185 DEFSUBR (Fquote);
|
|
5186 DEFSUBR (Ffunction);
|
|
5187 DEFSUBR (Fdefun);
|
|
5188 DEFSUBR (Fdefmacro);
|
|
5189 DEFSUBR (Fdefvar);
|
|
5190 DEFSUBR (Fdefconst);
|
|
5191 DEFSUBR (Fuser_variable_p);
|
|
5192 DEFSUBR (Flet);
|
|
5193 DEFSUBR (FletX);
|
|
5194 DEFSUBR (Fwhile);
|
|
5195 DEFSUBR (Fmacroexpand_internal);
|
|
5196 DEFSUBR (Fcatch);
|
|
5197 DEFSUBR (Fthrow);
|
|
5198 DEFSUBR (Funwind_protect);
|
|
5199 DEFSUBR (Fcondition_case);
|
|
5200 DEFSUBR (Fcall_with_condition_handler);
|
|
5201 DEFSUBR (Fsignal);
|
|
5202 DEFSUBR (Finteractive_p);
|
|
5203 DEFSUBR (Fcommandp);
|
|
5204 DEFSUBR (Fcommand_execute);
|
|
5205 DEFSUBR (Fautoload);
|
|
5206 DEFSUBR (Feval);
|
|
5207 DEFSUBR (Fapply);
|
|
5208 DEFSUBR (Ffuncall);
|
|
5209 DEFSUBR (Ffunction_min_args);
|
|
5210 DEFSUBR (Ffunction_max_args);
|
|
5211 DEFSUBR (Frun_hooks);
|
|
5212 DEFSUBR (Frun_hook_with_args);
|
|
5213 DEFSUBR (Frun_hook_with_args_until_success);
|
|
5214 DEFSUBR (Frun_hook_with_args_until_failure);
|
|
5215 DEFSUBR (Ffetch_bytecode);
|
|
5216 DEFSUBR (Fbacktrace_debug);
|
|
5217 DEFSUBR (Fbacktrace);
|
|
5218 DEFSUBR (Fbacktrace_frame);
|
0
|
5219 }
|
|
5220
|
|
5221 void
|
|
5222 reinit_eval (void)
|
|
5223 {
|
|
5224 specpdl_ptr = specpdl;
|
|
5225 specpdl_depth_counter = 0;
|
|
5226 catchlist = 0;
|
|
5227 Vcondition_handlers = Qnil;
|
|
5228 backtrace_list = 0;
|
|
5229 Vquit_flag = Qnil;
|
|
5230 debug_on_next_call = 0;
|
|
5231 lisp_eval_depth = 0;
|
|
5232 entering_debugger = 0;
|
|
5233 }
|
|
5234
|
|
5235 void
|
|
5236 vars_of_eval (void)
|
|
5237 {
|
|
5238 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /*
|
|
5239 Limit on number of Lisp variable bindings & unwind-protects before error.
|
|
5240 */ );
|
|
5241
|
|
5242 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /*
|
|
5243 Limit on depth in `eval', `apply' and `funcall' before error.
|
|
5244 This limit is to catch infinite recursions for you before they cause
|
|
5245 actual stack overflow in C, which would be fatal for Emacs.
|
|
5246 You can safely make it considerably larger than its default value,
|
|
5247 if that proves inconveniently small.
|
|
5248 */ );
|
|
5249
|
|
5250 DEFVAR_LISP ("quit-flag", &Vquit_flag /*
|
|
5251 Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
|
|
5252 Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'.
|
|
5253 */ );
|
|
5254 Vquit_flag = Qnil;
|
|
5255
|
|
5256 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /*
|
|
5257 Non-nil inhibits C-g quitting from happening immediately.
|
|
5258 Note that `quit-flag' will still be set by typing C-g,
|
|
5259 so a quit will be signalled as soon as `inhibit-quit' is nil.
|
|
5260 To prevent this happening, set `quit-flag' to nil
|
|
5261 before making `inhibit-quit' nil. The value of `inhibit-quit' is
|
|
5262 ignored if a critical quit is requested by typing control-shift-G in
|
|
5263 an X frame.
|
|
5264 */ );
|
|
5265 Vinhibit_quit = Qnil;
|
|
5266
|
|
5267 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /*
|
|
5268 *Non-nil means automatically display a backtrace buffer
|
|
5269 after any error that is not handled by a `condition-case'.
|
|
5270 If the value is a list, an error only means to display a backtrace
|
|
5271 if one of its condition symbols appears in the list.
|
|
5272 See also variable `stack-trace-on-signal'.
|
|
5273 */ );
|
|
5274 Vstack_trace_on_error = Qnil;
|
|
5275
|
|
5276 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /*
|
|
5277 *Non-nil means automatically display a backtrace buffer
|
|
5278 after any error that is signalled, whether or not it is handled by
|
|
5279 a `condition-case'.
|
|
5280 If the value is a list, an error only means to display a backtrace
|
|
5281 if one of its condition symbols appears in the list.
|
|
5282 See also variable `stack-trace-on-error'.
|
|
5283 */ );
|
|
5284 Vstack_trace_on_signal = Qnil;
|
|
5285
|
163
|
5286 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors /*
|
|
5287 *List of errors for which the debugger should not be called.
|
|
5288 Each element may be a condition-name or a regexp that matches error messages.
|
|
5289 If any element applies to a given error, that error skips the debugger
|
|
5290 and just returns to top level.
|
|
5291 This overrides the variable `debug-on-error'.
|
|
5292 It does not apply to errors handled by `condition-case'.
|
|
5293 */ );
|
|
5294 Vdebug_ignored_errors = Qnil;
|
|
5295
|
0
|
5296 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
|
|
5297 *Non-nil means enter debugger if an unhandled error is signalled.
|
|
5298 The debugger will not be entered if the error is handled by
|
|
5299 a `condition-case'.
|
|
5300 If the value is a list, an error only means to enter the debugger
|
|
5301 if one of its condition symbols appears in the list.
|
181
|
5302 This variable is overridden by `debug-ignored-errors'.
|
0
|
5303 See also variables `debug-on-quit' and `debug-on-signal'.
|
|
5304 */ );
|
|
5305 Vdebug_on_error = Qnil;
|
|
5306
|
|
5307 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /*
|
|
5308 *Non-nil means enter debugger if an error is signalled.
|
|
5309 The debugger will be entered whether or not the error is handled by
|
|
5310 a `condition-case'.
|
|
5311 If the value is a list, an error only means to enter the debugger
|
|
5312 if one of its condition symbols appears in the list.
|
|
5313 See also variable `debug-on-quit'.
|
|
5314 */ );
|
|
5315 Vdebug_on_signal = Qnil;
|
|
5316
|
|
5317 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /*
|
|
5318 *Non-nil means enter debugger if quit is signalled (C-G, for example).
|
|
5319 Does not apply if quit is handled by a `condition-case'. Entering the
|
|
5320 debugger can also be achieved at any time (for X11 console) by typing
|
|
5321 control-shift-G to signal a critical quit.
|
|
5322 */ );
|
|
5323 debug_on_quit = 0;
|
|
5324
|
|
5325 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /*
|
|
5326 Non-nil means enter debugger before next `eval', `apply' or `funcall'.
|
|
5327 */ );
|
|
5328
|
|
5329 DEFVAR_LISP ("debugger", &Vdebugger /*
|
|
5330 Function to call to invoke debugger.
|
|
5331 If due to frame exit, args are `exit' and the value being returned;
|
|
5332 this function's value will be returned instead of that.
|
|
5333 If due to error, args are `error' and a list of the args to `signal'.
|
|
5334 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
5335 If due to `eval' entry, one arg, t.
|
|
5336 */ );
|
|
5337 Vdebugger = Qnil;
|
|
5338
|
|
5339 preparing_for_armageddon = 0;
|
|
5340
|
|
5341 staticpro (&Vpending_warnings);
|
|
5342 Vpending_warnings = Qnil;
|
|
5343 Vpending_warnings_tail = Qnil; /* no need to protect this */
|
|
5344
|
|
5345 in_warnings = 0;
|
|
5346
|
|
5347 staticpro (&Vautoload_queue);
|
|
5348 Vautoload_queue = Qnil;
|
|
5349
|
|
5350 staticpro (&Vcondition_handlers);
|
|
5351
|
|
5352 staticpro (&Vcurrent_warning_class);
|
|
5353 Vcurrent_warning_class = Qnil;
|
|
5354
|
|
5355 staticpro (&Vcurrent_error_state);
|
|
5356 Vcurrent_error_state = Qnil; /* errors as normal */
|
|
5357
|
|
5358 Qunbound_suspended_errors_tag = make_opaque_long (0);
|
|
5359 staticpro (&Qunbound_suspended_errors_tag);
|
|
5360
|
|
5361 specpdl_size = 50;
|
|
5362 specpdl_depth_counter = 0;
|
185
|
5363 specpdl = xnew_array (struct specbinding, specpdl_size);
|
0
|
5364 /* XEmacs change: increase these values. */
|
|
5365 max_specpdl_size = 3000;
|
|
5366 max_lisp_eval_depth = 500;
|
|
5367 throw_level = 0;
|
|
5368
|
|
5369 reinit_eval ();
|
|
5370 }
|