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