272
|
1 /* Evaluator for GNU Emacs Lisp interpreter.
|
61901
787052160d87
(do_autoload): Record only autoloads in the autoload property of symbols.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001,
|
787052160d87
(do_autoload): Record only autoloads in the autoload property of symbols.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
3 2002, 2004, 2005 Free Software Foundation, Inc.
|
272
|
4
|
|
5 This file is part of GNU Emacs.
|
|
6
|
|
7 GNU Emacs is free software; you can redistribute it and/or modify
|
|
8 it under the terms of the GNU General Public License as published by
|
10342
01d13c22797e
(Fcommandp): Use & PSEUDOVECTOR_SIZE_MASK on `size' field of compiled
Roland McGrath <roland@gnu.org>
diff
changeset
|
9 the Free Software Foundation; either version 2, or (at your option)
|
272
|
10 any later version.
|
|
11
|
|
12 GNU Emacs is distributed in the hope that it will be useful,
|
|
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15 GNU General Public License for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with GNU Emacs; see the file COPYING. If not, write to
|
14186
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
272
|
21
|
|
22
|
4696
|
23 #include <config.h>
|
272
|
24 #include "lisp.h"
|
2439
|
25 #include "blockinput.h"
|
272
|
26 #include "commands.h"
|
515
|
27 #include "keyboard.h"
|
26764
|
28 #include "dispextern.h"
|
272
|
29 #include <setjmp.h>
|
|
30
|
|
31 /* This definition is duplicated in alloc.c and keyboard.c */
|
|
32 /* Putting it in lisp.h makes cc bomb out! */
|
|
33
|
|
34 struct backtrace
|
30080
|
35 {
|
|
36 struct backtrace *next;
|
|
37 Lisp_Object *function;
|
|
38 Lisp_Object *args; /* Points to vector of args. */
|
|
39 int nargs; /* Length of vector.
|
727
|
40 If nargs is UNEVALLED, args points to slot holding
|
|
41 list of unevalled args */
|
30080
|
42 char evalargs;
|
|
43 /* Nonzero means call value of debugger when done with this operation. */
|
|
44 char debug_on_exit;
|
|
45 };
|
272
|
46
|
|
47 struct backtrace *backtrace_list;
|
|
48
|
1196
|
49 /* This structure helps implement the `catch' and `throw' control
|
|
50 structure. A struct catchtag contains all the information needed
|
|
51 to restore the state of the interpreter after a non-local jump.
|
|
52
|
|
53 Handlers for error conditions (represented by `struct handler'
|
|
54 structures) just point to a catch tag to do the cleanup required
|
|
55 for their jumps.
|
|
56
|
|
57 catchtag structures are chained together in the C calling stack;
|
|
58 the `next' member points to the next outer catchtag.
|
|
59
|
|
60 A call like (throw TAG VAL) searches for a catchtag whose `tag'
|
|
61 member is TAG, and then unbinds to it. The `val' member is used to
|
|
62 hold VAL while the stack is unwound; `val' is returned as the value
|
|
63 of the catch form.
|
|
64
|
|
65 All the other members are concerned with restoring the interpreter
|
|
66 state. */
|
30080
|
67
|
272
|
68 struct catchtag
|
30080
|
69 {
|
|
70 Lisp_Object tag;
|
|
71 Lisp_Object val;
|
|
72 struct catchtag *next;
|
|
73 struct gcpro *gcpro;
|
|
74 jmp_buf jmp;
|
|
75 struct backtrace *backlist;
|
|
76 struct handler *handlerlist;
|
|
77 int lisp_eval_depth;
|
|
78 int pdlcount;
|
|
79 int poll_suppress_count;
|
48909
|
80 int interrupt_input_blocked;
|
30080
|
81 struct byte_stack *byte_stack;
|
|
82 };
|
272
|
83
|
|
84 struct catchtag *catchlist;
|
|
85
|
26297
|
86 #ifdef DEBUG_GCPRO
|
|
87 /* Count levels of GCPRO to detect failure to UNGCPRO. */
|
|
88 int gcpro_level;
|
|
89 #endif
|
|
90
|
59109
|
91 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
|
381
|
92 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
|
272
|
93 Lisp_Object Qand_rest, Qand_optional;
|
|
94 Lisp_Object Qdebug_on_error;
|
44132
|
95 Lisp_Object Qdeclare;
|
272
|
96
|
16296
|
97 /* This holds either the symbol `run-hooks' or nil.
|
|
98 It is nil at an early stage of startup, and when Emacs
|
|
99 is shutting down. */
|
30080
|
100
|
272
|
101 Lisp_Object Vrun_hooks;
|
|
102
|
|
103 /* Non-nil means record all fset's and provide's, to be undone
|
|
104 if the file being autoloaded is not fully loaded.
|
|
105 They are recorded by being consed onto the front of Vautoload_queue:
|
|
106 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
|
|
107
|
|
108 Lisp_Object Vautoload_queue;
|
|
109
|
|
110 /* Current number of specbindings allocated in specpdl. */
|
30080
|
111
|
272
|
112 int specpdl_size;
|
|
113
|
|
114 /* Pointer to beginning of specpdl. */
|
30080
|
115
|
272
|
116 struct specbinding *specpdl;
|
|
117
|
|
118 /* Pointer to first unused element in specpdl. */
|
30080
|
119
|
50919
|
120 volatile struct specbinding *specpdl_ptr;
|
272
|
121
|
|
122 /* Maximum size allowed for specpdl allocation */
|
30080
|
123
|
43713
f92c4d87863a
Change defvar_int def and vars to use EMACS_INT instead of just int.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
124 EMACS_INT max_specpdl_size;
|
272
|
125
|
|
126 /* Depth in Lisp evaluations and function calls. */
|
30080
|
127
|
272
|
128 int lisp_eval_depth;
|
|
129
|
|
130 /* Maximum allowed depth in Lisp evaluations and function calls. */
|
30080
|
131
|
43713
f92c4d87863a
Change defvar_int def and vars to use EMACS_INT instead of just int.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
132 EMACS_INT max_lisp_eval_depth;
|
272
|
133
|
|
134 /* Nonzero means enter debugger before next function call */
|
30080
|
135
|
272
|
136 int debug_on_next_call;
|
|
137
|
40661
|
138 /* Non-zero means debugger may continue. This is zero when the
|
26947
|
139 debugger is called during redisplay, where it might not be safe to
|
|
140 continue the interrupted redisplay. */
|
|
141
|
|
142 int debugger_may_continue;
|
|
143
|
684
|
144 /* List of conditions (non-nil atom means all) which cause a backtrace
|
706
|
145 if an error is handled by the command loop's error handler. */
|
30080
|
146
|
684
|
147 Lisp_Object Vstack_trace_on_error;
|
272
|
148
|
684
|
149 /* List of conditions (non-nil atom means all) which enter the debugger
|
706
|
150 if an error is handled by the command loop's error handler. */
|
30080
|
151
|
684
|
152 Lisp_Object Vdebug_on_error;
|
272
|
153
|
13768
|
154 /* List of conditions and regexps specifying error messages which
|
40661
|
155 do not enter the debugger even if Vdebug_on_error says they should. */
|
30080
|
156
|
13768
|
157 Lisp_Object Vdebug_ignored_errors;
|
|
158
|
16355
|
159 /* Non-nil means call the debugger even if the error will be handled. */
|
30080
|
160
|
16443
|
161 Lisp_Object Vdebug_on_signal;
|
16355
|
162
|
|
163 /* Hook for edebug to use. */
|
30080
|
164
|
16355
|
165 Lisp_Object Vsignal_hook_function;
|
|
166
|
272
|
167 /* Nonzero means enter debugger if a quit signal
|
684
|
168 is handled by the command loop's error handler. */
|
30080
|
169
|
272
|
170 int debug_on_quit;
|
|
171
|
17872
|
172 /* The value of num_nonmacro_input_events as of the last time we
|
1196
|
173 started to enter the debugger. If we decide to enter the debugger
|
17872
|
174 again when this is still equal to num_nonmacro_input_events, then we
|
1196
|
175 know that the debugger itself has an error, and we should just
|
|
176 signal the error instead of entering an infinite loop of debugger
|
|
177 invocations. */
|
30080
|
178
|
1196
|
179 int when_entered_debugger;
|
272
|
180
|
|
181 Lisp_Object Vdebugger;
|
|
182
|
30073
|
183 /* The function from which the last `signal' was called. Set in
|
|
184 Fsignal. */
|
|
185
|
|
186 Lisp_Object Vsignaling_function;
|
|
187
|
30080
|
188 /* Set to non-zero while processing X events. Checked in Feval to
|
|
189 make sure the Lisp interpreter isn't called from a signal handler,
|
|
190 which is unsafe because the interpreter isn't reentrant. */
|
|
191
|
|
192 int handling_signal;
|
|
193
|
44132
|
194 /* Function to process declarations in defmacro forms. */
|
|
195
|
|
196 Lisp_Object Vmacro_declaration_function;
|
|
197
|
|
198
|
41114
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
199 static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
|
272
|
200
|
21514
|
201 void
|
272
|
202 init_eval_once ()
|
|
203 {
|
|
204 specpdl_size = 50;
|
7885
|
205 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
|
14600
|
206 specpdl_ptr = specpdl;
|
58827
|
207 max_specpdl_size = 1000;
|
17061
|
208 max_lisp_eval_depth = 300;
|
8980
|
209
|
|
210 Vrun_hooks = Qnil;
|
272
|
211 }
|
|
212
|
21514
|
213 void
|
272
|
214 init_eval ()
|
|
215 {
|
|
216 specpdl_ptr = specpdl;
|
|
217 catchlist = 0;
|
|
218 handlerlist = 0;
|
|
219 backtrace_list = 0;
|
|
220 Vquit_flag = Qnil;
|
|
221 debug_on_next_call = 0;
|
|
222 lisp_eval_depth = 0;
|
26307
|
223 #ifdef DEBUG_GCPRO
|
26297
|
224 gcpro_level = 0;
|
26307
|
225 #endif
|
17872
|
226 /* This is less than the initial value of num_nonmacro_input_events. */
|
7213
|
227 when_entered_debugger = -1;
|
272
|
228 }
|
|
229
|
|
230 Lisp_Object
|
|
231 call_debugger (arg)
|
|
232 Lisp_Object arg;
|
|
233 {
|
26764
|
234 int debug_while_redisplaying;
|
46293
|
235 int count = SPECPDL_INDEX ();
|
26764
|
236 Lisp_Object val;
|
49600
|
237
|
272
|
238 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
|
|
239 max_lisp_eval_depth = lisp_eval_depth + 20;
|
49600
|
240
|
272
|
241 if (specpdl_size + 40 > max_specpdl_size)
|
|
242 max_specpdl_size = specpdl_size + 40;
|
49600
|
243
|
28383
|
244 #ifdef HAVE_X_WINDOWS
|
36256
e033d60bd048
Use display_hourglass_p, start_hourglass, cancel_hourglass instead of
Gerd Moellmann <gerd@gnu.org>
diff
changeset
|
245 if (display_hourglass_p)
|
e033d60bd048
Use display_hourglass_p, start_hourglass, cancel_hourglass instead of
Gerd Moellmann <gerd@gnu.org>
diff
changeset
|
246 cancel_hourglass ();
|
28383
|
247 #endif
|
|
248
|
272
|
249 debug_on_next_call = 0;
|
17872
|
250 when_entered_debugger = num_nonmacro_input_events;
|
26764
|
251
|
|
252 /* Resetting redisplaying_p to 0 makes sure that debug output is
|
|
253 displayed if the debugger is invoked during redisplay. */
|
|
254 debug_while_redisplaying = redisplaying_p;
|
|
255 redisplaying_p = 0;
|
26947
|
256 specbind (intern ("debugger-may-continue"),
|
|
257 debug_while_redisplaying ? Qnil : Qt);
|
37043
|
258 specbind (Qinhibit_redisplay, Qnil);
|
37799
|
259
|
|
260 #if 0 /* Binding this prevents execution of Lisp code during
|
|
261 redisplay, which necessarily leads to display problems. */
|
37043
|
262 specbind (Qinhibit_eval_during_redisplay, Qt);
|
37799
|
263 #endif
|
49600
|
264
|
26764
|
265 val = apply1 (Vdebugger, arg);
|
|
266
|
|
267 /* Interrupting redisplay and resuming it later is not safe under
|
|
268 all circumstances. So, when the debugger returns, abort the
|
40661
|
269 interrupted redisplay by going back to the top-level. */
|
26764
|
270 if (debug_while_redisplaying)
|
|
271 Ftop_level ();
|
|
272
|
26947
|
273 return unbind_to (count, val);
|
272
|
274 }
|
|
275
|
21514
|
276 void
|
272
|
277 do_debug_on_call (code)
|
|
278 Lisp_Object code;
|
|
279 {
|
|
280 debug_on_next_call = 0;
|
|
281 backtrace_list->debug_on_exit = 1;
|
|
282 call_debugger (Fcons (code, Qnil));
|
|
283 }
|
|
284
|
|
285 /* NOTE!!! Every function that can call EVAL must protect its args
|
|
286 and temporaries from garbage collection while it needs them.
|
|
287 The definition of `For' shows what you have to do. */
|
|
288
|
|
289 DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
|
40570
|
290 doc: /* Eval args until one of them yields non-nil, then return that value.
|
|
291 The remaining args are not evalled at all.
|
|
292 If all args return nil, return nil.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
293 usage: (or CONDITIONS ...) */)
|
40570
|
294 (args)
|
272
|
295 Lisp_Object args;
|
|
296 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
297 register Lisp_Object val = Qnil;
|
272
|
298 struct gcpro gcpro1;
|
|
299
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
300 GCPRO1 (args);
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
301
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
302 while (CONSP (args))
|
272
|
303 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
304 val = Feval (XCAR (args));
|
485
|
305 if (!NILP (val))
|
272
|
306 break;
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
307 args = XCDR (args);
|
272
|
308 }
|
|
309
|
|
310 UNGCPRO;
|
|
311 return val;
|
|
312 }
|
|
313
|
|
314 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
|
40983
|
315 doc: /* Eval args until one of them yields nil, then return nil.
|
40570
|
316 The remaining args are not evalled at all.
|
|
317 If no arg yields nil, return the last arg's value.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
318 usage: (and CONDITIONS ...) */)
|
40570
|
319 (args)
|
272
|
320 Lisp_Object args;
|
|
321 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
322 register Lisp_Object val = Qt;
|
272
|
323 struct gcpro gcpro1;
|
|
324
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
325 GCPRO1 (args);
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
326
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
327 while (CONSP (args))
|
272
|
328 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
329 val = Feval (XCAR (args));
|
485
|
330 if (NILP (val))
|
272
|
331 break;
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
332 args = XCDR (args);
|
272
|
333 }
|
|
334
|
|
335 UNGCPRO;
|
|
336 return val;
|
|
337 }
|
|
338
|
|
339 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
|
40983
|
340 doc: /* If COND yields non-nil, do THEN, else do ELSE...
|
40570
|
341 Returns the value of THEN or the value of the last of the ELSE's.
|
|
342 THEN must be one expression, but ELSE... can be zero or more expressions.
|
|
343 If COND yields nil, and there are no ELSE's, the value is nil.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
344 usage: (if COND THEN ELSE...) */)
|
40570
|
345 (args)
|
272
|
346 Lisp_Object args;
|
|
347 {
|
|
348 register Lisp_Object cond;
|
|
349 struct gcpro gcpro1;
|
|
350
|
|
351 GCPRO1 (args);
|
|
352 cond = Feval (Fcar (args));
|
|
353 UNGCPRO;
|
|
354
|
485
|
355 if (!NILP (cond))
|
272
|
356 return Feval (Fcar (Fcdr (args)));
|
|
357 return Fprogn (Fcdr (Fcdr (args)));
|
|
358 }
|
|
359
|
|
360 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
|
40570
|
361 doc: /* Try each clause until one succeeds.
|
|
362 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
|
|
363 and, if the value is non-nil, this clause succeeds:
|
|
364 then the expressions in BODY are evaluated and the last one's
|
|
365 value is the value of the cond-form.
|
|
366 If no clause succeeds, cond returns nil.
|
|
367 If a clause has one element, as in (CONDITION),
|
|
368 CONDITION's value if non-nil is returned from the cond-form.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
369 usage: (cond CLAUSES...) */)
|
40570
|
370 (args)
|
272
|
371 Lisp_Object args;
|
|
372 {
|
|
373 register Lisp_Object clause, val;
|
|
374 struct gcpro gcpro1;
|
|
375
|
|
376 val = Qnil;
|
|
377 GCPRO1 (args);
|
485
|
378 while (!NILP (args))
|
272
|
379 {
|
|
380 clause = Fcar (args);
|
|
381 val = Feval (Fcar (clause));
|
485
|
382 if (!NILP (val))
|
272
|
383 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
384 if (!EQ (XCDR (clause), Qnil))
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
385 val = Fprogn (XCDR (clause));
|
272
|
386 break;
|
|
387 }
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
388 args = XCDR (args);
|
272
|
389 }
|
|
390 UNGCPRO;
|
|
391
|
|
392 return val;
|
|
393 }
|
|
394
|
|
395 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
|
40570
|
396 doc: /* Eval BODY forms sequentially and return value of last one.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
397 usage: (progn BODY ...) */)
|
40570
|
398 (args)
|
272
|
399 Lisp_Object args;
|
|
400 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
401 register Lisp_Object val = Qnil;
|
272
|
402 struct gcpro gcpro1;
|
|
403
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
404 GCPRO1 (args);
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
405
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
406 while (CONSP (args))
|
272
|
407 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
408 val = Feval (XCAR (args));
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
409 args = XCDR (args);
|
272
|
410 }
|
|
411
|
|
412 UNGCPRO;
|
|
413 return val;
|
|
414 }
|
|
415
|
|
416 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
|
40570
|
417 doc: /* Eval FIRST and BODY sequentially; value from FIRST.
|
|
418 The value of FIRST is saved during the evaluation of the remaining args,
|
|
419 whose values are discarded.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
420 usage: (prog1 FIRST BODY...) */)
|
40570
|
421 (args)
|
272
|
422 Lisp_Object args;
|
|
423 {
|
|
424 Lisp_Object val;
|
|
425 register Lisp_Object args_left;
|
|
426 struct gcpro gcpro1, gcpro2;
|
|
427 register int argnum = 0;
|
|
428
|
485
|
429 if (NILP(args))
|
272
|
430 return Qnil;
|
|
431
|
|
432 args_left = args;
|
|
433 val = Qnil;
|
|
434 GCPRO2 (args, val);
|
|
435
|
|
436 do
|
|
437 {
|
|
438 if (!(argnum++))
|
|
439 val = Feval (Fcar (args_left));
|
|
440 else
|
|
441 Feval (Fcar (args_left));
|
|
442 args_left = Fcdr (args_left);
|
|
443 }
|
485
|
444 while (!NILP(args_left));
|
272
|
445
|
|
446 UNGCPRO;
|
|
447 return val;
|
|
448 }
|
|
449
|
|
450 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
|
40570
|
451 doc: /* Eval X, Y and BODY sequentially; value from Y.
|
|
452 The value of Y is saved during the evaluation of the remaining args,
|
|
453 whose values are discarded.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
454 usage: (prog2 X Y BODY...) */)
|
40570
|
455 (args)
|
272
|
456 Lisp_Object args;
|
|
457 {
|
|
458 Lisp_Object val;
|
|
459 register Lisp_Object args_left;
|
|
460 struct gcpro gcpro1, gcpro2;
|
|
461 register int argnum = -1;
|
|
462
|
|
463 val = Qnil;
|
|
464
|
6803
|
465 if (NILP (args))
|
272
|
466 return Qnil;
|
|
467
|
|
468 args_left = args;
|
|
469 val = Qnil;
|
|
470 GCPRO2 (args, val);
|
|
471
|
|
472 do
|
|
473 {
|
|
474 if (!(argnum++))
|
|
475 val = Feval (Fcar (args_left));
|
|
476 else
|
|
477 Feval (Fcar (args_left));
|
|
478 args_left = Fcdr (args_left);
|
|
479 }
|
6803
|
480 while (!NILP (args_left));
|
272
|
481
|
|
482 UNGCPRO;
|
|
483 return val;
|
|
484 }
|
|
485
|
|
486 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
|
40570
|
487 doc: /* Set each SYM to the value of its VAL.
|
|
488 The symbols SYM are variables; they are literal (not evaluated).
|
|
489 The values VAL are expressions; they are evaluated.
|
|
490 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.
|
|
491 The second VAL is not computed until after the first SYM is set, and so on;
|
|
492 each VAL can use the new value of variables set earlier in the `setq'.
|
|
493 The return value of the `setq' form is the value of the last VAL.
|
|
494 usage: (setq SYM VAL SYM VAL ...) */)
|
|
495 (args)
|
272
|
496 Lisp_Object args;
|
|
497 {
|
|
498 register Lisp_Object args_left;
|
|
499 register Lisp_Object val, sym;
|
|
500 struct gcpro gcpro1;
|
|
501
|
485
|
502 if (NILP(args))
|
272
|
503 return Qnil;
|
|
504
|
|
505 args_left = args;
|
|
506 GCPRO1 (args);
|
|
507
|
|
508 do
|
|
509 {
|
|
510 val = Feval (Fcar (Fcdr (args_left)));
|
|
511 sym = Fcar (args_left);
|
|
512 Fset (sym, val);
|
|
513 args_left = Fcdr (Fcdr (args_left));
|
|
514 }
|
485
|
515 while (!NILP(args_left));
|
272
|
516
|
|
517 UNGCPRO;
|
|
518 return val;
|
|
519 }
|
49600
|
520
|
272
|
521 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
|
40570
|
522 doc: /* Return the argument, without evaluating it. `(quote x)' yields `x'.
|
|
523 usage: (quote ARG) */)
|
|
524 (args)
|
272
|
525 Lisp_Object args;
|
|
526 {
|
|
527 return Fcar (args);
|
|
528 }
|
49600
|
529
|
272
|
530 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
|
40570
|
531 doc: /* Like `quote', but preferred for objects which are functions.
|
|
532 In byte compilation, `function' causes its argument to be compiled.
|
|
533 `quote' cannot do that.
|
|
534 usage: (function ARG) */)
|
|
535 (args)
|
272
|
536 Lisp_Object args;
|
|
537 {
|
|
538 return Fcar (args);
|
|
539 }
|
|
540
|
35774
|
541
|
272
|
542 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
|
57873
|
543 doc: /* Return t if the function was run directly by user input.
|
40570
|
544 This means that the function was called with call-interactively (which
|
|
545 includes being called as the binding of a key)
|
57873
|
546 and input is currently coming from the keyboard (not in keyboard macro),
|
|
547 and Emacs is not running in batch mode (`noninteractive' is nil).
|
|
548
|
|
549 The only known proper use of `interactive-p' is in deciding whether to
|
|
550 display a helpful message, or how to display it. If you're thinking
|
|
551 of using it for any other purpose, it is quite likely that you're
|
|
552 making a mistake. Think: what do you want to do when the command is
|
|
553 called from a keyboard macro?
|
|
554
|
|
555 If you want to test whether your function was called with
|
|
556 `call-interactively', the way to do that is by adding an extra
|
|
557 optional argument, and making the `interactive' spec specify non-nil
|
|
558 unconditionally for that argument. (`p' is a good way to do this.) */)
|
40570
|
559 ()
|
272
|
560 {
|
57873
|
561 return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
|
35774
|
562 }
|
|
563
|
|
564
|
57889
|
565 DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 0, 0,
|
57873
|
566 doc: /* Return t if the function using this was called with call-interactively.
|
|
567 This is used for implementing advice and other function-modifying
|
|
568 features of Emacs.
|
|
569
|
|
570 The cleanest way to test whether your function was called with
|
|
571 `call-interactively', the way to do that is by adding an extra
|
|
572 optional argument, and making the `interactive' spec specify non-nil
|
|
573 unconditionally for that argument. (`p' is a good way to do this.) */)
|
|
574 ()
|
|
575 {
|
58734
|
576 return interactive_p (1) ? Qt : Qnil;
|
57873
|
577 }
|
|
578
|
|
579
|
|
580 /* Return 1 if function in which this appears was called using
|
|
581 call-interactively.
|
35774
|
582
|
|
583 EXCLUDE_SUBRS_P non-zero means always return 0 if the function
|
|
584 called is a built-in. */
|
|
585
|
|
586 int
|
|
587 interactive_p (exclude_subrs_p)
|
|
588 int exclude_subrs_p;
|
|
589 {
|
|
590 struct backtrace *btp;
|
|
591 Lisp_Object fun;
|
272
|
592
|
|
593 btp = backtrace_list;
|
727
|
594
|
|
595 /* If this isn't a byte-compiled function, there may be a frame at
|
35774
|
596 the top for Finteractive_p. If so, skip it. */
|
727
|
597 fun = Findirect_function (*btp->function);
|
58734
|
598 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
|
|
599 || XSUBR (fun) == &Scalled_interactively_p))
|
323
|
600 btp = btp->next;
|
|
601
|
727
|
602 /* If we're running an Emacs 18-style byte-compiled function, there
|
48492
|
603 may be a frame for Fbytecode at the top level. In any version of
|
|
604 Emacs there can be Fbytecode frames for subexpressions evaluated
|
|
605 inside catch and condition-case. Skip past them.
|
|
606
|
|
607 If this isn't a byte-compiled function, then we may now be
|
727
|
608 looking at several frames for special forms. Skip past them. */
|
48492
|
609 while (btp
|
|
610 && (EQ (*btp->function, Qbytecode)
|
|
611 || btp->nargs == UNEVALLED))
|
727
|
612 btp = btp->next;
|
|
613
|
|
614 /* btp now points at the frame of the innermost function that isn't
|
|
615 a special form, ignoring frames for Finteractive_p and/or
|
|
616 Fbytecode at the top. If this frame is for a built-in function
|
|
617 (such as load or eval-region) return nil. */
|
648
|
618 fun = Findirect_function (*btp->function);
|
35774
|
619 if (exclude_subrs_p && SUBRP (fun))
|
|
620 return 0;
|
49600
|
621
|
272
|
622 /* btp points to the frame of a Lisp function that called interactive-p.
|
|
623 Return t if that function was called interactively. */
|
|
624 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively))
|
35774
|
625 return 1;
|
|
626 return 0;
|
272
|
627 }
|
|
628
|
35774
|
629
|
272
|
630 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0,
|
40570
|
631 doc: /* Define NAME as a function.
|
|
632 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
|
|
633 See also the function `interactive'.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
634 usage: (defun NAME ARGLIST [DOCSTRING] BODY...) */)
|
40570
|
635 (args)
|
272
|
636 Lisp_Object args;
|
|
637 {
|
|
638 register Lisp_Object fn_name;
|
|
639 register Lisp_Object defn;
|
|
640
|
|
641 fn_name = Fcar (args);
|
56052
|
642 CHECK_SYMBOL (fn_name);
|
272
|
643 defn = Fcons (Qlambda, Fcdr (args));
|
485
|
644 if (!NILP (Vpurify_flag))
|
272
|
645 defn = Fpurecopy (defn);
|
48724
ccd782f27e54
(Fdefun, Fdefmacro): Record in load-history redefining an autoload.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
646 if (CONSP (XSYMBOL (fn_name)->function)
|
ccd782f27e54
(Fdefun, Fdefmacro): Record in load-history redefining an autoload.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
647 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
|
ccd782f27e54
(Fdefun, Fdefmacro): Record in load-history redefining an autoload.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
648 LOADHIST_ATTACH (Fcons (Qt, fn_name));
|
272
|
649 Ffset (fn_name, defn);
|
59109
|
650 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
|
272
|
651 return fn_name;
|
|
652 }
|
|
653
|
|
654 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0,
|
40570
|
655 doc: /* Define NAME as a macro.
|
46198
|
656 The actual definition looks like
|
|
657 (macro lambda ARGLIST [DOCSTRING] [DECL] BODY...).
|
40570
|
658 When the macro is called, as in (NAME ARGS...),
|
|
659 the function (lambda ARGLIST BODY...) is applied to
|
|
660 the list ARGS... as it appears in the expression,
|
|
661 and the result should be a form to be evaluated instead of the original.
|
46198
|
662
|
|
663 DECL is a declaration, optional, which can specify how to indent
|
|
664 calls to this macro and how Edebug should handle it. It looks like this:
|
|
665 (declare SPECS...)
|
|
666 The elements can look like this:
|
|
667 (indent INDENT)
|
|
668 Set NAME's `lisp-indent-function' property to INDENT.
|
|
669
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
670 (debug DEBUG)
|
46198
|
671 Set NAME's `edebug-form-spec' property to DEBUG. (This is
|
49752
|
672 equivalent to writing a `def-edebug-spec' for the macro.)
|
46198
|
673 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */)
|
40570
|
674 (args)
|
272
|
675 Lisp_Object args;
|
|
676 {
|
|
677 register Lisp_Object fn_name;
|
|
678 register Lisp_Object defn;
|
44132
|
679 Lisp_Object lambda_list, doc, tail;
|
272
|
680
|
|
681 fn_name = Fcar (args);
|
56356
|
682 CHECK_SYMBOL (fn_name);
|
44132
|
683 lambda_list = Fcar (Fcdr (args));
|
|
684 tail = Fcdr (Fcdr (args));
|
|
685
|
|
686 doc = Qnil;
|
|
687 if (STRINGP (Fcar (tail)))
|
|
688 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
689 doc = XCAR (tail);
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
690 tail = XCDR (tail);
|
44132
|
691 }
|
|
692
|
|
693 while (CONSP (Fcar (tail))
|
|
694 && EQ (Fcar (Fcar (tail)), Qdeclare))
|
|
695 {
|
|
696 if (!NILP (Vmacro_declaration_function))
|
|
697 {
|
|
698 struct gcpro gcpro1;
|
|
699 GCPRO1 (args);
|
|
700 call2 (Vmacro_declaration_function, fn_name, Fcar (tail));
|
|
701 UNGCPRO;
|
|
702 }
|
49600
|
703
|
44132
|
704 tail = Fcdr (tail);
|
|
705 }
|
|
706
|
|
707 if (NILP (doc))
|
|
708 tail = Fcons (lambda_list, tail);
|
|
709 else
|
|
710 tail = Fcons (lambda_list, Fcons (doc, tail));
|
|
711 defn = Fcons (Qmacro, Fcons (Qlambda, tail));
|
49600
|
712
|
485
|
713 if (!NILP (Vpurify_flag))
|
272
|
714 defn = Fpurecopy (defn);
|
48724
ccd782f27e54
(Fdefun, Fdefmacro): Record in load-history redefining an autoload.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
715 if (CONSP (XSYMBOL (fn_name)->function)
|
ccd782f27e54
(Fdefun, Fdefmacro): Record in load-history redefining an autoload.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
716 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload))
|
ccd782f27e54
(Fdefun, Fdefmacro): Record in load-history redefining an autoload.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
717 LOADHIST_ATTACH (Fcons (Qt, fn_name));
|
272
|
718 Ffset (fn_name, defn);
|
59109
|
719 LOADHIST_ATTACH (Fcons (Qdefun, fn_name));
|
272
|
720 return fn_name;
|
|
721 }
|
|
722
|
39577
|
723
|
46388
|
724 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0,
|
40570
|
725 doc: /* Make SYMBOL a variable alias for symbol ALIASED.
|
|
726 Setting the value of SYMBOL will subsequently set the value of ALIASED,
|
|
727 and getting the value of SYMBOL will return the value ALIASED has.
|
62091
|
728 Third arg DOCSTRING, if non-nil, is documentation for SYMBOL. If it is
|
|
729 omitted or nil, SYMBOL gets the documentation string of ALIASED, or of the
|
|
730 variable at the end of the chain of aliases, if ALIASED is itself an alias.
|
52960
|
731 The return value is ALIASED. */)
|
46388
|
732 (symbol, aliased, docstring)
|
|
733 Lisp_Object symbol, aliased, docstring;
|
39577
|
734 {
|
|
735 struct Lisp_Symbol *sym;
|
46388
|
736
|
40656
|
737 CHECK_SYMBOL (symbol);
|
|
738 CHECK_SYMBOL (aliased);
|
39577
|
739
|
|
740 if (SYMBOL_CONSTANT_P (symbol))
|
|
741 error ("Cannot make a constant an alias");
|
|
742
|
|
743 sym = XSYMBOL (symbol);
|
|
744 sym->indirect_variable = 1;
|
|
745 sym->value = aliased;
|
|
746 sym->constant = SYMBOL_CONSTANT_P (aliased);
|
59109
|
747 LOADHIST_ATTACH (symbol);
|
46388
|
748 if (!NILP (docstring))
|
|
749 Fput (symbol, Qvariable_documentation, docstring);
|
62178
91b45e7531ea
(Fdefvaralias): Remove any pre-existing variable-documentation
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
750 else
|
91b45e7531ea
(Fdefvaralias): Remove any pre-existing variable-documentation
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
751 Fput (symbol, Qvariable_documentation, Qnil);
|
46388
|
752
|
39577
|
753 return aliased;
|
|
754 }
|
|
755
|
|
756
|
272
|
757 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0,
|
40570
|
758 doc: /* Define SYMBOL as a variable.
|
|
759 You are not required to define a variable in order to use it,
|
|
760 but the definition can supply documentation and an initial value
|
|
761 in a way that tags can recognize.
|
|
762
|
|
763 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.
|
|
764 If SYMBOL is buffer-local, its default value is what is set;
|
|
765 buffer-local values are not affected.
|
|
766 INITVALUE and DOCSTRING are optional.
|
|
767 If DOCSTRING starts with *, this variable is identified as a user option.
|
|
768 This means that M-x set-variable recognizes it.
|
|
769 See also `user-variable-p'.
|
|
770 If INITVALUE is missing, SYMBOL's value is not set.
|
56557
|
771
|
|
772 If SYMBOL has a local binding, then this form affects the local
|
|
773 binding. This is usually not what you want. Thus, if you need to
|
|
774 load a file defining variables, with this form or with `defconst' or
|
|
775 `defcustom', you should always load that file _outside_ any bindings
|
|
776 for these variables. \(`defconst' and `defcustom' behave similarly in
|
|
777 this respect.)
|
40703
21597de09a0d
(top_level_value, top_level_set): Remove commented and #ifdef'd-out code.
Pavel Janík <Pavel@Janik.cz>
diff
changeset
|
778 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */)
|
40570
|
779 (args)
|
272
|
780 Lisp_Object args;
|
|
781 {
|
10161
|
782 register Lisp_Object sym, tem, tail;
|
272
|
783
|
|
784 sym = Fcar (args);
|
10161
|
785 tail = Fcdr (args);
|
|
786 if (!NILP (Fcdr (Fcdr (tail))))
|
|
787 error ("too many arguments");
|
|
788
|
37732
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
789 tem = Fdefault_boundp (sym);
|
10161
|
790 if (!NILP (tail))
|
272
|
791 {
|
485
|
792 if (NILP (tem))
|
37732
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
793 Fset_default (sym, Feval (Fcar (tail)));
|
58413
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
794 else
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
795 { /* Check if there is really a global binding rather than just a let
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
796 binding that shadows the global unboundness of the var. */
|
58523
|
797 volatile struct specbinding *pdl = specpdl_ptr;
|
58413
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
798 while (--pdl >= specpdl)
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
799 {
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
800 if (EQ (pdl->symbol, sym) && !pdl->func
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
801 && EQ (pdl->old_value, Qunbound))
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
802 {
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
803 message_with_string ("Warning: defvar ignored because %s is let-bound",
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
804 SYMBOL_NAME (sym), 1);
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
805 break;
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
806 }
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
807 }
|
73c39b73a189
(Fdefvar): Warn when var is let-bound but globally void.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
808 }
|
37732
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
809 tail = Fcdr (tail);
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
810 tem = Fcar (tail);
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
811 if (!NILP (tem))
|
37732
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
812 {
|
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
813 if (!NILP (Vpurify_flag))
|
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
814 tem = Fpurecopy (tem);
|
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
815 Fput (sym, Qvariable_documentation, tem);
|
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
816 }
|
59109
|
817 LOADHIST_ATTACH (sym);
|
272
|
818 }
|
37732
f98176963881
(Fdefvar): Only record (defvar <var>) in the load-history
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
819 else
|
47022
|
820 /* Simple (defvar <var>) should not count as a definition at all.
|
|
821 It could get in the way of other definitions, and unloading this
|
|
822 package could try to make the variable unbound. */
|
47026
|
823 ;
|
|
824
|
272
|
825 return sym;
|
|
826 }
|
|
827
|
|
828 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0,
|
40570
|
829 doc: /* Define SYMBOL as a constant variable.
|
|
830 The intent is that neither programs nor users should ever change this value.
|
|
831 Always sets the value of SYMBOL to the result of evalling INITVALUE.
|
|
832 If SYMBOL is buffer-local, its default value is what is set;
|
|
833 buffer-local values are not affected.
|
|
834 DOCSTRING is optional.
|
56557
|
835
|
|
836 If SYMBOL has a local binding, then this form sets the local binding's
|
|
837 value. However, you should normally not make local bindings for
|
|
838 variables defined with this form.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
839 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */)
|
40570
|
840 (args)
|
272
|
841 Lisp_Object args;
|
|
842 {
|
|
843 register Lisp_Object sym, tem;
|
|
844
|
|
845 sym = Fcar (args);
|
10161
|
846 if (!NILP (Fcdr (Fcdr (Fcdr (args)))))
|
|
847 error ("too many arguments");
|
|
848
|
27554
|
849 tem = Feval (Fcar (Fcdr (args)));
|
|
850 if (!NILP (Vpurify_flag))
|
|
851 tem = Fpurecopy (tem);
|
|
852 Fset_default (sym, tem);
|
272
|
853 tem = Fcar (Fcdr (Fcdr (args)));
|
485
|
854 if (!NILP (tem))
|
272
|
855 {
|
485
|
856 if (!NILP (Vpurify_flag))
|
272
|
857 tem = Fpurecopy (tem);
|
|
858 Fput (sym, Qvariable_documentation, tem);
|
|
859 }
|
59109
|
860 LOADHIST_ATTACH (sym);
|
272
|
861 return sym;
|
|
862 }
|
|
863
|
|
864 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0,
|
40570
|
865 doc: /* Returns t if VARIABLE is intended to be set and modified by users.
|
|
866 \(The alternative is a variable used internally in a Lisp program.)
|
|
867 Determined by whether the first character of the documentation
|
|
868 for the variable is `*' or if the variable is customizable (has a non-nil
|
49105
|
869 value of `standard-value' or of `custom-autoload' on its property list). */)
|
40570
|
870 (variable)
|
272
|
871 Lisp_Object variable;
|
|
872 {
|
|
873 Lisp_Object documentation;
|
49600
|
874
|
17275
|
875 if (!SYMBOLP (variable))
|
|
876 return Qnil;
|
|
877
|
272
|
878 documentation = Fget (variable, Qvariable_documentation);
|
9148
|
879 if (INTEGERP (documentation) && XINT (documentation) < 0)
|
272
|
880 return Qt;
|
11251
|
881 if (STRINGP (documentation)
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
882 && ((unsigned char) SREF (documentation, 0) == '*'))
|
11251
|
883 return Qt;
|
|
884 /* If it is (STRING . INTEGER), a negative integer means a user variable. */
|
|
885 if (CONSP (documentation)
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
886 && STRINGP (XCAR (documentation))
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
887 && INTEGERP (XCDR (documentation))
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
888 && XINT (XCDR (documentation)) < 0)
|
272
|
889 return Qt;
|
49105
|
890 /* Customizable? See `custom-variable-p'. */
|
|
891 if ((!NILP (Fget (variable, intern ("standard-value"))))
|
|
892 || (!NILP (Fget (variable, intern ("custom-autoload")))))
|
27226
|
893 return Qt;
|
272
|
894 return Qnil;
|
49600
|
895 }
|
272
|
896
|
|
897 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0,
|
40570
|
898 doc: /* Bind variables according to VARLIST then eval BODY.
|
|
899 The value of the last form in BODY is returned.
|
|
900 Each element of VARLIST is a symbol (which is bound to nil)
|
|
901 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
902 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
903 usage: (let* VARLIST BODY...) */)
|
40570
|
904 (args)
|
272
|
905 Lisp_Object args;
|
|
906 {
|
|
907 Lisp_Object varlist, val, elt;
|
46293
|
908 int count = SPECPDL_INDEX ();
|
272
|
909 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
910
|
|
911 GCPRO3 (args, elt, varlist);
|
|
912
|
|
913 varlist = Fcar (args);
|
485
|
914 while (!NILP (varlist))
|
272
|
915 {
|
|
916 QUIT;
|
|
917 elt = Fcar (varlist);
|
9148
|
918 if (SYMBOLP (elt))
|
272
|
919 specbind (elt, Qnil);
|
604
|
920 else if (! NILP (Fcdr (Fcdr (elt))))
|
|
921 Fsignal (Qerror,
|
|
922 Fcons (build_string ("`let' bindings can have only one value-form"),
|
|
923 elt));
|
272
|
924 else
|
|
925 {
|
|
926 val = Feval (Fcar (Fcdr (elt)));
|
|
927 specbind (Fcar (elt), val);
|
|
928 }
|
|
929 varlist = Fcdr (varlist);
|
|
930 }
|
|
931 UNGCPRO;
|
|
932 val = Fprogn (Fcdr (args));
|
|
933 return unbind_to (count, val);
|
|
934 }
|
|
935
|
|
936 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0,
|
40570
|
937 doc: /* Bind variables according to VARLIST then eval BODY.
|
|
938 The value of the last form in BODY is returned.
|
|
939 Each element of VARLIST is a symbol (which is bound to nil)
|
|
940 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).
|
|
941 All the VALUEFORMs are evalled before any symbols are bound.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
942 usage: (let VARLIST BODY...) */)
|
40570
|
943 (args)
|
272
|
944 Lisp_Object args;
|
|
945 {
|
|
946 Lisp_Object *temps, tem;
|
|
947 register Lisp_Object elt, varlist;
|
46293
|
948 int count = SPECPDL_INDEX ();
|
272
|
949 register int argnum;
|
|
950 struct gcpro gcpro1, gcpro2;
|
|
951
|
|
952 varlist = Fcar (args);
|
|
953
|
|
954 /* Make space to hold the values to give the bound variables */
|
|
955 elt = Flength (varlist);
|
|
956 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object));
|
|
957
|
|
958 /* Compute the values and store them in `temps' */
|
|
959
|
|
960 GCPRO2 (args, *temps);
|
|
961 gcpro2.nvars = 0;
|
|
962
|
485
|
963 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
|
272
|
964 {
|
|
965 QUIT;
|
|
966 elt = Fcar (varlist);
|
9148
|
967 if (SYMBOLP (elt))
|
272
|
968 temps [argnum++] = Qnil;
|
604
|
969 else if (! NILP (Fcdr (Fcdr (elt))))
|
|
970 Fsignal (Qerror,
|
|
971 Fcons (build_string ("`let' bindings can have only one value-form"),
|
|
972 elt));
|
272
|
973 else
|
|
974 temps [argnum++] = Feval (Fcar (Fcdr (elt)));
|
|
975 gcpro2.nvars = argnum;
|
|
976 }
|
|
977 UNGCPRO;
|
|
978
|
|
979 varlist = Fcar (args);
|
485
|
980 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist))
|
272
|
981 {
|
|
982 elt = Fcar (varlist);
|
|
983 tem = temps[argnum++];
|
9148
|
984 if (SYMBOLP (elt))
|
272
|
985 specbind (elt, tem);
|
|
986 else
|
|
987 specbind (Fcar (elt), tem);
|
|
988 }
|
|
989
|
|
990 elt = Fprogn (Fcdr (args));
|
|
991 return unbind_to (count, elt);
|
|
992 }
|
|
993
|
|
994 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0,
|
40570
|
995 doc: /* If TEST yields non-nil, eval BODY... and repeat.
|
|
996 The order of execution is thus TEST, BODY, TEST, BODY and so on
|
|
997 until TEST returns nil.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
998 usage: (while TEST BODY...) */)
|
40570
|
999 (args)
|
272
|
1000 Lisp_Object args;
|
|
1001 {
|
42277
|
1002 Lisp_Object test, body;
|
272
|
1003 struct gcpro gcpro1, gcpro2;
|
|
1004
|
|
1005 GCPRO2 (test, body);
|
|
1006
|
|
1007 test = Fcar (args);
|
|
1008 body = Fcdr (args);
|
42277
|
1009 while (!NILP (Feval (test)))
|
272
|
1010 {
|
|
1011 QUIT;
|
|
1012 Fprogn (body);
|
|
1013 }
|
|
1014
|
|
1015 UNGCPRO;
|
|
1016 return Qnil;
|
|
1017 }
|
|
1018
|
|
1019 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0,
|
40570
|
1020 doc: /* Return result of expanding macros at top level of FORM.
|
|
1021 If FORM is not a macro call, it is returned unchanged.
|
|
1022 Otherwise, the macro is expanded and the expansion is considered
|
|
1023 in place of FORM. When a non-macro-call results, it is returned.
|
|
1024
|
|
1025 The second optional arg ENVIRONMENT specifies an environment of macro
|
|
1026 definitions to shadow the loaded ones for use in file byte-compilation. */)
|
|
1027 (form, environment)
|
16113
|
1028 Lisp_Object form;
|
14073
|
1029 Lisp_Object environment;
|
272
|
1030 {
|
753
|
1031 /* With cleanups from Hallvard Furuseth. */
|
272
|
1032 register Lisp_Object expander, sym, def, tem;
|
|
1033
|
|
1034 while (1)
|
|
1035 {
|
|
1036 /* Come back here each time we expand a macro call,
|
|
1037 in case it expands into another macro call. */
|
9148
|
1038 if (!CONSP (form))
|
272
|
1039 break;
|
753
|
1040 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1041 def = sym = XCAR (form);
|
753
|
1042 tem = Qnil;
|
272
|
1043 /* Trace symbols aliases to other symbols
|
|
1044 until we get a symbol that is not an alias. */
|
9148
|
1045 while (SYMBOLP (def))
|
272
|
1046 {
|
|
1047 QUIT;
|
753
|
1048 sym = def;
|
14073
|
1049 tem = Fassq (sym, environment);
|
485
|
1050 if (NILP (tem))
|
272
|
1051 {
|
|
1052 def = XSYMBOL (sym)->function;
|
753
|
1053 if (!EQ (def, Qunbound))
|
|
1054 continue;
|
272
|
1055 }
|
753
|
1056 break;
|
272
|
1057 }
|
14073
|
1058 /* Right now TEM is the result from SYM in ENVIRONMENT,
|
272
|
1059 and if TEM is nil then DEF is SYM's function definition. */
|
485
|
1060 if (NILP (tem))
|
272
|
1061 {
|
14073
|
1062 /* SYM is not mentioned in ENVIRONMENT.
|
272
|
1063 Look at its function definition. */
|
9148
|
1064 if (EQ (def, Qunbound) || !CONSP (def))
|
272
|
1065 /* Not defined or definition not suitable */
|
|
1066 break;
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1067 if (EQ (XCAR (def), Qautoload))
|
272
|
1068 {
|
|
1069 /* Autoloading function: will it be a macro when loaded? */
|
1564
|
1070 tem = Fnth (make_number (4), def);
|
5254
|
1071 if (EQ (tem, Qt) || EQ (tem, Qmacro))
|
1564
|
1072 /* Yes, load it and try again. */
|
|
1073 {
|
16108
|
1074 struct gcpro gcpro1;
|
|
1075 GCPRO1 (form);
|
1564
|
1076 do_autoload (def, sym);
|
16108
|
1077 UNGCPRO;
|
1564
|
1078 continue;
|
|
1079 }
|
|
1080 else
|
272
|
1081 break;
|
|
1082 }
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1083 else if (!EQ (XCAR (def), Qmacro))
|
272
|
1084 break;
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1085 else expander = XCDR (def);
|
272
|
1086 }
|
|
1087 else
|
|
1088 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1089 expander = XCDR (tem);
|
485
|
1090 if (NILP (expander))
|
272
|
1091 break;
|
|
1092 }
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1093 form = apply1 (expander, XCDR (form));
|
272
|
1094 }
|
|
1095 return form;
|
|
1096 }
|
|
1097
|
|
1098 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0,
|
40570
|
1099 doc: /* Eval BODY allowing nonlocal exits using `throw'.
|
|
1100 TAG is evalled to get the tag to use; it must not be nil.
|
|
1101
|
|
1102 Then the BODY is executed.
|
|
1103 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
|
|
1104 If no throw happens, `catch' returns the value of the last BODY form.
|
|
1105 If a throw happens, it specifies the value to return from `catch'.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1106 usage: (catch TAG BODY...) */)
|
40570
|
1107 (args)
|
272
|
1108 Lisp_Object args;
|
|
1109 {
|
|
1110 register Lisp_Object tag;
|
|
1111 struct gcpro gcpro1;
|
|
1112
|
|
1113 GCPRO1 (args);
|
|
1114 tag = Feval (Fcar (args));
|
|
1115 UNGCPRO;
|
|
1116 return internal_catch (tag, Fprogn, Fcdr (args));
|
|
1117 }
|
|
1118
|
|
1119 /* Set up a catch, then call C function FUNC on argument ARG.
|
|
1120 FUNC should return a Lisp_Object.
|
|
1121 This is how catches are done from within C code. */
|
|
1122
|
|
1123 Lisp_Object
|
|
1124 internal_catch (tag, func, arg)
|
|
1125 Lisp_Object tag;
|
|
1126 Lisp_Object (*func) ();
|
|
1127 Lisp_Object arg;
|
|
1128 {
|
|
1129 /* This structure is made part of the chain `catchlist'. */
|
|
1130 struct catchtag c;
|
|
1131
|
|
1132 /* Fill in the components of c, and put it on the list. */
|
|
1133 c.next = catchlist;
|
|
1134 c.tag = tag;
|
|
1135 c.val = Qnil;
|
|
1136 c.backlist = backtrace_list;
|
|
1137 c.handlerlist = handlerlist;
|
|
1138 c.lisp_eval_depth = lisp_eval_depth;
|
46293
|
1139 c.pdlcount = SPECPDL_INDEX ();
|
272
|
1140 c.poll_suppress_count = poll_suppress_count;
|
48909
|
1141 c.interrupt_input_blocked = interrupt_input_blocked;
|
272
|
1142 c.gcpro = gcprolist;
|
26365
|
1143 c.byte_stack = byte_stack_list;
|
272
|
1144 catchlist = &c;
|
|
1145
|
|
1146 /* Call FUNC. */
|
|
1147 if (! _setjmp (c.jmp))
|
|
1148 c.val = (*func) (arg);
|
|
1149
|
|
1150 /* Throw works by a longjmp that comes right here. */
|
|
1151 catchlist = c.next;
|
|
1152 return c.val;
|
|
1153 }
|
|
1154
|
1199
|
1155 /* Unwind the specbind, catch, and handler stacks back to CATCH, and
|
|
1156 jump to that CATCH, returning VALUE as the value of that catch.
|
|
1157
|
|
1158 This is the guts Fthrow and Fsignal; they differ only in the way
|
|
1159 they choose the catch tag to throw to. A catch tag for a
|
|
1160 condition-case form has a TAG of Qnil.
|
272
|
1161
|
1199
|
1162 Before each catch is discarded, unbind all special bindings and
|
|
1163 execute all unwind-protect clauses made above that catch. Unwind
|
|
1164 the handler stack as we go, so that the proper handlers are in
|
|
1165 effect for each unwind-protect clause we run. At the end, restore
|
|
1166 some static info saved in CATCH, and longjmp to the location
|
|
1167 specified in the
|
272
|
1168
|
1199
|
1169 This is used for correct unwinding in Fthrow and Fsignal. */
|
272
|
1170
|
|
1171 static void
|
1199
|
1172 unwind_to_catch (catch, value)
|
272
|
1173 struct catchtag *catch;
|
1199
|
1174 Lisp_Object value;
|
272
|
1175 {
|
|
1176 register int last_time;
|
|
1177
|
1199
|
1178 /* Save the value in the tag. */
|
|
1179 catch->val = value;
|
|
1180
|
58734
|
1181 /* Restore certain special C variables. */
|
4474
|
1182 set_poll_suppress_count (catch->poll_suppress_count);
|
60418
|
1183 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked);
|
58734
|
1184 handling_signal = 0;
|
59051
|
1185 immediate_quit = 0;
|
1196
|
1186
|
272
|
1187 do
|
|
1188 {
|
|
1189 last_time = catchlist == catch;
|
1196
|
1190
|
|
1191 /* Unwind the specpdl stack, and then restore the proper set of
|
|
1192 handlers. */
|
272
|
1193 unbind_to (catchlist->pdlcount, Qnil);
|
|
1194 handlerlist = catchlist->handlerlist;
|
|
1195 catchlist = catchlist->next;
|
|
1196 }
|
|
1197 while (! last_time);
|
|
1198
|
26365
|
1199 byte_stack_list = catch->byte_stack;
|
272
|
1200 gcprolist = catch->gcpro;
|
26297
|
1201 #ifdef DEBUG_GCPRO
|
|
1202 if (gcprolist != 0)
|
|
1203 gcpro_level = gcprolist->level + 1;
|
|
1204 else
|
|
1205 gcpro_level = 0;
|
|
1206 #endif
|
272
|
1207 backtrace_list = catch->backlist;
|
|
1208 lisp_eval_depth = catch->lisp_eval_depth;
|
49600
|
1209
|
1199
|
1210 _longjmp (catch->jmp, 1);
|
272
|
1211 }
|
|
1212
|
|
1213 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0,
|
40570
|
1214 doc: /* Throw to the catch for TAG and return VALUE from it.
|
|
1215 Both TAG and VALUE are evalled. */)
|
|
1216 (tag, value)
|
14073
|
1217 register Lisp_Object tag, value;
|
272
|
1218 {
|
|
1219 register struct catchtag *c;
|
|
1220
|
|
1221 while (1)
|
|
1222 {
|
485
|
1223 if (!NILP (tag))
|
272
|
1224 for (c = catchlist; c; c = c->next)
|
|
1225 {
|
|
1226 if (EQ (c->tag, tag))
|
14073
|
1227 unwind_to_catch (c, value);
|
272
|
1228 }
|
14073
|
1229 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (value, Qnil)));
|
272
|
1230 }
|
|
1231 }
|
|
1232
|
|
1233
|
|
1234 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0,
|
40570
|
1235 doc: /* Do BODYFORM, protecting with UNWINDFORMS.
|
|
1236 If BODYFORM completes normally, its value is returned
|
|
1237 after executing the UNWINDFORMS.
|
|
1238 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
|
41846
680de0f18330
Undo last change. Consistency doesn't seem to be desired.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1239 usage: (unwind-protect BODYFORM UNWINDFORMS...) */)
|
40570
|
1240 (args)
|
272
|
1241 Lisp_Object args;
|
|
1242 {
|
|
1243 Lisp_Object val;
|
46293
|
1244 int count = SPECPDL_INDEX ();
|
272
|
1245
|
50774
cddacf81f5e7
(Funwind_protect): Use func = Fprogn rather symbol = Qnil.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1246 record_unwind_protect (Fprogn, Fcdr (args));
|
272
|
1247 val = Feval (Fcar (args));
|
49600
|
1248 return unbind_to (count, val);
|
272
|
1249 }
|
|
1250
|
|
1251 /* Chain of condition handlers currently in effect.
|
|
1252 The elements of this chain are contained in the stack frames
|
|
1253 of Fcondition_case and internal_condition_case.
|
|
1254 When an error is signaled (by calling Fsignal, below),
|
|
1255 this chain is searched for an element that applies. */
|
|
1256
|
|
1257 struct handler *handlerlist;
|
|
1258
|
|
1259 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0,
|
40570
|
1260 doc: /* Regain control when an error is signaled.
|
40661
|
1261 Executes BODYFORM and returns its value if no error happens.
|
40570
|
1262 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
|
|
1263 where the BODY is made of Lisp expressions.
|
|
1264
|
|
1265 A handler is applicable to an error
|
|
1266 if CONDITION-NAME is one of the error's condition names.
|
|
1267 If an error happens, the first applicable handler is run.
|
|
1268
|
|
1269 The car of a handler may be a list of condition names
|
|
1270 instead of a single condition name.
|
|
1271
|
|
1272 When a handler handles an error,
|
|
1273 control returns to the condition-case and the handler BODY... is executed
|
|
1274 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).
|
|
1275 VAR may be nil; then you do not get access to the signal information.
|
|
1276
|
|
1277 The value of the last BODY form is returned from the condition-case.
|
|
1278 See also the function `signal' for more info.
|
55879
|
1279 usage: (condition-case VAR BODYFORM &rest HANDLERS) */)
|
40570
|
1280 (args)
|
272
|
1281 Lisp_Object args;
|
|
1282 {
|
|
1283 Lisp_Object val;
|
|
1284 struct catchtag c;
|
|
1285 struct handler h;
|
32657
|
1286 register Lisp_Object bodyform, handlers;
|
|
1287 volatile Lisp_Object var;
|
1196
|
1288
|
|
1289 var = Fcar (args);
|
|
1290 bodyform = Fcar (Fcdr (args));
|
|
1291 handlers = Fcdr (Fcdr (args));
|
40656
|
1292 CHECK_SYMBOL (var);
|
272
|
1293
|
55879
|
1294 for (val = handlers; CONSP (val); val = XCDR (val))
|
1196
|
1295 {
|
|
1296 Lisp_Object tem;
|
55879
|
1297 tem = XCAR (val);
|
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1298 if (! (NILP (tem)
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1299 || (CONSP (tem)
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1300 && (SYMBOLP (XCAR (tem))
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1301 || CONSP (XCAR (tem))))))
|
1196
|
1302 error ("Invalid condition handler", tem);
|
|
1303 }
|
272
|
1304
|
|
1305 c.tag = Qnil;
|
|
1306 c.val = Qnil;
|
|
1307 c.backlist = backtrace_list;
|
|
1308 c.handlerlist = handlerlist;
|
|
1309 c.lisp_eval_depth = lisp_eval_depth;
|
46293
|
1310 c.pdlcount = SPECPDL_INDEX ();
|
272
|
1311 c.poll_suppress_count = poll_suppress_count;
|
48909
|
1312 c.interrupt_input_blocked = interrupt_input_blocked;
|
272
|
1313 c.gcpro = gcprolist;
|
26365
|
1314 c.byte_stack = byte_stack_list;
|
272
|
1315 if (_setjmp (c.jmp))
|
|
1316 {
|
485
|
1317 if (!NILP (h.var))
|
6132
|
1318 specbind (h.var, c.val);
|
|
1319 val = Fprogn (Fcdr (h.chosen_clause));
|
1196
|
1320
|
|
1321 /* Note that this just undoes the binding of h.var; whoever
|
|
1322 longjumped to us unwound the stack to c.pdlcount before
|
|
1323 throwing. */
|
272
|
1324 unbind_to (c.pdlcount, Qnil);
|
|
1325 return val;
|
|
1326 }
|
|
1327 c.next = catchlist;
|
|
1328 catchlist = &c;
|
49600
|
1329
|
1196
|
1330 h.var = var;
|
|
1331 h.handler = handlers;
|
272
|
1332 h.next = handlerlist;
|
|
1333 h.tag = &c;
|
|
1334 handlerlist = &h;
|
|
1335
|
1196
|
1336 val = Feval (bodyform);
|
272
|
1337 catchlist = c.next;
|
|
1338 handlerlist = h.next;
|
|
1339 return val;
|
|
1340 }
|
|
1341
|
14218
|
1342 /* Call the function BFUN with no arguments, catching errors within it
|
|
1343 according to HANDLERS. If there is an error, call HFUN with
|
|
1344 one argument which is the data that describes the error:
|
|
1345 (SIGNALNAME . DATA)
|
|
1346
|
|
1347 HANDLERS can be a list of conditions to catch.
|
|
1348 If HANDLERS is Qt, catch all errors.
|
|
1349 If HANDLERS is Qerror, catch all errors
|
|
1350 but allow the debugger to run if that is enabled. */
|
|
1351
|
272
|
1352 Lisp_Object
|
|
1353 internal_condition_case (bfun, handlers, hfun)
|
|
1354 Lisp_Object (*bfun) ();
|
|
1355 Lisp_Object handlers;
|
|
1356 Lisp_Object (*hfun) ();
|
|
1357 {
|
|
1358 Lisp_Object val;
|
|
1359 struct catchtag c;
|
|
1360 struct handler h;
|
|
1361
|
48909
|
1362 #if 0 /* We now handle interrupt_input_blocked properly.
|
|
1363 What we still do not handle is exiting a signal handler. */
|
11365
|
1364 abort ();
|
30058
|
1365 #endif
|
11365
|
1366
|
272
|
1367 c.tag = Qnil;
|
|
1368 c.val = Qnil;
|
|
1369 c.backlist = backtrace_list;
|
|
1370 c.handlerlist = handlerlist;
|
|
1371 c.lisp_eval_depth = lisp_eval_depth;
|
46293
|
1372 c.pdlcount = SPECPDL_INDEX ();
|
272
|
1373 c.poll_suppress_count = poll_suppress_count;
|
48909
|
1374 c.interrupt_input_blocked = interrupt_input_blocked;
|
272
|
1375 c.gcpro = gcprolist;
|
26365
|
1376 c.byte_stack = byte_stack_list;
|
272
|
1377 if (_setjmp (c.jmp))
|
|
1378 {
|
6132
|
1379 return (*hfun) (c.val);
|
272
|
1380 }
|
|
1381 c.next = catchlist;
|
|
1382 catchlist = &c;
|
|
1383 h.handler = handlers;
|
|
1384 h.var = Qnil;
|
|
1385 h.next = handlerlist;
|
|
1386 h.tag = &c;
|
|
1387 handlerlist = &h;
|
|
1388
|
|
1389 val = (*bfun) ();
|
|
1390 catchlist = c.next;
|
|
1391 handlerlist = h.next;
|
|
1392 return val;
|
|
1393 }
|
|
1394
|
48909
|
1395 /* Like internal_condition_case but call BFUN with ARG as its argument. */
|
14218
|
1396
|
5807
|
1397 Lisp_Object
|
|
1398 internal_condition_case_1 (bfun, arg, handlers, hfun)
|
|
1399 Lisp_Object (*bfun) ();
|
|
1400 Lisp_Object arg;
|
|
1401 Lisp_Object handlers;
|
|
1402 Lisp_Object (*hfun) ();
|
|
1403 {
|
|
1404 Lisp_Object val;
|
|
1405 struct catchtag c;
|
|
1406 struct handler h;
|
|
1407
|
|
1408 c.tag = Qnil;
|
|
1409 c.val = Qnil;
|
|
1410 c.backlist = backtrace_list;
|
|
1411 c.handlerlist = handlerlist;
|
|
1412 c.lisp_eval_depth = lisp_eval_depth;
|
46293
|
1413 c.pdlcount = SPECPDL_INDEX ();
|
5807
|
1414 c.poll_suppress_count = poll_suppress_count;
|
48909
|
1415 c.interrupt_input_blocked = interrupt_input_blocked;
|
5807
|
1416 c.gcpro = gcprolist;
|
26365
|
1417 c.byte_stack = byte_stack_list;
|
5807
|
1418 if (_setjmp (c.jmp))
|
|
1419 {
|
6132
|
1420 return (*hfun) (c.val);
|
5807
|
1421 }
|
|
1422 c.next = catchlist;
|
|
1423 catchlist = &c;
|
|
1424 h.handler = handlers;
|
|
1425 h.var = Qnil;
|
|
1426 h.next = handlerlist;
|
|
1427 h.tag = &c;
|
|
1428 handlerlist = &h;
|
|
1429
|
|
1430 val = (*bfun) (arg);
|
|
1431 catchlist = c.next;
|
|
1432 handlerlist = h.next;
|
|
1433 return val;
|
|
1434 }
|
30217
|
1435
|
|
1436
|
48909
|
1437 /* Like internal_condition_case but call BFUN with NARGS as first,
|
30217
|
1438 and ARGS as second argument. */
|
|
1439
|
|
1440 Lisp_Object
|
|
1441 internal_condition_case_2 (bfun, nargs, args, handlers, hfun)
|
|
1442 Lisp_Object (*bfun) ();
|
|
1443 int nargs;
|
|
1444 Lisp_Object *args;
|
|
1445 Lisp_Object handlers;
|
|
1446 Lisp_Object (*hfun) ();
|
|
1447 {
|
|
1448 Lisp_Object val;
|
|
1449 struct catchtag c;
|
|
1450 struct handler h;
|
|
1451
|
|
1452 c.tag = Qnil;
|
|
1453 c.val = Qnil;
|
|
1454 c.backlist = backtrace_list;
|
|
1455 c.handlerlist = handlerlist;
|
|
1456 c.lisp_eval_depth = lisp_eval_depth;
|
46293
|
1457 c.pdlcount = SPECPDL_INDEX ();
|
30217
|
1458 c.poll_suppress_count = poll_suppress_count;
|
48909
|
1459 c.interrupt_input_blocked = interrupt_input_blocked;
|
30217
|
1460 c.gcpro = gcprolist;
|
|
1461 c.byte_stack = byte_stack_list;
|
|
1462 if (_setjmp (c.jmp))
|
|
1463 {
|
|
1464 return (*hfun) (c.val);
|
|
1465 }
|
|
1466 c.next = catchlist;
|
|
1467 catchlist = &c;
|
|
1468 h.handler = handlers;
|
|
1469 h.var = Qnil;
|
|
1470 h.next = handlerlist;
|
|
1471 h.tag = &c;
|
|
1472 handlerlist = &h;
|
|
1473
|
|
1474 val = (*bfun) (nargs, args);
|
|
1475 catchlist = c.next;
|
|
1476 handlerlist = h.next;
|
|
1477 return val;
|
|
1478 }
|
|
1479
|
5807
|
1480
|
41114
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1481 static Lisp_Object find_handler_clause P_ ((Lisp_Object, Lisp_Object,
|
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1482 Lisp_Object, Lisp_Object,
|
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1483 Lisp_Object *));
|
272
|
1484
|
|
1485 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0,
|
40570
|
1486 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA.
|
|
1487 This function does not return.
|
|
1488
|
|
1489 An error symbol is a symbol with an `error-conditions' property
|
|
1490 that is a list of condition names.
|
|
1491 A handler for any of those names will get to handle this signal.
|
|
1492 The symbol `error' should normally be one of them.
|
|
1493
|
|
1494 DATA should be a list. Its elements are printed as part of the error message.
|
53461
abbbd322a247
(Fsignal): Add hyperlink to the definition of `signal' in the Elisp manual.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
1495 See Info anchor `(elisp)Definition of signal' for some details on how this
|
abbbd322a247
(Fsignal): Add hyperlink to the definition of `signal' in the Elisp manual.
Luc Teirlinck <teirllm@auburn.edu>
diff
changeset
|
1496 error message is constructed.
|
40570
|
1497 If the signal is handled, DATA is made available to the handler.
|
|
1498 See also the function `condition-case'. */)
|
|
1499 (error_symbol, data)
|
5566
|
1500 Lisp_Object error_symbol, data;
|
272
|
1501 {
|
24171
|
1502 /* When memory is full, ERROR-SYMBOL is nil,
|
46315
|
1503 and DATA is (REAL-ERROR-SYMBOL . REAL-DATA).
|
|
1504 That is a special case--don't do this in other situations. */
|
272
|
1505 register struct handler *allhandlers = handlerlist;
|
|
1506 Lisp_Object conditions;
|
|
1507 extern int gc_in_progress;
|
|
1508 extern int waiting_for_input;
|
|
1509 Lisp_Object debugger_value;
|
16895
|
1510 Lisp_Object string;
|
18636
|
1511 Lisp_Object real_error_symbol;
|
30073
|
1512 struct backtrace *bp;
|
25008
|
1513
|
33988
|
1514 immediate_quit = handling_signal = 0;
|
50747
|
1515 abort_on_gc = 0;
|
272
|
1516 if (gc_in_progress || waiting_for_input)
|
|
1517 abort ();
|
|
1518
|
18636
|
1519 if (NILP (error_symbol))
|
|
1520 real_error_symbol = Fcar (data);
|
|
1521 else
|
|
1522 real_error_symbol = error_symbol;
|
|
1523
|
46315
|
1524 #if 0 /* rms: I don't know why this was here,
|
|
1525 but it is surely wrong for an error that is handled. */
|
25008
|
1526 #ifdef HAVE_X_WINDOWS
|
36256
e033d60bd048
Use display_hourglass_p, start_hourglass, cancel_hourglass instead of
Gerd Moellmann <gerd@gnu.org>
diff
changeset
|
1527 if (display_hourglass_p)
|
e033d60bd048
Use display_hourglass_p, start_hourglass, cancel_hourglass instead of
Gerd Moellmann <gerd@gnu.org>
diff
changeset
|
1528 cancel_hourglass ();
|
25008
|
1529 #endif
|
49600
|
1530 #endif
|
25008
|
1531
|
16355
|
1532 /* This hook is used by edebug. */
|
46315
|
1533 if (! NILP (Vsignal_hook_function)
|
|
1534 && ! NILP (error_symbol))
|
18018
|
1535 call2 (Vsignal_hook_function, error_symbol, data);
|
16355
|
1536
|
18636
|
1537 conditions = Fget (real_error_symbol, Qerror_conditions);
|
272
|
1538
|
30073
|
1539 /* Remember from where signal was called. Skip over the frame for
|
|
1540 `signal' itself. If a frame for `error' follows, skip that,
|
46315
|
1541 too. Don't do this when ERROR_SYMBOL is nil, because that
|
|
1542 is a memory-full error. */
|
30106
|
1543 Vsignaling_function = Qnil;
|
46315
|
1544 if (backtrace_list && !NILP (error_symbol))
|
30106
|
1545 {
|
|
1546 bp = backtrace_list->next;
|
|
1547 if (bp && bp->function && EQ (*bp->function, Qerror))
|
|
1548 bp = bp->next;
|
|
1549 if (bp && bp->function)
|
|
1550 Vsignaling_function = *bp->function;
|
|
1551 }
|
30073
|
1552
|
272
|
1553 for (; handlerlist; handlerlist = handlerlist->next)
|
|
1554 {
|
|
1555 register Lisp_Object clause;
|
49600
|
1556
|
28779
|
1557 if (lisp_eval_depth + 20 > max_lisp_eval_depth)
|
|
1558 max_lisp_eval_depth = lisp_eval_depth + 20;
|
49600
|
1559
|
28779
|
1560 if (specpdl_size + 40 > max_specpdl_size)
|
|
1561 max_specpdl_size = specpdl_size + 40;
|
49600
|
1562
|
272
|
1563 clause = find_handler_clause (handlerlist->handler, conditions,
|
5566
|
1564 error_symbol, data, &debugger_value);
|
272
|
1565
|
|
1566 if (EQ (clause, Qlambda))
|
1196
|
1567 {
|
13945
|
1568 /* We can't return values to code which signaled an error, but we
|
|
1569 can continue code which has signaled a quit. */
|
18636
|
1570 if (EQ (real_error_symbol, Qquit))
|
1196
|
1571 return Qnil;
|
|
1572 else
|
3973
|
1573 error ("Cannot return from the debugger in an error");
|
1196
|
1574 }
|
272
|
1575
|
485
|
1576 if (!NILP (clause))
|
272
|
1577 {
|
6132
|
1578 Lisp_Object unwind_data;
|
272
|
1579 struct handler *h = handlerlist;
|
6132
|
1580
|
272
|
1581 handlerlist = allhandlers;
|
18636
|
1582
|
|
1583 if (NILP (error_symbol))
|
|
1584 unwind_data = data;
|
6132
|
1585 else
|
|
1586 unwind_data = Fcons (error_symbol, data);
|
|
1587 h->chosen_clause = clause;
|
|
1588 unwind_to_catch (h->tag, unwind_data);
|
272
|
1589 }
|
|
1590 }
|
|
1591
|
|
1592 handlerlist = allhandlers;
|
|
1593 /* If no handler is present now, try to run the debugger,
|
|
1594 and if that fails, throw to top level. */
|
5566
|
1595 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value);
|
16895
|
1596 if (catchlist != 0)
|
|
1597 Fthrow (Qtop_level, Qt);
|
|
1598
|
18636
|
1599 if (! NILP (error_symbol))
|
16895
|
1600 data = Fcons (error_symbol, data);
|
|
1601
|
|
1602 string = Ferror_message_string (data);
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1603 fatal ("%s", SDATA (string), 0);
|
272
|
1604 }
|
|
1605
|
684
|
1606 /* Return nonzero iff LIST is a non-nil atom or
|
|
1607 a list containing one of CONDITIONS. */
|
|
1608
|
|
1609 static int
|
|
1610 wants_debugger (list, conditions)
|
|
1611 Lisp_Object list, conditions;
|
|
1612 {
|
706
|
1613 if (NILP (list))
|
684
|
1614 return 0;
|
|
1615 if (! CONSP (list))
|
|
1616 return 1;
|
|
1617
|
878
|
1618 while (CONSP (conditions))
|
684
|
1619 {
|
878
|
1620 Lisp_Object this, tail;
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1621 this = XCAR (conditions);
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1622 for (tail = list; CONSP (tail); tail = XCDR (tail))
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1623 if (EQ (XCAR (tail), this))
|
684
|
1624 return 1;
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1625 conditions = XCDR (conditions);
|
684
|
1626 }
|
878
|
1627 return 0;
|
684
|
1628 }
|
|
1629
|
13768
|
1630 /* Return 1 if an error with condition-symbols CONDITIONS,
|
|
1631 and described by SIGNAL-DATA, should skip the debugger
|
40661
|
1632 according to debugger-ignored-errors. */
|
13768
|
1633
|
|
1634 static int
|
|
1635 skip_debugger (conditions, data)
|
|
1636 Lisp_Object conditions, data;
|
|
1637 {
|
|
1638 Lisp_Object tail;
|
|
1639 int first_string = 1;
|
|
1640 Lisp_Object error_message;
|
|
1641
|
32657
|
1642 error_message = Qnil;
|
|
1643 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail))
|
13768
|
1644 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1645 if (STRINGP (XCAR (tail)))
|
13768
|
1646 {
|
|
1647 if (first_string)
|
|
1648 {
|
|
1649 error_message = Ferror_message_string (data);
|
|
1650 first_string = 0;
|
|
1651 }
|
49600
|
1652
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1653 if (fast_string_match (XCAR (tail), error_message) >= 0)
|
13768
|
1654 return 1;
|
|
1655 }
|
|
1656 else
|
|
1657 {
|
|
1658 Lisp_Object contail;
|
|
1659
|
32657
|
1660 for (contail = conditions; CONSP (contail); contail = XCDR (contail))
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1661 if (EQ (XCAR (tail), XCAR (contail)))
|
13768
|
1662 return 1;
|
|
1663 }
|
|
1664 }
|
|
1665
|
|
1666 return 0;
|
|
1667 }
|
|
1668
|
684
|
1669 /* Value of Qlambda means we have called debugger and user has continued.
|
18636
|
1670 There are two ways to pass SIG and DATA:
|
24054
|
1671 = SIG is the error symbol, and DATA is the rest of the data.
|
18636
|
1672 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
|
24054
|
1673 This is for memory-full errors only.
|
18636
|
1674
|
684
|
1675 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */
|
272
|
1676
|
|
1677 static Lisp_Object
|
|
1678 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr)
|
|
1679 Lisp_Object handlers, conditions, sig, data;
|
|
1680 Lisp_Object *debugger_value_ptr;
|
|
1681 {
|
|
1682 register Lisp_Object h;
|
|
1683 register Lisp_Object tem;
|
|
1684
|
|
1685 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */
|
|
1686 return Qt;
|
16355
|
1687 /* error is used similarly, but means print an error message
|
|
1688 and run the debugger if that is enabled. */
|
|
1689 if (EQ (handlers, Qerror)
|
16443
|
1690 || !NILP (Vdebug_on_signal)) /* This says call debugger even if
|
|
1691 there is a handler. */
|
272
|
1692 {
|
46293
|
1693 int count = SPECPDL_INDEX ();
|
16355
|
1694 int debugger_called = 0;
|
18636
|
1695 Lisp_Object sig_symbol, combined_data;
|
24054
|
1696 /* This is set to 1 if we are handling a memory-full error,
|
|
1697 because these must not run the debugger.
|
|
1698 (There is no room in memory to do that!) */
|
|
1699 int no_debugger = 0;
|
18636
|
1700
|
|
1701 if (NILP (sig))
|
|
1702 {
|
|
1703 combined_data = data;
|
|
1704 sig_symbol = Fcar (data);
|
24054
|
1705 no_debugger = 1;
|
18636
|
1706 }
|
|
1707 else
|
|
1708 {
|
|
1709 combined_data = Fcons (sig, data);
|
|
1710 sig_symbol = sig;
|
|
1711 }
|
16355
|
1712
|
684
|
1713 if (wants_debugger (Vstack_trace_on_error, conditions))
|
21853
|
1714 {
|
28056
|
1715 #ifdef PROTOTYPES
|
21853
|
1716 internal_with_output_to_temp_buffer ("*Backtrace*",
|
|
1717 (Lisp_Object (*) (Lisp_Object)) Fbacktrace,
|
|
1718 Qnil);
|
|
1719 #else
|
|
1720 internal_with_output_to_temp_buffer ("*Backtrace*",
|
|
1721 Fbacktrace, Qnil);
|
|
1722 #endif
|
|
1723 }
|
24054
|
1724 if (! no_debugger
|
|
1725 && (EQ (sig_symbol, Qquit)
|
|
1726 ? debug_on_quit
|
|
1727 : wants_debugger (Vdebug_on_error, conditions))
|
18636
|
1728 && ! skip_debugger (conditions, combined_data)
|
17872
|
1729 && when_entered_debugger < num_nonmacro_input_events)
|
272
|
1730 {
|
|
1731 specbind (Qdebug_on_error, Qnil);
|
13768
|
1732 *debugger_value_ptr
|
|
1733 = call_debugger (Fcons (Qerror,
|
18636
|
1734 Fcons (combined_data, Qnil)));
|
16355
|
1735 debugger_called = 1;
|
272
|
1736 }
|
16355
|
1737 /* If there is no handler, return saying whether we ran the debugger. */
|
|
1738 if (EQ (handlers, Qerror))
|
|
1739 {
|
|
1740 if (debugger_called)
|
|
1741 return unbind_to (count, Qlambda);
|
|
1742 return Qt;
|
|
1743 }
|
272
|
1744 }
|
|
1745 for (h = handlers; CONSP (h); h = Fcdr (h))
|
|
1746 {
|
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1747 Lisp_Object handler, condit;
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1748
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1749 handler = Fcar (h);
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1750 if (!CONSP (handler))
|
272
|
1751 continue;
|
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1752 condit = Fcar (handler);
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1753 /* Handle a single condition name in handler HANDLER. */
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1754 if (SYMBOLP (condit))
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1755 {
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1756 tem = Fmemq (Fcar (handler), conditions);
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1757 if (!NILP (tem))
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1758 return handler;
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1759 }
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1760 /* Handle a list of condition names in handler HANDLER. */
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1761 else if (CONSP (condit))
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1762 {
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1763 while (CONSP (condit))
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1764 {
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1765 tem = Fmemq (Fcar (condit), conditions);
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1766 if (!NILP (tem))
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1767 return handler;
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1768 condit = XCDR (condit);
|
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1769 }
|
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
1770 }
|
272
|
1771 }
|
|
1772 return Qnil;
|
|
1773 }
|
|
1774
|
|
1775 /* dump an error message; called like printf */
|
|
1776
|
|
1777 /* VARARGS 1 */
|
|
1778 void
|
|
1779 error (m, a1, a2, a3)
|
|
1780 char *m;
|
6225
|
1781 char *a1, *a2, *a3;
|
272
|
1782 {
|
|
1783 char buf[200];
|
6225
|
1784 int size = 200;
|
|
1785 int mlen;
|
|
1786 char *buffer = buf;
|
|
1787 char *args[3];
|
|
1788 int allocated = 0;
|
|
1789 Lisp_Object string;
|
|
1790
|
|
1791 args[0] = a1;
|
|
1792 args[1] = a2;
|
|
1793 args[2] = a3;
|
|
1794
|
|
1795 mlen = strlen (m);
|
272
|
1796
|
|
1797 while (1)
|
6225
|
1798 {
|
23206
|
1799 int used = doprnt (buffer, size, m, m + mlen, 3, args);
|
6225
|
1800 if (used < size)
|
|
1801 break;
|
|
1802 size *= 2;
|
|
1803 if (allocated)
|
|
1804 buffer = (char *) xrealloc (buffer, size);
|
7353
|
1805 else
|
|
1806 {
|
|
1807 buffer = (char *) xmalloc (size);
|
|
1808 allocated = 1;
|
|
1809 }
|
6225
|
1810 }
|
|
1811
|
23206
|
1812 string = build_string (buffer);
|
6225
|
1813 if (allocated)
|
30610
|
1814 xfree (buffer);
|
6225
|
1815
|
|
1816 Fsignal (Qerror, Fcons (string, Qnil));
|
32066
|
1817 abort ();
|
272
|
1818 }
|
|
1819
|
44941
|
1820 DEFUN ("commandp", Fcommandp, Scommandp, 1, 2, 0,
|
40570
|
1821 doc: /* Non-nil if FUNCTION makes provisions for interactive calling.
|
|
1822 This means it contains a description for how to read arguments to give it.
|
|
1823 The value is nil for an invalid function or a symbol with no function
|
|
1824 definition.
|
|
1825
|
|
1826 Interactively callable functions include strings and vectors (treated
|
|
1827 as keyboard macros), lambda-expressions that contain a top-level call
|
|
1828 to `interactive', autoload definitions made by `autoload' with non-nil
|
|
1829 fourth argument, and some of the built-in functions of Lisp.
|
|
1830
|
44941
|
1831 Also, a symbol satisfies `commandp' if its function definition does so.
|
|
1832
|
|
1833 If the optional argument FOR-CALL-INTERACTIVELY is non-nil,
|
45303
|
1834 then strings and vectors are not accepted. */)
|
44941
|
1835 (function, for_call_interactively)
|
|
1836 Lisp_Object function, for_call_interactively;
|
272
|
1837 {
|
|
1838 register Lisp_Object fun;
|
|
1839 register Lisp_Object funcar;
|
|
1840
|
|
1841 fun = function;
|
|
1842
|
648
|
1843 fun = indirect_function (fun);
|
|
1844 if (EQ (fun, Qunbound))
|
|
1845 return Qnil;
|
272
|
1846
|
|
1847 /* Emacs primitives are interactive if their DEFUN specifies an
|
|
1848 interactive spec. */
|
9148
|
1849 if (SUBRP (fun))
|
272
|
1850 {
|
|
1851 if (XSUBR (fun)->prompt)
|
|
1852 return Qt;
|
|
1853 else
|
|
1854 return Qnil;
|
|
1855 }
|
|
1856
|
|
1857 /* Bytecode objects are interactive if they are long enough to
|
|
1858 have an element whose index is COMPILED_INTERACTIVE, which is
|
|
1859 where the interactive spec is stored. */
|
9148
|
1860 else if (COMPILEDP (fun))
|
41597
|
1861 return ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE
|
272
|
1862 ? Qt : Qnil);
|
|
1863
|
|
1864 /* Strings and vectors are keyboard macros. */
|
44941
|
1865 if (NILP (for_call_interactively) && (STRINGP (fun) || VECTORP (fun)))
|
272
|
1866 return Qt;
|
|
1867
|
|
1868 /* Lists may represent commands. */
|
|
1869 if (!CONSP (fun))
|
|
1870 return Qnil;
|
54630
|
1871 funcar = XCAR (fun);
|
272
|
1872 if (EQ (funcar, Qlambda))
|
54630
|
1873 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
|
272
|
1874 if (EQ (funcar, Qautoload))
|
54630
|
1875 return Fcar (Fcdr (Fcdr (XCDR (fun))));
|
272
|
1876 else
|
|
1877 return Qnil;
|
|
1878 }
|
|
1879
|
|
1880 /* ARGSUSED */
|
|
1881 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0,
|
40570
|
1882 doc: /* Define FUNCTION to autoload from FILE.
|
|
1883 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
|
|
1884 Third arg DOCSTRING is documentation for the function.
|
|
1885 Fourth arg INTERACTIVE if non-nil says function can be called interactively.
|
|
1886 Fifth arg TYPE indicates the type of the object:
|
|
1887 nil or omitted says FUNCTION is a function,
|
|
1888 `keymap' says FUNCTION is really a keymap, and
|
|
1889 `macro' or t says FUNCTION is really a macro.
|
|
1890 Third through fifth args give info about the real definition.
|
|
1891 They default to nil.
|
|
1892 If FUNCTION is already defined other than as an autoload,
|
|
1893 this does nothing and returns nil. */)
|
|
1894 (function, file, docstring, interactive, type)
|
1564
|
1895 Lisp_Object function, file, docstring, interactive, type;
|
272
|
1896 {
|
|
1897 #ifdef NO_ARG_ARRAY
|
|
1898 Lisp_Object args[4];
|
|
1899 #endif
|
|
1900
|
40656
|
1901 CHECK_SYMBOL (function);
|
|
1902 CHECK_STRING (file);
|
272
|
1903
|
|
1904 /* If function is defined and not as an autoload, don't override */
|
|
1905 if (!EQ (XSYMBOL (function)->function, Qunbound)
|
9148
|
1906 && !(CONSP (XSYMBOL (function)->function)
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1907 && EQ (XCAR (XSYMBOL (function)->function), Qautoload)))
|
272
|
1908 return Qnil;
|
|
1909
|
28297
f37b25e59751
* eval.c (Fautoload): Add entry in load-history (if after dump).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1910 if (NILP (Vpurify_flag))
|
f37b25e59751
* eval.c (Fautoload): Add entry in load-history (if after dump).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1911 /* Only add entries after dumping, because the ones before are
|
f37b25e59751
* eval.c (Fautoload): Add entry in load-history (if after dump).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1912 not useful and else we get loads of them from the loaddefs.el. */
|
f37b25e59751
* eval.c (Fautoload): Add entry in load-history (if after dump).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1913 LOADHIST_ATTACH (Fcons (Qautoload, function));
|
f37b25e59751
* eval.c (Fautoload): Add entry in load-history (if after dump).
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1914
|
272
|
1915 #ifdef NO_ARG_ARRAY
|
|
1916 args[0] = file;
|
|
1917 args[1] = docstring;
|
|
1918 args[2] = interactive;
|
1564
|
1919 args[3] = type;
|
272
|
1920
|
|
1921 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0])));
|
|
1922 #else /* NO_ARG_ARRAY */
|
|
1923 return Ffset (function, Fcons (Qautoload, Flist (4, &file)));
|
|
1924 #endif /* not NO_ARG_ARRAY */
|
|
1925 }
|
|
1926
|
|
1927 Lisp_Object
|
|
1928 un_autoload (oldqueue)
|
|
1929 Lisp_Object oldqueue;
|
|
1930 {
|
|
1931 register Lisp_Object queue, first, second;
|
|
1932
|
|
1933 /* Queue to unwind is current value of Vautoload_queue.
|
|
1934 oldqueue is the shadowed value to leave in Vautoload_queue. */
|
|
1935 queue = Vautoload_queue;
|
|
1936 Vautoload_queue = oldqueue;
|
|
1937 while (CONSP (queue))
|
|
1938 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1939 first = XCAR (queue);
|
272
|
1940 second = Fcdr (first);
|
|
1941 first = Fcar (first);
|
|
1942 if (EQ (second, Qnil))
|
|
1943 Vfeatures = first;
|
|
1944 else
|
|
1945 Ffset (first, second);
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1946 queue = XCDR (queue);
|
272
|
1947 }
|
|
1948 return Qnil;
|
|
1949 }
|
|
1950
|
16108
|
1951 /* Load an autoloaded function.
|
|
1952 FUNNAME is the symbol which is the function's name.
|
|
1953 FUNDEF is the autoload definition (a list). */
|
|
1954
|
20378
|
1955 void
|
272
|
1956 do_autoload (fundef, funname)
|
|
1957 Lisp_Object fundef, funname;
|
|
1958 {
|
46293
|
1959 int count = SPECPDL_INDEX ();
|
25783
|
1960 Lisp_Object fun, queue, first, second;
|
16108
|
1961 struct gcpro gcpro1, gcpro2, gcpro3;
|
272
|
1962
|
45039
|
1963 /* This is to make sure that loadup.el gives a clear picture
|
|
1964 of what files are preloaded and when. */
|
45036
|
1965 if (! NILP (Vpurify_flag))
|
|
1966 error ("Attempt to autoload %s while preparing to dump",
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
1967 SDATA (SYMBOL_NAME (funname)));
|
45036
|
1968
|
272
|
1969 fun = funname;
|
40656
|
1970 CHECK_SYMBOL (funname);
|
16108
|
1971 GCPRO3 (fun, funname, fundef);
|
272
|
1972
|
24605
|
1973 /* Preserve the match data. */
|
|
1974 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil));
|
49600
|
1975
|
24605
|
1976 /* Value saved here is to be restored into Vautoload_queue. */
|
272
|
1977 record_unwind_protect (un_autoload, Vautoload_queue);
|
|
1978 Vautoload_queue = Qt;
|
19237
|
1979 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt);
|
2547
|
1980
|
24605
|
1981 /* Save the old autoloads, in case we ever do an unload. */
|
2547
|
1982 queue = Vautoload_queue;
|
|
1983 while (CONSP (queue))
|
|
1984 {
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1985 first = XCAR (queue);
|
2547
|
1986 second = Fcdr (first);
|
|
1987 first = Fcar (first);
|
2599
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
diff
changeset
|
1988
|
61901
787052160d87
(do_autoload): Record only autoloads in the autoload property of symbols.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
1989 if (CONSP (second) && EQ (XCAR (second), Qautoload))
|
50630
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1990 Fput (first, Qautoload, (XCDR (second)));
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1991
|
dfbdcffdcfc9
(For, Fand, Fprogn, un_autoload, do_autoload): Use XCDR, XCAR, CONSP.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
1992 queue = XCDR (queue);
|
2547
|
1993 }
|
|
1994
|
272
|
1995 /* Once loading finishes, don't undo it. */
|
|
1996 Vautoload_queue = Qt;
|
|
1997 unbind_to (count, Qnil);
|
|
1998
|
648
|
1999 fun = Findirect_function (fun);
|
|
2000
|
4462
|
2001 if (!NILP (Fequal (fun, fundef)))
|
272
|
2002 error ("Autoloading failed to define function %s",
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2003 SDATA (SYMBOL_NAME (funname)));
|
16108
|
2004 UNGCPRO;
|
272
|
2005 }
|
30080
|
2006
|
272
|
2007
|
|
2008 DEFUN ("eval", Feval, Seval, 1, 1, 0,
|
40570
|
2009 doc: /* Evaluate FORM and return its value. */)
|
|
2010 (form)
|
272
|
2011 Lisp_Object form;
|
|
2012 {
|
|
2013 Lisp_Object fun, val, original_fun, original_args;
|
|
2014 Lisp_Object funcar;
|
|
2015 struct backtrace backtrace;
|
|
2016 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2017
|
57965
|
2018 if (handling_signal)
|
25008
|
2019 abort ();
|
49600
|
2020
|
9148
|
2021 if (SYMBOLP (form))
|
42277
|
2022 return Fsymbol_value (form);
|
272
|
2023 if (!CONSP (form))
|
|
2024 return form;
|
|
2025
|
|
2026 QUIT;
|
|
2027 if (consing_since_gc > gc_cons_threshold)
|
|
2028 {
|
|
2029 GCPRO1 (form);
|
|
2030 Fgarbage_collect ();
|
|
2031 UNGCPRO;
|
|
2032 }
|
|
2033
|
|
2034 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
2035 {
|
|
2036 if (max_lisp_eval_depth < 100)
|
|
2037 max_lisp_eval_depth = 100;
|
|
2038 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
2039 error ("Lisp nesting exceeds max-lisp-eval-depth");
|
|
2040 }
|
|
2041
|
|
2042 original_fun = Fcar (form);
|
|
2043 original_args = Fcdr (form);
|
|
2044
|
|
2045 backtrace.next = backtrace_list;
|
|
2046 backtrace_list = &backtrace;
|
|
2047 backtrace.function = &original_fun; /* This also protects them from gc */
|
|
2048 backtrace.args = &original_args;
|
|
2049 backtrace.nargs = UNEVALLED;
|
|
2050 backtrace.evalargs = 1;
|
|
2051 backtrace.debug_on_exit = 0;
|
|
2052
|
|
2053 if (debug_on_next_call)
|
|
2054 do_debug_on_call (Qt);
|
|
2055
|
|
2056 /* At this point, only original_fun and original_args
|
|
2057 have values that will be used below */
|
|
2058 retry:
|
648
|
2059 fun = Findirect_function (original_fun);
|
272
|
2060
|
9148
|
2061 if (SUBRP (fun))
|
272
|
2062 {
|
|
2063 Lisp_Object numargs;
|
19544
|
2064 Lisp_Object argvals[8];
|
272
|
2065 Lisp_Object args_left;
|
|
2066 register int i, maxargs;
|
|
2067
|
|
2068 args_left = original_args;
|
|
2069 numargs = Flength (args_left);
|
|
2070
|
60418
|
2071 CHECK_CONS_LIST ();
|
|
2072
|
272
|
2073 if (XINT (numargs) < XSUBR (fun)->min_args ||
|
|
2074 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs)))
|
|
2075 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil)));
|
|
2076
|
|
2077 if (XSUBR (fun)->max_args == UNEVALLED)
|
|
2078 {
|
|
2079 backtrace.evalargs = 0;
|
|
2080 val = (*XSUBR (fun)->function) (args_left);
|
|
2081 goto done;
|
|
2082 }
|
|
2083
|
|
2084 if (XSUBR (fun)->max_args == MANY)
|
|
2085 {
|
|
2086 /* Pass a vector of evaluated arguments */
|
|
2087 Lisp_Object *vals;
|
|
2088 register int argnum = 0;
|
|
2089
|
|
2090 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
|
|
2091
|
|
2092 GCPRO3 (args_left, fun, fun);
|
|
2093 gcpro3.var = vals;
|
|
2094 gcpro3.nvars = 0;
|
|
2095
|
485
|
2096 while (!NILP (args_left))
|
272
|
2097 {
|
|
2098 vals[argnum++] = Feval (Fcar (args_left));
|
|
2099 args_left = Fcdr (args_left);
|
|
2100 gcpro3.nvars = argnum;
|
|
2101 }
|
|
2102
|
|
2103 backtrace.args = vals;
|
|
2104 backtrace.nargs = XINT (numargs);
|
|
2105
|
|
2106 val = (*XSUBR (fun)->function) (XINT (numargs), vals);
|
323
|
2107 UNGCPRO;
|
272
|
2108 goto done;
|
|
2109 }
|
|
2110
|
|
2111 GCPRO3 (args_left, fun, fun);
|
|
2112 gcpro3.var = argvals;
|
|
2113 gcpro3.nvars = 0;
|
|
2114
|
|
2115 maxargs = XSUBR (fun)->max_args;
|
|
2116 for (i = 0; i < maxargs; args_left = Fcdr (args_left))
|
|
2117 {
|
|
2118 argvals[i] = Feval (Fcar (args_left));
|
|
2119 gcpro3.nvars = ++i;
|
|
2120 }
|
|
2121
|
|
2122 UNGCPRO;
|
|
2123
|
|
2124 backtrace.args = argvals;
|
|
2125 backtrace.nargs = XINT (numargs);
|
|
2126
|
|
2127 switch (i)
|
|
2128 {
|
|
2129 case 0:
|
|
2130 val = (*XSUBR (fun)->function) ();
|
|
2131 goto done;
|
|
2132 case 1:
|
|
2133 val = (*XSUBR (fun)->function) (argvals[0]);
|
|
2134 goto done;
|
|
2135 case 2:
|
|
2136 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]);
|
|
2137 goto done;
|
|
2138 case 3:
|
|
2139 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
|
|
2140 argvals[2]);
|
|
2141 goto done;
|
|
2142 case 4:
|
|
2143 val = (*XSUBR (fun)->function) (argvals[0], argvals[1],
|
|
2144 argvals[2], argvals[3]);
|
|
2145 goto done;
|
|
2146 case 5:
|
|
2147 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
|
|
2148 argvals[3], argvals[4]);
|
|
2149 goto done;
|
|
2150 case 6:
|
|
2151 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
|
|
2152 argvals[3], argvals[4], argvals[5]);
|
|
2153 goto done;
|
863
|
2154 case 7:
|
|
2155 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
|
|
2156 argvals[3], argvals[4], argvals[5],
|
|
2157 argvals[6]);
|
|
2158 goto done;
|
272
|
2159
|
19544
|
2160 case 8:
|
|
2161 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2],
|
|
2162 argvals[3], argvals[4], argvals[5],
|
|
2163 argvals[6], argvals[7]);
|
|
2164 goto done;
|
|
2165
|
272
|
2166 default:
|
604
|
2167 /* Someone has created a subr that takes more arguments than
|
|
2168 is supported by this code. We need to either rewrite the
|
|
2169 subr to use a different argument protocol, or add more
|
|
2170 cases to this switch. */
|
|
2171 abort ();
|
272
|
2172 }
|
|
2173 }
|
9148
|
2174 if (COMPILEDP (fun))
|
272
|
2175 val = apply_lambda (fun, original_args, 1);
|
|
2176 else
|
|
2177 {
|
|
2178 if (!CONSP (fun))
|
|
2179 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2180 funcar = Fcar (fun);
|
9148
|
2181 if (!SYMBOLP (funcar))
|
272
|
2182 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2183 if (EQ (funcar, Qautoload))
|
|
2184 {
|
|
2185 do_autoload (fun, original_fun);
|
|
2186 goto retry;
|
|
2187 }
|
|
2188 if (EQ (funcar, Qmacro))
|
|
2189 val = Feval (apply1 (Fcdr (fun), original_args));
|
|
2190 else if (EQ (funcar, Qlambda))
|
|
2191 val = apply_lambda (fun, original_args, 1);
|
|
2192 else
|
|
2193 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2194 }
|
|
2195 done:
|
60418
|
2196 CHECK_CONS_LIST ();
|
|
2197
|
272
|
2198 lisp_eval_depth--;
|
|
2199 if (backtrace.debug_on_exit)
|
|
2200 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
|
|
2201 backtrace_list = backtrace.next;
|
48742
7b5cd8383f0b
Feval: On Carbon/MacOSX call mac_check_for_quit_char at each stack frame.
Steven Tamm <steventamm@mac.com>
diff
changeset
|
2202
|
272
|
2203 return val;
|
|
2204 }
|
|
2205
|
|
2206 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0,
|
40570
|
2207 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args.
|
|
2208 Then return the value FUNCTION returns.
|
|
2209 Thus, (apply '+ 1 2 '(3 4)) returns 10.
|
|
2210 usage: (apply FUNCTION &rest ARGUMENTS) */)
|
|
2211 (nargs, args)
|
272
|
2212 int nargs;
|
|
2213 Lisp_Object *args;
|
|
2214 {
|
|
2215 register int i, numargs;
|
|
2216 register Lisp_Object spread_arg;
|
|
2217 register Lisp_Object *funcall_args;
|
|
2218 Lisp_Object fun;
|
50644
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2219 struct gcpro gcpro1;
|
272
|
2220
|
|
2221 fun = args [0];
|
|
2222 funcall_args = 0;
|
|
2223 spread_arg = args [nargs - 1];
|
40656
|
2224 CHECK_LIST (spread_arg);
|
49600
|
2225
|
272
|
2226 numargs = XINT (Flength (spread_arg));
|
|
2227
|
|
2228 if (numargs == 0)
|
|
2229 return Ffuncall (nargs - 1, args);
|
|
2230 else if (numargs == 1)
|
|
2231 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2232 args [nargs - 1] = XCAR (spread_arg);
|
272
|
2233 return Ffuncall (nargs, args);
|
|
2234 }
|
|
2235
|
323
|
2236 numargs += nargs - 2;
|
272
|
2237
|
648
|
2238 fun = indirect_function (fun);
|
|
2239 if (EQ (fun, Qunbound))
|
272
|
2240 {
|
648
|
2241 /* Let funcall get the error */
|
|
2242 fun = args[0];
|
|
2243 goto funcall;
|
272
|
2244 }
|
|
2245
|
9148
|
2246 if (SUBRP (fun))
|
272
|
2247 {
|
|
2248 if (numargs < XSUBR (fun)->min_args
|
|
2249 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
|
|
2250 goto funcall; /* Let funcall get the error */
|
|
2251 else if (XSUBR (fun)->max_args > numargs)
|
|
2252 {
|
|
2253 /* Avoid making funcall cons up a yet another new vector of arguments
|
|
2254 by explicitly supplying nil's for optional values */
|
|
2255 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args)
|
|
2256 * sizeof (Lisp_Object));
|
|
2257 for (i = numargs; i < XSUBR (fun)->max_args;)
|
|
2258 funcall_args[++i] = Qnil;
|
50644
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2259 GCPRO1 (*funcall_args);
|
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2260 gcpro1.nvars = 1 + XSUBR (fun)->max_args;
|
272
|
2261 }
|
|
2262 }
|
|
2263 funcall:
|
|
2264 /* We add 1 to numargs because funcall_args includes the
|
|
2265 function itself as well as its arguments. */
|
|
2266 if (!funcall_args)
|
323
|
2267 {
|
|
2268 funcall_args = (Lisp_Object *) alloca ((1 + numargs)
|
|
2269 * sizeof (Lisp_Object));
|
50644
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2270 GCPRO1 (*funcall_args);
|
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2271 gcpro1.nvars = 1 + numargs;
|
323
|
2272 }
|
|
2273
|
272
|
2274 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object));
|
|
2275 /* Spread the last arg we got. Its first element goes in
|
|
2276 the slot that it used to occupy, hence this value of I. */
|
|
2277 i = nargs - 1;
|
485
|
2278 while (!NILP (spread_arg))
|
272
|
2279 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2280 funcall_args [i++] = XCAR (spread_arg);
|
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2281 spread_arg = XCDR (spread_arg);
|
272
|
2282 }
|
323
|
2283
|
50644
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2284 /* By convention, the caller needs to gcpro Ffuncall's args. */
|
0c4bf42e6557
(Fapply): Undo last change and add a comment about why.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2285 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args));
|
272
|
2286 }
|
|
2287
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2288 /* Run hook variables in various ways. */
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2289
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2290 enum run_hooks_condition {to_completion, until_success, until_failure};
|
41114
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2291 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *,
|
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2292 enum run_hooks_condition));
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2293
|
34013
|
2294 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0,
|
40570
|
2295 doc: /* Run each hook in HOOKS. Major mode functions use this.
|
|
2296 Each argument should be a symbol, a hook variable.
|
|
2297 These symbols are processed in the order specified.
|
|
2298 If a hook symbol has a non-nil value, that value may be a function
|
|
2299 or a list of functions to be called to run the hook.
|
|
2300 If the value is a function, it is called with no arguments.
|
|
2301 If it is a list, the elements are called, in order, with no arguments.
|
|
2302
|
40629
|
2303 Do not use `make-local-variable' to make a hook variable buffer-local.
|
|
2304 Instead, use `add-hook' and specify t for the LOCAL argument.
|
40570
|
2305 usage: (run-hooks &rest HOOKS) */)
|
|
2306 (nargs, args)
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2307 int nargs;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2308 Lisp_Object *args;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2309 {
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2310 Lisp_Object hook[1];
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2311 register int i;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2312
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2313 for (i = 0; i < nargs; i++)
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2314 {
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2315 hook[0] = args[i];
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2316 run_hook_with_args (1, hook, to_completion);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2317 }
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2318
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2319 return Qnil;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2320 }
|
49600
|
2321
|
16485
|
2322 DEFUN ("run-hook-with-args", Frun_hook_with_args,
|
40570
|
2323 Srun_hook_with_args, 1, MANY, 0,
|
|
2324 doc: /* Run HOOK with the specified arguments ARGS.
|
|
2325 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
2326 value, that value may be a function or a list of functions to be
|
|
2327 called to run the hook. If the value is a function, it is called with
|
|
2328 the given arguments and its return value is returned. If it is a list
|
|
2329 of functions, those functions are called, in order,
|
|
2330 with the given arguments ARGS.
|
59953
|
2331 It is best not to depend on the value returned by `run-hook-with-args',
|
40570
|
2332 as that may change.
|
|
2333
|
40629
|
2334 Do not use `make-local-variable' to make a hook variable buffer-local.
|
|
2335 Instead, use `add-hook' and specify t for the LOCAL argument.
|
40570
|
2336 usage: (run-hook-with-args HOOK &rest ARGS) */)
|
|
2337 (nargs, args)
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2338 int nargs;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2339 Lisp_Object *args;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2340 {
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2341 return run_hook_with_args (nargs, args, to_completion);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2342 }
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2343
|
16485
|
2344 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success,
|
40570
|
2345 Srun_hook_with_args_until_success, 1, MANY, 0,
|
|
2346 doc: /* Run HOOK with the specified arguments ARGS.
|
59953
|
2347 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
2348 value, that value may be a function or a list of functions to be
|
|
2349 called to run the hook. If the value is a function, it is called with
|
|
2350 the given arguments and its return value is returned.
|
|
2351 If it is a list of functions, those functions are called, in order,
|
|
2352 with the given arguments ARGS, until one of them
|
40570
|
2353 returns a non-nil value. Then we return that value.
|
59953
|
2354 However, if they all return nil, we return nil.
|
40570
|
2355
|
40629
|
2356 Do not use `make-local-variable' to make a hook variable buffer-local.
|
|
2357 Instead, use `add-hook' and specify t for the LOCAL argument.
|
40570
|
2358 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */)
|
|
2359 (nargs, args)
|
12654
|
2360 int nargs;
|
|
2361 Lisp_Object *args;
|
|
2362 {
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2363 return run_hook_with_args (nargs, args, until_success);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2364 }
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2365
|
16485
|
2366 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure,
|
40570
|
2367 Srun_hook_with_args_until_failure, 1, MANY, 0,
|
|
2368 doc: /* Run HOOK with the specified arguments ARGS.
|
59953
|
2369 HOOK should be a symbol, a hook variable. If HOOK has a non-nil
|
|
2370 value, that value may be a function or a list of functions to be
|
|
2371 called to run the hook. If the value is a function, it is called with
|
|
2372 the given arguments and its return value is returned.
|
|
2373 If it is a list of functions, those functions are called, in order,
|
|
2374 with the given arguments ARGS, until one of them returns nil.
|
|
2375 Then we return nil. However, if they all return non-nil, we return non-nil.
|
40570
|
2376
|
40629
|
2377 Do not use `make-local-variable' to make a hook variable buffer-local.
|
|
2378 Instead, use `add-hook' and specify t for the LOCAL argument.
|
40570
|
2379 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */)
|
|
2380 (nargs, args)
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2381 int nargs;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2382 Lisp_Object *args;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2383 {
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2384 return run_hook_with_args (nargs, args, until_failure);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2385 }
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2386
|
12781
|
2387 /* ARGS[0] should be a hook symbol.
|
|
2388 Call each of the functions in the hook value, passing each of them
|
|
2389 as arguments all the rest of ARGS (all NARGS - 1 elements).
|
|
2390 COND specifies a condition to test after each call
|
|
2391 to decide whether to stop.
|
|
2392 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
2393 except that it isn't necessary to gcpro ARGS[0]. */
|
|
2394
|
41114
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2395 static Lisp_Object
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2396 run_hook_with_args (nargs, args, cond)
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2397 int nargs;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2398 Lisp_Object *args;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2399 enum run_hooks_condition cond;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2400 {
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2401 Lisp_Object sym, val, ret;
|
25257
|
2402 Lisp_Object globals;
|
|
2403 struct gcpro gcpro1, gcpro2, gcpro3;
|
12654
|
2404
|
14218
|
2405 /* If we are dying or still initializing,
|
|
2406 don't do anything--it would probably crash if we tried. */
|
|
2407 if (NILP (Vrun_hooks))
|
27226
|
2408 return Qnil;
|
14218
|
2409
|
12654
|
2410 sym = args[0];
|
12663
|
2411 val = find_symbol_value (sym);
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2412 ret = (cond == until_failure ? Qt : Qnil);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2413
|
12654
|
2414 if (EQ (val, Qunbound) || NILP (val))
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2415 return ret;
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2416 else if (!CONSP (val) || EQ (XCAR (val), Qlambda))
|
12654
|
2417 {
|
|
2418 args[0] = val;
|
|
2419 return Ffuncall (nargs, args);
|
|
2420 }
|
|
2421 else
|
|
2422 {
|
25257
|
2423 globals = Qnil;
|
|
2424 GCPRO3 (sym, val, globals);
|
12788
|
2425
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2426 for (;
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2427 CONSP (val) && ((cond == to_completion)
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2428 || (cond == until_success ? NILP (ret)
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2429 : !NILP (ret)));
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2430 val = XCDR (val))
|
12654
|
2431 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2432 if (EQ (XCAR (val), Qt))
|
12654
|
2433 {
|
|
2434 /* t indicates this hook has a local binding;
|
|
2435 it means to run the global binding too. */
|
|
2436
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2437 for (globals = Fdefault_value (sym);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2438 CONSP (globals) && ((cond == to_completion)
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2439 || (cond == until_success ? NILP (ret)
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2440 : !NILP (ret)));
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2441 globals = XCDR (globals))
|
12654
|
2442 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2443 args[0] = XCAR (globals);
|
13444
|
2444 /* In a global value, t should not occur. If it does, we
|
|
2445 must ignore it to avoid an endless loop. */
|
|
2446 if (!EQ (args[0], Qt))
|
|
2447 ret = Ffuncall (nargs, args);
|
12654
|
2448 }
|
|
2449 }
|
|
2450 else
|
|
2451 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2452 args[0] = XCAR (val);
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2453 ret = Ffuncall (nargs, args);
|
12654
|
2454 }
|
|
2455 }
|
12788
|
2456
|
|
2457 UNGCPRO;
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2458 return ret;
|
12654
|
2459 }
|
|
2460 }
|
12781
|
2461
|
|
2462 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual
|
|
2463 present value of that symbol.
|
|
2464 Call each element of FUNLIST,
|
|
2465 passing each of them the rest of ARGS.
|
|
2466 The caller (or its caller, etc) must gcpro all of ARGS,
|
|
2467 except that it isn't necessary to gcpro ARGS[0]. */
|
|
2468
|
|
2469 Lisp_Object
|
|
2470 run_hook_list_with_args (funlist, nargs, args)
|
|
2471 Lisp_Object funlist;
|
|
2472 int nargs;
|
|
2473 Lisp_Object *args;
|
|
2474 {
|
|
2475 Lisp_Object sym;
|
|
2476 Lisp_Object val;
|
25257
|
2477 Lisp_Object globals;
|
|
2478 struct gcpro gcpro1, gcpro2, gcpro3;
|
12781
|
2479
|
|
2480 sym = args[0];
|
25257
|
2481 globals = Qnil;
|
|
2482 GCPRO3 (sym, val, globals);
|
12781
|
2483
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2484 for (val = funlist; CONSP (val); val = XCDR (val))
|
12781
|
2485 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2486 if (EQ (XCAR (val), Qt))
|
12781
|
2487 {
|
|
2488 /* t indicates this hook has a local binding;
|
|
2489 it means to run the global binding too. */
|
|
2490
|
|
2491 for (globals = Fdefault_value (sym);
|
|
2492 CONSP (globals);
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2493 globals = XCDR (globals))
|
12781
|
2494 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2495 args[0] = XCAR (globals);
|
13444
|
2496 /* In a global value, t should not occur. If it does, we
|
|
2497 must ignore it to avoid an endless loop. */
|
|
2498 if (!EQ (args[0], Qt))
|
|
2499 Ffuncall (nargs, args);
|
12781
|
2500 }
|
|
2501 }
|
|
2502 else
|
|
2503 {
|
25662
0a7261c1d487
Use XCAR, XCDR, and XFLOAT_DATA instead of explicit member access.
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2504 args[0] = XCAR (val);
|
12781
|
2505 Ffuncall (nargs, args);
|
|
2506 }
|
|
2507 }
|
|
2508 UNGCPRO;
|
|
2509 return Qnil;
|
|
2510 }
|
13103
|
2511
|
|
2512 /* Run the hook HOOK, giving each function the two args ARG1 and ARG2. */
|
|
2513
|
|
2514 void
|
|
2515 run_hook_with_args_2 (hook, arg1, arg2)
|
|
2516 Lisp_Object hook, arg1, arg2;
|
|
2517 {
|
|
2518 Lisp_Object temp[3];
|
|
2519 temp[0] = hook;
|
|
2520 temp[1] = arg1;
|
|
2521 temp[2] = arg2;
|
|
2522
|
|
2523 Frun_hook_with_args (3, temp);
|
|
2524 }
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
2525
|
272
|
2526 /* Apply fn to arg */
|
|
2527 Lisp_Object
|
|
2528 apply1 (fn, arg)
|
|
2529 Lisp_Object fn, arg;
|
|
2530 {
|
323
|
2531 struct gcpro gcpro1;
|
|
2532
|
|
2533 GCPRO1 (fn);
|
485
|
2534 if (NILP (arg))
|
323
|
2535 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
|
2536 gcpro1.nvars = 2;
|
272
|
2537 #ifdef NO_ARG_ARRAY
|
|
2538 {
|
|
2539 Lisp_Object args[2];
|
|
2540 args[0] = fn;
|
|
2541 args[1] = arg;
|
323
|
2542 gcpro1.var = args;
|
|
2543 RETURN_UNGCPRO (Fapply (2, args));
|
272
|
2544 }
|
|
2545 #else /* not NO_ARG_ARRAY */
|
323
|
2546 RETURN_UNGCPRO (Fapply (2, &fn));
|
272
|
2547 #endif /* not NO_ARG_ARRAY */
|
|
2548 }
|
|
2549
|
|
2550 /* Call function fn on no arguments */
|
|
2551 Lisp_Object
|
|
2552 call0 (fn)
|
|
2553 Lisp_Object fn;
|
|
2554 {
|
323
|
2555 struct gcpro gcpro1;
|
|
2556
|
|
2557 GCPRO1 (fn);
|
|
2558 RETURN_UNGCPRO (Ffuncall (1, &fn));
|
272
|
2559 }
|
|
2560
|
3703
|
2561 /* Call function fn with 1 argument arg1 */
|
272
|
2562 /* ARGSUSED */
|
|
2563 Lisp_Object
|
3703
|
2564 call1 (fn, arg1)
|
|
2565 Lisp_Object fn, arg1;
|
272
|
2566 {
|
323
|
2567 struct gcpro gcpro1;
|
272
|
2568 #ifdef NO_ARG_ARRAY
|
49600
|
2569 Lisp_Object args[2];
|
323
|
2570
|
272
|
2571 args[0] = fn;
|
3703
|
2572 args[1] = arg1;
|
323
|
2573 GCPRO1 (args[0]);
|
|
2574 gcpro1.nvars = 2;
|
|
2575 RETURN_UNGCPRO (Ffuncall (2, args));
|
272
|
2576 #else /* not NO_ARG_ARRAY */
|
323
|
2577 GCPRO1 (fn);
|
|
2578 gcpro1.nvars = 2;
|
|
2579 RETURN_UNGCPRO (Ffuncall (2, &fn));
|
272
|
2580 #endif /* not NO_ARG_ARRAY */
|
|
2581 }
|
|
2582
|
3703
|
2583 /* Call function fn with 2 arguments arg1, arg2 */
|
272
|
2584 /* ARGSUSED */
|
|
2585 Lisp_Object
|
3703
|
2586 call2 (fn, arg1, arg2)
|
|
2587 Lisp_Object fn, arg1, arg2;
|
272
|
2588 {
|
323
|
2589 struct gcpro gcpro1;
|
272
|
2590 #ifdef NO_ARG_ARRAY
|
|
2591 Lisp_Object args[3];
|
|
2592 args[0] = fn;
|
3703
|
2593 args[1] = arg1;
|
|
2594 args[2] = arg2;
|
323
|
2595 GCPRO1 (args[0]);
|
|
2596 gcpro1.nvars = 3;
|
|
2597 RETURN_UNGCPRO (Ffuncall (3, args));
|
272
|
2598 #else /* not NO_ARG_ARRAY */
|
323
|
2599 GCPRO1 (fn);
|
|
2600 gcpro1.nvars = 3;
|
|
2601 RETURN_UNGCPRO (Ffuncall (3, &fn));
|
272
|
2602 #endif /* not NO_ARG_ARRAY */
|
|
2603 }
|
|
2604
|
3703
|
2605 /* Call function fn with 3 arguments arg1, arg2, arg3 */
|
272
|
2606 /* ARGSUSED */
|
|
2607 Lisp_Object
|
3703
|
2608 call3 (fn, arg1, arg2, arg3)
|
|
2609 Lisp_Object fn, arg1, arg2, arg3;
|
272
|
2610 {
|
323
|
2611 struct gcpro gcpro1;
|
272
|
2612 #ifdef NO_ARG_ARRAY
|
|
2613 Lisp_Object args[4];
|
|
2614 args[0] = fn;
|
3703
|
2615 args[1] = arg1;
|
|
2616 args[2] = arg2;
|
|
2617 args[3] = arg3;
|
323
|
2618 GCPRO1 (args[0]);
|
|
2619 gcpro1.nvars = 4;
|
|
2620 RETURN_UNGCPRO (Ffuncall (4, args));
|
272
|
2621 #else /* not NO_ARG_ARRAY */
|
323
|
2622 GCPRO1 (fn);
|
|
2623 gcpro1.nvars = 4;
|
|
2624 RETURN_UNGCPRO (Ffuncall (4, &fn));
|
272
|
2625 #endif /* not NO_ARG_ARRAY */
|
|
2626 }
|
|
2627
|
3703
|
2628 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */
|
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2629 /* ARGSUSED */
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2630 Lisp_Object
|
3703
|
2631 call4 (fn, arg1, arg2, arg3, arg4)
|
|
2632 Lisp_Object fn, arg1, arg2, arg3, arg4;
|
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2633 {
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2634 struct gcpro gcpro1;
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2635 #ifdef NO_ARG_ARRAY
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2636 Lisp_Object args[5];
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2637 args[0] = fn;
|
3703
|
2638 args[1] = arg1;
|
|
2639 args[2] = arg2;
|
|
2640 args[3] = arg3;
|
|
2641 args[4] = arg4;
|
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2642 GCPRO1 (args[0]);
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2643 gcpro1.nvars = 5;
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2644 RETURN_UNGCPRO (Ffuncall (5, args));
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2645 #else /* not NO_ARG_ARRAY */
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2646 GCPRO1 (fn);
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2647 gcpro1.nvars = 5;
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2648 RETURN_UNGCPRO (Ffuncall (5, &fn));
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2649 #endif /* not NO_ARG_ARRAY */
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2650 }
|
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
diff
changeset
|
2651
|
3703
|
2652 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */
|
|
2653 /* ARGSUSED */
|
|
2654 Lisp_Object
|
|
2655 call5 (fn, arg1, arg2, arg3, arg4, arg5)
|
|
2656 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5;
|
|
2657 {
|
|
2658 struct gcpro gcpro1;
|
|
2659 #ifdef NO_ARG_ARRAY
|
|
2660 Lisp_Object args[6];
|
|
2661 args[0] = fn;
|
|
2662 args[1] = arg1;
|
|
2663 args[2] = arg2;
|
|
2664 args[3] = arg3;
|
|
2665 args[4] = arg4;
|
|
2666 args[5] = arg5;
|
|
2667 GCPRO1 (args[0]);
|
|
2668 gcpro1.nvars = 6;
|
|
2669 RETURN_UNGCPRO (Ffuncall (6, args));
|
|
2670 #else /* not NO_ARG_ARRAY */
|
|
2671 GCPRO1 (fn);
|
|
2672 gcpro1.nvars = 6;
|
|
2673 RETURN_UNGCPRO (Ffuncall (6, &fn));
|
|
2674 #endif /* not NO_ARG_ARRAY */
|
|
2675 }
|
|
2676
|
|
2677 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */
|
|
2678 /* ARGSUSED */
|
|
2679 Lisp_Object
|
|
2680 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6)
|
|
2681 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6;
|
|
2682 {
|
|
2683 struct gcpro gcpro1;
|
|
2684 #ifdef NO_ARG_ARRAY
|
|
2685 Lisp_Object args[7];
|
|
2686 args[0] = fn;
|
|
2687 args[1] = arg1;
|
|
2688 args[2] = arg2;
|
|
2689 args[3] = arg3;
|
|
2690 args[4] = arg4;
|
|
2691 args[5] = arg5;
|
|
2692 args[6] = arg6;
|
|
2693 GCPRO1 (args[0]);
|
|
2694 gcpro1.nvars = 7;
|
|
2695 RETURN_UNGCPRO (Ffuncall (7, args));
|
|
2696 #else /* not NO_ARG_ARRAY */
|
|
2697 GCPRO1 (fn);
|
|
2698 gcpro1.nvars = 7;
|
|
2699 RETURN_UNGCPRO (Ffuncall (7, &fn));
|
|
2700 #endif /* not NO_ARG_ARRAY */
|
|
2701 }
|
|
2702
|
53362
|
2703 /* The caller should GCPRO all the elements of ARGS. */
|
|
2704
|
272
|
2705 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
|
40570
|
2706 doc: /* Call first argument as a function, passing remaining arguments to it.
|
|
2707 Return the value that function returns.
|
|
2708 Thus, (funcall 'cons 'x 'y) returns (x . y).
|
|
2709 usage: (funcall FUNCTION &rest ARGUMENTS) */)
|
|
2710 (nargs, args)
|
272
|
2711 int nargs;
|
|
2712 Lisp_Object *args;
|
|
2713 {
|
|
2714 Lisp_Object fun;
|
|
2715 Lisp_Object funcar;
|
|
2716 int numargs = nargs - 1;
|
|
2717 Lisp_Object lisp_numargs;
|
|
2718 Lisp_Object val;
|
|
2719 struct backtrace backtrace;
|
|
2720 register Lisp_Object *internal_args;
|
|
2721 register int i;
|
|
2722
|
|
2723 QUIT;
|
|
2724 if (consing_since_gc > gc_cons_threshold)
|
323
|
2725 Fgarbage_collect ();
|
272
|
2726
|
|
2727 if (++lisp_eval_depth > max_lisp_eval_depth)
|
|
2728 {
|
|
2729 if (max_lisp_eval_depth < 100)
|
|
2730 max_lisp_eval_depth = 100;
|
|
2731 if (lisp_eval_depth > max_lisp_eval_depth)
|
|
2732 error ("Lisp nesting exceeds max-lisp-eval-depth");
|
|
2733 }
|
|
2734
|
|
2735 backtrace.next = backtrace_list;
|
|
2736 backtrace_list = &backtrace;
|
|
2737 backtrace.function = &args[0];
|
|
2738 backtrace.args = &args[1];
|
|
2739 backtrace.nargs = nargs - 1;
|
|
2740 backtrace.evalargs = 0;
|
|
2741 backtrace.debug_on_exit = 0;
|
|
2742
|
|
2743 if (debug_on_next_call)
|
|
2744 do_debug_on_call (Qlambda);
|
|
2745
|
61250
|
2746 CHECK_CONS_LIST ();
|
|
2747
|
272
|
2748 retry:
|
|
2749
|
|
2750 fun = args[0];
|
648
|
2751
|
|
2752 fun = Findirect_function (fun);
|
272
|
2753
|
9148
|
2754 if (SUBRP (fun))
|
272
|
2755 {
|
61250
|
2756 if (numargs < XSUBR (fun)->min_args
|
272
|
2757 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs))
|
|
2758 {
|
9306
ac852c183fa1
(Feval, Ffuncall, funcall_lambda, Fbacktrace): Don't use XFASTINT as an
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
2759 XSETFASTINT (lisp_numargs, numargs);
|
272
|
2760 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil)));
|
|
2761 }
|
|
2762
|
|
2763 if (XSUBR (fun)->max_args == UNEVALLED)
|
|
2764 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2765
|
|
2766 if (XSUBR (fun)->max_args == MANY)
|
|
2767 {
|
|
2768 val = (*XSUBR (fun)->function) (numargs, args + 1);
|
|
2769 goto done;
|
|
2770 }
|
|
2771
|
|
2772 if (XSUBR (fun)->max_args > numargs)
|
|
2773 {
|
|
2774 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object));
|
|
2775 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object));
|
|
2776 for (i = numargs; i < XSUBR (fun)->max_args; i++)
|
|
2777 internal_args[i] = Qnil;
|
|
2778 }
|
|
2779 else
|
|
2780 internal_args = args + 1;
|
|
2781 switch (XSUBR (fun)->max_args)
|
|
2782 {
|
|
2783 case 0:
|
|
2784 val = (*XSUBR (fun)->function) ();
|
|
2785 goto done;
|
|
2786 case 1:
|
|
2787 val = (*XSUBR (fun)->function) (internal_args[0]);
|
|
2788 goto done;
|
|
2789 case 2:
|
|
2790 val = (*XSUBR (fun)->function) (internal_args[0],
|
|
2791 internal_args[1]);
|
|
2792 goto done;
|
|
2793 case 3:
|
|
2794 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
|
|
2795 internal_args[2]);
|
|
2796 goto done;
|
|
2797 case 4:
|
|
2798 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
|
|
2799 internal_args[2],
|
|
2800 internal_args[3]);
|
|
2801 goto done;
|
|
2802 case 5:
|
|
2803 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
|
|
2804 internal_args[2], internal_args[3],
|
|
2805 internal_args[4]);
|
|
2806 goto done;
|
|
2807 case 6:
|
|
2808 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
|
|
2809 internal_args[2], internal_args[3],
|
|
2810 internal_args[4], internal_args[5]);
|
|
2811 goto done;
|
863
|
2812 case 7:
|
|
2813 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
|
|
2814 internal_args[2], internal_args[3],
|
|
2815 internal_args[4], internal_args[5],
|
|
2816 internal_args[6]);
|
|
2817 goto done;
|
272
|
2818
|
19544
|
2819 case 8:
|
|
2820 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1],
|
|
2821 internal_args[2], internal_args[3],
|
|
2822 internal_args[4], internal_args[5],
|
|
2823 internal_args[6], internal_args[7]);
|
|
2824 goto done;
|
|
2825
|
272
|
2826 default:
|
573
|
2827
|
19544
|
2828 /* If a subr takes more than 8 arguments without using MANY
|
49600
|
2829 or UNEVALLED, we need to extend this function to support it.
|
573
|
2830 Until this is done, there is no way to call the function. */
|
|
2831 abort ();
|
272
|
2832 }
|
|
2833 }
|
9148
|
2834 if (COMPILEDP (fun))
|
272
|
2835 val = funcall_lambda (fun, numargs, args + 1);
|
|
2836 else
|
|
2837 {
|
|
2838 if (!CONSP (fun))
|
|
2839 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2840 funcar = Fcar (fun);
|
9148
|
2841 if (!SYMBOLP (funcar))
|
272
|
2842 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2843 if (EQ (funcar, Qlambda))
|
|
2844 val = funcall_lambda (fun, numargs, args + 1);
|
|
2845 else if (EQ (funcar, Qautoload))
|
|
2846 {
|
|
2847 do_autoload (fun, args[0]);
|
61250
|
2848 CHECK_CONS_LIST ();
|
272
|
2849 goto retry;
|
|
2850 }
|
|
2851 else
|
|
2852 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2853 }
|
|
2854 done:
|
60418
|
2855 CHECK_CONS_LIST ();
|
272
|
2856 lisp_eval_depth--;
|
|
2857 if (backtrace.debug_on_exit)
|
|
2858 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil)));
|
|
2859 backtrace_list = backtrace.next;
|
|
2860 return val;
|
|
2861 }
|
|
2862
|
|
2863 Lisp_Object
|
|
2864 apply_lambda (fun, args, eval_flag)
|
|
2865 Lisp_Object fun, args;
|
|
2866 int eval_flag;
|
|
2867 {
|
|
2868 Lisp_Object args_left;
|
|
2869 Lisp_Object numargs;
|
|
2870 register Lisp_Object *arg_vector;
|
|
2871 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
2872 register int i;
|
|
2873 register Lisp_Object tem;
|
|
2874
|
|
2875 numargs = Flength (args);
|
|
2876 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object));
|
|
2877 args_left = args;
|
|
2878
|
|
2879 GCPRO3 (*arg_vector, args_left, fun);
|
|
2880 gcpro1.nvars = 0;
|
|
2881
|
|
2882 for (i = 0; i < XINT (numargs);)
|
|
2883 {
|
|
2884 tem = Fcar (args_left), args_left = Fcdr (args_left);
|
|
2885 if (eval_flag) tem = Feval (tem);
|
|
2886 arg_vector[i++] = tem;
|
|
2887 gcpro1.nvars = i;
|
|
2888 }
|
|
2889
|
|
2890 UNGCPRO;
|
|
2891
|
|
2892 if (eval_flag)
|
|
2893 {
|
|
2894 backtrace_list->args = arg_vector;
|
|
2895 backtrace_list->nargs = i;
|
|
2896 }
|
|
2897 backtrace_list->evalargs = 0;
|
|
2898 tem = funcall_lambda (fun, XINT (numargs), arg_vector);
|
|
2899
|
|
2900 /* Do the debug-on-exit now, while arg_vector still exists. */
|
|
2901 if (backtrace_list->debug_on_exit)
|
|
2902 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil)));
|
|
2903 /* Don't do it again when we return to eval. */
|
|
2904 backtrace_list->debug_on_exit = 0;
|
|
2905 return tem;
|
|
2906 }
|
|
2907
|
|
2908 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
|
|
2909 and return the result of evaluation.
|
|
2910 FUN must be either a lambda-expression or a compiled-code object. */
|
|
2911
|
41114
242c6928accc
(max_specpdl_size, max_lisp_eval_depth): Use EMACS_INT.
Stefan Monnier <monnier@iro.umontreal.ca>
diff
changeset
|
2912 static Lisp_Object
|
272
|
2913 funcall_lambda (fun, nargs, arg_vector)
|
|
2914 Lisp_Object fun;
|
|
2915 int nargs;
|
|
2916 register Lisp_Object *arg_vector;
|
|
2917 {
|
27781
|
2918 Lisp_Object val, syms_left, next;
|
46293
|
2919 int count = SPECPDL_INDEX ();
|
27781
|
2920 int i, optional, rest;
|
|
2921
|
9148
|
2922 if (CONSP (fun))
|
27781
|
2923 {
|
|
2924 syms_left = XCDR (fun);
|
|
2925 if (CONSP (syms_left))
|
|
2926 syms_left = XCAR (syms_left);
|
|
2927 else
|
|
2928 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2929 }
|
9148
|
2930 else if (COMPILEDP (fun))
|
41597
|
2931 syms_left = AREF (fun, COMPILED_ARGLIST);
|
27781
|
2932 else
|
|
2933 abort ();
|
|
2934
|
|
2935 i = optional = rest = 0;
|
|
2936 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
|
272
|
2937 {
|
|
2938 QUIT;
|
49600
|
2939
|
27781
|
2940 next = XCAR (syms_left);
|
9148
|
2941 while (!SYMBOLP (next))
|
431
|
2942 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
49600
|
2943
|
272
|
2944 if (EQ (next, Qand_rest))
|
|
2945 rest = 1;
|
|
2946 else if (EQ (next, Qand_optional))
|
|
2947 optional = 1;
|
|
2948 else if (rest)
|
|
2949 {
|
431
|
2950 specbind (next, Flist (nargs - i, &arg_vector[i]));
|
272
|
2951 i = nargs;
|
|
2952 }
|
|
2953 else if (i < nargs)
|
27781
|
2954 specbind (next, arg_vector[i++]);
|
272
|
2955 else if (!optional)
|
27781
|
2956 return Fsignal (Qwrong_number_of_arguments,
|
|
2957 Fcons (fun, Fcons (make_number (nargs), Qnil)));
|
272
|
2958 else
|
|
2959 specbind (next, Qnil);
|
|
2960 }
|
|
2961
|
27781
|
2962 if (!NILP (syms_left))
|
|
2963 return Fsignal (Qinvalid_function, Fcons (fun, Qnil));
|
|
2964 else if (i < nargs)
|
|
2965 return Fsignal (Qwrong_number_of_arguments,
|
|
2966 Fcons (fun, Fcons (make_number (nargs), Qnil)));
|
272
|
2967
|
9148
|
2968 if (CONSP (fun))
|
27781
|
2969 val = Fprogn (XCDR (XCDR (fun)));
|
272
|
2970 else
|
10201
|
2971 {
|
|
2972 /* If we have not actually read the bytecode string
|
|
2973 and constants vector yet, fetch them from the file. */
|
41597
|
2974 if (CONSP (AREF (fun, COMPILED_BYTECODE)))
|
11205
|
2975 Ffetch_bytecode (fun);
|
41597
|
2976 val = Fbyte_code (AREF (fun, COMPILED_BYTECODE),
|
|
2977 AREF (fun, COMPILED_CONSTANTS),
|
|
2978 AREF (fun, COMPILED_STACK_DEPTH));
|
10201
|
2979 }
|
49600
|
2980
|
272
|
2981 return unbind_to (count, val);
|
|
2982 }
|
11205
|
2983
|
|
2984 DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode,
|
40570
|
2985 1, 1, 0,
|
|
2986 doc: /* If byte-compiled OBJECT is lazy-loaded, fetch it now. */)
|
|
2987 (object)
|
11205
|
2988 Lisp_Object object;
|
|
2989 {
|
|
2990 Lisp_Object tem;
|
|
2991
|
41597
|
2992 if (COMPILEDP (object) && CONSP (AREF (object, COMPILED_BYTECODE)))
|
11205
|
2993 {
|
41597
|
2994 tem = read_doc_string (AREF (object, COMPILED_BYTECODE));
|
11481
af7833ecb551
(Ffetch_bytecode): Check the type of the object being read from the file.
Richard M. Stallman <rms@gnu.org>
diff
changeset
|
2995 if (!CONSP (tem))
|
41597
|
2996 {
|
|
2997 tem = AREF (object, COMPILED_BYTECODE);
|
|
2998 if (CONSP (tem) && STRINGP (XCAR (tem)))
|
46370
40db0673e6f0
Most uses of XSTRING combined with STRING_BYTES or indirection changed to
Ken Raeburn <raeburn@raeburn.org>
diff
changeset
|
2999 error ("Invalid byte code in %s", SDATA (XCAR (tem)));
|
41597
|
3000 else
|
|
3001 error ("Invalid byte code");
|
|
3002 }
|
|
3003 AREF (object, COMPILED_BYTECODE) = XCAR (tem);
|
|
3004 AREF (object, COMPILED_CONSTANTS) = XCDR (tem);
|
11205
|
3005 }
|
|
3006 return object;
|
|
3007 }
|
272
|
3008
|
|
3009 void
|
|
3010 grow_specpdl ()
|
|
3011 {
|
46293
|
3012 register int count = SPECPDL_INDEX ();
|
272
|
3013 if (specpdl_size >= max_specpdl_size)
|
|
3014 {
|
|
3015 if (max_specpdl_size < 400)
|
|
3016 max_specpdl_size = 400;
|
|
3017 if (specpdl_size >= max_specpdl_size)
|
|
3018 {
|
1452
|
3019 if (!NILP (Vdebug_on_error))
|
|
3020 /* Leave room for some specpdl in the debugger. */
|
|
3021 max_specpdl_size = specpdl_size + 100;
|
272
|
3022 Fsignal (Qerror,
|
|
3023 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil));
|
|
3024 }
|
|
3025 }
|
|
3026 specpdl_size *= 2;
|
|
3027 if (specpdl_size > max_specpdl_size)
|
|
3028 specpdl_size = max_specpdl_size;
|
|
3029 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding));
|
|
3030 specpdl_ptr = specpdl + count;
|
|
3031 }
|
|
3032
|
|
3033 void
|
|
3034 specbind (symbol, value)
|
|
3035 Lisp_Object symbol, value;
|
|
3036 {
|
|
3037 Lisp_Object ovalue;
|
39577
|
3038 Lisp_Object valcontents;
|
272
|
3039
|
40656
|
3040 CHECK_SYMBOL (symbol);
|
272
|
3041 if (specpdl_ptr == specpdl + specpdl_size)
|
|
3042 grow_specpdl ();
|
27781
|
3043
|
39577
|
3044 /* The most common case is that of a non-constant symbol with a
|
|
3045 trivial value. Make that as fast as we can. */
|
|
3046 valcontents = SYMBOL_VALUE (symbol);
|
|
3047 if (!MISCP (valcontents) && !SYMBOL_CONSTANT_P (symbol))
|
27295
|
3048 {
|
27781
|
3049 specpdl_ptr->symbol = symbol;
|
39577
|
3050 specpdl_ptr->old_value = valcontents;
|
27781
|
3051 specpdl_ptr->func = NULL;
|
|
3052 ++specpdl_ptr;
|
39577
|
3053 SET_SYMBOL_VALUE (symbol, value);
|
27295
|
3054 }
|
|
3055 else
|
27781
|
3056 {
|
38276
|
3057 Lisp_Object valcontents;
|
49600
|
3058
|
27781
|
3059 ovalue = find_symbol_value (symbol);
|
|
3060 specpdl_ptr->func = 0;
|
|
3061 specpdl_ptr->old_value = ovalue;
|
|
3062
|
38276
|
3063 valcontents = XSYMBOL (symbol)->value;
|
|
3064
|
|
3065 if (BUFFER_LOCAL_VALUEP (valcontents)
|
|
3066 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
|
|
3067 || BUFFER_OBJFWDP (valcontents))
|
27781
|
3068 {
|
38290
|
3069 Lisp_Object where, current_buffer;
|
|
3070
|
|
3071 current_buffer = Fcurrent_buffer ();
|
49600
|
3072
|
27781
|
3073 /* For a local variable, record both the symbol and which
|
38276
|
3074 buffer's or frame's value we are saving. */
|
|
3075 if (!NILP (Flocal_variable_p (symbol, Qnil)))
|
38290
|
3076 where = current_buffer;
|
38276
|
3077 else if (!BUFFER_OBJFWDP (valcontents)
|
|
3078 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
|
|
3079 where = XBUFFER_LOCAL_VALUE (valcontents)->frame;
|
|
3080 else
|
|
3081 where = Qnil;
|
|
3082
|
|
3083 /* We're not using the `unused' slot in the specbinding
|
|
3084 structure because this would mean we have to do more
|
|
3085 work for simple variables. */
|
38290
|
3086 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, current_buffer));
|
35394
|
3087
|
|
3088 /* If SYMBOL is a per-buffer variable which doesn't have a
|
|
3089 buffer-local value here, make the `let' change the global
|
|
3090 value by changing the value of SYMBOL in all buffers not
|
|
3091 having their own value. This is consistent with what
|
|
3092 happens with other buffer-local variables. */
|
38276
|
3093 if (NILP (where)
|
|
3094 && BUFFER_OBJFWDP (valcontents))
|
35394
|
3095 {
|
|
3096 ++specpdl_ptr;
|
|
3097 Fset_default (symbol, value);
|
|
3098 return;
|
|
3099 }
|
27781
|
3100 }
|
|
3101 else
|
|
3102 specpdl_ptr->symbol = symbol;
|
|
3103
|
|
3104 specpdl_ptr++;
|
|
3105 if (BUFFER_OBJFWDP (ovalue) || KBOARD_OBJFWDP (ovalue))
|
36817
|
3106 store_symval_forwarding (symbol, ovalue, value, NULL);
|
27781
|
3107 else
|
|
3108 set_internal (symbol, value, 0, 1);
|
|
3109 }
|
272
|
3110 }
|
|
3111
|
|
3112 void
|
|
3113 record_unwind_protect (function, arg)
|
20312
|
3114 Lisp_Object (*function) P_ ((Lisp_Object));
|
272
|
3115 Lisp_Object arg;
|
|
3116 {
|
|
3117 if (specpdl_ptr == specpdl + specpdl_size)
|
|
3118 grow_specpdl ();
|
|
3119 specpdl_ptr->func = function;
|
|
3120 specpdl_ptr->symbol = Qnil;
|
|
3121 specpdl_ptr->old_value = arg;
|
|
3122 specpdl_ptr++;
|
|
3123 }
|
|
3124
|
|
3125 Lisp_Object
|
|
3126 unbind_to (count, value)
|
|
3127 int count;
|
|
3128 Lisp_Object value;
|
|
3129 {
|
485
|
3130 int quitf = !NILP (Vquit_flag);
|
272
|
3131 struct gcpro gcpro1;
|
|
3132
|
|
3133 GCPRO1 (value);
|
|
3134 Vquit_flag = Qnil;
|
|
3135
|
|
3136 while (specpdl_ptr != specpdl + count)
|
|
3137 {
|
50919
|
3138 /* Copy the binding, and decrement specpdl_ptr, before we do
|
|
3139 the work to unbind it. We decrement first
|
|
3140 so that an error in unbinding won't try to unbind
|
|
3141 the same entry again, and we copy the binding first
|
|
3142 in case more bindings are made during some of the code we run. */
|
|
3143
|
51294
|
3144 struct specbinding this_binding;
|
|
3145 this_binding = *--specpdl_ptr;
|
50919
|
3146
|
|
3147 if (this_binding.func != 0)
|
|
3148 (*this_binding.func) (this_binding.old_value);
|
38290
|
3149 /* If the symbol is a list, it is really (SYMBOL WHERE
|
|
3150 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a
|
|
3151 frame. If WHERE is a buffer or frame, this indicates we
|
40661
|
3152 bound a variable that had a buffer-local or frame-local
|
|
3153 binding. WHERE nil means that the variable had the default
|
38290
|
3154 value when it was bound. CURRENT-BUFFER is the buffer that
|
|
3155 was current when the variable was bound. */
|
50919
|
3156 else if (CONSP (this_binding.symbol))
|
27295
|
3157 {
|
38276
|
3158 Lisp_Object symbol, where;
|
27295
|
3159
|
50919
|
3160 symbol = XCAR (this_binding.symbol);
|
|
3161 where = XCAR (XCDR (this_binding.symbol));
|
38276
|
3162
|
|
3163 if (NILP (where))
|
50919
|
3164 Fset_default (symbol, this_binding.old_value);
|
38276
|
3165 else if (BUFFERP (where))
|
50919
|
3166 set_internal (symbol, this_binding.old_value, XBUFFER (where), 1);
|
49600
|
3167 else
|
50919
|
3168 set_internal (symbol, this_binding.old_value, NULL, 1);
|
27295
|
3169 }
|
272
|
3170 else
|
27781
|
3171 {
|
|
3172 /* If variable has a trivial value (no forwarding), we can
|
|
3173 just set it. No need to check for constant symbols here,
|
|
3174 since that was already done by specbind. */
|
50919
|
3175 if (!MISCP (SYMBOL_VALUE (this_binding.symbol)))
|
|
3176 SET_SYMBOL_VALUE (this_binding.symbol, this_binding.old_value);
|
27781
|
3177 else
|
50919
|
3178 set_internal (this_binding.symbol, this_binding.old_value, 0, 1);
|
27781
|
3179 }
|
272
|
3180 }
|
49600
|
3181
|
27781
|
3182 if (NILP (Vquit_flag) && quitf)
|
|
3183 Vquit_flag = Qt;
|
272
|
3184
|
|
3185 UNGCPRO;
|
|
3186 return value;
|
|
3187 }
|
|
3188
|
|
3189 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0,
|
40570
|
3190 doc: /* Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
|
|
3191 The debugger is entered when that frame exits, if the flag is non-nil. */)
|
|
3192 (level, flag)
|
272
|
3193 Lisp_Object level, flag;
|
|
3194 {
|
|
3195 register struct backtrace *backlist = backtrace_list;
|
|
3196 register int i;
|
|
3197
|
40656
|
3198 CHECK_NUMBER (level);
|
272
|
3199
|
|
3200 for (i = 0; backlist && i < XINT (level); i++)
|
|
3201 {
|
|
3202 backlist = backlist->next;
|
|
3203 }
|
|
3204
|
|
3205 if (backlist)
|
485
|
3206 backlist->debug_on_exit = !NILP (flag);
|
272
|
3207
|
|
3208 return flag;
|
|
3209 }
|
|
3210
|
|
3211 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "",
|
40570
|
3212 doc: /* Print a trace of Lisp function calls currently active.
|
|
3213 Output stream used is value of `standard-output'. */)
|
|
3214 ()
|
272
|
3215 {
|
|
3216 register struct backtrace *backlist = backtrace_list;
|
|
3217 register int i;
|
|
3218 Lisp_Object tail;
|
|
3219 Lisp_Object tem;
|
|
3220 extern Lisp_Object Vprint_level;
|
|
3221 struct gcpro gcpro1;
|
|
3222
|
9306
ac852c183fa1
(Feval, Ffuncall, funcall_lambda, Fbacktrace): Don't use XFASTINT as an
Karl Heuer <kwzh@gnu.org>
diff
changeset
|
3223 XSETFASTINT (Vprint_level, 3);
|
272
|
3224
|
|
3225 tail = Qnil;
|
|
3226 GCPRO1 (tail);
|
|
3227
|
|
3228 while (backlist)
|
|
3229 {
|
|
3230 write_string (backlist->debug_on_exit ? "* " : " ", 2);
|
|
3231 if (backlist->nargs == UNEVALLED)
|
|
3232 {
|
|
3233 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil);
|
7533
|
3234 write_string ("\n", -1);
|
272
|
3235 }
|
|
3236 else
|
|
3237 {
|
|
3238 tem = *backlist->function;
|
|
3239 Fprin1 (tem, Qnil); /* This can QUIT */
|
|
3240 write_string ("(", -1);
|
|
3241 if (backlist->nargs == MANY)
|
|
3242 {
|
|
3243 for (tail = *backlist->args, i = 0;
|
485
|
3244 !NILP (tail);
|
272
|
3245 tail = Fcdr (tail), i++)
|
|
3246 {
|
|
3247 if (i) write_string (" ", -1);
|
|
3248 Fprin1 (Fcar (tail), Qnil);
|
|
3249 }
|
|
3250 }
|
|
3251 else
|
|
3252 {
|
|
3253 for (i = 0; i < backlist->nargs; i++)
|
|
3254 {
|
|
3255 if (i) write_string (" ", -1);
|
|
3256 Fprin1 (backlist->args[i], Qnil);
|
|
3257 }
|
|
3258 }
|
7533
|
3259 write_string (")\n", -1);
|
272
|
3260 }
|
|
3261 backlist = backlist->next;
|
|
3262 }
|
|
3263
|
|
3264 Vprint_level = Qnil;
|
|
3265 UNGCPRO;
|
|
3266 return Qnil;
|
|
3267 }
|
|
3268
|
32657
|
3269 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, NULL,
|
40570
|
3270 doc: /* Return the function and arguments NFRAMES up from current execution point.
|
|
3271 If that frame has not evaluated the arguments yet (or is a special form),
|
|
3272 the value is (nil FUNCTION ARG-FORMS...).
|
|
3273 If that frame has evaluated its arguments and called its function already,
|
|
3274 the value is (t FUNCTION ARG-VALUES...).
|
|
3275 A &rest arg is represented as the tail of the list ARG-VALUES.
|
|
3276 FUNCTION is whatever was supplied as car of evaluated list,
|
|
3277 or a lambda expression for macro calls.
|
|
3278 If NFRAMES is more than the number of frames, the value is nil. */)
|
|
3279 (nframes)
|
272
|
3280 Lisp_Object nframes;
|
|
3281 {
|
|
3282 register struct backtrace *backlist = backtrace_list;
|
|
3283 register int i;
|
|
3284 Lisp_Object tem;
|
|
3285
|
40656
|
3286 CHECK_NATNUM (nframes);
|
272
|
3287
|
|
3288 /* Find the frame requested. */
|
7533
|
3289 for (i = 0; backlist && i < XFASTINT (nframes); i++)
|
272
|
3290 backlist = backlist->next;
|
|
3291
|
|
3292 if (!backlist)
|
|
3293 return Qnil;
|
|
3294 if (backlist->nargs == UNEVALLED)
|
|
3295 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args));
|
|
3296 else
|
|
3297 {
|
|
3298 if (backlist->nargs == MANY)
|
|
3299 tem = *backlist->args;
|
|
3300 else
|
|
3301 tem = Flist (backlist->nargs, backlist->args);
|
|
3302
|
|
3303 return Fcons (Qt, Fcons (*backlist->function, tem));
|
|
3304 }
|
|
3305 }
|
30073
|
3306
|
272
|
3307
|
21514
|
3308 void
|
55796
|
3309 mark_backtrace ()
|
|
3310 {
|
|
3311 register struct backtrace *backlist;
|
|
3312 register int i;
|
|
3313
|
|
3314 for (backlist = backtrace_list; backlist; backlist = backlist->next)
|
|
3315 {
|
|
3316 mark_object (*backlist->function);
|
|
3317
|
|
3318 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY)
|
|
3319 i = 0;
|
|
3320 else
|
|
3321 i = backlist->nargs - 1;
|
|
3322 for (; i >= 0; i--)
|
|
3323 mark_object (backlist->args[i]);
|
|
3324 }
|
|
3325 }
|
|
3326
|
|
3327 void
|
272
|
3328 syms_of_eval ()
|
|
3329 {
|
|
3330 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size,
|
40570
|
3331 doc: /* *Limit on number of Lisp variable bindings & unwind-protects.
|
|
3332 If Lisp code tries to make more than this many at once,
|
45560
|
3333 an error is signaled.
|
|
3334 You can safely use a value considerably larger than the default value,
|
|
3335 if that proves inconveniently small. However, if you increase it too far,
|
|
3336 Emacs could run out of memory trying to make the stack bigger. */);
|
272
|
3337
|
|
3338 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth,
|
40570
|
3339 doc: /* *Limit on depth in `eval', `apply' and `funcall' before error.
|
45560
|
3340
|
|
3341 This limit serves to catch infinite recursions for you before they cause
|
40570
|
3342 actual stack overflow in C, which would be fatal for Emacs.
|
|
3343 You can safely make it considerably larger than its default value,
|
45560
|
3344 if that proves inconveniently small. However, if you increase it too far,
|
|
3345 Emacs could overflow the real C stack, and crash. */);
|
272
|
3346
|
|
3347 DEFVAR_LISP ("quit-flag", &Vquit_flag,
|
40570
|
3348 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.
|
58933
|
3349 If the value is t, that means do an ordinary quit.
|
|
3350 If the value equals `throw-on-input', that means quit by throwing
|
|
3351 to the tag specified in `throw-on-input'; it's for handling `while-no-input'.
|
|
3352 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit',
|
|
3353 but `inhibit-quit' non-nil prevents anything from taking notice of that. */);
|
272
|
3354 Vquit_flag = Qnil;
|
|
3355
|
|
3356 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit,
|
40570
|
3357 doc: /* Non-nil inhibits C-g quitting from happening immediately.
|
|
3358 Note that `quit-flag' will still be set by typing C-g,
|
|
3359 so a quit will be signaled as soon as `inhibit-quit' is nil.
|
|
3360 To prevent this happening, set `quit-flag' to nil
|
|
3361 before making `inhibit-quit' nil. */);
|
272
|
3362 Vinhibit_quit = Qnil;
|
|
3363
|
381
|
3364 Qinhibit_quit = intern ("inhibit-quit");
|
|
3365 staticpro (&Qinhibit_quit);
|
|
3366
|
272
|
3367 Qautoload = intern ("autoload");
|
|
3368 staticpro (&Qautoload);
|
|
3369
|
|
3370 Qdebug_on_error = intern ("debug-on-error");
|
|
3371 staticpro (&Qdebug_on_error);
|
|
3372
|
|
3373 Qmacro = intern ("macro");
|
|
3374 staticpro (&Qmacro);
|
|
3375
|
44132
|
3376 Qdeclare = intern ("declare");
|
|
3377 staticpro (&Qdeclare);
|
49600
|
3378
|
272
|
3379 /* Note that the process handling also uses Qexit, but we don't want
|
|
3380 to staticpro it twice, so we just do it here. */
|
|
3381 Qexit = intern ("exit");
|
|
3382 staticpro (&Qexit);
|
|
3383
|
|
3384 Qinteractive = intern ("interactive");
|
|
3385 staticpro (&Qinteractive);
|
|
3386
|
|
3387 Qcommandp = intern ("commandp");
|
|
3388 staticpro (&Qcommandp);
|
|
3389
|
|
3390 Qdefun = intern ("defun");
|
|
3391 staticpro (&Qdefun);
|
|
3392
|
|
3393 Qand_rest = intern ("&rest");
|
|
3394 staticpro (&Qand_rest);
|
|
3395
|
|
3396 Qand_optional = intern ("&optional");
|
|
3397 staticpro (&Qand_optional);
|
|
3398
|
684
|
3399 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error,
|
41029
|
3400 doc: /* *Non-nil means errors display a backtrace buffer.
|
|
3401 More precisely, this happens for any error that is handled
|
|
3402 by the editor command loop.
|
40570
|
3403 If the value is a list, an error only means to display a backtrace
|
|
3404 if one of its condition symbols appears in the list. */);
|
684
|
3405 Vstack_trace_on_error = Qnil;
|
272
|
3406
|
684
|
3407 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error,
|
40570
|
3408 doc: /* *Non-nil means enter debugger if an error is signaled.
|
|
3409 Does not apply to errors handled by `condition-case' or those
|
|
3410 matched by `debug-ignored-errors'.
|
|
3411 If the value is a list, an error only means to enter the debugger
|
|
3412 if one of its condition symbols appears in the list.
|
|
3413 When you evaluate an expression interactively, this variable
|
|
3414 is temporarily non-nil if `eval-expression-debug-on-error' is non-nil.
|
|
3415 See also variable `debug-on-quit'. */);
|
684
|
3416 Vdebug_on_error = Qnil;
|
272
|
3417
|
13768
|
3418 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors,
|
40570
|
3419 doc: /* *List of errors for which the debugger should not be called.
|
|
3420 Each element may be a condition-name or a regexp that matches error messages.
|
|
3421 If any element applies to a given error, that error skips the debugger
|
|
3422 and just returns to top level.
|
|
3423 This overrides the variable `debug-on-error'.
|
|
3424 It does not apply to errors handled by `condition-case'. */);
|
13768
|
3425 Vdebug_ignored_errors = Qnil;
|
|
3426
|
272
|
3427 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit,
|
40570
|
3428 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example).
|
|
3429 Does not apply if quit is handled by a `condition-case'.
|
|
3430 When you evaluate an expression interactively, this variable
|
|
3431 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */);
|
272
|
3432 debug_on_quit = 0;
|
|
3433
|
|
3434 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call,
|
40570
|
3435 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */);
|
272
|
3436
|
26947
|
3437 DEFVAR_BOOL ("debugger-may-continue", &debugger_may_continue,
|
40570
|
3438 doc: /* Non-nil means debugger may continue execution.
|
|
3439 This is nil when the debugger is called under circumstances where it
|
|
3440 might not be safe to continue. */);
|
27031
|
3441 debugger_may_continue = 1;
|
26947
|
3442
|
272
|
3443 DEFVAR_LISP ("debugger", &Vdebugger,
|
40570
|
3444 doc: /* Function to call to invoke debugger.
|
|
3445 If due to frame exit, args are `exit' and the value being returned;
|
|
3446 this function's value will be returned instead of that.
|
|
3447 If due to error, args are `error' and a list of the args to `signal'.
|
|
3448 If due to `apply' or `funcall' entry, one arg, `lambda'.
|
|
3449 If due to `eval' entry, one arg, t. */);
|
272
|
3450 Vdebugger = Qnil;
|
|
3451
|
16355
|
3452 DEFVAR_LISP ("signal-hook-function", &Vsignal_hook_function,
|
40570
|
3453 doc: /* If non-nil, this is a function for `signal' to call.
|
|
3454 It receives the same arguments that `signal' was given.
|
|
3455 The Edebug package uses this to regain control. */);
|
16355
|
3456 Vsignal_hook_function = Qnil;
|
|
3457
|
16443
|
3458 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal,
|
40570
|
3459 doc: /* *Non-nil means call the debugger regardless of condition handlers.
|
|
3460 Note that `debug-on-error', `debug-on-quit' and friends
|
|
3461 still determine whether to handle the particular condition. */);
|
16443
|
3462 Vdebug_on_signal = Qnil;
|
16355
|
3463
|
44132
|
3464 DEFVAR_LISP ("macro-declaration-function", &Vmacro_declaration_function,
|
|
3465 doc: /* Function to process declarations in a macro definition.
|
|
3466 The function will be called with two args MACRO and DECL.
|
|
3467 MACRO is the name of the macro being defined.
|
|
3468 DECL is a list `(declare ...)' containing the declarations.
|
|
3469 The value the function returns is not used. */);
|
|
3470 Vmacro_declaration_function = Qnil;
|
|
3471
|
16296
|
3472 Vrun_hooks = intern ("run-hooks");
|
|
3473 staticpro (&Vrun_hooks);
|
272
|
3474
|
|
3475 staticpro (&Vautoload_queue);
|
|
3476 Vautoload_queue = Qnil;
|
30073
|
3477 staticpro (&Vsignaling_function);
|
|
3478 Vsignaling_function = Qnil;
|
272
|
3479
|
|
3480 defsubr (&Sor);
|
|
3481 defsubr (&Sand);
|
|
3482 defsubr (&Sif);
|
|
3483 defsubr (&Scond);
|
|
3484 defsubr (&Sprogn);
|
|
3485 defsubr (&Sprog1);
|
|
3486 defsubr (&Sprog2);
|
|
3487 defsubr (&Ssetq);
|
|
3488 defsubr (&Squote);
|
|
3489 defsubr (&Sfunction);
|
|
3490 defsubr (&Sdefun);
|
|
3491 defsubr (&Sdefmacro);
|
|
3492 defsubr (&Sdefvar);
|
39577
|
3493 defsubr (&Sdefvaralias);
|
272
|
3494 defsubr (&Sdefconst);
|
|
3495 defsubr (&Suser_variable_p);
|
|
3496 defsubr (&Slet);
|
|
3497 defsubr (&SletX);
|
|
3498 defsubr (&Swhile);
|
|
3499 defsubr (&Smacroexpand);
|
|
3500 defsubr (&Scatch);
|
|
3501 defsubr (&Sthrow);
|
|
3502 defsubr (&Sunwind_protect);
|
|
3503 defsubr (&Scondition_case);
|
|
3504 defsubr (&Ssignal);
|
|
3505 defsubr (&Sinteractive_p);
|
57889
|
3506 defsubr (&Scalled_interactively_p);
|
272
|
3507 defsubr (&Scommandp);
|
|
3508 defsubr (&Sautoload);
|
|
3509 defsubr (&Seval);
|
|
3510 defsubr (&Sapply);
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
3511 defsubr (&Sfuncall);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
3512 defsubr (&Srun_hooks);
|
12711
|
3513 defsubr (&Srun_hook_with_args);
|
12732
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
3514 defsubr (&Srun_hook_with_args_until_success);
|
981b924c832b
Add Frun_hooks, Frun_hook_with_args, Frun_hook_with_args_until_success, Frun_hook_with_args_until_failure in terms of run_hook_with_args.
Simon Marshall <simon@gnu.org>
diff
changeset
|
3515 defsubr (&Srun_hook_with_args_until_failure);
|
11205
|
3516 defsubr (&Sfetch_bytecode);
|
272
|
3517 defsubr (&Sbacktrace_debug);
|
|
3518 defsubr (&Sbacktrace);
|
|
3519 defsubr (&Sbacktrace_frame);
|
|
3520 }
|
52401
|
3521
|
|
3522 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb
|
|
3523 (do not change this comment) */
|