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