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