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
|
70
|
221 static Lisp_Object primitive_funcall (Lisp_Object (*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);
|
70
|
2057 return (primitive_funcall
|
|
2058 ((Lisp_Object (*)()) get_opaque_ptr (kludgy_args[0]),
|
|
2059 XINT (kludgy_args[1]), kludgy_args + 2));
|
0
|
2060 }
|
|
2061
|
|
2062 static Lisp_Object
|
|
2063 restore_current_warning_class (Lisp_Object warning_class)
|
|
2064 {
|
|
2065 Vcurrent_warning_class = warning_class;
|
|
2066 return Qnil;
|
|
2067 }
|
|
2068
|
|
2069 static Lisp_Object
|
|
2070 restore_current_error_state (Lisp_Object error_state)
|
|
2071 {
|
|
2072 Vcurrent_error_state = error_state;
|
|
2073 return Qnil;
|
|
2074 }
|
|
2075
|
|
2076 /* Many functions would like to do one of three things if an error
|
|
2077 occurs:
|
|
2078
|
|
2079 (1) signal the error, as usual.
|
|
2080 (2) silently fail and return some error value.
|
|
2081 (3) do as (2) but issue a warning in the process.
|
|
2082
|
|
2083 Currently there's lots of stuff that passes an Error_behavior
|
|
2084 value and calls maybe_signal_error() and other such functions.
|
|
2085 This approach is inherently error-prone and broken. A much
|
|
2086 more robust and easier approach is to use call_with_suspended_errors().
|
|
2087 Wrap this around any function in which you might want errors
|
|
2088 to not be errors.
|
|
2089 */
|
|
2090
|
|
2091 Lisp_Object
|
70
|
2092 call_with_suspended_errors (Lisp_Object (*fun)(), Lisp_Object retval,
|
0
|
2093 Lisp_Object class, Error_behavior errb,
|
|
2094 int nargs, ...)
|
|
2095 {
|
|
2096 va_list vargs;
|
|
2097 int speccount;
|
|
2098 Lisp_Object kludgy_args[22];
|
|
2099 Lisp_Object *args = kludgy_args + 2;
|
|
2100 int i;
|
|
2101 Lisp_Object no_error;
|
|
2102
|
|
2103 assert (SYMBOLP (class)); /* sanity-check */
|
|
2104 assert (!NILP (class));
|
|
2105 assert (nargs >= 0 && nargs < 20);
|
|
2106
|
|
2107 /* ERROR_ME means don't trap errors. (However, if errors are
|
|
2108 already trapped, we leave them trapped.)
|
|
2109
|
|
2110 Otherwise, we trap errors, and trap warnings if ERROR_ME_WARN.
|
|
2111
|
|
2112 If ERROR_ME_NOT, it causes no warnings even if warnings
|
|
2113 were previously enabled. However, we never change the
|
|
2114 warning class from one to another. */
|
|
2115 if (!ERRB_EQ (errb, ERROR_ME))
|
|
2116 {
|
|
2117 if (ERRB_EQ (errb, ERROR_ME_NOT)) /* person wants no warnings */
|
|
2118 class = Qnil;
|
|
2119 errb = ERROR_ME_NOT;
|
|
2120 no_error = Qt;
|
|
2121 }
|
|
2122 else
|
|
2123 no_error = Qnil;
|
|
2124
|
|
2125 va_start (vargs, nargs);
|
|
2126 for (i = 0; i < nargs; i++)
|
|
2127 args[i] = va_arg (vargs, Lisp_Object);
|
|
2128 va_end (vargs);
|
|
2129
|
|
2130 /* If error-checking is not disabled, just call the function.
|
|
2131 It's important not to override disabled error-checking with
|
|
2132 enabled error-checking. */
|
|
2133
|
|
2134 if (ERRB_EQ (errb, ERROR_ME))
|
|
2135 return primitive_funcall (fun, nargs, args);
|
|
2136
|
|
2137 speccount = specpdl_depth ();
|
|
2138 if (NILP (class) || NILP (Vcurrent_warning_class))
|
|
2139 {
|
|
2140 /* If we're currently calling for no warnings, then make it so.
|
|
2141 If we're currently calling for warnings and we weren't
|
|
2142 previously, then set our warning class; otherwise, leave
|
|
2143 the existing one alone. */
|
|
2144 record_unwind_protect (restore_current_warning_class,
|
|
2145 Vcurrent_warning_class);
|
|
2146 Vcurrent_warning_class = class;
|
|
2147 }
|
|
2148 if (!EQ (Vcurrent_error_state, no_error))
|
|
2149 {
|
|
2150 record_unwind_protect (restore_current_error_state,
|
|
2151 Vcurrent_error_state);
|
|
2152 Vcurrent_error_state = no_error;
|
|
2153 }
|
|
2154
|
|
2155 {
|
|
2156 int threw;
|
|
2157 Lisp_Object the_retval;
|
|
2158 Lisp_Object opaque1 = make_opaque_ptr (kludgy_args);
|
|
2159 Lisp_Object opaque2 = make_opaque_ptr ((void *) fun);
|
|
2160 struct gcpro gcpro1, gcpro2;
|
|
2161
|
|
2162 GCPRO2 (opaque1, opaque2);
|
|
2163 kludgy_args[0] = opaque2;
|
|
2164 kludgy_args[1] = make_int (nargs);
|
|
2165 the_retval = internal_catch (Qunbound_suspended_errors_tag,
|
|
2166 call_with_suspended_errors_1,
|
|
2167 opaque1, &threw);
|
|
2168 free_opaque_ptr (opaque1);
|
|
2169 free_opaque_ptr (opaque2);
|
|
2170 UNGCPRO;
|
|
2171 /* Use the returned value except in non-local exit, when
|
|
2172 RETVAL applies. */
|
|
2173 if (!threw)
|
|
2174 retval = the_retval;
|
|
2175 return unbind_to (speccount, retval);
|
|
2176 }
|
|
2177 }
|
|
2178
|
|
2179 /* Signal a non-continuable error or display a warning or do nothing,
|
|
2180 according to ERRB. CLASS is the class of warning and should
|
|
2181 refer to what sort of operation is being done (e.g. Qtoolbar,
|
|
2182 Qresource, etc.). */
|
|
2183
|
|
2184 void
|
|
2185 maybe_signal_error (Lisp_Object sig, Lisp_Object data, Lisp_Object class,
|
|
2186 Error_behavior errb)
|
|
2187 {
|
|
2188 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2189 return;
|
|
2190 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2191 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2192 else
|
|
2193 for (;;)
|
|
2194 Fsignal (sig, data);
|
|
2195 }
|
|
2196
|
|
2197 /* Signal a continuable error or display a warning or do nothing,
|
|
2198 according to ERRB. */
|
|
2199
|
|
2200 Lisp_Object
|
|
2201 maybe_signal_continuable_error (Lisp_Object sig, Lisp_Object data,
|
|
2202 Lisp_Object class, Error_behavior errb)
|
|
2203 {
|
|
2204 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2205 return Qnil;
|
|
2206 else if (ERRB_EQ (errb, ERROR_ME_WARN))
|
|
2207 {
|
|
2208 warn_when_safe_lispobj (class, Qwarning, Fcons (sig, data));
|
|
2209 return Qnil;
|
|
2210 }
|
|
2211 else
|
|
2212 return Fsignal (sig, data);
|
|
2213 }
|
|
2214
|
|
2215
|
|
2216 /****************** Error functions class 2 ******************/
|
|
2217
|
|
2218 /* Class 2: Printf-like functions that signal an error.
|
|
2219 These functions signal an error of type Qerror, whose data
|
|
2220 is a single string, created using the arguments. */
|
|
2221
|
|
2222 /* dump an error message; called like printf */
|
|
2223
|
|
2224 DOESNT_RETURN
|
|
2225 error (CONST char *fmt, ...)
|
|
2226 {
|
|
2227 Lisp_Object obj;
|
|
2228 va_list args;
|
|
2229
|
|
2230 va_start (args, fmt);
|
|
2231 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2232 args);
|
|
2233 va_end (args);
|
|
2234
|
|
2235 /* Fsignal GC-protects its args */
|
|
2236 signal_error (Qerror, list1 (obj));
|
|
2237 }
|
|
2238
|
|
2239 void
|
|
2240 maybe_error (Lisp_Object class, Error_behavior errb, CONST char *fmt, ...)
|
|
2241 {
|
|
2242 Lisp_Object obj;
|
|
2243 va_list args;
|
|
2244
|
|
2245 /* Optimization: */
|
|
2246 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2247 return;
|
|
2248
|
|
2249 va_start (args, fmt);
|
|
2250 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2251 args);
|
|
2252 va_end (args);
|
|
2253
|
|
2254 /* Fsignal GC-protects its args */
|
|
2255 maybe_signal_error (Qerror, list1 (obj), class, errb);
|
|
2256 }
|
|
2257
|
|
2258 Lisp_Object
|
|
2259 continuable_error (CONST char *fmt, ...)
|
|
2260 {
|
|
2261 Lisp_Object obj;
|
|
2262 va_list args;
|
|
2263
|
|
2264 va_start (args, fmt);
|
|
2265 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2266 args);
|
|
2267 va_end (args);
|
|
2268
|
|
2269 /* Fsignal GC-protects its args */
|
|
2270 return Fsignal (Qerror, list1 (obj));
|
|
2271 }
|
|
2272
|
|
2273 Lisp_Object
|
|
2274 maybe_continuable_error (Lisp_Object class, Error_behavior errb,
|
|
2275 CONST char *fmt, ...)
|
|
2276 {
|
|
2277 Lisp_Object obj;
|
|
2278 va_list args;
|
|
2279
|
|
2280 /* Optimization: */
|
|
2281 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2282 return Qnil;
|
|
2283
|
|
2284 va_start (args, fmt);
|
|
2285 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2286 args);
|
|
2287 va_end (args);
|
|
2288
|
|
2289 /* Fsignal GC-protects its args */
|
|
2290 return maybe_signal_continuable_error (Qerror, list1 (obj), class, errb);
|
|
2291 }
|
|
2292
|
|
2293
|
|
2294 /****************** Error functions class 3 ******************/
|
|
2295
|
|
2296 /* Class 3: Signal an error with a string and an associated object.
|
|
2297 These functions signal an error of type Qerror, whose data
|
|
2298 is two objects, a string and a related Lisp object (usually the object
|
|
2299 where the error is occurring). */
|
|
2300
|
|
2301 DOESNT_RETURN
|
|
2302 signal_simple_error (CONST char *reason, Lisp_Object frob)
|
|
2303 {
|
|
2304 signal_error (Qerror, list2 (build_translated_string (reason), frob));
|
|
2305 }
|
|
2306
|
|
2307 void
|
|
2308 maybe_signal_simple_error (CONST char *reason, Lisp_Object frob,
|
|
2309 Lisp_Object class, Error_behavior errb)
|
|
2310 {
|
|
2311 /* Optimization: */
|
|
2312 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2313 return;
|
|
2314 maybe_signal_error (Qerror, list2 (build_translated_string (reason), frob),
|
|
2315 class, errb);
|
|
2316 }
|
|
2317
|
|
2318 Lisp_Object
|
|
2319 signal_simple_continuable_error (CONST char *reason, Lisp_Object frob)
|
|
2320 {
|
|
2321 return Fsignal (Qerror, list2 (build_translated_string (reason), frob));
|
|
2322 }
|
|
2323
|
|
2324 Lisp_Object
|
|
2325 maybe_signal_simple_continuable_error (CONST char *reason, Lisp_Object frob,
|
|
2326 Lisp_Object class, Error_behavior errb)
|
|
2327 {
|
|
2328 /* Optimization: */
|
|
2329 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2330 return Qnil;
|
|
2331 return maybe_signal_continuable_error
|
|
2332 (Qerror, list2 (build_translated_string (reason),
|
|
2333 frob), class, errb);
|
|
2334 }
|
|
2335
|
|
2336
|
|
2337 /****************** Error functions class 4 ******************/
|
|
2338
|
|
2339 /* Class 4: Printf-like functions that signal an error.
|
|
2340 These functions signal an error of type Qerror, whose data
|
|
2341 is a two objects, a string (created using the arguments) and a
|
|
2342 Lisp object.
|
|
2343 */
|
|
2344
|
|
2345 DOESNT_RETURN
|
|
2346 error_with_frob (Lisp_Object frob, CONST char *fmt, ...)
|
|
2347 {
|
|
2348 Lisp_Object obj;
|
|
2349 va_list args;
|
|
2350
|
|
2351 va_start (args, fmt);
|
|
2352 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2353 args);
|
|
2354 va_end (args);
|
|
2355
|
|
2356 /* Fsignal GC-protects its args */
|
|
2357 signal_error (Qerror, list2 (obj, frob));
|
|
2358 }
|
|
2359
|
|
2360 void
|
|
2361 maybe_error_with_frob (Lisp_Object frob, Lisp_Object class,
|
|
2362 Error_behavior errb, CONST char *fmt, ...)
|
|
2363 {
|
|
2364 Lisp_Object obj;
|
|
2365 va_list args;
|
|
2366
|
|
2367 /* Optimization: */
|
|
2368 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2369 return;
|
|
2370
|
|
2371 va_start (args, fmt);
|
|
2372 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2373 args);
|
|
2374 va_end (args);
|
|
2375
|
|
2376 /* Fsignal GC-protects its args */
|
|
2377 maybe_signal_error (Qerror, list2 (obj, frob), class, errb);
|
|
2378 }
|
|
2379
|
|
2380 Lisp_Object
|
|
2381 continuable_error_with_frob (Lisp_Object frob, CONST char *fmt, ...)
|
|
2382 {
|
|
2383 Lisp_Object obj;
|
|
2384 va_list args;
|
|
2385
|
|
2386 va_start (args, fmt);
|
|
2387 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2388 args);
|
|
2389 va_end (args);
|
|
2390
|
|
2391 /* Fsignal GC-protects its args */
|
|
2392 return Fsignal (Qerror, list2 (obj, frob));
|
|
2393 }
|
|
2394
|
|
2395 Lisp_Object
|
|
2396 maybe_continuable_error_with_frob (Lisp_Object frob, Lisp_Object class,
|
|
2397 Error_behavior errb, CONST char *fmt, ...)
|
|
2398 {
|
|
2399 Lisp_Object obj;
|
|
2400 va_list args;
|
|
2401
|
|
2402 /* Optimization: */
|
|
2403 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2404 return Qnil;
|
|
2405
|
|
2406 va_start (args, fmt);
|
|
2407 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt), Qnil, -1,
|
|
2408 args);
|
|
2409 va_end (args);
|
|
2410
|
|
2411 /* Fsignal GC-protects its args */
|
|
2412 return maybe_signal_continuable_error (Qerror, list2 (obj, frob),
|
|
2413 class, errb);
|
|
2414 }
|
|
2415
|
|
2416
|
|
2417 /****************** Error functions class 5 ******************/
|
|
2418
|
|
2419 /* Class 5: Signal an error with a string and two associated objects.
|
|
2420 These functions signal an error of type Qerror, whose data
|
|
2421 is three objects, a string and two related Lisp objects. */
|
|
2422
|
|
2423 DOESNT_RETURN
|
|
2424 signal_simple_error_2 (CONST char *reason,
|
|
2425 Lisp_Object frob0, Lisp_Object frob1)
|
|
2426 {
|
|
2427 signal_error (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2428 frob1));
|
|
2429 }
|
|
2430
|
|
2431 void
|
|
2432 maybe_signal_simple_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2433 Lisp_Object frob1, Lisp_Object class,
|
|
2434 Error_behavior errb)
|
|
2435 {
|
|
2436 /* Optimization: */
|
|
2437 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2438 return;
|
|
2439 maybe_signal_error (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2440 frob1), class, errb);
|
|
2441 }
|
|
2442
|
|
2443
|
|
2444 Lisp_Object
|
|
2445 signal_simple_continuable_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2446 Lisp_Object frob1)
|
|
2447 {
|
|
2448 return Fsignal (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2449 frob1));
|
|
2450 }
|
|
2451
|
|
2452 Lisp_Object
|
|
2453 maybe_signal_simple_continuable_error_2 (CONST char *reason, Lisp_Object frob0,
|
|
2454 Lisp_Object frob1, Lisp_Object class,
|
|
2455 Error_behavior errb)
|
|
2456 {
|
|
2457 /* Optimization: */
|
|
2458 if (ERRB_EQ (errb, ERROR_ME_NOT))
|
|
2459 return Qnil;
|
|
2460 return maybe_signal_continuable_error
|
|
2461 (Qerror, list3 (build_translated_string (reason), frob0,
|
|
2462 frob1),
|
|
2463 class, errb);
|
|
2464 }
|
|
2465
|
|
2466
|
|
2467 /* This is what the QUIT macro calls to signal a quit */
|
|
2468 void
|
|
2469 signal_quit (void)
|
|
2470 {
|
|
2471 /* This function can GC */
|
|
2472 if (EQ (Vquit_flag, Qcritical))
|
|
2473 debug_on_quit |= 2; /* set critical bit. */
|
|
2474 Vquit_flag = Qnil;
|
|
2475 /* note that this is continuable. */
|
|
2476 Fsignal (Qquit, Qnil);
|
|
2477 }
|
|
2478
|
|
2479
|
|
2480 /**********************************************************************/
|
|
2481 /* User commands */
|
|
2482 /**********************************************************************/
|
|
2483
|
20
|
2484 DEFUN ("commandp", Fcommandp, 1, 1, 0, /*
|
0
|
2485 T if FUNCTION makes provisions for interactive calling.
|
|
2486 This means it contains a description for how to read arguments to give it.
|
|
2487 The value is nil for an invalid function or a symbol with no function
|
|
2488 definition.
|
|
2489
|
|
2490 Interactively callable functions include
|
|
2491
|
|
2492 -- strings and vectors (treated as keyboard macros)
|
|
2493 -- lambda-expressions that contain a top-level call to `interactive'
|
|
2494 -- autoload definitions made by `autoload' with non-nil fourth argument
|
|
2495 (i.e. the interactive flag)
|
|
2496 -- compiled-function objects with a non-nil `compiled-function-interactive'
|
|
2497 value
|
|
2498 -- subrs (built-in functions) that are interactively callable
|
|
2499
|
|
2500 Also, a symbol satisfies `commandp' if its function definition does so.
|
20
|
2501 */
|
|
2502 (function))
|
0
|
2503 {
|
|
2504 REGISTER Lisp_Object fun;
|
|
2505 REGISTER Lisp_Object funcar;
|
|
2506
|
|
2507 fun = function;
|
|
2508
|
|
2509 fun = indirect_function (fun, 0);
|
|
2510 if (UNBOUNDP (fun))
|
|
2511 return Qnil;
|
|
2512
|
|
2513 /* Emacs primitives are interactive if their DEFUN specifies an
|
|
2514 interactive spec. */
|
|
2515 if (SUBRP (fun))
|
|
2516 {
|
|
2517 if (XSUBR (fun)->prompt)
|
|
2518 return Qt;
|
|
2519 else
|
|
2520 return Qnil;
|
|
2521 }
|
|
2522
|
|
2523 else if (COMPILED_FUNCTIONP (fun))
|
|
2524 {
|
|
2525 return (((XCOMPILED_FUNCTION (fun)->flags.interactivep) ? Qt : Qnil));
|
|
2526 }
|
|
2527
|
|
2528 /* Strings and vectors are keyboard macros. */
|
|
2529 if (VECTORP (fun) || STRINGP (fun))
|
|
2530 return Qt;
|
|
2531
|
|
2532 /* Lists may represent commands. */
|
|
2533 if (!CONSP (fun))
|
|
2534 return Qnil;
|
|
2535 funcar = Fcar (fun);
|
|
2536 if (!SYMBOLP (funcar))
|
|
2537 return Fsignal (Qinvalid_function, list1 (fun));
|
|
2538 if (EQ (funcar, Qlambda))
|
|
2539 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
|
|
2540 #ifdef MOCKLISP_SUPPORT
|
|
2541 if (EQ (funcar, Qmocklisp))
|
|
2542 return Qt; /* All mocklisp functions can be called interactively */
|
|
2543 #endif
|
|
2544 if (EQ (funcar, Qautoload))
|
|
2545 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
|
|
2546 else
|
|
2547 return Qnil;
|
|
2548 }
|
|
2549
|
20
|
2550 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /*
|
0
|
2551 Execute CMD as an editor command.
|
|
2552 CMD must be an object that satisfies the `commandp' predicate.
|
|
2553 Optional second arg RECORD-FLAG is as in `call-interactively'.
|
|
2554 The argument KEYS specifies the value to use instead of (this-command-keys)
|
|
2555 when reading the arguments.
|
20
|
2556 */
|
|
2557 (cmd, record, keys))
|
0
|
2558 {
|
|
2559 /* This function can GC */
|
|
2560 Lisp_Object prefixarg;
|
|
2561 Lisp_Object final = cmd;
|
|
2562 struct backtrace backtrace;
|
|
2563 struct console *con = XCONSOLE (Vselected_console);
|
|
2564
|
|
2565 prefixarg = con->prefix_arg;
|
|
2566 con->prefix_arg = Qnil;
|
|
2567 Vcurrent_prefix_arg = prefixarg;
|
|
2568 debug_on_next_call = 0; /* #### from FSFmacs; correct? */
|
|
2569
|
|
2570 if (SYMBOLP (cmd) && !NILP (Fget (cmd, Qdisabled, Qnil)))
|
|
2571 return run_hook (Vdisabled_command_hook);
|
|
2572
|
|
2573 for (;;)
|
|
2574 {
|
|
2575 final = indirect_function (cmd, 1);
|
|
2576 if (CONSP (final) && EQ (Fcar (final), Qautoload))
|
|
2577 do_autoload (final, cmd);
|
|
2578 else
|
|
2579 break;
|
|
2580 }
|
|
2581
|
|
2582 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final))
|
|
2583 {
|
|
2584 #ifdef EMACS_BTL
|
|
2585 backtrace.id_number = 0;
|
|
2586 #endif
|
70
|
2587 backtrace.next = backtrace_list;
|
|
2588 backtrace_list = &backtrace;
|
0
|
2589 backtrace.function = &Qcall_interactively;
|
|
2590 backtrace.args = &cmd;
|
|
2591 backtrace.nargs = 1;
|
|
2592 backtrace.evalargs = 0;
|
|
2593 backtrace.pdlcount = specpdl_depth ();
|
|
2594 backtrace.debug_on_exit = 0;
|
|
2595
|
|
2596 final = Fcall_interactively (cmd, record, keys);
|
|
2597
|
70
|
2598 backtrace_list = backtrace.next;
|
0
|
2599 return (final);
|
|
2600 }
|
|
2601 else if (STRINGP (final) || VECTORP (final))
|
|
2602 {
|
|
2603 return Fexecute_kbd_macro (final, prefixarg);
|
|
2604 }
|
|
2605 else
|
|
2606 {
|
|
2607 Fsignal (Qwrong_type_argument,
|
|
2608 Fcons (Qcommandp,
|
|
2609 ((EQ (cmd, final))
|
|
2610 ? list1 (cmd)
|
|
2611 : list2 (cmd, final))));
|
|
2612 return Qnil;
|
|
2613 }
|
|
2614 }
|
|
2615
|
20
|
2616 DEFUN ("interactive-p", Finteractive_p, 0, 0, 0, /*
|
0
|
2617 Return t if function in which this appears was called interactively.
|
|
2618 This means that the function was called with call-interactively (which
|
|
2619 includes being called as the binding of a key)
|
|
2620 and input is currently coming from the keyboard (not in keyboard macro).
|
20
|
2621 */
|
|
2622 ())
|
0
|
2623 {
|
|
2624 REGISTER struct backtrace *btp;
|
|
2625 REGISTER Lisp_Object fun;
|
|
2626
|
|
2627 if (!INTERACTIVE)
|
|
2628 return Qnil;
|
|
2629
|
|
2630 /* Unless the object was compiled, skip the frame of interactive-p itself
|
|
2631 (if interpreted) or the frame of byte-code (if called from a compiled
|
|
2632 function). Note that *btp->function may be a symbol pointing at a
|
|
2633 compiled function. */
|
|
2634 btp = backtrace_list;
|
|
2635
|
|
2636 #if 0 /* FSFmacs */
|
|
2637
|
|
2638 /* #### FSFmacs does the following instead. I can't figure
|
|
2639 out which one is more correct. */
|
|
2640 /* If this isn't a byte-compiled function, there may be a frame at
|
|
2641 the top for Finteractive_p itself. If so, skip it. */
|
|
2642 fun = Findirect_function (*btp->function);
|
|
2643 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p)
|
|
2644 btp = btp->next;
|
|
2645
|
|
2646 /* If we're running an Emacs 18-style byte-compiled function, there
|
|
2647 may be a frame for Fbyte_code. Now, given the strictest
|
|
2648 definition, this function isn't really being called
|
|
2649 interactively, but because that's the way Emacs 18 always builds
|
|
2650 byte-compiled functions, we'll accept it for now. */
|
|
2651 if (EQ (*btp->function, Qbyte_code))
|
|
2652 btp = btp->next;
|
|
2653
|
|
2654 /* If this isn't a byte-compiled function, then we may now be
|
|
2655 looking at several frames for special forms. Skip past them. */
|
|
2656 while (btp &&
|
|
2657 btp->nargs == UNEVALLED)
|
|
2658 btp = btp->next;
|
|
2659
|
|
2660 #else
|
|
2661
|
|
2662 if (! (COMPILED_FUNCTIONP (Findirect_function (*btp->function))))
|
|
2663 btp = btp->next;
|
|
2664 for (;
|
|
2665 btp && (btp->nargs == UNEVALLED
|
|
2666 || EQ (*btp->function, Qbyte_code));
|
|
2667 btp = btp->next)
|
|
2668 {}
|
|
2669 /* btp now points at the frame of the innermost function
|
|
2670 that DOES eval its args.
|
|
2671 If it is a built-in function (such as load or eval-region)
|
|
2672 return nil. */
|
|
2673 /* Beats me why this is necessary, but it is */
|
|
2674 if (btp && EQ (*btp->function, Qcall_interactively))
|
|
2675 return Qt;
|
|
2676
|
|
2677 #endif
|
|
2678
|
|
2679 fun = Findirect_function (*btp->function);
|
|
2680 if (SUBRP (fun))
|
|
2681 return Qnil;
|
|
2682 /* btp points to the frame of a Lisp function that called interactive-p.
|
|
2683 Return t if that function was called interactively. */
|
|
2684 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
|
|
2685 return Qt;
|
|
2686 return Qnil;
|
|
2687 }
|
|
2688
|
|
2689
|
|
2690 /**********************************************************************/
|
|
2691 /* Autoloading */
|
|
2692 /**********************************************************************/
|
|
2693
|
20
|
2694 DEFUN ("autoload", Fautoload, 2, 5, 0, /*
|
0
|
2695 Define FUNCTION to autoload from FILE.
|
|
2696 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
|
|
2697 Third arg DOCSTRING is documentation for the function.
|
|
2698 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
|
|
2699 Fifth arg TYPE indicates the type of the object:
|
|
2700 nil or omitted says FUNCTION is a function,
|
|
2701 `keymap' says FUNCTION is really a keymap, and
|
|
2702 `macro' or t says FUNCTION is really a macro.
|
|
2703 Third through fifth args give info about the real definition.
|
|
2704 They default to nil.
|
|
2705 If FUNCTION is already defined other than as an autoload,
|
|
2706 this does nothing and returns nil.
|
20
|
2707 */
|
|
2708 (function, file, docstring, interactive, type))
|
0
|
2709 {
|
|
2710 /* This function can GC */
|
|
2711 CHECK_SYMBOL (function);
|
|
2712 CHECK_STRING (file);
|
|
2713
|
|
2714 /* If function is defined and not as an autoload, don't override */
|
|
2715 if (!UNBOUNDP (XSYMBOL (function)->function)
|
|
2716 && !(CONSP (XSYMBOL (function)->function)
|
|
2717 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
|
|
2718 return Qnil;
|
|
2719
|
|
2720 if (purify_flag)
|
|
2721 {
|
|
2722 /* Attempt to avoid consing identical (string=) pure strings. */
|
|
2723 file = Fsymbol_name (Fintern (file, Qnil));
|
|
2724 }
|
|
2725
|
|
2726 return Ffset (function,
|
|
2727 Fpurecopy (Fcons (Qautoload, list4 (file,
|
|
2728 docstring,
|
|
2729 interactive,
|
|
2730 type))));
|
|
2731 }
|
|
2732
|
|
2733 Lisp_Object
|
|
2734 un_autoload (Lisp_Object oldqueue)
|
|
2735 {
|
|
2736 /* This function can GC */
|
|
2737 REGISTER Lisp_Object queue, first, second;
|
|
2738
|
|
2739 /* Queue to unwind is current value of Vautoload_queue.
|
|
2740 oldqueue is the shadowed value to leave in Vautoload_queue. */
|
|
2741 queue = Vautoload_queue;
|
|
2742 Vautoload_queue = oldqueue;
|
|
2743 while (CONSP (queue))
|
|
2744 {
|
|
2745 first = Fcar (queue);
|
|
2746 second = Fcdr (first);
|
|
2747 first = Fcar (first);
|
|
2748 if (NILP (second))
|
|
2749 Vfeatures = first;
|
|
2750 else
|
|
2751 Ffset (first, second);
|
|
2752 queue = Fcdr (queue);
|
|
2753 }
|
|
2754 return Qnil;
|
|
2755 }
|
|
2756
|
|
2757 void
|
|
2758 do_autoload (Lisp_Object fundef,
|
|
2759 Lisp_Object funname)
|
|
2760 {
|
|
2761 /* This function can GC */
|
|
2762 int speccount = specpdl_depth_counter;
|
|
2763 Lisp_Object fun = funname;
|
|
2764 struct gcpro gcpro1, gcpro2;
|
|
2765
|
|
2766 CHECK_SYMBOL (funname);
|
|
2767 GCPRO2 (fun, funname);
|
|
2768
|
|
2769 /* Value saved here is to be restored into Vautoload_queue */
|
|
2770 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
2771 Vautoload_queue = Qt;
|
|
2772 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil,
|
|
2773 Qnil);
|
|
2774
|
|
2775 {
|
|
2776 Lisp_Object queue = Vautoload_queue;
|
|
2777
|
|
2778 /* Save the old autoloads, in case we ever do an unload. */
|
|
2779 queue = Vautoload_queue;
|
|
2780 while (CONSP (queue))
|
|
2781 {
|
|
2782 Lisp_Object first = Fcar (queue);
|
|
2783 Lisp_Object second = Fcdr (first);
|
|
2784
|
|
2785 first = Fcar (first);
|
|
2786
|
|
2787 /* Note: This test is subtle. The cdr of an autoload-queue entry
|
|
2788 may be an atom if the autoload entry was generated by a defalias
|
|
2789 or fset. */
|
|
2790 if (CONSP (second))
|
|
2791 Fput (first, Qautoload, (Fcdr (second)));
|
|
2792
|
|
2793 queue = Fcdr (queue);
|
|
2794 }
|
|
2795 }
|
|
2796
|
|
2797 /* Once loading finishes, don't undo it. */
|
|
2798 Vautoload_queue = Qt;
|
|
2799 unbind_to (speccount, Qnil);
|
|
2800
|
|
2801 fun = indirect_function (fun, 0);
|
|
2802
|
|
2803 #if 0 /* FSFmacs */
|
|
2804 if (!NILP (Fequal (fun, fundef)))
|
|
2805 #else
|
|
2806 if (UNBOUNDP (fun)
|
|
2807 || (CONSP (fun)
|
|
2808 && EQ (XCAR (fun), Qautoload)))
|
|
2809 #endif
|
|
2810 error ("Autoloading failed to define function %s",
|
|
2811 string_data (XSYMBOL (funname)->name));
|
|
2812 UNGCPRO;
|
|
2813 }
|
|
2814
|
|
2815
|
|
2816 /**********************************************************************/
|
|
2817 /* eval, funcall, apply */
|
|
2818 /**********************************************************************/
|
|
2819
|
|
2820 static Lisp_Object funcall_lambda (Lisp_Object fun,
|
|
2821 int nargs, Lisp_Object args[]);
|
|
2822 static Lisp_Object apply_lambda (Lisp_Object fun,
|
|
2823 int nargs, Lisp_Object args);
|
|
2824 static Lisp_Object funcall_subr (struct Lisp_Subr *sub, Lisp_Object args[]);
|
|
2825
|
|
2826 static int in_warnings;
|
|
2827
|
|
2828 static Lisp_Object
|
|
2829 in_warnings_restore (Lisp_Object minimus)
|
|
2830 {
|
|
2831 in_warnings = 0;
|
|
2832 return Qnil;
|
|
2833 }
|
|
2834
|
|
2835
|
20
|
2836 DEFUN ("eval", Feval, 1, 1, 0, /*
|
0
|
2837 Evaluate FORM and return its value.
|
20
|
2838 */
|
|
2839 (form))
|
0
|
2840 {
|
|
2841 /* This function can GC */
|
|
2842 Lisp_Object fun, val, original_fun, original_args;
|
|
2843 int nargs;
|
|
2844 struct backtrace backtrace;
|
|
2845
|
|
2846 /* I think this is a pretty safe place to call Lisp code, don't you? */
|
|
2847 while (!in_warnings && !NILP (Vpending_warnings))
|
|
2848 {
|
|
2849 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
2850 int speccount = specpdl_depth ();
|
|
2851 Lisp_Object this_warning_cons, this_warning, class, level, messij;
|
|
2852
|
|
2853 record_unwind_protect (in_warnings_restore, Qnil);
|
|
2854 in_warnings = 1;
|
|
2855 this_warning_cons = Vpending_warnings;
|
|
2856 this_warning = XCAR (this_warning_cons);
|
|
2857 /* in case an error occurs in the warn function, at least
|
|
2858 it won't happen infinitely */
|
|
2859 Vpending_warnings = XCDR (Vpending_warnings);
|
|
2860 free_cons (XCONS (this_warning_cons));
|
|
2861 class = XCAR (this_warning);
|
|
2862 level = XCAR (XCDR (this_warning));
|
|
2863 messij = XCAR (XCDR (XCDR (this_warning)));
|
|
2864 free_list (this_warning);
|
|
2865
|
|
2866 if (NILP (Vpending_warnings))
|
|
2867 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary,
|
|
2868 but safer */
|
|
2869
|
|
2870 GCPRO4 (form, class, level, messij);
|
|
2871 if (!STRINGP (messij))
|
|
2872 messij = Fprin1_to_string (messij, Qnil);
|
|
2873 call3 (Qdisplay_warning, class, messij, level);
|
|
2874 UNGCPRO;
|
|
2875 unbind_to (speccount, Qnil);
|
|
2876 }
|
|
2877
|
|
2878 if (!CONSP (form))
|
|
2879 {
|
|
2880 if (!SYMBOLP (form))
|
|
2881 return form;
|
|
2882
|
|
2883 val = Fsymbol_value (form);
|
|
2884
|
|
2885 #ifdef MOCKLISP_SUPPORT
|
|
2886 if (!EQ (Vmocklisp_arguments, Qt))
|
|
2887 {
|
|
2888 if (NILP (val))
|
|
2889 val = Qzero;
|
|
2890 else if (EQ (val, Qt))
|
|
2891 val = make_int (1);
|
|
2892 }
|
|
2893 #endif
|
|
2894 return val;
|
|
2895 }
|
|
2896
|
|
2897 QUIT;
|
|
2898 if ((consing_since_gc > gc_cons_threshold) || always_gc)
|
|
2899 {
|
|
2900 struct gcpro gcpro1;
|
|
2901 GCPRO1 (form);
|
|
2902 garbage_collect_1 ();
|
|
2903 UNGCPRO;
|
|
2904 }
|
|
2905
|
|
2906 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
2907 {
|
|
2908 if (max_lisp_eval_depth < 100)
|
|
2909 max_lisp_eval_depth = 100;
|
|
2910 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
2911 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
|
|
2912 }
|
|
2913
|
|
2914 original_fun = Fcar (form);
|
|
2915 original_args = Fcdr (form);
|
|
2916 nargs = XINT (Flength (original_args));
|
|
2917
|
|
2918 #ifdef EMACS_BTL
|
|
2919 backtrace.id_number = 0;
|
|
2920 #endif
|
|
2921 backtrace.pdlcount = specpdl_depth_counter;
|
70
|
2922 backtrace.next = backtrace_list;
|
|
2923 backtrace_list = &backtrace;
|
0
|
2924 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
2925 backtrace.args = &original_args;
|
|
2926 backtrace.nargs = UNEVALLED;
|
|
2927 backtrace.evalargs = 1;
|
|
2928 backtrace.debug_on_exit = 0;
|
|
2929
|
|
2930 if (debug_on_next_call)
|
|
2931 do_debug_on_call (Qt);
|
|
2932
|
|
2933 /* At this point, only original_fun and original_args
|
|
2934 have values that will be used below */
|
|
2935 retry:
|
|
2936 fun = indirect_function (original_fun, 1);
|
|
2937
|
|
2938 if (SUBRP (fun))
|
|
2939 {
|
|
2940 struct Lisp_Subr *subr = XSUBR (fun);
|
|
2941 int max_args = subr->max_args;
|
|
2942 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
2943 Lisp_Object args_left;
|
|
2944 REGISTER int i;
|
|
2945
|
|
2946 args_left = original_args;
|
|
2947
|
|
2948 if (nargs < subr->min_args
|
|
2949 || (max_args >= 0 && max_args < nargs))
|
|
2950 {
|
|
2951 return Fsignal (Qwrong_number_of_arguments,
|
|
2952 list2 (fun, make_int (nargs)));
|
|
2953 }
|
|
2954
|
|
2955 if (max_args == UNEVALLED)
|
|
2956 {
|
|
2957 backtrace.evalargs = 0;
|
|
2958 val = ((subr_function (subr)) (args_left));
|
|
2959 }
|
|
2960
|
|
2961 else if (max_args == MANY)
|
|
2962 {
|
|
2963 /* Pass a vector of evaluated arguments */
|
|
2964 Lisp_Object *vals;
|
|
2965 REGISTER int argnum;
|
|
2966 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2967
|
|
2968 vals = (Lisp_Object *) alloca (nargs * sizeof (Lisp_Object));
|
|
2969
|
|
2970 GCPRO3 (args_left, fun, vals[0]);
|
|
2971 gcpro3.nvars = 0;
|
|
2972
|
|
2973 argnum = 0;
|
|
2974 while (!NILP (args_left))
|
|
2975 {
|
|
2976 vals[argnum++] = Feval (Fcar (args_left));
|
|
2977 args_left = Fcdr (args_left);
|
|
2978 gcpro3.nvars = argnum;
|
|
2979 }
|
|
2980
|
|
2981 backtrace.args = vals;
|
|
2982 backtrace.nargs = nargs;
|
|
2983
|
70
|
2984 val = ((subr_function (subr)) (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 {
|
70
|
3157 val = ((subr_function (subr)) (nargs, args + 1));
|
0
|
3158 }
|
|
3159
|
|
3160 else if (max_args > nargs)
|
|
3161 {
|
|
3162 Lisp_Object argvals[SUBR_MAX_ARGS];
|
|
3163
|
|
3164 /* Default optionals to nil */
|
|
3165 for (i = 0; i < nargs; i++)
|
|
3166 argvals[i] = args[i + 1];
|
|
3167 for (i = nargs; i < max_args; i++)
|
|
3168 argvals[i] = Qnil;
|
|
3169
|
|
3170 val = funcall_subr (subr, argvals);
|
|
3171 }
|
|
3172 else
|
|
3173 val = funcall_subr (subr, args + 1);
|
|
3174 }
|
|
3175 else if (COMPILED_FUNCTIONP (fun))
|
|
3176 val = funcall_lambda (fun, nargs, args + 1);
|
|
3177 else if (!CONSP (fun))
|
|
3178 {
|
|
3179 invalid_function:
|
|
3180 return Fsignal (Qinvalid_function, list1 (fun));
|
|
3181 }
|
|
3182 else
|
|
3183 {
|
|
3184 Lisp_Object funcar = Fcar (fun);
|
|
3185
|
|
3186 if (!SYMBOLP (funcar))
|
|
3187 goto invalid_function;
|
|
3188 if (EQ (funcar, Qlambda))
|
|
3189 val = funcall_lambda (fun, nargs, args + 1);
|
|
3190 #ifdef MOCKLISP_SUPPORT
|
|
3191 else if (EQ (funcar, Qmocklisp))
|
|
3192 val = ml_apply (fun, Flist (nargs, args + 1));
|
|
3193 #endif
|
|
3194 else if (EQ (funcar, Qautoload))
|
|
3195 {
|
|
3196 do_autoload (fun, args[0]);
|
|
3197 goto retry;
|
|
3198 }
|
|
3199 else
|
|
3200 {
|
|
3201 goto invalid_function;
|
|
3202 }
|
|
3203 }
|
|
3204 lisp_eval_depth--;
|
|
3205 if (backtrace.debug_on_exit)
|
|
3206 val = do_debug_on_exit (val);
|
70
|
3207 backtrace_list = backtrace.next;
|
0
|
3208 return val;
|
|
3209 }
|
|
3210
|
20
|
3211 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
|
0
|
3212 Call first argument as a function, passing remaining arguments to it.
|
|
3213 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
20
|
3214 */
|
|
3215 (int nargs, Lisp_Object *args))
|
0
|
3216 {
|
|
3217 return funcall_recording_as (args[0], nargs, args);
|
|
3218 }
|
|
3219
|
20
|
3220 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
|
0
|
3221 Return the number of arguments a function may be called with. The
|
|
3222 function may be any form that can be passed to `funcall', any special
|
|
3223 form, or any macro.
|
20
|
3224 */
|
|
3225 (function))
|
0
|
3226 {
|
|
3227 Lisp_Object orig_function = function;
|
|
3228 Lisp_Object arglist;
|
|
3229 int argcount;
|
|
3230
|
|
3231 retry:
|
|
3232
|
|
3233 if (SYMBOLP (function))
|
|
3234 function = indirect_function (function, 1);
|
|
3235
|
|
3236 if (SUBRP (function))
|
|
3237 return Fsubr_min_args (function);
|
|
3238 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3239 {
|
|
3240 invalid_function:
|
|
3241 return Fsignal (Qinvalid_function, list1 (function));
|
|
3242 }
|
|
3243
|
|
3244 if (CONSP (function))
|
|
3245 {
|
|
3246 Lisp_Object funcar = Fcar (function);
|
|
3247
|
|
3248 if (!SYMBOLP (funcar))
|
|
3249 goto invalid_function;
|
|
3250 if (EQ (funcar, Qmacro))
|
|
3251 {
|
|
3252 function = Fcdr (function);
|
|
3253 goto retry;
|
|
3254 }
|
|
3255 if (EQ (funcar, Qautoload))
|
|
3256 {
|
|
3257 do_autoload (function, orig_function);
|
|
3258 goto retry;
|
|
3259 }
|
|
3260 if (EQ (funcar, Qlambda))
|
|
3261 arglist = Fcar (Fcdr (function));
|
|
3262 else
|
|
3263 goto invalid_function;
|
|
3264 }
|
|
3265 else
|
|
3266 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3267
|
|
3268 argcount = 0;
|
|
3269 while (!NILP (arglist))
|
|
3270 {
|
|
3271 QUIT;
|
|
3272 if (EQ (Fcar (arglist), Qand_optional)
|
|
3273 || EQ (Fcar (arglist), Qand_rest))
|
|
3274 break;
|
|
3275 argcount++;
|
|
3276 arglist = Fcdr (arglist);
|
|
3277 }
|
|
3278
|
|
3279 return make_int (argcount);
|
|
3280 }
|
|
3281
|
20
|
3282 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
|
0
|
3283 Return the number of arguments a function may be called with. If the
|
|
3284 function takes an arbitrary number of arguments or is a built-in
|
|
3285 special form, nil is returned. The function may be any form that can
|
|
3286 be passed to `funcall', any special form, or any macro.
|
20
|
3287 */
|
|
3288 (function))
|
0
|
3289 {
|
|
3290 Lisp_Object orig_function = function;
|
|
3291 Lisp_Object arglist;
|
|
3292 int argcount;
|
|
3293
|
|
3294 retry:
|
|
3295
|
|
3296 if (SYMBOLP (function))
|
|
3297 function = indirect_function (function, 1);
|
|
3298
|
|
3299 if (SUBRP (function))
|
|
3300 return Fsubr_max_args (function);
|
|
3301 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function))
|
|
3302 {
|
|
3303 invalid_function:
|
|
3304 return Fsignal (Qinvalid_function, list1 (function));
|
|
3305 }
|
|
3306
|
|
3307 if (CONSP (function))
|
|
3308 {
|
|
3309 Lisp_Object funcar = Fcar (function);
|
|
3310
|
|
3311 if (!SYMBOLP (funcar))
|
|
3312 goto invalid_function;
|
|
3313 if (EQ (funcar, Qmacro))
|
|
3314 {
|
|
3315 function = Fcdr (function);
|
|
3316 goto retry;
|
|
3317 }
|
|
3318 if (EQ (funcar, Qautoload))
|
|
3319 {
|
|
3320 do_autoload (function, orig_function);
|
|
3321 goto retry;
|
|
3322 }
|
|
3323 if (EQ (funcar, Qlambda))
|
|
3324 arglist = Fcar (Fcdr (function));
|
|
3325 else
|
|
3326 goto invalid_function;
|
|
3327 }
|
|
3328 else
|
|
3329 arglist = XCOMPILED_FUNCTION (function)->arglist;
|
|
3330
|
|
3331 argcount = 0;
|
|
3332 while (!NILP (arglist))
|
|
3333 {
|
|
3334 QUIT;
|
|
3335 if (EQ (Fcar (arglist), Qand_optional))
|
|
3336 {
|
|
3337 arglist = Fcdr (arglist);
|
|
3338 continue;
|
|
3339 }
|
|
3340 if (EQ (Fcar (arglist), Qand_rest))
|
|
3341 return Qnil;
|
|
3342 argcount++;
|
|
3343 arglist = Fcdr (arglist);
|
|
3344 }
|
|
3345
|
|
3346 return make_int (argcount);
|
|
3347 }
|
|
3348
|
|
3349
|
20
|
3350 DEFUN ("apply", Fapply, 2, MANY, 0, /*
|
0
|
3351 Call FUNCTION with our remaining args, using our last arg as list of args.
|
|
3352 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
20
|
3353 */
|
|
3354 (int nargs, Lisp_Object *args))
|
0
|
3355 {
|
|
3356 /* This function can GC */
|
|
3357 Lisp_Object fun = args[0];
|
|
3358 Lisp_Object spread_arg = args [nargs - 1];
|
|
3359 int numargs;
|
|
3360 int funcall_nargs;
|
|
3361
|
|
3362 CHECK_LIST (spread_arg);
|
|
3363
|
|
3364 numargs = XINT (Flength (spread_arg));
|
|
3365
|
|
3366 if (numargs == 0)
|
|
3367 /* (apply foo 0 1 '()) */
|
|
3368 return Ffuncall (nargs - 1, args);
|
|
3369 else if (numargs == 1)
|
|
3370 {
|
|
3371 /* (apply foo 0 1 '(2)) */
|
|
3372 args [nargs - 1] = XCAR (spread_arg);
|
|
3373 return Ffuncall (nargs, args);
|
|
3374 }
|
|
3375
|
|
3376 /* -1 for function, -1 for spread arg */
|
|
3377 numargs = nargs - 2 + numargs;
|
|
3378 /* +1 for function */
|
|
3379 funcall_nargs = 1 + numargs;
|
|
3380
|
|
3381 if (SYMBOLP (fun))
|
|
3382 fun = indirect_function (fun, 0);
|
|
3383 if (UNBOUNDP (fun))
|
|
3384 {
|
|
3385 /* Let funcall get the error */
|
|
3386 fun = args[0];
|
|
3387 }
|
|
3388 else if (SUBRP (fun))
|
|
3389 {
|
|
3390 struct Lisp_Subr *subr = XSUBR (fun);
|
|
3391 int max_args = subr->max_args;
|
|
3392
|
|
3393 if (numargs < subr->min_args
|
|
3394 || (max_args >= 0 && max_args < numargs))
|
|
3395 {
|
|
3396 /* Let funcall get the error */
|
|
3397 }
|
|
3398 else if (max_args > numargs)
|
|
3399 {
|
|
3400 /* Avoid having funcall cons up yet another new vector of arguments
|
|
3401 by explicitly supplying nil's for optional values */
|
|
3402 funcall_nargs += (max_args - numargs);
|
|
3403 }
|
|
3404 }
|
|
3405 {
|
|
3406 REGISTER int i;
|
|
3407 REGISTER Lisp_Object *funcall_args
|
|
3408 = (Lisp_Object *) alloca (funcall_nargs * sizeof (Lisp_Object));
|
|
3409 struct gcpro gcpro1;
|
|
3410
|
|
3411 GCPRO1 (*funcall_args);
|
|
3412 gcpro1.nvars = funcall_nargs;
|
|
3413
|
|
3414 /* Copy in the unspread args */
|
|
3415 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object));
|
|
3416 /* Spread the last arg we got. Its first element goes in
|
|
3417 the slot that it used to occupy, hence this value of I. */
|
|
3418 for (i = nargs - 1;
|
|
3419 !NILP (spread_arg); /* i < 1 + numargs */
|
|
3420 i++, spread_arg = XCDR (spread_arg))
|
|
3421 {
|
|
3422 funcall_args [i] = XCAR (spread_arg);
|
|
3423 }
|
|
3424 /* Supply nil for optional args (to subrs) */
|
|
3425 for (; i < funcall_nargs; i++)
|
|
3426 funcall_args[i] = Qnil;
|
|
3427
|
|
3428
|
|
3429 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
|
|
3430 }
|
|
3431 }
|
|
3432
|
|
3433
|
|
3434 static Lisp_Object
|
70
|
3435 primitive_funcall (Lisp_Object (*fn) (), int nargs, Lisp_Object args[])
|
0
|
3436 {
|
|
3437 switch (nargs)
|
|
3438 {
|
70
|
3439 case 0:
|
|
3440 return ((*fn) ());
|
|
3441 case 1:
|
|
3442 return ((*fn) (args[0]));
|
|
3443 case 2:
|
|
3444 return ((*fn) (args[0], args[1]));
|
|
3445 case 3:
|
|
3446 return ((*fn) (args[0], args[1], args[2]));
|
|
3447 case 4:
|
|
3448 return ((*fn) (args[0], args[1], args[2], args[3]));
|
|
3449 case 5:
|
|
3450 return ((*fn) (args[0], args[1], args[2], args[3], args[4]));
|
|
3451 case 6:
|
|
3452 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5]));
|
|
3453 case 7:
|
|
3454 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5],
|
|
3455 args[6]));
|
|
3456 case 8:
|
|
3457 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5],
|
|
3458 args[6], args[7]));
|
|
3459 case 9:
|
|
3460 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5],
|
|
3461 args[6], args[7], args[8]));
|
|
3462 case 10:
|
|
3463 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5],
|
|
3464 args[6], args[7], args[8], args[9]));
|
|
3465 case 11:
|
|
3466 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5],
|
|
3467 args[6], args[7], args[8], args[9], args[10]));
|
|
3468 case 12:
|
|
3469 return ((*fn) (args[0], args[1], args[2], args[3], args[4], args[5],
|
|
3470 args[6], args[7], args[8], args[9], args[10], args[11]));
|
|
3471 default:
|
|
3472 /* Someone has created a subr that takes more arguments than
|
|
3473 is supported by this code. We need to either rewrite the
|
|
3474 subr to use a different argument protocol, or add more
|
|
3475 cases to this switch. */
|
|
3476 abort ();
|
0
|
3477 }
|
|
3478 return Qnil; /* suppress compiler warning */
|
|
3479 }
|
|
3480
|
|
3481 static Lisp_Object
|
|
3482 funcall_subr (struct Lisp_Subr *subr, Lisp_Object args[])
|
|
3483 {
|
|
3484 return primitive_funcall (subr_function (subr), subr->max_args, args);
|
|
3485 }
|
|
3486
|
|
3487 /* FSFmacs has an extra arg EVAL_FLAG. If false, some of
|
|
3488 the statements below are not done. But it's always true
|
|
3489 in all the calls to apply_lambda(). */
|
|
3490
|
|
3491 static Lisp_Object
|
|
3492 apply_lambda (Lisp_Object fun, int numargs, Lisp_Object unevalled_args)
|
|
3493 {
|
|
3494 /* This function can GC */
|
|
3495 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
3496 REGISTER int i;
|
|
3497 REGISTER Lisp_Object tem;
|
|
3498 REGISTER Lisp_Object *arg_vector
|
|
3499 = (Lisp_Object *) alloca (numargs * sizeof (Lisp_Object));
|
|
3500
|
|
3501 GCPRO3 (*arg_vector, unevalled_args, fun);
|
|
3502 gcpro1.nvars = 0;
|
|
3503
|
|
3504 for (i = 0; i < numargs;)
|
|
3505 {
|
|
3506 tem = Fcar (unevalled_args), unevalled_args = Fcdr (unevalled_args);
|
|
3507 tem = Feval (tem);
|
|
3508 arg_vector[i++] = tem;
|
|
3509 gcpro1.nvars = i;
|
|
3510 }
|
|
3511
|
|
3512 UNGCPRO;
|
|
3513
|
|
3514 backtrace_list->args = arg_vector;
|
|
3515 backtrace_list->nargs = i;
|
|
3516 backtrace_list->evalargs = 0;
|
|
3517 tem = funcall_lambda (fun, numargs, arg_vector);
|
|
3518
|
|
3519 /* Do the debug-on-exit now, while arg_vector still exists. */
|
|
3520 if (backtrace_list->debug_on_exit)
|
|
3521 tem = do_debug_on_exit (tem);
|
|
3522 /* Don't do it again when we return to eval. */
|
|
3523 backtrace_list->debug_on_exit = 0;
|
|
3524 return (tem);
|
|
3525 }
|
|
3526
|
|
3527 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
|
|
3528 and return the result of evaluation.
|
|
3529 FUN must be either a lambda-expression or a compiled-code object. */
|
|
3530
|
|
3531 static Lisp_Object
|
|
3532 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object arg_vector[])
|
|
3533 {
|
|
3534 /* This function can GC */
|
|
3535 Lisp_Object val, tem;
|
|
3536 REGISTER Lisp_Object syms_left;
|
|
3537 REGISTER Lisp_Object next;
|
|
3538 int speccount = specpdl_depth_counter;
|
|
3539 REGISTER int i;
|
|
3540 int optional = 0, rest = 0;
|
|
3541
|
|
3542 #ifdef MOCKLISP_SUPPORT
|
|
3543 if (!EQ (Vmocklisp_arguments, Qt))
|
|
3544 specbind (Qmocklisp_arguments, Qt); /* t means NOT mocklisp! */
|
|
3545 #endif
|
|
3546
|
|
3547 if (CONSP (fun))
|
|
3548 syms_left = Fcar (Fcdr (fun));
|
|
3549 else if (COMPILED_FUNCTIONP (fun))
|
|
3550 syms_left = XCOMPILED_FUNCTION (fun)->arglist;
|
|
3551 else abort ();
|
|
3552
|
|
3553 i = 0;
|
|
3554 for (; !NILP (syms_left); syms_left = Fcdr (syms_left))
|
|
3555 {
|
|
3556 QUIT;
|
|
3557 next = Fcar (syms_left);
|
|
3558 if (!SYMBOLP (next))
|
|
3559 signal_error (Qinvalid_function, list1 (fun));
|
|
3560 if (EQ (next, Qand_rest))
|
|
3561 rest = 1;
|
|
3562 else if (EQ (next, Qand_optional))
|
|
3563 optional = 1;
|
|
3564 else if (rest)
|
|
3565 {
|
|
3566 specbind (next, Flist (nargs - i, &arg_vector[i]));
|
|
3567 i = nargs;
|
|
3568 }
|
|
3569 else if (i < nargs)
|
|
3570 {
|
|
3571 tem = arg_vector[i++];
|
|
3572 specbind (next, tem);
|
|
3573 }
|
|
3574 else if (!optional)
|
|
3575 return Fsignal (Qwrong_number_of_arguments,
|
|
3576 list2 (fun, make_int (nargs)));
|
|
3577 else
|
|
3578 specbind (next, Qnil);
|
|
3579 }
|
|
3580
|
|
3581 if (i < nargs)
|
|
3582 return Fsignal (Qwrong_number_of_arguments,
|
|
3583 list2 (fun, make_int (nargs)));
|
|
3584
|
|
3585 if (CONSP (fun))
|
|
3586 val = Fprogn (Fcdr (Fcdr (fun)));
|
|
3587 else
|
|
3588 {
|
|
3589 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun);
|
|
3590 /* If we have not actually read the bytecode string
|
|
3591 and constants vector yet, fetch them from the file. */
|
|
3592 if (CONSP (b->bytecodes))
|
|
3593 Ffetch_bytecode (fun);
|
|
3594 val = Fbyte_code (b->bytecodes,
|
|
3595 b->constants,
|
|
3596 make_int (b->maxdepth));
|
|
3597 }
|
|
3598 return unbind_to (speccount, val);
|
|
3599 }
|
|
3600
|
20
|
3601 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /*
|
0
|
3602 If byte-compiled OBJECT is lazy-loaded, fetch it now.
|
20
|
3603 */
|
|
3604 (object))
|
0
|
3605 {
|
|
3606 Lisp_Object tem;
|
|
3607
|
|
3608 if (COMPILED_FUNCTIONP (object)
|
|
3609 && CONSP (XCOMPILED_FUNCTION (object)->bytecodes))
|
|
3610 {
|
|
3611 tem = read_doc_string (XCOMPILED_FUNCTION (object)->bytecodes);
|
|
3612 if (!CONSP (tem))
|
|
3613 signal_simple_error ("invalid lazy-loaded byte code", tem);
|
70
|
3614 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
3615 if (XCOMPILED_FUNCTION (object)->flags.ebolified
|
|
3616 && VECTORP (XCDR (tem)))
|
|
3617 ebolify_bytecode_constants (XCDR (tem));
|
0
|
3618 /* VERY IMPORTANT to purecopy here!!!!!
|
|
3619 See load_force_doc_string_unwind. */
|
|
3620 XCOMPILED_FUNCTION (object)->bytecodes = Fpurecopy (XCAR (tem));
|
|
3621 XCOMPILED_FUNCTION (object)->constants = Fpurecopy (XCDR (tem));
|
|
3622 }
|
|
3623 return object;
|
|
3624 }
|
|
3625
|
|
3626
|
|
3627 /**********************************************************************/
|
|
3628 /* Run hook variables in various ways. */
|
|
3629 /**********************************************************************/
|
|
3630
|
20
|
3631 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
|
0
|
3632 Run each hook in HOOKS. Major mode functions use this.
|
|
3633 Each argument should be a symbol, a hook variable.
|
|
3634 These symbols are processed in the order specified.
|
|
3635 If a hook symbol has a non-nil value, that value may be a function
|
|
3636 or a list of functions to be called to run the hook.
|
|
3637 If the value is a function, it is called with no arguments.
|
|
3638 If it is a list, the elements are called, in order, with no arguments.
|
|
3639
|
|
3640 To make a hook variable buffer-local, use `make-local-hook',
|
|
3641 not `make-local-variable'.
|
20
|
3642 */
|
|
3643 (int nargs, Lisp_Object *args))
|
0
|
3644 {
|
|
3645 Lisp_Object hook[1];
|
|
3646 REGISTER int i;
|
|
3647
|
|
3648 for (i = 0; i < nargs; i++)
|
|
3649 {
|
|
3650 hook[0] = args[i];
|
|
3651 run_hook_with_args (1, hook, RUN_HOOKS_TO_COMPLETION);
|
|
3652 }
|
|
3653
|
|
3654 return Qnil;
|
|
3655 }
|
|
3656
|
20
|
3657 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /*
|
0
|
3658 Run HOOK with the specified arguments ARGS.
|
|
3659 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
3660 value, that value may be a function or a list of functions to be
|
|
3661 called to run the hook. If the value is a function, it is called with
|
|
3662 the given arguments and its return value is returned. If it is a list
|
|
3663 of functions, those functions are called, in order,
|
|
3664 with the given arguments ARGS.
|
|
3665 It is best not to depend on the value return by `run-hook-with-args',
|
|
3666 as that may change.
|
|
3667
|
|
3668 To make a hook variable buffer-local, use `make-local-hook',
|
|
3669 not `make-local-variable'.
|
20
|
3670 */
|
|
3671 (int nargs, Lisp_Object *args))
|
0
|
3672 {
|
|
3673 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION);
|
|
3674 }
|
|
3675
|
20
|
3676 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /*
|
0
|
3677 Run HOOK with the specified arguments ARGS.
|
|
3678 HOOK should be a symbol, a hook variable. Its value should
|
|
3679 be a list of functions. We call those functions, one by one,
|
|
3680 passing arguments ARGS to each of them, until one of them
|
|
3681 returns a non-nil value. Then we return that value.
|
|
3682 If all the functions return nil, we return nil.
|
|
3683
|
|
3684 To make a hook variable buffer-local, use `make-local-hook',
|
|
3685 not `make-local-variable'.
|
20
|
3686 */
|
|
3687 (int nargs, Lisp_Object *args))
|
0
|
3688 {
|
|
3689 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS);
|
|
3690 }
|
|
3691
|
20
|
3692 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /*
|
0
|
3693 Run HOOK with the specified arguments ARGS.
|
|
3694 HOOK should be a symbol, a hook variable. Its value should
|
|
3695 be a list of functions. We call those functions, one by one,
|
|
3696 passing arguments ARGS to each of them, until one of them
|
|
3697 returns nil. Then we return nil.
|
|
3698 If all the functions return non-nil, we return non-nil.
|
|
3699
|
|
3700 To make a hook variable buffer-local, use `make-local-hook',
|
|
3701 not `make-local-variable'.
|
20
|
3702 */
|
|
3703 (int nargs, Lisp_Object *args))
|
0
|
3704 {
|
|
3705 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE);
|
|
3706 }
|
|
3707
|
|
3708 /* ARGS[0] should be a hook symbol.
|
|
3709 Call each of the functions in the hook value, passing each of them
|
|
3710 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
3711 COND specifies a condition to test after each call
|
|
3712 to decide whether to stop.
|
|
3713 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3714 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3715
|
|
3716 Lisp_Object
|
|
3717 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
|
|
3718 enum run_hooks_condition cond)
|
|
3719 {
|
|
3720 Lisp_Object sym, val, ret;
|
|
3721 struct gcpro gcpro1, gcpro2;
|
|
3722
|
|
3723 if (!initialized || preparing_for_armageddon)
|
|
3724 /* We need to bail out of here pronto. */
|
|
3725 return Qnil;
|
|
3726
|
|
3727 /* Whenever gc_in_progress is true, preparing_for_armageddon
|
|
3728 will also be true unless something is really hosed. */
|
|
3729 assert (!gc_in_progress);
|
|
3730
|
|
3731 sym = args[0];
|
|
3732 val = symbol_value_in_buffer (sym, make_buffer (buf));
|
|
3733 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil);
|
|
3734
|
|
3735 if (UNBOUNDP (val) || NILP (val))
|
|
3736 return ret;
|
|
3737 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
|
3738 {
|
|
3739 args[0] = val;
|
|
3740 return Ffuncall (nargs, args);
|
|
3741 }
|
|
3742 else
|
|
3743 {
|
|
3744 GCPRO2 (sym, val);
|
|
3745
|
|
3746 for (;
|
|
3747 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3748 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
|
|
3749 : !NILP (ret)));
|
|
3750 val = XCDR (val))
|
|
3751 {
|
|
3752 if (EQ (XCAR (val), Qt))
|
|
3753 {
|
|
3754 /* t indicates this hook has a local binding;
|
|
3755 it means to run the global binding too. */
|
|
3756 Lisp_Object globals;
|
|
3757
|
|
3758 for (globals = Fdefault_value (sym);
|
|
3759 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION)
|
|
3760 || (cond == RUN_HOOKS_UNTIL_SUCCESS
|
|
3761 ? NILP (ret)
|
|
3762 : !NILP (ret)));
|
|
3763 globals = XCDR (globals))
|
|
3764 {
|
|
3765 args[0] = XCAR (globals);
|
|
3766 /* In a global value, t should not occur. If it does, we
|
|
3767 must ignore it to avoid an endless loop. */
|
|
3768 if (!EQ (args[0], Qt))
|
|
3769 ret = Ffuncall (nargs, args);
|
|
3770 }
|
|
3771 }
|
|
3772 else
|
|
3773 {
|
|
3774 args[0] = XCAR (val);
|
|
3775 ret = Ffuncall (nargs, args);
|
|
3776 }
|
|
3777 }
|
|
3778
|
|
3779 UNGCPRO;
|
|
3780 return ret;
|
|
3781 }
|
|
3782 }
|
|
3783
|
|
3784 Lisp_Object
|
|
3785 run_hook_with_args (int nargs, Lisp_Object *args,
|
|
3786 enum run_hooks_condition cond)
|
|
3787 {
|
|
3788 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond);
|
|
3789 }
|
|
3790
|
|
3791 #if 0
|
|
3792
|
|
3793 /* From FSF 19.30, not currently used */
|
|
3794
|
|
3795 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
3796 present value of that symbol.
|
|
3797 Call each element of FUNLIST,
|
|
3798 passing each of them the rest of ARGS.
|
|
3799 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
3800 except that it isn't necessary to gcpro ARGS[0]. */
|
|
3801
|
|
3802 Lisp_Object
|
|
3803 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
|
|
3804 {
|
|
3805 Lisp_Object sym;
|
|
3806 Lisp_Object val;
|
|
3807 struct gcpro gcpro1, gcpro2;
|
|
3808
|
|
3809 sym = args[0];
|
|
3810 GCPRO2 (sym, val);
|
|
3811
|
|
3812 for (val = funlist; CONSP (val); val = XCDR (val))
|
|
3813 {
|
|
3814 if (EQ (XCAR (val), Qt))
|
|
3815 {
|
|
3816 /* t indicates this hook has a local binding;
|
|
3817 it means to run the global binding too. */
|
|
3818 Lisp_Object globals;
|
|
3819
|
|
3820 for (globals = Fdefault_value (sym);
|
|
3821 CONSP (globals);
|
|
3822 globals = XCDR (globals))
|
|
3823 {
|
|
3824 args[0] = XCAR (globals);
|
|
3825 /* In a global value, t should not occur. If it does, we
|
|
3826 must ignore it to avoid an endless loop. */
|
|
3827 if (!EQ (args[0], Qt))
|
|
3828 Ffuncall (nargs, args);
|
|
3829 }
|
|
3830 }
|
|
3831 else
|
|
3832 {
|
|
3833 args[0] = XCAR (val);
|
|
3834 Ffuncall (nargs, args);
|
|
3835 }
|
|
3836 }
|
|
3837 UNGCPRO;
|
|
3838 return Qnil;
|
|
3839 }
|
|
3840
|
|
3841 #endif /* 0 */
|
|
3842
|
|
3843 void
|
|
3844 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...)
|
|
3845 {
|
|
3846 /* This function can GC */
|
|
3847 struct gcpro gcpro1;
|
|
3848 int i;
|
|
3849 va_list vargs;
|
|
3850 Lisp_Object *funcall_args =
|
|
3851 (Lisp_Object *) alloca ((1 + nargs) * sizeof (Lisp_Object));
|
|
3852
|
|
3853 va_start (vargs, nargs);
|
|
3854 funcall_args[0] = hook_var;
|
|
3855 for (i = 0; i < nargs; i++)
|
|
3856 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3857 va_end (vargs);
|
|
3858
|
|
3859 GCPRO1 (*funcall_args);
|
|
3860 gcpro1.nvars = nargs + 1;
|
|
3861 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION);
|
|
3862 UNGCPRO;
|
|
3863 }
|
|
3864
|
|
3865 void
|
|
3866 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var,
|
|
3867 int nargs, ...)
|
|
3868 {
|
|
3869 /* This function can GC */
|
|
3870 struct gcpro gcpro1;
|
|
3871 int i;
|
|
3872 va_list vargs;
|
|
3873 Lisp_Object *funcall_args =
|
|
3874 (Lisp_Object *) alloca ((1 + nargs) * sizeof (Lisp_Object));
|
|
3875
|
|
3876 va_start (vargs, nargs);
|
|
3877 funcall_args[0] = hook_var;
|
|
3878 for (i = 0; i < nargs; i++)
|
|
3879 funcall_args[i + 1] = va_arg (vargs, Lisp_Object);
|
|
3880 va_end (vargs);
|
|
3881
|
|
3882 GCPRO1 (*funcall_args);
|
|
3883 gcpro1.nvars = nargs + 1;
|
|
3884 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args,
|
|
3885 RUN_HOOKS_TO_COMPLETION);
|
|
3886 UNGCPRO;
|
|
3887 }
|
|
3888
|
|
3889 Lisp_Object
|
|
3890 run_hook (Lisp_Object hook)
|
|
3891 {
|
|
3892 Frun_hooks (1, &hook);
|
|
3893 return Qnil;
|
|
3894 }
|
|
3895
|
|
3896
|
|
3897 /**********************************************************************/
|
|
3898 /* Front-ends to eval, funcall, apply */
|
|
3899 /**********************************************************************/
|
|
3900
|
|
3901 /* Apply fn to arg */
|
|
3902 Lisp_Object
|
|
3903 apply1 (Lisp_Object fn, Lisp_Object arg)
|
|
3904 {
|
|
3905 /* This function can GC */
|
|
3906 struct gcpro gcpro1;
|
|
3907 Lisp_Object args[2];
|
|
3908
|
|
3909 if (NILP (arg))
|
|
3910 return (Ffuncall (1, &fn));
|
|
3911 GCPRO1 (args[0]);
|
|
3912 gcpro1.nvars = 2;
|
|
3913 args[0] = fn;
|
|
3914 args[1] = arg;
|
|
3915 RETURN_UNGCPRO (Fapply (2, args));
|
|
3916 }
|
|
3917
|
|
3918 /* Call function fn on no arguments */
|
|
3919 Lisp_Object
|
|
3920 call0 (Lisp_Object fn)
|
|
3921 {
|
|
3922 /* This function can GC */
|
|
3923 struct gcpro gcpro1;
|
|
3924
|
|
3925 GCPRO1 (fn);
|
|
3926 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
3927 }
|
|
3928
|
|
3929 /* Call function fn with argument arg0 */
|
|
3930 Lisp_Object
|
|
3931 call1 (Lisp_Object fn,
|
|
3932 Lisp_Object arg0)
|
|
3933 {
|
|
3934 /* This function can GC */
|
|
3935 struct gcpro gcpro1;
|
|
3936 Lisp_Object args[2];
|
|
3937 args[0] = fn;
|
|
3938 args[1] = arg0;
|
|
3939 GCPRO1 (args[0]);
|
|
3940 gcpro1.nvars = 2;
|
|
3941 RETURN_UNGCPRO (Ffuncall (2, args));
|
|
3942 }
|
|
3943
|
|
3944 /* Call function fn with arguments arg0, arg1 */
|
|
3945 Lisp_Object
|
|
3946 call2 (Lisp_Object fn,
|
|
3947 Lisp_Object arg0, Lisp_Object arg1)
|
|
3948 {
|
|
3949 /* This function can GC */
|
|
3950 struct gcpro gcpro1;
|
|
3951 Lisp_Object args[3];
|
|
3952 args[0] = fn;
|
|
3953 args[1] = arg0;
|
|
3954 args[2] = arg1;
|
|
3955 GCPRO1 (args[0]);
|
|
3956 gcpro1.nvars = 3;
|
|
3957 RETURN_UNGCPRO (Ffuncall (3, args));
|
|
3958 }
|
|
3959
|
|
3960 /* Call function fn with arguments arg0, arg1, arg2 */
|
|
3961 Lisp_Object
|
|
3962 call3 (Lisp_Object fn,
|
|
3963 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
3964 {
|
|
3965 /* This function can GC */
|
|
3966 struct gcpro gcpro1;
|
|
3967 Lisp_Object args[4];
|
|
3968 args[0] = fn;
|
|
3969 args[1] = arg0;
|
|
3970 args[2] = arg1;
|
|
3971 args[3] = arg2;
|
|
3972 GCPRO1 (args[0]);
|
|
3973 gcpro1.nvars = 4;
|
|
3974 RETURN_UNGCPRO (Ffuncall (4, args));
|
|
3975 }
|
|
3976
|
|
3977 /* Call function fn with arguments arg0, arg1, arg2, arg3 */
|
|
3978 Lisp_Object
|
|
3979 call4 (Lisp_Object fn,
|
|
3980 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
3981 Lisp_Object arg3)
|
|
3982 {
|
|
3983 /* This function can GC */
|
|
3984 struct gcpro gcpro1;
|
|
3985 Lisp_Object args[5];
|
|
3986 args[0] = fn;
|
|
3987 args[1] = arg0;
|
|
3988 args[2] = arg1;
|
|
3989 args[3] = arg2;
|
|
3990 args[4] = arg3;
|
|
3991 GCPRO1 (args[0]);
|
|
3992 gcpro1.nvars = 5;
|
|
3993 RETURN_UNGCPRO (Ffuncall (5, args));
|
|
3994 }
|
|
3995
|
|
3996 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */
|
|
3997 Lisp_Object
|
|
3998 call5 (Lisp_Object fn,
|
|
3999 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4000 Lisp_Object arg3, Lisp_Object arg4)
|
|
4001 {
|
|
4002 /* This function can GC */
|
|
4003 struct gcpro gcpro1;
|
|
4004 Lisp_Object args[6];
|
|
4005 args[0] = fn;
|
|
4006 args[1] = arg0;
|
|
4007 args[2] = arg1;
|
|
4008 args[3] = arg2;
|
|
4009 args[4] = arg3;
|
|
4010 args[5] = arg4;
|
|
4011 GCPRO1 (args[0]);
|
|
4012 gcpro1.nvars = 6;
|
|
4013 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
4014 }
|
|
4015
|
|
4016 Lisp_Object
|
|
4017 call6 (Lisp_Object fn,
|
|
4018 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4019 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4020 {
|
|
4021 /* This function can GC */
|
|
4022 struct gcpro gcpro1;
|
|
4023 Lisp_Object args[7];
|
|
4024 args[0] = fn;
|
|
4025 args[1] = arg0;
|
|
4026 args[2] = arg1;
|
|
4027 args[3] = arg2;
|
|
4028 args[4] = arg3;
|
|
4029 args[5] = arg4;
|
|
4030 args[6] = arg5;
|
|
4031 GCPRO1 (args[0]);
|
|
4032 gcpro1.nvars = 7;
|
|
4033 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
4034 }
|
|
4035
|
|
4036 Lisp_Object
|
|
4037 call7 (Lisp_Object fn,
|
|
4038 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4039 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4040 Lisp_Object arg6)
|
|
4041 {
|
|
4042 /* This function can GC */
|
|
4043 struct gcpro gcpro1;
|
|
4044 Lisp_Object args[8];
|
|
4045 args[0] = fn;
|
|
4046 args[1] = arg0;
|
|
4047 args[2] = arg1;
|
|
4048 args[3] = arg2;
|
|
4049 args[4] = arg3;
|
|
4050 args[5] = arg4;
|
|
4051 args[6] = arg5;
|
|
4052 args[7] = arg6;
|
|
4053 GCPRO1 (args[0]);
|
|
4054 gcpro1.nvars = 8;
|
|
4055 RETURN_UNGCPRO (Ffuncall (8, args));
|
|
4056 }
|
|
4057
|
|
4058 Lisp_Object
|
|
4059 call8 (Lisp_Object fn,
|
|
4060 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4061 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5,
|
|
4062 Lisp_Object arg6, Lisp_Object arg7)
|
|
4063 {
|
|
4064 /* This function can GC */
|
|
4065 struct gcpro gcpro1;
|
|
4066 Lisp_Object args[9];
|
|
4067 args[0] = fn;
|
|
4068 args[1] = arg0;
|
|
4069 args[2] = arg1;
|
|
4070 args[3] = arg2;
|
|
4071 args[4] = arg3;
|
|
4072 args[5] = arg4;
|
|
4073 args[6] = arg5;
|
|
4074 args[7] = arg6;
|
|
4075 args[8] = arg7;
|
|
4076 GCPRO1 (args[0]);
|
|
4077 gcpro1.nvars = 9;
|
|
4078 RETURN_UNGCPRO (Ffuncall (9, args));
|
|
4079 }
|
|
4080
|
|
4081 Lisp_Object
|
|
4082 call0_in_buffer (struct buffer *buf, Lisp_Object fn)
|
|
4083 {
|
|
4084 int speccount = specpdl_depth ();
|
|
4085 Lisp_Object val;
|
|
4086
|
|
4087 if (current_buffer != buf)
|
|
4088 {
|
|
4089 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4090 set_buffer_internal (buf);
|
|
4091 }
|
|
4092 val = call0 (fn);
|
|
4093 unbind_to (speccount, Qnil);
|
|
4094 return val;
|
|
4095 }
|
|
4096
|
|
4097 Lisp_Object
|
|
4098 call1_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4099 Lisp_Object arg0)
|
|
4100 {
|
|
4101 int speccount = specpdl_depth ();
|
|
4102 Lisp_Object val;
|
|
4103
|
|
4104 if (current_buffer != buf)
|
|
4105 {
|
|
4106 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4107 set_buffer_internal (buf);
|
|
4108 }
|
|
4109 val = call1 (fn, arg0);
|
|
4110 unbind_to (speccount, Qnil);
|
|
4111 return val;
|
|
4112 }
|
|
4113
|
|
4114 Lisp_Object
|
|
4115 call2_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4116 Lisp_Object arg0, Lisp_Object arg1)
|
|
4117 {
|
|
4118 int speccount = specpdl_depth ();
|
|
4119 Lisp_Object val;
|
|
4120
|
|
4121 if (current_buffer != buf)
|
|
4122 {
|
|
4123 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4124 set_buffer_internal (buf);
|
|
4125 }
|
|
4126 val = call2 (fn, arg0, arg1);
|
|
4127 unbind_to (speccount, Qnil);
|
|
4128 return val;
|
|
4129 }
|
|
4130
|
|
4131 Lisp_Object
|
|
4132 call3_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4133 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2)
|
|
4134 {
|
|
4135 int speccount = specpdl_depth ();
|
|
4136 Lisp_Object val;
|
|
4137
|
|
4138 if (current_buffer != buf)
|
|
4139 {
|
|
4140 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4141 set_buffer_internal (buf);
|
|
4142 }
|
|
4143 val = call3 (fn, arg0, arg1, arg2);
|
|
4144 unbind_to (speccount, Qnil);
|
|
4145 return val;
|
|
4146 }
|
|
4147
|
|
4148 Lisp_Object
|
|
4149 call4_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4150 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4151 Lisp_Object arg3)
|
|
4152 {
|
|
4153 int speccount = specpdl_depth ();
|
|
4154 Lisp_Object val;
|
|
4155
|
|
4156 if (current_buffer != buf)
|
|
4157 {
|
|
4158 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4159 set_buffer_internal (buf);
|
|
4160 }
|
|
4161 val = call4 (fn, arg0, arg1, arg2, arg3);
|
|
4162 unbind_to (speccount, Qnil);
|
|
4163 return val;
|
|
4164 }
|
|
4165
|
|
4166 Lisp_Object
|
|
4167 call5_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4168 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4169 Lisp_Object arg3, Lisp_Object arg4)
|
|
4170 {
|
|
4171 int speccount = specpdl_depth ();
|
|
4172 Lisp_Object val;
|
|
4173
|
|
4174 if (current_buffer != buf)
|
|
4175 {
|
|
4176 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4177 set_buffer_internal (buf);
|
|
4178 }
|
|
4179 val = call5 (fn, arg0, arg1, arg2, arg3, arg4);
|
|
4180 unbind_to (speccount, Qnil);
|
|
4181 return val;
|
|
4182 }
|
|
4183
|
|
4184 Lisp_Object
|
|
4185 call6_in_buffer (struct buffer *buf, Lisp_Object fn,
|
|
4186 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2,
|
|
4187 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5)
|
|
4188 {
|
|
4189 int speccount = specpdl_depth ();
|
|
4190 Lisp_Object val;
|
|
4191
|
|
4192 if (current_buffer != buf)
|
|
4193 {
|
|
4194 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4195 set_buffer_internal (buf);
|
|
4196 }
|
|
4197 val = call6 (fn, arg0, arg1, arg2, arg3, arg4, arg5);
|
|
4198 unbind_to (speccount, Qnil);
|
|
4199 return val;
|
|
4200 }
|
|
4201
|
|
4202 Lisp_Object
|
|
4203 eval_in_buffer (struct buffer *buf, Lisp_Object form)
|
|
4204 {
|
|
4205 int speccount = specpdl_depth ();
|
|
4206 Lisp_Object val;
|
|
4207
|
|
4208 if (current_buffer != buf)
|
|
4209 {
|
|
4210 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
|
|
4211 set_buffer_internal (buf);
|
|
4212 }
|
|
4213 val = Feval (form);
|
|
4214 unbind_to (speccount, Qnil);
|
|
4215 return val;
|
|
4216 }
|
|
4217
|
|
4218
|
|
4219 /***** Error-catching front-ends to eval, funcall, apply */
|
|
4220
|
|
4221 /* Call function fn on no arguments, with condition handler */
|
|
4222 Lisp_Object
|
|
4223 call0_with_handler (Lisp_Object handler, Lisp_Object fn)
|
|
4224 {
|
|
4225 /* This function can GC */
|
|
4226 struct gcpro gcpro1;
|
|
4227 Lisp_Object args[2];
|
|
4228 args[0] = handler;
|
|
4229 args[1] = fn;
|
|
4230 GCPRO1 (args[0]);
|
|
4231 gcpro1.nvars = 2;
|
|
4232 RETURN_UNGCPRO (Fcall_with_condition_handler (2, args));
|
|
4233 }
|
|
4234
|
|
4235 /* Call function fn with argument arg0, with condition handler */
|
|
4236 Lisp_Object
|
|
4237 call1_with_handler (Lisp_Object handler, Lisp_Object fn,
|
|
4238 Lisp_Object arg0)
|
|
4239 {
|
|
4240 /* This function can GC */
|
|
4241 struct gcpro gcpro1;
|
|
4242 Lisp_Object args[3];
|
|
4243 args[0] = handler;
|
|
4244 args[1] = fn;
|
|
4245 args[2] = arg0;
|
|
4246 GCPRO1 (args[0]);
|
|
4247 gcpro1.nvars = 3;
|
|
4248 RETURN_UNGCPRO (Fcall_with_condition_handler (3, args));
|
|
4249 }
|
|
4250
|
|
4251
|
|
4252 /* The following functions provide you with error-trapping versions
|
|
4253 of the various front-ends above. They take an additional
|
|
4254 "warning_string" argument; if non-zero, a warning with this
|
|
4255 string and the actual error that occurred will be displayed
|
|
4256 in the *Warnings* buffer if an error occurs. In all cases,
|
|
4257 QUIT is inhibited while these functions are running, and if
|
|
4258 an error occurs, Qunbound is returned instead of the normal
|
|
4259 return value.
|
|
4260 */
|
|
4261
|
|
4262 /* #### This stuff needs to catch throws as well. We need to
|
|
4263 improve internal_catch() so it can take a "catch anything"
|
|
4264 argument similar to Qt or Qerror for condition_case_1(). */
|
|
4265
|
|
4266 static Lisp_Object
|
|
4267 caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4268 {
|
|
4269 if (!NILP (errordata))
|
|
4270 {
|
|
4271 Lisp_Object args[2];
|
|
4272
|
|
4273 if (!NILP (arg))
|
|
4274 {
|
|
4275 char *str = (char *) get_opaque_ptr (arg);
|
|
4276 args[0] = build_string (str);
|
|
4277 }
|
|
4278 else
|
|
4279 args[0] = build_string ("error");
|
|
4280 /* #### This should call
|
|
4281 (with-output-to-string (display-error errordata))
|
|
4282 but that stuff is all in Lisp currently. */
|
|
4283 args[1] = errordata;
|
|
4284 warn_when_safe_lispobj
|
|
4285 (Qerror, Qwarning,
|
|
4286 emacs_doprnt_string_lisp ((CONST Bufbyte *) "%s: %s",
|
|
4287 Qnil, -1, 2, args));
|
|
4288 }
|
|
4289 return Qunbound;
|
|
4290 }
|
|
4291
|
|
4292 static Lisp_Object
|
|
4293 allow_quit_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4294 {
|
|
4295 if (CONSP (errordata) && EQ (XCAR (errordata), Qquit))
|
|
4296 return Fsignal (Qquit, XCDR (errordata));
|
|
4297 return caught_a_squirmer (errordata, arg);
|
|
4298 }
|
|
4299
|
|
4300 static Lisp_Object
|
|
4301 safe_run_hook_caught_a_squirmer (Lisp_Object errordata, Lisp_Object arg)
|
|
4302 {
|
|
4303 Lisp_Object hook = Fcar (arg);
|
|
4304 arg = Fcdr (arg);
|
|
4305 /* Clear out the hook. */
|
|
4306 Fset (hook, Qnil);
|
|
4307 return caught_a_squirmer (errordata, arg);
|
|
4308 }
|
|
4309
|
|
4310 static Lisp_Object
|
|
4311 allow_quit_safe_run_hook_caught_a_squirmer (Lisp_Object errordata,
|
|
4312 Lisp_Object arg)
|
|
4313 {
|
|
4314 Lisp_Object hook = Fcar (arg);
|
|
4315 arg = Fcdr (arg);
|
|
4316 if (!CONSP (errordata) || !EQ (XCAR (errordata), Qquit))
|
|
4317 /* Clear out the hook. */
|
|
4318 Fset (hook, Qnil);
|
|
4319 return allow_quit_caught_a_squirmer (errordata, arg);
|
|
4320 }
|
|
4321
|
|
4322 static Lisp_Object
|
|
4323 catch_them_squirmers_eval_in_buffer (Lisp_Object cons)
|
|
4324 {
|
|
4325 return eval_in_buffer (XBUFFER (XCAR (cons)), XCDR (cons));
|
|
4326 }
|
|
4327
|
|
4328 Lisp_Object
|
|
4329 eval_in_buffer_trapping_errors (CONST char *warning_string,
|
|
4330 struct buffer *buf, Lisp_Object form)
|
|
4331 {
|
|
4332 int speccount = specpdl_depth ();
|
|
4333 Lisp_Object tem;
|
|
4334 Lisp_Object buffer = Qnil;
|
|
4335 Lisp_Object cons;
|
|
4336 Lisp_Object opaque;
|
|
4337 struct gcpro gcpro1, gcpro2;
|
|
4338
|
|
4339 XSETBUFFER (buffer, buf);
|
|
4340
|
|
4341 specbind (Qinhibit_quit, Qt);
|
|
4342 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4343
|
|
4344 cons = noseeum_cons (buffer, form);
|
|
4345 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4346 GCPRO2 (cons, opaque);
|
|
4347 /* Qerror not Qt, so you can get a backtrace */
|
|
4348 tem = condition_case_1 (Qerror,
|
|
4349 catch_them_squirmers_eval_in_buffer, cons,
|
|
4350 caught_a_squirmer, opaque);
|
|
4351 free_cons (XCONS (cons));
|
|
4352 if (OPAQUEP (opaque))
|
|
4353 free_opaque_ptr (opaque);
|
|
4354 UNGCPRO;
|
|
4355
|
|
4356 /* gc_currently_forbidden = 0; */
|
|
4357 return unbind_to (speccount, tem);
|
|
4358 }
|
|
4359
|
|
4360 static Lisp_Object
|
|
4361 catch_them_squirmers_run_hook (Lisp_Object hook_symbol)
|
|
4362 {
|
|
4363 /* This function can GC */
|
|
4364 run_hook (hook_symbol);
|
|
4365 return Qnil;
|
|
4366 }
|
|
4367
|
|
4368 Lisp_Object
|
|
4369 run_hook_trapping_errors (CONST char *warning_string, Lisp_Object hook_symbol)
|
|
4370 {
|
|
4371 int speccount = specpdl_depth ();
|
|
4372 Lisp_Object tem;
|
|
4373 Lisp_Object opaque;
|
|
4374 struct gcpro gcpro1;
|
|
4375
|
|
4376 if (!initialized || preparing_for_armageddon)
|
|
4377 return Qnil;
|
|
4378 tem = find_symbol_value (hook_symbol);
|
|
4379 if (NILP (tem) || UNBOUNDP (tem))
|
|
4380 return Qnil;
|
|
4381
|
|
4382 specbind (Qinhibit_quit, Qt);
|
|
4383
|
|
4384 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4385 GCPRO1 (opaque);
|
|
4386 /* Qerror not Qt, so you can get a backtrace */
|
|
4387 tem = condition_case_1 (Qerror,
|
|
4388 catch_them_squirmers_run_hook, hook_symbol,
|
|
4389 caught_a_squirmer, opaque);
|
|
4390 if (OPAQUEP (opaque))
|
|
4391 free_opaque_ptr (opaque);
|
|
4392 UNGCPRO;
|
|
4393
|
|
4394 return unbind_to (speccount, tem);
|
|
4395 }
|
|
4396
|
|
4397 /* Same as run_hook_trapping_errors() but also set the hook to nil
|
|
4398 if an error occurs. */
|
|
4399
|
|
4400 Lisp_Object
|
|
4401 safe_run_hook_trapping_errors (CONST char *warning_string,
|
|
4402 Lisp_Object hook_symbol,
|
|
4403 int allow_quit)
|
|
4404 {
|
|
4405 int speccount = specpdl_depth ();
|
|
4406 Lisp_Object tem;
|
|
4407 Lisp_Object cons = Qnil;
|
|
4408 struct gcpro gcpro1;
|
|
4409
|
|
4410 if (!initialized || preparing_for_armageddon)
|
|
4411 return Qnil;
|
|
4412 tem = find_symbol_value (hook_symbol);
|
|
4413 if (NILP (tem) || UNBOUNDP (tem))
|
|
4414 return Qnil;
|
|
4415
|
|
4416 if (!allow_quit)
|
|
4417 specbind (Qinhibit_quit, Qt);
|
|
4418
|
|
4419 cons = noseeum_cons (hook_symbol,
|
|
4420 warning_string ? make_opaque_ptr (warning_string)
|
|
4421 : Qnil);
|
|
4422 GCPRO1 (cons);
|
|
4423 /* Qerror not Qt, so you can get a backtrace */
|
|
4424 tem = condition_case_1 (Qerror,
|
|
4425 catch_them_squirmers_run_hook,
|
|
4426 hook_symbol,
|
|
4427 allow_quit ?
|
|
4428 allow_quit_safe_run_hook_caught_a_squirmer :
|
|
4429 safe_run_hook_caught_a_squirmer,
|
|
4430 cons);
|
|
4431 if (OPAQUEP (XCDR (cons)))
|
|
4432 free_opaque_ptr (XCDR (cons));
|
|
4433 free_cons (XCONS (cons));
|
|
4434 UNGCPRO;
|
|
4435
|
|
4436 return unbind_to (speccount, tem);
|
|
4437 }
|
|
4438
|
|
4439 static Lisp_Object
|
|
4440 catch_them_squirmers_call0 (Lisp_Object function)
|
|
4441 {
|
|
4442 /* This function can GC */
|
|
4443 return call0 (function);
|
|
4444 }
|
|
4445
|
|
4446 Lisp_Object
|
|
4447 call0_trapping_errors (CONST char *warning_string, Lisp_Object function)
|
|
4448 {
|
|
4449 int speccount = specpdl_depth ();
|
|
4450 Lisp_Object tem;
|
|
4451 Lisp_Object opaque = Qnil;
|
|
4452 struct gcpro gcpro1, gcpro2;
|
|
4453
|
|
4454 if (SYMBOLP (function))
|
|
4455 {
|
|
4456 tem = XSYMBOL (function)->function;
|
|
4457 if (NILP (tem) || UNBOUNDP (tem))
|
|
4458 return (Qnil);
|
|
4459 }
|
|
4460
|
|
4461 GCPRO2 (opaque, function);
|
|
4462 specbind (Qinhibit_quit, Qt);
|
|
4463 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4464
|
|
4465 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4466 /* Qerror not Qt, so you can get a backtrace */
|
|
4467 tem = condition_case_1 (Qerror,
|
|
4468 catch_them_squirmers_call0, function,
|
|
4469 caught_a_squirmer, opaque);
|
|
4470 if (OPAQUEP (opaque))
|
|
4471 free_opaque_ptr (opaque);
|
|
4472 UNGCPRO;
|
|
4473
|
|
4474 /* gc_currently_forbidden = 0; */
|
|
4475 return unbind_to (speccount, tem);
|
|
4476 }
|
|
4477
|
|
4478 static Lisp_Object
|
|
4479 catch_them_squirmers_call1 (Lisp_Object cons)
|
|
4480 {
|
|
4481 /* This function can GC */
|
|
4482 return call1 (XCAR (cons), XCDR (cons));
|
|
4483 }
|
|
4484
|
|
4485 static Lisp_Object
|
|
4486 catch_them_squirmers_call2 (Lisp_Object cons)
|
|
4487 {
|
|
4488 /* This function can GC */
|
|
4489 return call2 (XCAR (cons), XCAR (XCDR (cons)), XCAR (XCDR (XCDR (cons))));
|
|
4490 }
|
|
4491
|
|
4492 Lisp_Object
|
|
4493 call1_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4494 Lisp_Object object)
|
|
4495 {
|
|
4496 int speccount = specpdl_depth ();
|
|
4497 Lisp_Object tem;
|
|
4498 Lisp_Object cons = Qnil;
|
|
4499 Lisp_Object opaque = Qnil;
|
|
4500 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
|
|
4501
|
|
4502 if (SYMBOLP (function))
|
|
4503 {
|
|
4504 tem = XSYMBOL (function)->function;
|
|
4505 if (NILP (tem) || UNBOUNDP (tem))
|
|
4506 return (Qnil);
|
|
4507 }
|
|
4508
|
|
4509 GCPRO4 (cons, opaque, function, object);
|
|
4510
|
|
4511 specbind (Qinhibit_quit, Qt);
|
|
4512 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4513
|
|
4514 cons = noseeum_cons (function, object);
|
|
4515 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4516 /* Qerror not Qt, so you can get a backtrace */
|
|
4517 tem = condition_case_1 (Qerror,
|
|
4518 catch_them_squirmers_call1, cons,
|
|
4519 caught_a_squirmer, opaque);
|
|
4520 if (OPAQUEP (opaque))
|
|
4521 free_opaque_ptr (opaque);
|
|
4522 free_cons (XCONS (cons));
|
|
4523 UNGCPRO;
|
|
4524
|
|
4525 /* gc_currently_forbidden = 0; */
|
|
4526 return unbind_to (speccount, tem);
|
|
4527 }
|
|
4528
|
|
4529 Lisp_Object
|
|
4530 call2_trapping_errors (CONST char *warning_string, Lisp_Object function,
|
|
4531 Lisp_Object object1, Lisp_Object object2)
|
|
4532 {
|
|
4533 int speccount = specpdl_depth ();
|
|
4534 Lisp_Object tem;
|
|
4535 Lisp_Object cons = Qnil;
|
|
4536 Lisp_Object opaque = Qnil;
|
|
4537 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
|
|
4538
|
|
4539 if (SYMBOLP (function))
|
|
4540 {
|
|
4541 tem = XSYMBOL (function)->function;
|
|
4542 if (NILP (tem) || UNBOUNDP (tem))
|
|
4543 return (Qnil);
|
|
4544 }
|
|
4545
|
|
4546 GCPRO5 (cons, opaque, function, object1, object2);
|
|
4547 specbind (Qinhibit_quit, Qt);
|
|
4548 /* gc_currently_forbidden = 1; Currently no reason to do this; */
|
|
4549
|
|
4550 cons = list3 (function, object1, object2);
|
|
4551 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
|
|
4552 /* Qerror not Qt, so you can get a backtrace */
|
|
4553 tem = condition_case_1 (Qerror,
|
|
4554 catch_them_squirmers_call2, cons,
|
|
4555 caught_a_squirmer, opaque);
|
|
4556 if (OPAQUEP (opaque))
|
|
4557 free_opaque_ptr (opaque);
|
|
4558 free_list (cons);
|
|
4559 UNGCPRO;
|
|
4560
|
|
4561 /* gc_currently_forbidden = 0; */
|
|
4562 return unbind_to (speccount, tem);
|
|
4563 }
|
|
4564
|
|
4565
|
|
4566 /**********************************************************************/
|
|
4567 /* The special binding stack */
|
|
4568 /**********************************************************************/
|
|
4569
|
2
|
4570 #define min_max_specpdl_size 400
|
|
4571
|
0
|
4572 static void
|
|
4573 grow_specpdl (void)
|
|
4574 {
|
|
4575 if (specpdl_size >= max_specpdl_size)
|
|
4576 {
|
2
|
4577 if (max_specpdl_size < min_max_specpdl_size)
|
|
4578 max_specpdl_size = min_max_specpdl_size;
|
0
|
4579 if (specpdl_size >= max_specpdl_size)
|
|
4580 {
|
|
4581 if (!NILP (Vdebug_on_error) || !NILP (Vdebug_on_signal))
|
|
4582 /* Leave room for some specpdl in the debugger. */
|
|
4583 max_specpdl_size = specpdl_size + 100;
|
|
4584 continuable_error
|
|
4585 ("Variable binding depth exceeds max-specpdl-size");
|
|
4586 }
|
|
4587 }
|
|
4588 specpdl_size *= 2;
|
|
4589 if (specpdl_size > max_specpdl_size)
|
|
4590 specpdl_size = max_specpdl_size;
|
|
4591 specpdl = ((struct specbinding *)
|
|
4592 xrealloc (specpdl, specpdl_size * sizeof (struct specbinding)));
|
|
4593 specpdl_ptr = specpdl + specpdl_depth_counter;
|
|
4594 }
|
|
4595
|
|
4596
|
|
4597 /* Handle unbinding buffer-local variables */
|
|
4598 static Lisp_Object
|
|
4599 specbind_unwind_local (Lisp_Object ovalue)
|
|
4600 {
|
|
4601 Lisp_Object current = Fcurrent_buffer ();
|
|
4602 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4603 struct Lisp_Cons *victim = XCONS (ovalue);
|
|
4604 Lisp_Object buf = get_buffer (victim->car, 0);
|
|
4605 ovalue = victim->cdr;
|
|
4606
|
|
4607 free_cons (victim);
|
|
4608
|
|
4609 if (NILP (buf))
|
|
4610 {
|
|
4611 /* Deleted buffer -- do nothing */
|
|
4612 }
|
|
4613 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0)
|
|
4614 {
|
|
4615 /* Was buffer-local when binding was made, now no longer is.
|
|
4616 * (kill-local-variable can do this.)
|
|
4617 * Do nothing in this case.
|
|
4618 */
|
|
4619 }
|
|
4620 else if (EQ (buf, current))
|
|
4621 Fset (symbol, ovalue);
|
|
4622 else
|
|
4623 {
|
|
4624 /* Urk! Somebody switched buffers */
|
|
4625 struct gcpro gcpro1;
|
|
4626 GCPRO1 (current);
|
|
4627 Fset_buffer (buf);
|
|
4628 Fset (symbol, ovalue);
|
|
4629 Fset_buffer (current);
|
|
4630 UNGCPRO;
|
|
4631 }
|
|
4632 return (symbol);
|
|
4633 }
|
|
4634
|
|
4635 static Lisp_Object
|
|
4636 specbind_unwind_wasnt_local (Lisp_Object buffer)
|
|
4637 {
|
|
4638 Lisp_Object current = Fcurrent_buffer ();
|
|
4639 Lisp_Object symbol = specpdl_ptr->symbol;
|
|
4640
|
|
4641 buffer = get_buffer (buffer, 0);
|
|
4642 if (NILP (buffer))
|
|
4643 {
|
|
4644 /* Deleted buffer -- do nothing */
|
|
4645 }
|
|
4646 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0)
|
|
4647 {
|
|
4648 /* Was buffer-local when binding was made, now no longer is.
|
|
4649 * (kill-local-variable can do this.)
|
|
4650 * Do nothing in this case.
|
|
4651 */
|
|
4652 }
|
|
4653 else if (EQ (buffer, current))
|
|
4654 Fkill_local_variable (symbol);
|
|
4655 else
|
|
4656 {
|
|
4657 /* Urk! Somebody switched buffers */
|
|
4658 struct gcpro gcpro1;
|
|
4659 GCPRO1 (current);
|
|
4660 Fset_buffer (buffer);
|
|
4661 Fkill_local_variable (symbol);
|
|
4662 Fset_buffer (current);
|
|
4663 UNGCPRO;
|
|
4664 }
|
|
4665 return (symbol);
|
|
4666 }
|
|
4667
|
|
4668
|
|
4669 /* Don't want to include buffer.h just for this */
|
|
4670 extern struct buffer *current_buffer;
|
|
4671
|
|
4672 void
|
|
4673 specbind (Lisp_Object symbol, Lisp_Object value)
|
|
4674 {
|
|
4675 int buffer_local;
|
|
4676
|
|
4677 CHECK_SYMBOL (symbol);
|
|
4678
|
|
4679 if (specpdl_depth_counter >= specpdl_size)
|
|
4680 grow_specpdl ();
|
|
4681
|
|
4682 buffer_local = symbol_value_buffer_local_info (symbol, current_buffer);
|
|
4683 if (buffer_local == 0)
|
|
4684 {
|
|
4685 specpdl_ptr->old_value = find_symbol_value (symbol);
|
|
4686 specpdl_ptr->func = 0; /* Handled specially by unbind_to */
|
|
4687 }
|
|
4688 else if (buffer_local > 0)
|
|
4689 {
|
|
4690 /* Already buffer-local */
|
|
4691 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (),
|
|
4692 find_symbol_value (symbol));
|
|
4693 specpdl_ptr->func = specbind_unwind_local;
|
|
4694 }
|
|
4695 else
|
|
4696 {
|
|
4697 /* About to become buffer-local */
|
|
4698 specpdl_ptr->old_value = Fcurrent_buffer ();
|
|
4699 specpdl_ptr->func = specbind_unwind_wasnt_local;
|
|
4700 }
|
|
4701
|
|
4702 specpdl_ptr->symbol = symbol;
|
|
4703 specpdl_ptr++;
|
|
4704 specpdl_depth_counter++;
|
|
4705
|
|
4706 Fset (symbol, value);
|
|
4707 }
|
|
4708
|
|
4709 void
|
|
4710 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
|
|
4711 Lisp_Object arg)
|
|
4712 {
|
|
4713 if (specpdl_depth_counter >= specpdl_size)
|
|
4714 grow_specpdl ();
|
|
4715 specpdl_ptr->func = function;
|
|
4716 specpdl_ptr->symbol = Qnil;
|
|
4717 specpdl_ptr->old_value = arg;
|
|
4718 specpdl_ptr++;
|
|
4719 specpdl_depth_counter++;
|
|
4720 }
|
|
4721
|
|
4722 extern int check_sigio (void);
|
|
4723
|
|
4724 Lisp_Object
|
|
4725 unbind_to (int count, Lisp_Object value)
|
|
4726 {
|
|
4727 int quitf;
|
|
4728 struct gcpro gcpro1;
|
|
4729
|
|
4730 GCPRO1 (value);
|
|
4731
|
|
4732 check_quit (); /* make Vquit_flag accurate */
|
|
4733 quitf = !NILP (Vquit_flag);
|
|
4734 Vquit_flag = Qnil;
|
|
4735
|
|
4736 while (specpdl_depth_counter != count)
|
|
4737 {
|
|
4738 Lisp_Object ovalue;
|
|
4739 --specpdl_ptr;
|
|
4740 --specpdl_depth_counter;
|
|
4741
|
|
4742 ovalue = specpdl_ptr->old_value;
|
|
4743 if (specpdl_ptr->func != 0)
|
|
4744 /* An unwind-protect */
|
|
4745 (*specpdl_ptr->func) (ovalue);
|
|
4746 else
|
|
4747 Fset (specpdl_ptr->symbol, ovalue);
|
|
4748
|
|
4749 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
|
|
4750 /* There should never be anything here for us to remove.
|
|
4751 If so, it indicates a logic error in Emacs. Catches
|
|
4752 should get removed when a throw or signal occurs, or
|
|
4753 when a catch or condition-case exits normally. But
|
|
4754 it's too dangerous to just remove this code. --ben */
|
|
4755
|
|
4756 /* Furthermore, this code is not in FSFmacs!!!
|
|
4757 Braino on mly's part? */
|
|
4758 /* If we're unwound past the pdlcount of a catch frame,
|
|
4759 that catch can't possibly still be valid. */
|
|
4760 while (catchlist && catchlist->pdlcount > specpdl_depth_counter)
|
|
4761 {
|
|
4762 catchlist = catchlist->next;
|
|
4763 /* Don't mess with gcprolist, backtrace_list here */
|
|
4764 }
|
|
4765 #endif
|
|
4766 }
|
|
4767 if (quitf)
|
|
4768 Vquit_flag = Qt;
|
|
4769
|
|
4770 UNGCPRO;
|
|
4771
|
|
4772 return (value);
|
|
4773 }
|
|
4774
|
|
4775
|
|
4776 int
|
|
4777 specpdl_depth (void)
|
|
4778 {
|
|
4779 return (specpdl_depth_counter);
|
|
4780 }
|
|
4781
|
|
4782
|
|
4783 /* Get the value of symbol's global binding, even if that binding is
|
|
4784 not now dynamically visible. May return Qunbound or magic values. */
|
|
4785
|
|
4786 Lisp_Object
|
|
4787 top_level_value (Lisp_Object symbol)
|
|
4788 {
|
|
4789 REGISTER struct specbinding *ptr = specpdl;
|
|
4790
|
|
4791 CHECK_SYMBOL (symbol);
|
|
4792 for (; ptr != specpdl_ptr; ptr++)
|
|
4793 {
|
|
4794 if (EQ (ptr->symbol, symbol))
|
|
4795 return ptr->old_value;
|
|
4796 }
|
|
4797 return XSYMBOL (symbol)->value;
|
|
4798 }
|
|
4799
|
|
4800 #if 0
|
|
4801
|
|
4802 Lisp_Object
|
|
4803 top_level_set (Lisp_Object symbol, Lisp_Object newval)
|
|
4804 {
|
|
4805 REGISTER struct specbinding *ptr = specpdl;
|
|
4806
|
|
4807 CHECK_SYMBOL (symbol);
|
|
4808 for (; ptr != specpdl_ptr; ptr++)
|
|
4809 {
|
|
4810 if (EQ (ptr->symbol, symbol))
|
|
4811 {
|
|
4812 ptr->old_value = newval;
|
|
4813 return newval;
|
|
4814 }
|
|
4815 }
|
|
4816 return Fset (symbol, newval);
|
|
4817 }
|
|
4818
|
|
4819 #endif /* 0 */
|
|
4820
|
|
4821
|
|
4822 /**********************************************************************/
|
|
4823 /* Backtraces */
|
|
4824 /**********************************************************************/
|
|
4825
|
20
|
4826 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
|
0
|
4827 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
4828 The debugger is entered when that frame exits, if the flag is non-nil.
|
20
|
4829 */
|
|
4830 (level, flag))
|
0
|
4831 {
|
|
4832 REGISTER struct backtrace *backlist = backtrace_list;
|
|
4833 REGISTER int i;
|
|
4834
|
|
4835 CHECK_INT (level);
|
|
4836
|
|
4837 for (i = 0; backlist && i < XINT (level); i++)
|
|
4838 {
|
|
4839 backlist = backlist->next;
|
|
4840 }
|
|
4841
|
|
4842 if (backlist)
|
|
4843 backlist->debug_on_exit = !NILP (flag);
|
|
4844
|
|
4845 return flag;
|
|
4846 }
|
|
4847
|
|
4848 static void
|
|
4849 backtrace_specials (int speccount, int speclimit, Lisp_Object stream)
|
|
4850 {
|
|
4851 int printing_bindings = 0;
|
|
4852
|
|
4853 for (; speccount > speclimit; speccount--)
|
|
4854 {
|
|
4855 if (specpdl[speccount - 1].func == 0
|
|
4856 || specpdl[speccount - 1].func == specbind_unwind_local
|
|
4857 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local)
|
|
4858 {
|
|
4859 write_c_string (((!printing_bindings) ? " # bind (" : " "),
|
|
4860 stream);
|
|
4861 Fprin1 (specpdl[speccount - 1].symbol, stream);
|
|
4862 printing_bindings = 1;
|
|
4863 }
|
|
4864 else
|
|
4865 {
|
|
4866 if (printing_bindings) write_c_string (")\n", stream);
|
|
4867 write_c_string (" # (unwind-protect ...)\n", stream);
|
|
4868 printing_bindings = 0;
|
|
4869 }
|
|
4870 }
|
|
4871 if (printing_bindings) write_c_string (")\n", stream);
|
|
4872 }
|
|
4873
|
20
|
4874 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /*
|
0
|
4875 Print a trace of Lisp function calls currently active.
|
|
4876 Option arg STREAM specifies the output stream to send the backtrace to,
|
|
4877 and defaults to the value of `standard-output'. Optional second arg
|
|
4878 DETAILED means show places where currently active variable bindings,
|
|
4879 catches, condition-cases, and unwind-protects were made as well as
|
|
4880 function calls.
|
20
|
4881 */
|
|
4882 (stream, detailed))
|
0
|
4883 {
|
|
4884 struct backtrace *backlist = backtrace_list;
|
|
4885 struct catchtag *catches = catchlist;
|
|
4886 int speccount = specpdl_depth_counter;
|
|
4887
|
|
4888 int old_nl = print_escape_newlines;
|
|
4889 int old_pr = print_readably;
|
|
4890 Lisp_Object old_level = Vprint_level;
|
|
4891 Lisp_Object oiq = Vinhibit_quit;
|
|
4892 struct gcpro gcpro1, gcpro2;
|
|
4893
|
|
4894 /* We can't allow quits in here because that could cause the values
|
|
4895 of print_readably and print_escape_newlines to get screwed up.
|
|
4896 Normally we would use a record_unwind_protect but that would
|
|
4897 screw up the functioning of this function. */
|
|
4898 Vinhibit_quit = Qt;
|
|
4899
|
|
4900 entering_debugger = 0;
|
|
4901
|
|
4902 Vprint_level = make_int (3);
|
|
4903 print_readably = 0;
|
|
4904 print_escape_newlines = 1;
|
|
4905
|
|
4906 GCPRO2 (stream, old_level);
|
|
4907
|
|
4908 if (NILP (stream))
|
|
4909 stream = Vstandard_output;
|
|
4910 if (!noninteractive && (NILP (stream) || EQ (stream, Qt)))
|
|
4911 stream = Fselected_frame (Qnil);
|
|
4912
|
|
4913 for (;;)
|
|
4914 {
|
|
4915 if (!NILP (detailed) && catches && catches->backlist == backlist)
|
|
4916 {
|
|
4917 int catchpdl = catches->pdlcount;
|
|
4918 if (specpdl[catchpdl].func == condition_case_unwind
|
|
4919 && speccount > catchpdl)
|
|
4920 /* This is a condition-case catchpoint */
|
|
4921 catchpdl = catchpdl + 1;
|
|
4922
|
|
4923 backtrace_specials (speccount, catchpdl, stream);
|
|
4924
|
|
4925 speccount = catches->pdlcount;
|
|
4926 if (catchpdl == speccount)
|
|
4927 {
|
|
4928 write_c_string (" # (catch ", stream);
|
|
4929 Fprin1 (catches->tag, stream);
|
|
4930 write_c_string (" ...)\n", stream);
|
|
4931 }
|
|
4932 else
|
|
4933 {
|
|
4934 write_c_string (" # (condition-case ... . ", stream);
|
|
4935 Fprin1 (Fcdr (Fcar (catches->tag)), stream);
|
|
4936 write_c_string (")\n", stream);
|
|
4937 }
|
|
4938 catches = catches->next;
|
|
4939 }
|
|
4940 else if (!backlist)
|
|
4941 break;
|
|
4942 else
|
|
4943 {
|
|
4944 if (!NILP (detailed) && backlist->pdlcount < speccount)
|
|
4945 {
|
|
4946 backtrace_specials (speccount, backlist->pdlcount, stream);
|
|
4947 speccount = backlist->pdlcount;
|
|
4948 }
|
|
4949 write_c_string (((backlist->debug_on_exit) ? "* " : " "),
|
|
4950 stream);
|
|
4951 if (backlist->nargs == UNEVALLED)
|
|
4952 {
|
|
4953 Fprin1 (Fcons (*backlist->function, *backlist->args), stream);
|
|
4954 write_c_string ("\n", stream); /* from FSFmacs 19.30 */
|
|
4955 }
|
|
4956 else
|
|
4957 {
|
|
4958 Lisp_Object tem = *backlist->function;
|
|
4959 Fprin1 (tem, stream); /* This can QUIT */
|
|
4960 write_c_string ("(", stream);
|
|
4961 if (backlist->nargs == MANY)
|
|
4962 {
|
|
4963 int i;
|
|
4964 Lisp_Object tail = Qnil;
|
|
4965 struct gcpro ngcpro1;
|
|
4966
|
|
4967 NGCPRO1 (tail);
|
|
4968 for (tail = *backlist->args, i = 0;
|
|
4969 !NILP (tail);
|
|
4970 tail = Fcdr (tail), i++)
|
|
4971 {
|
|
4972 if (i != 0) write_c_string (" ", stream);
|
|
4973 Fprin1 (Fcar (tail), stream);
|
|
4974 }
|
|
4975 NUNGCPRO;
|
|
4976 }
|
|
4977 else
|
|
4978 {
|
|
4979 int i;
|
|
4980 for (i = 0; i < backlist->nargs; i++)
|
|
4981 {
|
|
4982 if (i != 0) write_c_string (" ", stream);
|
|
4983 Fprin1 (backlist->args[i], stream);
|
|
4984 }
|
|
4985 }
|
|
4986 }
|
|
4987 write_c_string (")\n", stream);
|
|
4988 backlist = backlist->next;
|
|
4989 }
|
|
4990 }
|
|
4991 Vprint_level = old_level;
|
|
4992 print_readably = old_pr;
|
|
4993 print_escape_newlines = old_nl;
|
|
4994 UNGCPRO;
|
|
4995 Vinhibit_quit = oiq;
|
|
4996 return Qnil;
|
|
4997 }
|
|
4998
|
|
4999
|
20
|
5000 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, "", /*
|
0
|
5001 Return the function and arguments N frames up from current execution point.
|
|
5002 If that frame has not evaluated the arguments yet (or is a special form),
|
|
5003 the value is (nil FUNCTION ARG-FORMS...).
|
|
5004 If that frame has evaluated its arguments and called its function already,
|
|
5005 the value is (t FUNCTION ARG-VALUES...).
|
|
5006 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
5007 FUNCTION is whatever was supplied as car of evaluated list,
|
|
5008 or a lambda expression for macro calls.
|
|
5009 If N is more than the number of frames, the value is nil.
|
20
|
5010 */
|
|
5011 (nframes))
|
0
|
5012 {
|
|
5013 REGISTER struct backtrace *backlist = backtrace_list;
|
|
5014 REGISTER int i;
|
|
5015 Lisp_Object tem;
|
|
5016
|
|
5017 CHECK_NATNUM (nframes);
|
|
5018
|
|
5019 /* Find the frame requested. */
|
|
5020 for (i = XINT (nframes); backlist && (i-- > 0);)
|
|
5021 backlist = backlist->next;
|
|
5022
|
|
5023 if (!backlist)
|
|
5024 return Qnil;
|
|
5025 if (backlist->nargs == UNEVALLED)
|
|
5026 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
|
|
5027 else
|
|
5028 {
|
|
5029 if (backlist->nargs == MANY)
|
|
5030 tem = *backlist->args;
|
|
5031 else
|
|
5032 tem = Flist (backlist->nargs, backlist->args);
|
|
5033
|
|
5034 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
5035 }
|
|
5036 }
|
|
5037
|
|
5038
|
|
5039 /**********************************************************************/
|
|
5040 /* Warnings */
|
|
5041 /**********************************************************************/
|
|
5042
|
|
5043 void
|
|
5044 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level,
|
|
5045 Lisp_Object obj)
|
|
5046 {
|
|
5047 obj = list1 (list3 (class, level, obj));
|
|
5048 if (NILP (Vpending_warnings))
|
|
5049 Vpending_warnings = Vpending_warnings_tail = obj;
|
|
5050 else
|
|
5051 {
|
|
5052 Fsetcdr (Vpending_warnings_tail, obj);
|
|
5053 Vpending_warnings_tail = obj;
|
|
5054 }
|
|
5055 }
|
|
5056
|
|
5057 /* #### This should probably accept Lisp objects; but then we have
|
|
5058 to make sure that Feval() isn't called, since it might not be safe.
|
|
5059
|
|
5060 An alternative approach is to just pass some non-string type of
|
|
5061 Lisp Object to warn_when_safe_lispobj(); `prin1-to-string' will
|
|
5062 automatically be called when it is safe to do so. */
|
|
5063
|
|
5064 void
|
|
5065 warn_when_safe (Lisp_Object class, Lisp_Object level, CONST char *fmt, ...)
|
|
5066 {
|
|
5067 Lisp_Object obj;
|
|
5068 va_list args;
|
|
5069
|
|
5070 va_start (args, fmt);
|
|
5071 obj = emacs_doprnt_string_va ((CONST Bufbyte *) GETTEXT (fmt),
|
|
5072 Qnil, -1, args);
|
|
5073 va_end (args);
|
|
5074
|
|
5075 warn_when_safe_lispobj (class, level, obj);
|
|
5076 }
|
|
5077
|
|
5078
|
|
5079
|
|
5080
|
|
5081 /**********************************************************************/
|
|
5082 /* Initialization */
|
|
5083 /**********************************************************************/
|
|
5084
|
|
5085 void
|
|
5086 syms_of_eval (void)
|
|
5087 {
|
|
5088 defsymbol (&Qinhibit_quit, "inhibit-quit");
|
|
5089 defsymbol (&Qautoload, "autoload");
|
|
5090 defsymbol (&Qdebug_on_error, "debug-on-error");
|
|
5091 defsymbol (&Qstack_trace_on_error, "stack-trace-on-error");
|
|
5092 defsymbol (&Qdebug_on_signal, "debug-on-signal");
|
|
5093 defsymbol (&Qstack_trace_on_signal, "stack-trace-on-signal");
|
|
5094 defsymbol (&Qdebugger, "debugger");
|
|
5095 defsymbol (&Qmacro, "macro");
|
|
5096 defsymbol (&Qand_rest, "&rest");
|
|
5097 defsymbol (&Qand_optional, "&optional");
|
|
5098 /* Note that the process code also uses Qexit */
|
|
5099 defsymbol (&Qexit, "exit");
|
|
5100 defsymbol (&Qsetq, "setq");
|
|
5101 defsymbol (&Qinteractive, "interactive");
|
|
5102 defsymbol (&Qcommandp, "commandp");
|
|
5103 defsymbol (&Qdefun, "defun");
|
|
5104 defsymbol (&Qprogn, "progn");
|
|
5105 defsymbol (&Qvalues, "values");
|
|
5106 defsymbol (&Qdisplay_warning, "display-warning");
|
|
5107 defsymbol (&Qrun_hooks, "run-hooks");
|
|
5108
|
20
|
5109 DEFSUBR (For);
|
|
5110 DEFSUBR (Fand);
|
|
5111 DEFSUBR (Fif);
|
|
5112 DEFSUBR (Fcond);
|
|
5113 DEFSUBR (Fprogn);
|
|
5114 DEFSUBR (Fprog1);
|
|
5115 DEFSUBR (Fprog2);
|
|
5116 DEFSUBR (Fsetq);
|
|
5117 DEFSUBR (Fquote);
|
|
5118 DEFSUBR (Ffunction);
|
|
5119 DEFSUBR (Fdefun);
|
|
5120 DEFSUBR (Fdefmacro);
|
|
5121 DEFSUBR (Fdefvar);
|
|
5122 DEFSUBR (Fdefconst);
|
|
5123 DEFSUBR (Fuser_variable_p);
|
|
5124 DEFSUBR (Flet);
|
|
5125 DEFSUBR (FletX);
|
|
5126 DEFSUBR (Fwhile);
|
|
5127 DEFSUBR (Fmacroexpand_internal);
|
|
5128 DEFSUBR (Fcatch);
|
|
5129 DEFSUBR (Fthrow);
|
|
5130 DEFSUBR (Funwind_protect);
|
|
5131 DEFSUBR (Fcondition_case);
|
|
5132 DEFSUBR (Fcall_with_condition_handler);
|
|
5133 DEFSUBR (Fsignal);
|
|
5134 DEFSUBR (Finteractive_p);
|
|
5135 DEFSUBR (Fcommandp);
|
|
5136 DEFSUBR (Fcommand_execute);
|
|
5137 DEFSUBR (Fautoload);
|
|
5138 DEFSUBR (Feval);
|
|
5139 DEFSUBR (Fapply);
|
|
5140 DEFSUBR (Ffuncall);
|
|
5141 DEFSUBR (Ffunction_min_args);
|
|
5142 DEFSUBR (Ffunction_max_args);
|
|
5143 DEFSUBR (Frun_hooks);
|
|
5144 DEFSUBR (Frun_hook_with_args);
|
|
5145 DEFSUBR (Frun_hook_with_args_until_success);
|
|
5146 DEFSUBR (Frun_hook_with_args_until_failure);
|
|
5147 DEFSUBR (Ffetch_bytecode);
|
|
5148 DEFSUBR (Fbacktrace_debug);
|
|
5149 DEFSUBR (Fbacktrace);
|
|
5150 DEFSUBR (Fbacktrace_frame);
|
0
|
5151 }
|
|
5152
|
|
5153 void
|
|
5154 reinit_eval (void)
|
|
5155 {
|
|
5156 specpdl_ptr = specpdl;
|
|
5157 specpdl_depth_counter = 0;
|
|
5158 catchlist = 0;
|
|
5159 Vcondition_handlers = Qnil;
|
|
5160 backtrace_list = 0;
|
|
5161 Vquit_flag = Qnil;
|
|
5162 debug_on_next_call = 0;
|
|
5163 lisp_eval_depth = 0;
|
|
5164 entering_debugger = 0;
|
|
5165 }
|
|
5166
|
|
5167 void
|
|
5168 vars_of_eval (void)
|
|
5169 {
|
|
5170 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /*
|
|
5171 Limit on number of Lisp variable bindings & unwind-protects before error.
|
|
5172 */ );
|
|
5173
|
|
5174 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /*
|
|
5175 Limit on depth in `eval', `apply' and `funcall' before error.
|
|
5176 This limit is to catch infinite recursions for you before they cause
|
|
5177 actual stack overflow in C, which would be fatal for Emacs.
|
|
5178 You can safely make it considerably larger than its default value,
|
|
5179 if that proves inconveniently small.
|
|
5180 */ );
|
|
5181
|
|
5182 DEFVAR_LISP ("quit-flag", &Vquit_flag /*
|
|
5183 Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
|
|
5184 Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'.
|
|
5185 */ );
|
|
5186 Vquit_flag = Qnil;
|
|
5187
|
|
5188 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /*
|
|
5189 Non-nil inhibits C-g quitting from happening immediately.
|
|
5190 Note that `quit-flag' will still be set by typing C-g,
|
|
5191 so a quit will be signalled as soon as `inhibit-quit' is nil.
|
|
5192 To prevent this happening, set `quit-flag' to nil
|
|
5193 before making `inhibit-quit' nil. The value of `inhibit-quit' is
|
|
5194 ignored if a critical quit is requested by typing control-shift-G in
|
|
5195 an X frame.
|
|
5196 */ );
|
|
5197 Vinhibit_quit = Qnil;
|
|
5198
|
|
5199 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /*
|
|
5200 *Non-nil means automatically display a backtrace buffer
|
|
5201 after any error that is not handled by a `condition-case'.
|
|
5202 If the value is a list, an error only means to display a backtrace
|
|
5203 if one of its condition symbols appears in the list.
|
|
5204 See also variable `stack-trace-on-signal'.
|
|
5205 */ );
|
|
5206 Vstack_trace_on_error = Qnil;
|
|
5207
|
|
5208 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /*
|
|
5209 *Non-nil means automatically display a backtrace buffer
|
|
5210 after any error that is signalled, whether or not it is handled by
|
|
5211 a `condition-case'.
|
|
5212 If the value is a list, an error only means to display a backtrace
|
|
5213 if one of its condition symbols appears in the list.
|
|
5214 See also variable `stack-trace-on-error'.
|
|
5215 */ );
|
|
5216 Vstack_trace_on_signal = Qnil;
|
|
5217
|
|
5218 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /*
|
|
5219 *Non-nil means enter debugger if an unhandled error is signalled.
|
|
5220 The debugger will not be entered if the error is handled by
|
|
5221 a `condition-case'.
|
|
5222 If the value is a list, an error only means to enter the debugger
|
|
5223 if one of its condition symbols appears in the list.
|
|
5224 See also variables `debug-on-quit' and `debug-on-signal'.
|
|
5225 */ );
|
|
5226 Vdebug_on_error = Qnil;
|
|
5227
|
|
5228 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /*
|
|
5229 *Non-nil means enter debugger if an error is signalled.
|
|
5230 The debugger will be entered whether or not the error is handled by
|
|
5231 a `condition-case'.
|
|
5232 If the value is a list, an error only means to enter the debugger
|
|
5233 if one of its condition symbols appears in the list.
|
|
5234 See also variable `debug-on-quit'.
|
|
5235 */ );
|
|
5236 Vdebug_on_signal = Qnil;
|
|
5237
|
|
5238 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /*
|
|
5239 *Non-nil means enter debugger if quit is signalled (C-G, for example).
|
|
5240 Does not apply if quit is handled by a `condition-case'. Entering the
|
|
5241 debugger can also be achieved at any time (for X11 console) by typing
|
|
5242 control-shift-G to signal a critical quit.
|
|
5243 */ );
|
|
5244 debug_on_quit = 0;
|
|
5245
|
|
5246 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /*
|
|
5247 Non-nil means enter debugger before next `eval', `apply' or `funcall'.
|
|
5248 */ );
|
|
5249
|
|
5250 DEFVAR_LISP ("debugger", &Vdebugger /*
|
|
5251 Function to call to invoke debugger.
|
|
5252 If due to frame exit, args are `exit' and the value being returned;
|
|
5253 this function's value will be returned instead of that.
|
|
5254 If due to error, args are `error' and a list of the args to `signal'.
|
|
5255 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
5256 If due to `eval' entry, one arg, t.
|
|
5257 */ );
|
|
5258 Vdebugger = Qnil;
|
|
5259
|
|
5260 preparing_for_armageddon = 0;
|
|
5261
|
|
5262 staticpro (&Vpending_warnings);
|
|
5263 Vpending_warnings = Qnil;
|
|
5264 Vpending_warnings_tail = Qnil; /* no need to protect this */
|
|
5265
|
|
5266 in_warnings = 0;
|
|
5267
|
|
5268 staticpro (&Vautoload_queue);
|
|
5269 Vautoload_queue = Qnil;
|
|
5270
|
|
5271 staticpro (&Vcondition_handlers);
|
|
5272
|
|
5273 staticpro (&Vcurrent_warning_class);
|
|
5274 Vcurrent_warning_class = Qnil;
|
|
5275
|
|
5276 staticpro (&Vcurrent_error_state);
|
|
5277 Vcurrent_error_state = Qnil; /* errors as normal */
|
|
5278
|
|
5279 Qunbound_suspended_errors_tag = make_opaque_long (0);
|
|
5280 staticpro (&Qunbound_suspended_errors_tag);
|
|
5281
|
|
5282 specpdl_size = 50;
|
|
5283 specpdl_depth_counter = 0;
|
|
5284 specpdl = (struct specbinding *)
|
|
5285 xmalloc (specpdl_size * sizeof (struct specbinding));
|
|
5286 /* XEmacs change: increase these values. */
|
|
5287 max_specpdl_size = 3000;
|
|
5288 max_lisp_eval_depth = 500;
|
|
5289 throw_level = 0;
|
|
5290
|
|
5291 reinit_eval ();
|
|
5292 }
|