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