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