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