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