Mercurial > emacs
comparison src/eval.c @ 88155:d7ddb3e565de
sync with trunk
| author | Henrik Enberg <henrik.enberg@telia.com> |
|---|---|
| date | Mon, 16 Jan 2006 00:03:54 +0000 |
| parents | aa54553dad6b |
| children |
comparison
equal
deleted
inserted
replaced
| 88154:8ce476d3ba36 | 88155:d7ddb3e565de |
|---|---|
| 1 /* Evaluator for GNU Emacs Lisp interpreter. | 1 /* Evaluator for GNU Emacs Lisp interpreter. |
| 2 Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001, 2002 | 2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001, |
| 3 Free Software Foundation, Inc. | 3 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
| 4 | 4 |
| 5 This file is part of GNU Emacs. | 5 This file is part of GNU Emacs. |
| 6 | 6 |
| 7 GNU Emacs is free software; you can redistribute it and/or modify | 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 | 8 it under the terms of the GNU General Public License as published by |
| 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 GNU General Public License for more details. | 15 GNU General Public License for more details. |
| 16 | 16 |
| 17 You should have received a copy of the GNU General Public License | 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 | 18 along with GNU Emacs; see the file COPYING. If not, write to |
| 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 Boston, MA 02111-1307, USA. */ | 20 Boston, MA 02110-1301, USA. */ |
| 21 | 21 |
| 22 | 22 |
| 23 #include <config.h> | 23 #include <config.h> |
| 24 #include "lisp.h" | 24 #include "lisp.h" |
| 25 #include "blockinput.h" | 25 #include "blockinput.h" |
| 86 #ifdef DEBUG_GCPRO | 86 #ifdef DEBUG_GCPRO |
| 87 /* Count levels of GCPRO to detect failure to UNGCPRO. */ | 87 /* Count levels of GCPRO to detect failure to UNGCPRO. */ |
| 88 int gcpro_level; | 88 int gcpro_level; |
| 89 #endif | 89 #endif |
| 90 | 90 |
| 91 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun, Qdefvar; | 91 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun; |
| 92 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag; | 92 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag; |
| 93 Lisp_Object Qand_rest, Qand_optional; | 93 Lisp_Object Qand_rest, Qand_optional; |
| 94 Lisp_Object Qdebug_on_error; | 94 Lisp_Object Qdebug_on_error; |
| 95 Lisp_Object Qdeclare; | 95 Lisp_Object Qdeclare; |
| 96 | 96 |
| 101 Lisp_Object Vrun_hooks; | 101 Lisp_Object Vrun_hooks; |
| 102 | 102 |
| 103 /* Non-nil means record all fset's and provide's, to be undone | 103 /* Non-nil means record all fset's and provide's, to be undone |
| 104 if the file being autoloaded is not fully loaded. | 104 if the file being autoloaded is not fully loaded. |
| 105 They are recorded by being consed onto the front of Vautoload_queue: | 105 They are recorded by being consed onto the front of Vautoload_queue: |
| 106 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */ | 106 (FUN . ODEF) for a defun, (0 . OFEATURES) for a provide. */ |
| 107 | 107 |
| 108 Lisp_Object Vautoload_queue; | 108 Lisp_Object Vautoload_queue; |
| 109 | 109 |
| 110 /* Current number of specbindings allocated in specpdl. */ | 110 /* Current number of specbindings allocated in specpdl. */ |
| 111 | 111 |
| 115 | 115 |
| 116 struct specbinding *specpdl; | 116 struct specbinding *specpdl; |
| 117 | 117 |
| 118 /* Pointer to first unused element in specpdl. */ | 118 /* Pointer to first unused element in specpdl. */ |
| 119 | 119 |
| 120 struct specbinding *specpdl_ptr; | 120 volatile struct specbinding *specpdl_ptr; |
| 121 | 121 |
| 122 /* Maximum size allowed for specpdl allocation */ | 122 /* Maximum size allowed for specpdl allocation */ |
| 123 | 123 |
| 124 EMACS_INT max_specpdl_size; | 124 EMACS_INT max_specpdl_size; |
| 125 | 125 |
| 202 init_eval_once () | 202 init_eval_once () |
| 203 { | 203 { |
| 204 specpdl_size = 50; | 204 specpdl_size = 50; |
| 205 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding)); | 205 specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding)); |
| 206 specpdl_ptr = specpdl; | 206 specpdl_ptr = specpdl; |
| 207 max_specpdl_size = 600; | 207 max_specpdl_size = 1000; |
| 208 max_lisp_eval_depth = 300; | 208 max_lisp_eval_depth = 300; |
| 209 | 209 |
| 210 Vrun_hooks = Qnil; | 210 Vrun_hooks = Qnil; |
| 211 } | 211 } |
| 212 | 212 |
| 225 #endif | 225 #endif |
| 226 /* This is less than the initial value of num_nonmacro_input_events. */ | 226 /* This is less than the initial value of num_nonmacro_input_events. */ |
| 227 when_entered_debugger = -1; | 227 when_entered_debugger = -1; |
| 228 } | 228 } |
| 229 | 229 |
| 230 /* unwind-protect function used by call_debugger. */ | |
| 231 | |
| 232 static Lisp_Object | |
| 233 restore_stack_limits (data) | |
| 234 Lisp_Object data; | |
| 235 { | |
| 236 max_specpdl_size = XINT (XCAR (data)); | |
| 237 max_lisp_eval_depth = XINT (XCDR (data)); | |
| 238 return Qnil; | |
| 239 } | |
| 240 | |
| 241 /* Call the Lisp debugger, giving it argument ARG. */ | |
| 242 | |
| 230 Lisp_Object | 243 Lisp_Object |
| 231 call_debugger (arg) | 244 call_debugger (arg) |
| 232 Lisp_Object arg; | 245 Lisp_Object arg; |
| 233 { | 246 { |
| 234 int debug_while_redisplaying; | 247 int debug_while_redisplaying; |
| 235 int count = SPECPDL_INDEX (); | 248 int count = SPECPDL_INDEX (); |
| 236 Lisp_Object val; | 249 Lisp_Object val; |
| 237 | 250 int old_max = max_specpdl_size; |
| 238 if (lisp_eval_depth + 20 > max_lisp_eval_depth) | 251 |
| 239 max_lisp_eval_depth = lisp_eval_depth + 20; | 252 /* Temporarily bump up the stack limits, |
| 240 | 253 so the debugger won't run out of stack. */ |
| 241 if (specpdl_size + 40 > max_specpdl_size) | 254 |
| 242 max_specpdl_size = specpdl_size + 40; | 255 max_specpdl_size += 1; |
| 256 record_unwind_protect (restore_stack_limits, | |
| 257 Fcons (make_number (old_max), | |
| 258 make_number (max_lisp_eval_depth))); | |
| 259 max_specpdl_size = old_max; | |
| 260 | |
| 261 if (lisp_eval_depth + 40 > max_lisp_eval_depth) | |
| 262 max_lisp_eval_depth = lisp_eval_depth + 40; | |
| 263 | |
| 264 if (SPECPDL_INDEX () + 100 > max_specpdl_size) | |
| 265 max_specpdl_size = SPECPDL_INDEX () + 100; | |
| 243 | 266 |
| 244 #ifdef HAVE_X_WINDOWS | 267 #ifdef HAVE_X_WINDOWS |
| 245 if (display_hourglass_p) | 268 if (display_hourglass_p) |
| 246 cancel_hourglass (); | 269 cancel_hourglass (); |
| 247 #endif | 270 #endif |
| 254 debug_while_redisplaying = redisplaying_p; | 277 debug_while_redisplaying = redisplaying_p; |
| 255 redisplaying_p = 0; | 278 redisplaying_p = 0; |
| 256 specbind (intern ("debugger-may-continue"), | 279 specbind (intern ("debugger-may-continue"), |
| 257 debug_while_redisplaying ? Qnil : Qt); | 280 debug_while_redisplaying ? Qnil : Qt); |
| 258 specbind (Qinhibit_redisplay, Qnil); | 281 specbind (Qinhibit_redisplay, Qnil); |
| 282 specbind (Qdebug_on_error, Qnil); | |
| 259 | 283 |
| 260 #if 0 /* Binding this prevents execution of Lisp code during | 284 #if 0 /* Binding this prevents execution of Lisp code during |
| 261 redisplay, which necessarily leads to display problems. */ | 285 redisplay, which necessarily leads to display problems. */ |
| 262 specbind (Qinhibit_eval_during_redisplay, Qt); | 286 specbind (Qinhibit_eval_during_redisplay, Qt); |
| 263 #endif | 287 #endif |
| 292 If all args return nil, return nil. | 316 If all args return nil, return nil. |
| 293 usage: (or CONDITIONS ...) */) | 317 usage: (or CONDITIONS ...) */) |
| 294 (args) | 318 (args) |
| 295 Lisp_Object args; | 319 Lisp_Object args; |
| 296 { | 320 { |
| 297 register Lisp_Object val; | 321 register Lisp_Object val = Qnil; |
| 298 Lisp_Object args_left; | |
| 299 struct gcpro gcpro1; | 322 struct gcpro gcpro1; |
| 300 | 323 |
| 301 if (NILP(args)) | 324 GCPRO1 (args); |
| 302 return Qnil; | 325 |
| 303 | 326 while (CONSP (args)) |
| 304 args_left = args; | 327 { |
| 305 GCPRO1 (args_left); | 328 val = Feval (XCAR (args)); |
| 306 | |
| 307 do | |
| 308 { | |
| 309 val = Feval (Fcar (args_left)); | |
| 310 if (!NILP (val)) | 329 if (!NILP (val)) |
| 311 break; | 330 break; |
| 312 args_left = Fcdr (args_left); | 331 args = XCDR (args); |
| 313 } | 332 } |
| 314 while (!NILP(args_left)); | |
| 315 | 333 |
| 316 UNGCPRO; | 334 UNGCPRO; |
| 317 return val; | 335 return val; |
| 318 } | 336 } |
| 319 | 337 |
| 323 If no arg yields nil, return the last arg's value. | 341 If no arg yields nil, return the last arg's value. |
| 324 usage: (and CONDITIONS ...) */) | 342 usage: (and CONDITIONS ...) */) |
| 325 (args) | 343 (args) |
| 326 Lisp_Object args; | 344 Lisp_Object args; |
| 327 { | 345 { |
| 328 register Lisp_Object val; | 346 register Lisp_Object val = Qt; |
| 329 Lisp_Object args_left; | |
| 330 struct gcpro gcpro1; | 347 struct gcpro gcpro1; |
| 331 | 348 |
| 332 if (NILP(args)) | 349 GCPRO1 (args); |
| 333 return Qt; | 350 |
| 334 | 351 while (CONSP (args)) |
| 335 args_left = args; | 352 { |
| 336 GCPRO1 (args_left); | 353 val = Feval (XCAR (args)); |
| 337 | |
| 338 do | |
| 339 { | |
| 340 val = Feval (Fcar (args_left)); | |
| 341 if (NILP (val)) | 354 if (NILP (val)) |
| 342 break; | 355 break; |
| 343 args_left = Fcdr (args_left); | 356 args = XCDR (args); |
| 344 } | 357 } |
| 345 while (!NILP(args_left)); | |
| 346 | 358 |
| 347 UNGCPRO; | 359 UNGCPRO; |
| 348 return val; | 360 return val; |
| 349 } | 361 } |
| 350 | 362 |
| 408 doc: /* Eval BODY forms sequentially and return value of last one. | 420 doc: /* Eval BODY forms sequentially and return value of last one. |
| 409 usage: (progn BODY ...) */) | 421 usage: (progn BODY ...) */) |
| 410 (args) | 422 (args) |
| 411 Lisp_Object args; | 423 Lisp_Object args; |
| 412 { | 424 { |
| 413 register Lisp_Object val; | 425 register Lisp_Object val = Qnil; |
| 414 Lisp_Object args_left; | |
| 415 struct gcpro gcpro1; | 426 struct gcpro gcpro1; |
| 416 | 427 |
| 417 if (NILP(args)) | 428 GCPRO1 (args); |
| 418 return Qnil; | 429 |
| 419 | 430 while (CONSP (args)) |
| 420 args_left = args; | 431 { |
| 421 GCPRO1 (args_left); | 432 val = Feval (XCAR (args)); |
| 422 | 433 args = XCDR (args); |
| 423 do | 434 } |
| 424 { | |
| 425 val = Feval (Fcar (args_left)); | |
| 426 args_left = Fcdr (args_left); | |
| 427 } | |
| 428 while (!NILP(args_left)); | |
| 429 | 435 |
| 430 UNGCPRO; | 436 UNGCPRO; |
| 431 return val; | 437 return val; |
| 432 } | 438 } |
| 433 | 439 |
| 464 UNGCPRO; | 470 UNGCPRO; |
| 465 return val; | 471 return val; |
| 466 } | 472 } |
| 467 | 473 |
| 468 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0, | 474 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0, |
| 469 doc: /* Eval X, Y and BODY sequentially; value from Y. | 475 doc: /* Eval FORM1, FORM2 and BODY sequentially; value from FORM2. |
| 470 The value of Y is saved during the evaluation of the remaining args, | 476 The value of FORM2 is saved during the evaluation of the |
| 471 whose values are discarded. | 477 remaining args, whose values are discarded. |
| 472 usage: (prog2 X Y BODY...) */) | 478 usage: (prog2 FORM1 FORM2 BODY...) */) |
| 473 (args) | 479 (args) |
| 474 Lisp_Object args; | 480 Lisp_Object args; |
| 475 { | 481 { |
| 476 Lisp_Object val; | 482 Lisp_Object val; |
| 477 register Lisp_Object args_left; | 483 register Lisp_Object args_left; |
| 556 return Fcar (args); | 562 return Fcar (args); |
| 557 } | 563 } |
| 558 | 564 |
| 559 | 565 |
| 560 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0, | 566 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0, |
| 561 doc: /* Return t if function in which this appears was called interactively. | 567 doc: /* Return t if the function was run directly by user input. |
| 562 This means that the function was called with call-interactively (which | 568 This means that the function was called with `call-interactively' |
| 563 includes being called as the binding of a key) | 569 \(which includes being called as the binding of a key) |
| 564 and input is currently coming from the keyboard (not in keyboard macro). */) | 570 and input is currently coming from the keyboard (not in keyboard macro), |
| 571 and Emacs is not running in batch mode (`noninteractive' is nil). | |
| 572 | |
| 573 The only known proper use of `interactive-p' is in deciding whether to | |
| 574 display a helpful message, or how to display it. If you're thinking | |
| 575 of using it for any other purpose, it is quite likely that you're | |
| 576 making a mistake. Think: what do you want to do when the command is | |
| 577 called from a keyboard macro? | |
| 578 | |
| 579 If you want to test whether your function was called with | |
| 580 `call-interactively', the way to do that is by adding an extra | |
| 581 optional argument, and making the `interactive' spec specify non-nil | |
| 582 unconditionally for that argument. (`p' is a good way to do this.) */) | |
| 565 () | 583 () |
| 566 { | 584 { |
| 585 return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil; | |
| 586 } | |
| 587 | |
| 588 | |
| 589 DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 0, 0, | |
| 590 doc: /* Return t if the function using this was called with `call-interactively'. | |
| 591 This is used for implementing advice and other function-modifying | |
| 592 features of Emacs. | |
| 593 | |
| 594 The cleanest way to test whether your function was called with | |
| 595 `call-interactively' is by adding an extra optional argument, | |
| 596 and making the `interactive' spec specify non-nil unconditionally | |
| 597 for that argument. (`p' is a good way to do this.) */) | |
| 598 () | |
| 599 { | |
| 567 return interactive_p (1) ? Qt : Qnil; | 600 return interactive_p (1) ? Qt : Qnil; |
| 568 } | 601 } |
| 569 | 602 |
| 570 | 603 |
| 571 /* Return 1 if function in which this appears was called | 604 /* Return 1 if function in which this appears was called using |
| 572 interactively. This means that the function was called with | 605 call-interactively. |
| 573 call-interactively (which includes being called as the binding of | |
| 574 a key) and input is currently coming from the keyboard (not in | |
| 575 keyboard macro). | |
| 576 | 606 |
| 577 EXCLUDE_SUBRS_P non-zero means always return 0 if the function | 607 EXCLUDE_SUBRS_P non-zero means always return 0 if the function |
| 578 called is a built-in. */ | 608 called is a built-in. */ |
| 579 | 609 |
| 580 int | 610 int |
| 582 int exclude_subrs_p; | 612 int exclude_subrs_p; |
| 583 { | 613 { |
| 584 struct backtrace *btp; | 614 struct backtrace *btp; |
| 585 Lisp_Object fun; | 615 Lisp_Object fun; |
| 586 | 616 |
| 587 if (!INTERACTIVE) | |
| 588 return 0; | |
| 589 | |
| 590 btp = backtrace_list; | 617 btp = backtrace_list; |
| 591 | 618 |
| 592 /* If this isn't a byte-compiled function, there may be a frame at | 619 /* If this isn't a byte-compiled function, there may be a frame at |
| 593 the top for Finteractive_p. If so, skip it. */ | 620 the top for Finteractive_p. If so, skip it. */ |
| 594 fun = Findirect_function (*btp->function); | 621 fun = Findirect_function (*btp->function); |
| 595 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p) | 622 if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p |
| 623 || XSUBR (fun) == &Scalled_interactively_p)) | |
| 596 btp = btp->next; | 624 btp = btp->next; |
| 597 | 625 |
| 598 /* If we're running an Emacs 18-style byte-compiled function, there | 626 /* If we're running an Emacs 18-style byte-compiled function, there |
| 599 may be a frame for Fbytecode at the top level. In any version of | 627 may be a frame for Fbytecode at the top level. In any version of |
| 600 Emacs there can be Fbytecode frames for subexpressions evaluated | 628 Emacs there can be Fbytecode frames for subexpressions evaluated |
| 633 { | 661 { |
| 634 register Lisp_Object fn_name; | 662 register Lisp_Object fn_name; |
| 635 register Lisp_Object defn; | 663 register Lisp_Object defn; |
| 636 | 664 |
| 637 fn_name = Fcar (args); | 665 fn_name = Fcar (args); |
| 666 CHECK_SYMBOL (fn_name); | |
| 638 defn = Fcons (Qlambda, Fcdr (args)); | 667 defn = Fcons (Qlambda, Fcdr (args)); |
| 639 if (!NILP (Vpurify_flag)) | 668 if (!NILP (Vpurify_flag)) |
| 640 defn = Fpurecopy (defn); | 669 defn = Fpurecopy (defn); |
| 641 if (CONSP (XSYMBOL (fn_name)->function) | 670 if (CONSP (XSYMBOL (fn_name)->function) |
| 642 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload)) | 671 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload)) |
| 643 LOADHIST_ATTACH (Fcons (Qt, fn_name)); | 672 LOADHIST_ATTACH (Fcons (Qt, fn_name)); |
| 644 Ffset (fn_name, defn); | 673 Ffset (fn_name, defn); |
| 645 LOADHIST_ATTACH (fn_name); | 674 LOADHIST_ATTACH (Fcons (Qdefun, fn_name)); |
| 646 return fn_name; | 675 return fn_name; |
| 647 } | 676 } |
| 648 | 677 |
| 649 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0, | 678 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0, |
| 650 doc: /* Define NAME as a macro. | 679 doc: /* Define NAME as a macro. |
| 660 (declare SPECS...) | 689 (declare SPECS...) |
| 661 The elements can look like this: | 690 The elements can look like this: |
| 662 (indent INDENT) | 691 (indent INDENT) |
| 663 Set NAME's `lisp-indent-function' property to INDENT. | 692 Set NAME's `lisp-indent-function' property to INDENT. |
| 664 | 693 |
| 665 (edebug DEBUG) | 694 (debug DEBUG) |
| 666 Set NAME's `edebug-form-spec' property to DEBUG. (This is | 695 Set NAME's `edebug-form-spec' property to DEBUG. (This is |
| 667 equivalent to writing a `def-edebug-spec' for the macro.) | 696 equivalent to writing a `def-edebug-spec' for the macro.) |
| 668 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */) | 697 usage: (defmacro NAME ARGLIST [DOCSTRING] [DECL] BODY...) */) |
| 669 (args) | 698 (args) |
| 670 Lisp_Object args; | 699 Lisp_Object args; |
| 672 register Lisp_Object fn_name; | 701 register Lisp_Object fn_name; |
| 673 register Lisp_Object defn; | 702 register Lisp_Object defn; |
| 674 Lisp_Object lambda_list, doc, tail; | 703 Lisp_Object lambda_list, doc, tail; |
| 675 | 704 |
| 676 fn_name = Fcar (args); | 705 fn_name = Fcar (args); |
| 706 CHECK_SYMBOL (fn_name); | |
| 677 lambda_list = Fcar (Fcdr (args)); | 707 lambda_list = Fcar (Fcdr (args)); |
| 678 tail = Fcdr (Fcdr (args)); | 708 tail = Fcdr (Fcdr (args)); |
| 679 | 709 |
| 680 doc = Qnil; | 710 doc = Qnil; |
| 681 if (STRINGP (Fcar (tail))) | 711 if (STRINGP (Fcar (tail))) |
| 682 { | 712 { |
| 683 doc = Fcar (tail); | 713 doc = XCAR (tail); |
| 684 tail = Fcdr (tail); | 714 tail = XCDR (tail); |
| 685 } | 715 } |
| 686 | 716 |
| 687 while (CONSP (Fcar (tail)) | 717 while (CONSP (Fcar (tail)) |
| 688 && EQ (Fcar (Fcar (tail)), Qdeclare)) | 718 && EQ (Fcar (Fcar (tail)), Qdeclare)) |
| 689 { | 719 { |
| 708 defn = Fpurecopy (defn); | 738 defn = Fpurecopy (defn); |
| 709 if (CONSP (XSYMBOL (fn_name)->function) | 739 if (CONSP (XSYMBOL (fn_name)->function) |
| 710 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload)) | 740 && EQ (XCAR (XSYMBOL (fn_name)->function), Qautoload)) |
| 711 LOADHIST_ATTACH (Fcons (Qt, fn_name)); | 741 LOADHIST_ATTACH (Fcons (Qt, fn_name)); |
| 712 Ffset (fn_name, defn); | 742 Ffset (fn_name, defn); |
| 713 LOADHIST_ATTACH (fn_name); | 743 LOADHIST_ATTACH (Fcons (Qdefun, fn_name)); |
| 714 return fn_name; | 744 return fn_name; |
| 715 } | 745 } |
| 716 | 746 |
| 717 | 747 |
| 718 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0, | 748 DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0, |
| 719 doc: /* Make SYMBOL a variable alias for symbol ALIASED. | 749 doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE. |
| 720 Setting the value of SYMBOL will subsequently set the value of ALIASED, | 750 Setting the value of NEW-ALIAS will subsequently set the value of BASE-VARIABLE, |
| 721 and getting the value of SYMBOL will return the value ALIASED has. | 751 and getting the value of NEW-ALIAS will return the value BASE-VARIABLE has. |
| 722 ALIASED nil means remove the alias; SYMBOL is unbound after that. | 752 Third arg DOCSTRING, if non-nil, is documentation for NEW-ALIAS. If it is |
| 723 Third arg DOCSTRING, if non-nil, is documentation for SYMBOL. */) | 753 omitted or nil, NEW-ALIAS gets the documentation string of BASE-VARIABLE, |
| 724 (symbol, aliased, docstring) | 754 or of the variable at the end of the chain of aliases, if BASE-VARIABLE is |
| 725 Lisp_Object symbol, aliased, docstring; | 755 itself an alias. |
| 756 The return value is BASE-VARIABLE. */) | |
| 757 (new_alias, base_variable, docstring) | |
| 758 Lisp_Object new_alias, base_variable, docstring; | |
| 726 { | 759 { |
| 727 struct Lisp_Symbol *sym; | 760 struct Lisp_Symbol *sym; |
| 728 | 761 |
| 729 CHECK_SYMBOL (symbol); | 762 CHECK_SYMBOL (new_alias); |
| 730 CHECK_SYMBOL (aliased); | 763 CHECK_SYMBOL (base_variable); |
| 731 | 764 |
| 732 if (SYMBOL_CONSTANT_P (symbol)) | 765 if (SYMBOL_CONSTANT_P (new_alias)) |
| 733 error ("Cannot make a constant an alias"); | 766 error ("Cannot make a constant an alias"); |
| 734 | 767 |
| 735 sym = XSYMBOL (symbol); | 768 sym = XSYMBOL (new_alias); |
| 736 sym->indirect_variable = 1; | 769 sym->indirect_variable = 1; |
| 737 sym->value = aliased; | 770 sym->value = base_variable; |
| 738 sym->constant = SYMBOL_CONSTANT_P (aliased); | 771 sym->constant = SYMBOL_CONSTANT_P (base_variable); |
| 739 LOADHIST_ATTACH (Fcons (Qdefvar, symbol)); | 772 LOADHIST_ATTACH (new_alias); |
| 740 if (!NILP (docstring)) | 773 if (!NILP (docstring)) |
| 741 Fput (symbol, Qvariable_documentation, docstring); | 774 Fput (new_alias, Qvariable_documentation, docstring); |
| 742 | 775 else |
| 743 return aliased; | 776 Fput (new_alias, Qvariable_documentation, Qnil); |
| 777 | |
| 778 return base_variable; | |
| 744 } | 779 } |
| 745 | 780 |
| 746 | 781 |
| 747 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, | 782 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, |
| 748 doc: /* Define SYMBOL as a variable. | 783 doc: /* Define SYMBOL as a variable, and return SYMBOL. |
| 749 You are not required to define a variable in order to use it, | 784 You are not required to define a variable in order to use it, |
| 750 but the definition can supply documentation and an initial value | 785 but the definition can supply documentation and an initial value |
| 751 in a way that tags can recognize. | 786 in a way that tags can recognize. |
| 752 | 787 |
| 753 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void. | 788 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void. |
| 756 INITVALUE and DOCSTRING are optional. | 791 INITVALUE and DOCSTRING are optional. |
| 757 If DOCSTRING starts with *, this variable is identified as a user option. | 792 If DOCSTRING starts with *, this variable is identified as a user option. |
| 758 This means that M-x set-variable recognizes it. | 793 This means that M-x set-variable recognizes it. |
| 759 See also `user-variable-p'. | 794 See also `user-variable-p'. |
| 760 If INITVALUE is missing, SYMBOL's value is not set. | 795 If INITVALUE is missing, SYMBOL's value is not set. |
| 796 | |
| 797 If SYMBOL has a local binding, then this form affects the local | |
| 798 binding. This is usually not what you want. Thus, if you need to | |
| 799 load a file defining variables, with this form or with `defconst' or | |
| 800 `defcustom', you should always load that file _outside_ any bindings | |
| 801 for these variables. \(`defconst' and `defcustom' behave similarly in | |
| 802 this respect.) | |
| 761 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | 803 usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) |
| 762 (args) | 804 (args) |
| 763 Lisp_Object args; | 805 Lisp_Object args; |
| 764 { | 806 { |
| 765 register Lisp_Object sym, tem, tail; | 807 register Lisp_Object sym, tem, tail; |
| 766 | 808 |
| 767 sym = Fcar (args); | 809 sym = Fcar (args); |
| 768 tail = Fcdr (args); | 810 tail = Fcdr (args); |
| 769 if (!NILP (Fcdr (Fcdr (tail)))) | 811 if (!NILP (Fcdr (Fcdr (tail)))) |
| 770 error ("too many arguments"); | 812 error ("Too many arguments"); |
| 771 | 813 |
| 772 tem = Fdefault_boundp (sym); | 814 tem = Fdefault_boundp (sym); |
| 773 if (!NILP (tail)) | 815 if (!NILP (tail)) |
| 774 { | 816 { |
| 817 if (SYMBOL_CONSTANT_P (sym)) | |
| 818 { | |
| 819 /* For upward compatibility, allow (defvar :foo (quote :foo)). */ | |
| 820 Lisp_Object tem = Fcar (tail); | |
| 821 if (! (CONSP (tem) | |
| 822 && EQ (XCAR (tem), Qquote) | |
| 823 && CONSP (XCDR (tem)) | |
| 824 && EQ (XCAR (XCDR (tem)), sym))) | |
| 825 error ("Constant symbol `%s' specified in defvar", | |
| 826 SDATA (SYMBOL_NAME (sym))); | |
| 827 } | |
| 828 | |
| 775 if (NILP (tem)) | 829 if (NILP (tem)) |
| 776 Fset_default (sym, Feval (Fcar (tail))); | 830 Fset_default (sym, Feval (Fcar (tail))); |
| 831 else | |
| 832 { /* Check if there is really a global binding rather than just a let | |
| 833 binding that shadows the global unboundness of the var. */ | |
| 834 volatile struct specbinding *pdl = specpdl_ptr; | |
| 835 while (--pdl >= specpdl) | |
| 836 { | |
| 837 if (EQ (pdl->symbol, sym) && !pdl->func | |
| 838 && EQ (pdl->old_value, Qunbound)) | |
| 839 { | |
| 840 message_with_string ("Warning: defvar ignored because %s is let-bound", | |
| 841 SYMBOL_NAME (sym), 1); | |
| 842 break; | |
| 843 } | |
| 844 } | |
| 845 } | |
| 777 tail = Fcdr (tail); | 846 tail = Fcdr (tail); |
| 778 if (!NILP (Fcar (tail))) | 847 tem = Fcar (tail); |
| 779 { | 848 if (!NILP (tem)) |
| 780 tem = Fcar (tail); | 849 { |
| 781 if (!NILP (Vpurify_flag)) | 850 if (!NILP (Vpurify_flag)) |
| 782 tem = Fpurecopy (tem); | 851 tem = Fpurecopy (tem); |
| 783 Fput (sym, Qvariable_documentation, tem); | 852 Fput (sym, Qvariable_documentation, tem); |
| 784 } | 853 } |
| 785 LOADHIST_ATTACH (Fcons (Qdefvar, sym)); | 854 LOADHIST_ATTACH (sym); |
| 786 } | 855 } |
| 787 else | 856 else |
| 788 /* Simple (defvar <var>) should not count as a definition at all. | 857 /* Simple (defvar <var>) should not count as a definition at all. |
| 789 It could get in the way of other definitions, and unloading this | 858 It could get in the way of other definitions, and unloading this |
| 790 package could try to make the variable unbound. */ | 859 package could try to make the variable unbound. */ |
| 798 The intent is that neither programs nor users should ever change this value. | 867 The intent is that neither programs nor users should ever change this value. |
| 799 Always sets the value of SYMBOL to the result of evalling INITVALUE. | 868 Always sets the value of SYMBOL to the result of evalling INITVALUE. |
| 800 If SYMBOL is buffer-local, its default value is what is set; | 869 If SYMBOL is buffer-local, its default value is what is set; |
| 801 buffer-local values are not affected. | 870 buffer-local values are not affected. |
| 802 DOCSTRING is optional. | 871 DOCSTRING is optional. |
| 872 | |
| 873 If SYMBOL has a local binding, then this form sets the local binding's | |
| 874 value. However, you should normally not make local bindings for | |
| 875 variables defined with this form. | |
| 803 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */) | 876 usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */) |
| 804 (args) | 877 (args) |
| 805 Lisp_Object args; | 878 Lisp_Object args; |
| 806 { | 879 { |
| 807 register Lisp_Object sym, tem; | 880 register Lisp_Object sym, tem; |
| 808 | 881 |
| 809 sym = Fcar (args); | 882 sym = Fcar (args); |
| 810 if (!NILP (Fcdr (Fcdr (Fcdr (args))))) | 883 if (!NILP (Fcdr (Fcdr (Fcdr (args))))) |
| 811 error ("too many arguments"); | 884 error ("Too many arguments"); |
| 812 | 885 |
| 813 tem = Feval (Fcar (Fcdr (args))); | 886 tem = Feval (Fcar (Fcdr (args))); |
| 814 if (!NILP (Vpurify_flag)) | 887 if (!NILP (Vpurify_flag)) |
| 815 tem = Fpurecopy (tem); | 888 tem = Fpurecopy (tem); |
| 816 Fset_default (sym, tem); | 889 Fset_default (sym, tem); |
| 819 { | 892 { |
| 820 if (!NILP (Vpurify_flag)) | 893 if (!NILP (Vpurify_flag)) |
| 821 tem = Fpurecopy (tem); | 894 tem = Fpurecopy (tem); |
| 822 Fput (sym, Qvariable_documentation, tem); | 895 Fput (sym, Qvariable_documentation, tem); |
| 823 } | 896 } |
| 824 LOADHIST_ATTACH (Fcons (Qdefvar, sym)); | 897 LOADHIST_ATTACH (sym); |
| 825 return sym; | 898 return sym; |
| 826 } | 899 } |
| 827 | 900 |
| 901 /* Error handler used in Fuser_variable_p. */ | |
| 902 static Lisp_Object | |
| 903 user_variable_p_eh (ignore) | |
| 904 Lisp_Object ignore; | |
| 905 { | |
| 906 return Qnil; | |
| 907 } | |
| 908 | |
| 828 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0, | 909 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0, |
| 829 doc: /* Returns t if VARIABLE is intended to be set and modified by users. | 910 doc: /* Return t if VARIABLE is intended to be set and modified by users. |
| 830 \(The alternative is a variable used internally in a Lisp program.) | 911 \(The alternative is a variable used internally in a Lisp program.) |
| 831 Determined by whether the first character of the documentation | 912 A variable is a user variable if |
| 832 for the variable is `*' or if the variable is customizable (has a non-nil | 913 \(1) the first character of its documentation is `*', or |
| 833 value of `standard-value' or of `custom-autoload' on its property list). */) | 914 \(2) it is customizable (its property list contains a non-nil value |
| 915 of `standard-value' or `custom-autoload'), or | |
| 916 \(3) it is an alias for another user variable. | |
| 917 Return nil if VARIABLE is an alias and there is a loop in the | |
| 918 chain of symbols. */) | |
| 834 (variable) | 919 (variable) |
| 835 Lisp_Object variable; | 920 Lisp_Object variable; |
| 836 { | 921 { |
| 837 Lisp_Object documentation; | 922 Lisp_Object documentation; |
| 838 | 923 |
| 839 if (!SYMBOLP (variable)) | 924 if (!SYMBOLP (variable)) |
| 840 return Qnil; | 925 return Qnil; |
| 841 | 926 |
| 842 documentation = Fget (variable, Qvariable_documentation); | 927 /* If indirect and there's an alias loop, don't check anything else. */ |
| 843 if (INTEGERP (documentation) && XINT (documentation) < 0) | 928 if (XSYMBOL (variable)->indirect_variable |
| 844 return Qt; | 929 && NILP (internal_condition_case_1 (indirect_variable, variable, |
| 845 if (STRINGP (documentation) | 930 Qt, user_variable_p_eh))) |
| 846 && ((unsigned char) SREF (documentation, 0) == '*')) | 931 return Qnil; |
| 847 return Qt; | 932 |
| 848 /* If it is (STRING . INTEGER), a negative integer means a user variable. */ | 933 while (1) |
| 849 if (CONSP (documentation) | 934 { |
| 850 && STRINGP (XCAR (documentation)) | 935 documentation = Fget (variable, Qvariable_documentation); |
| 851 && INTEGERP (XCDR (documentation)) | 936 if (INTEGERP (documentation) && XINT (documentation) < 0) |
| 852 && XINT (XCDR (documentation)) < 0) | 937 return Qt; |
| 853 return Qt; | 938 if (STRINGP (documentation) |
| 854 /* Customizable? See `custom-variable-p'. */ | 939 && ((unsigned char) SREF (documentation, 0) == '*')) |
| 855 if ((!NILP (Fget (variable, intern ("standard-value")))) | 940 return Qt; |
| 856 || (!NILP (Fget (variable, intern ("custom-autoload"))))) | 941 /* If it is (STRING . INTEGER), a negative integer means a user variable. */ |
| 857 return Qt; | 942 if (CONSP (documentation) |
| 858 return Qnil; | 943 && STRINGP (XCAR (documentation)) |
| 944 && INTEGERP (XCDR (documentation)) | |
| 945 && XINT (XCDR (documentation)) < 0) | |
| 946 return Qt; | |
| 947 /* Customizable? See `custom-variable-p'. */ | |
| 948 if ((!NILP (Fget (variable, intern ("standard-value")))) | |
| 949 || (!NILP (Fget (variable, intern ("custom-autoload"))))) | |
| 950 return Qt; | |
| 951 | |
| 952 if (!XSYMBOL (variable)->indirect_variable) | |
| 953 return Qnil; | |
| 954 | |
| 955 /* An indirect variable? Let's follow the chain. */ | |
| 956 variable = XSYMBOL (variable)->value; | |
| 957 } | |
| 859 } | 958 } |
| 860 | 959 |
| 861 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0, | 960 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0, |
| 862 doc: /* Bind variables according to VARLIST then eval BODY. | 961 doc: /* Bind variables according to VARLIST then eval BODY. |
| 863 The value of the last form in BODY is returned. | 962 The value of the last form in BODY is returned. |
| 1140 register int last_time; | 1239 register int last_time; |
| 1141 | 1240 |
| 1142 /* Save the value in the tag. */ | 1241 /* Save the value in the tag. */ |
| 1143 catch->val = value; | 1242 catch->val = value; |
| 1144 | 1243 |
| 1145 /* Restore the polling-suppression count. */ | 1244 /* Restore certain special C variables. */ |
| 1146 set_poll_suppress_count (catch->poll_suppress_count); | 1245 set_poll_suppress_count (catch->poll_suppress_count); |
| 1147 interrupt_input_blocked = catch->interrupt_input_blocked; | 1246 UNBLOCK_INPUT_TO (catch->interrupt_input_blocked); |
| 1247 handling_signal = 0; | |
| 1248 immediate_quit = 0; | |
| 1148 | 1249 |
| 1149 do | 1250 do |
| 1150 { | 1251 { |
| 1151 last_time = catchlist == catch; | 1252 last_time = catchlist == catch; |
| 1152 | 1253 |
| 1203 Lisp_Object args; | 1304 Lisp_Object args; |
| 1204 { | 1305 { |
| 1205 Lisp_Object val; | 1306 Lisp_Object val; |
| 1206 int count = SPECPDL_INDEX (); | 1307 int count = SPECPDL_INDEX (); |
| 1207 | 1308 |
| 1208 record_unwind_protect (0, Fcdr (args)); | 1309 record_unwind_protect (Fprogn, Fcdr (args)); |
| 1209 val = Feval (Fcar (args)); | 1310 val = Feval (Fcar (args)); |
| 1210 return unbind_to (count, val); | 1311 return unbind_to (count, val); |
| 1211 } | 1312 } |
| 1212 | 1313 |
| 1213 /* Chain of condition handlers currently in effect. | 1314 /* Chain of condition handlers currently in effect. |
| 1236 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA). | 1337 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA). |
| 1237 VAR may be nil; then you do not get access to the signal information. | 1338 VAR may be nil; then you do not get access to the signal information. |
| 1238 | 1339 |
| 1239 The value of the last BODY form is returned from the condition-case. | 1340 The value of the last BODY form is returned from the condition-case. |
| 1240 See also the function `signal' for more info. | 1341 See also the function `signal' for more info. |
| 1241 usage: (condition-case VAR BODYFORM HANDLERS...) */) | 1342 usage: (condition-case VAR BODYFORM &rest HANDLERS) */) |
| 1242 (args) | 1343 (args) |
| 1243 Lisp_Object args; | 1344 Lisp_Object args; |
| 1345 { | |
| 1346 register Lisp_Object bodyform, handlers; | |
| 1347 volatile Lisp_Object var; | |
| 1348 | |
| 1349 var = Fcar (args); | |
| 1350 bodyform = Fcar (Fcdr (args)); | |
| 1351 handlers = Fcdr (Fcdr (args)); | |
| 1352 | |
| 1353 return internal_lisp_condition_case (var, bodyform, handlers); | |
| 1354 } | |
| 1355 | |
| 1356 /* Like Fcondition_case, but the args are separate | |
| 1357 rather than passed in a list. Used by Fbyte_code. */ | |
| 1358 | |
| 1359 Lisp_Object | |
| 1360 internal_lisp_condition_case (var, bodyform, handlers) | |
| 1361 volatile Lisp_Object var; | |
| 1362 Lisp_Object bodyform, handlers; | |
| 1244 { | 1363 { |
| 1245 Lisp_Object val; | 1364 Lisp_Object val; |
| 1246 struct catchtag c; | 1365 struct catchtag c; |
| 1247 struct handler h; | 1366 struct handler h; |
| 1248 register Lisp_Object bodyform, handlers; | 1367 |
| 1249 volatile Lisp_Object var; | |
| 1250 | |
| 1251 var = Fcar (args); | |
| 1252 bodyform = Fcar (Fcdr (args)); | |
| 1253 handlers = Fcdr (Fcdr (args)); | |
| 1254 CHECK_SYMBOL (var); | 1368 CHECK_SYMBOL (var); |
| 1255 | 1369 |
| 1256 for (val = handlers; ! NILP (val); val = Fcdr (val)) | 1370 for (val = handlers; CONSP (val); val = XCDR (val)) |
| 1257 { | 1371 { |
| 1258 Lisp_Object tem; | 1372 Lisp_Object tem; |
| 1259 tem = Fcar (val); | 1373 tem = XCAR (val); |
| 1260 if (! (NILP (tem) | 1374 if (! (NILP (tem) |
| 1261 || (CONSP (tem) | 1375 || (CONSP (tem) |
| 1262 && (SYMBOLP (XCAR (tem)) | 1376 && (SYMBOLP (XCAR (tem)) |
| 1263 || CONSP (XCAR (tem)))))) | 1377 || CONSP (XCAR (tem)))))) |
| 1264 error ("Invalid condition handler", tem); | 1378 error ("Invalid condition handler", tem); |
| 1452 that is a list of condition names. | 1566 that is a list of condition names. |
| 1453 A handler for any of those names will get to handle this signal. | 1567 A handler for any of those names will get to handle this signal. |
| 1454 The symbol `error' should normally be one of them. | 1568 The symbol `error' should normally be one of them. |
| 1455 | 1569 |
| 1456 DATA should be a list. Its elements are printed as part of the error message. | 1570 DATA should be a list. Its elements are printed as part of the error message. |
| 1571 See Info anchor `(elisp)Definition of signal' for some details on how this | |
| 1572 error message is constructed. | |
| 1457 If the signal is handled, DATA is made available to the handler. | 1573 If the signal is handled, DATA is made available to the handler. |
| 1458 See also the function `condition-case'. */) | 1574 See also the function `condition-case'. */) |
| 1459 (error_symbol, data) | 1575 (error_symbol, data) |
| 1460 Lisp_Object error_symbol, data; | 1576 Lisp_Object error_symbol, data; |
| 1461 { | 1577 { |
| 1470 Lisp_Object string; | 1586 Lisp_Object string; |
| 1471 Lisp_Object real_error_symbol; | 1587 Lisp_Object real_error_symbol; |
| 1472 struct backtrace *bp; | 1588 struct backtrace *bp; |
| 1473 | 1589 |
| 1474 immediate_quit = handling_signal = 0; | 1590 immediate_quit = handling_signal = 0; |
| 1591 abort_on_gc = 0; | |
| 1475 if (gc_in_progress || waiting_for_input) | 1592 if (gc_in_progress || waiting_for_input) |
| 1476 abort (); | 1593 abort (); |
| 1477 | 1594 |
| 1478 if (NILP (error_symbol)) | 1595 if (NILP (error_symbol)) |
| 1479 real_error_symbol = Fcar (data); | 1596 real_error_symbol = Fcar (data); |
| 1489 #endif | 1606 #endif |
| 1490 | 1607 |
| 1491 /* This hook is used by edebug. */ | 1608 /* This hook is used by edebug. */ |
| 1492 if (! NILP (Vsignal_hook_function) | 1609 if (! NILP (Vsignal_hook_function) |
| 1493 && ! NILP (error_symbol)) | 1610 && ! NILP (error_symbol)) |
| 1494 call2 (Vsignal_hook_function, error_symbol, data); | 1611 { |
| 1612 /* Edebug takes care of restoring these variables when it exits. */ | |
| 1613 if (lisp_eval_depth + 20 > max_lisp_eval_depth) | |
| 1614 max_lisp_eval_depth = lisp_eval_depth + 20; | |
| 1615 | |
| 1616 if (SPECPDL_INDEX () + 40 > max_specpdl_size) | |
| 1617 max_specpdl_size = SPECPDL_INDEX () + 40; | |
| 1618 | |
| 1619 call2 (Vsignal_hook_function, error_symbol, data); | |
| 1620 } | |
| 1495 | 1621 |
| 1496 conditions = Fget (real_error_symbol, Qerror_conditions); | 1622 conditions = Fget (real_error_symbol, Qerror_conditions); |
| 1497 | 1623 |
| 1498 /* Remember from where signal was called. Skip over the frame for | 1624 /* Remember from where signal was called. Skip over the frame for |
| 1499 `signal' itself. If a frame for `error' follows, skip that, | 1625 `signal' itself. If a frame for `error' follows, skip that, |
| 1511 | 1637 |
| 1512 for (; handlerlist; handlerlist = handlerlist->next) | 1638 for (; handlerlist; handlerlist = handlerlist->next) |
| 1513 { | 1639 { |
| 1514 register Lisp_Object clause; | 1640 register Lisp_Object clause; |
| 1515 | 1641 |
| 1516 if (lisp_eval_depth + 20 > max_lisp_eval_depth) | |
| 1517 max_lisp_eval_depth = lisp_eval_depth + 20; | |
| 1518 | |
| 1519 if (specpdl_size + 40 > max_specpdl_size) | |
| 1520 max_specpdl_size = specpdl_size + 40; | |
| 1521 | |
| 1522 clause = find_handler_clause (handlerlist->handler, conditions, | 1642 clause = find_handler_clause (handlerlist->handler, conditions, |
| 1523 error_symbol, data, &debugger_value); | 1643 error_symbol, data, &debugger_value); |
| 1524 | 1644 |
| 1525 if (EQ (clause, Qlambda)) | 1645 if (EQ (clause, Qlambda)) |
| 1526 { | 1646 { |
| 1629 There are two ways to pass SIG and DATA: | 1749 There are two ways to pass SIG and DATA: |
| 1630 = SIG is the error symbol, and DATA is the rest of the data. | 1750 = SIG is the error symbol, and DATA is the rest of the data. |
| 1631 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA). | 1751 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA). |
| 1632 This is for memory-full errors only. | 1752 This is for memory-full errors only. |
| 1633 | 1753 |
| 1634 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */ | 1754 Store value returned from debugger into *DEBUGGER_VALUE_PTR. |
| 1755 | |
| 1756 We need to increase max_specpdl_size temporarily around | |
| 1757 anything we do that can push on the specpdl, so as not to get | |
| 1758 a second error here in case we're handling specpdl overflow. */ | |
| 1635 | 1759 |
| 1636 static Lisp_Object | 1760 static Lisp_Object |
| 1637 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr) | 1761 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr) |
| 1638 Lisp_Object handlers, conditions, sig, data; | 1762 Lisp_Object handlers, conditions, sig, data; |
| 1639 Lisp_Object *debugger_value_ptr; | 1763 Lisp_Object *debugger_value_ptr; |
| 1647 and run the debugger if that is enabled. */ | 1771 and run the debugger if that is enabled. */ |
| 1648 if (EQ (handlers, Qerror) | 1772 if (EQ (handlers, Qerror) |
| 1649 || !NILP (Vdebug_on_signal)) /* This says call debugger even if | 1773 || !NILP (Vdebug_on_signal)) /* This says call debugger even if |
| 1650 there is a handler. */ | 1774 there is a handler. */ |
| 1651 { | 1775 { |
| 1652 int count = SPECPDL_INDEX (); | |
| 1653 int debugger_called = 0; | 1776 int debugger_called = 0; |
| 1654 Lisp_Object sig_symbol, combined_data; | 1777 Lisp_Object sig_symbol, combined_data; |
| 1655 /* This is set to 1 if we are handling a memory-full error, | 1778 /* This is set to 1 if we are handling a memory-full error, |
| 1656 because these must not run the debugger. | 1779 because these must not run the debugger. |
| 1657 (There is no room in memory to do that!) */ | 1780 (There is no room in memory to do that!) */ |
| 1669 sig_symbol = sig; | 1792 sig_symbol = sig; |
| 1670 } | 1793 } |
| 1671 | 1794 |
| 1672 if (wants_debugger (Vstack_trace_on_error, conditions)) | 1795 if (wants_debugger (Vstack_trace_on_error, conditions)) |
| 1673 { | 1796 { |
| 1797 max_specpdl_size++; | |
| 1674 #ifdef PROTOTYPES | 1798 #ifdef PROTOTYPES |
| 1675 internal_with_output_to_temp_buffer ("*Backtrace*", | 1799 internal_with_output_to_temp_buffer ("*Backtrace*", |
| 1676 (Lisp_Object (*) (Lisp_Object)) Fbacktrace, | 1800 (Lisp_Object (*) (Lisp_Object)) Fbacktrace, |
| 1677 Qnil); | 1801 Qnil); |
| 1678 #else | 1802 #else |
| 1679 internal_with_output_to_temp_buffer ("*Backtrace*", | 1803 internal_with_output_to_temp_buffer ("*Backtrace*", |
| 1680 Fbacktrace, Qnil); | 1804 Fbacktrace, Qnil); |
| 1681 #endif | 1805 #endif |
| 1806 max_specpdl_size--; | |
| 1682 } | 1807 } |
| 1683 if (! no_debugger | 1808 if (! no_debugger |
| 1684 && (EQ (sig_symbol, Qquit) | 1809 && (EQ (sig_symbol, Qquit) |
| 1685 ? debug_on_quit | 1810 ? debug_on_quit |
| 1686 : wants_debugger (Vdebug_on_error, conditions)) | 1811 : wants_debugger (Vdebug_on_error, conditions)) |
| 1687 && ! skip_debugger (conditions, combined_data) | 1812 && ! skip_debugger (conditions, combined_data) |
| 1688 && when_entered_debugger < num_nonmacro_input_events) | 1813 && when_entered_debugger < num_nonmacro_input_events) |
| 1689 { | 1814 { |
| 1690 specbind (Qdebug_on_error, Qnil); | |
| 1691 *debugger_value_ptr | 1815 *debugger_value_ptr |
| 1692 = call_debugger (Fcons (Qerror, | 1816 = call_debugger (Fcons (Qerror, |
| 1693 Fcons (combined_data, Qnil))); | 1817 Fcons (combined_data, Qnil))); |
| 1694 debugger_called = 1; | 1818 debugger_called = 1; |
| 1695 } | 1819 } |
| 1696 /* If there is no handler, return saying whether we ran the debugger. */ | 1820 /* If there is no handler, return saying whether we ran the debugger. */ |
| 1697 if (EQ (handlers, Qerror)) | 1821 if (EQ (handlers, Qerror)) |
| 1698 { | 1822 { |
| 1699 if (debugger_called) | 1823 if (debugger_called) |
| 1700 return unbind_to (count, Qlambda); | 1824 return Qlambda; |
| 1701 return Qt; | 1825 return Qt; |
| 1702 } | 1826 } |
| 1703 } | 1827 } |
| 1704 for (h = handlers; CONSP (h); h = Fcdr (h)) | 1828 for (h = handlers; CONSP (h); h = Fcdr (h)) |
| 1705 { | 1829 { |
| 1825 return Qt; | 1949 return Qt; |
| 1826 | 1950 |
| 1827 /* Lists may represent commands. */ | 1951 /* Lists may represent commands. */ |
| 1828 if (!CONSP (fun)) | 1952 if (!CONSP (fun)) |
| 1829 return Qnil; | 1953 return Qnil; |
| 1830 funcar = Fcar (fun); | 1954 funcar = XCAR (fun); |
| 1831 if (!SYMBOLP (funcar)) | |
| 1832 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
| 1833 if (EQ (funcar, Qlambda)) | 1955 if (EQ (funcar, Qlambda)) |
| 1834 return Fassq (Qinteractive, Fcdr (Fcdr (fun))); | 1956 return Fassq (Qinteractive, Fcdr (XCDR (fun))); |
| 1835 if (EQ (funcar, Qautoload)) | 1957 if (EQ (funcar, Qautoload)) |
| 1836 return Fcar (Fcdr (Fcdr (Fcdr (fun)))); | 1958 return Fcar (Fcdr (Fcdr (XCDR (fun)))); |
| 1837 else | 1959 else |
| 1838 return Qnil; | 1960 return Qnil; |
| 1839 } | 1961 } |
| 1840 | 1962 |
| 1841 /* ARGSUSED */ | 1963 /* ARGSUSED */ |
| 1895 oldqueue is the shadowed value to leave in Vautoload_queue. */ | 2017 oldqueue is the shadowed value to leave in Vautoload_queue. */ |
| 1896 queue = Vautoload_queue; | 2018 queue = Vautoload_queue; |
| 1897 Vautoload_queue = oldqueue; | 2019 Vautoload_queue = oldqueue; |
| 1898 while (CONSP (queue)) | 2020 while (CONSP (queue)) |
| 1899 { | 2021 { |
| 1900 first = Fcar (queue); | 2022 first = XCAR (queue); |
| 1901 second = Fcdr (first); | 2023 second = Fcdr (first); |
| 1902 first = Fcar (first); | 2024 first = Fcar (first); |
| 1903 if (EQ (second, Qnil)) | 2025 if (EQ (first, make_number (0))) |
| 1904 Vfeatures = first; | 2026 Vfeatures = second; |
| 1905 else | 2027 else |
| 1906 Ffset (first, second); | 2028 Ffset (first, second); |
| 1907 queue = Fcdr (queue); | 2029 queue = XCDR (queue); |
| 1908 } | 2030 } |
| 1909 return Qnil; | 2031 return Qnil; |
| 1910 } | 2032 } |
| 1911 | 2033 |
| 1912 /* Load an autoloaded function. | 2034 /* Load an autoloaded function. |
| 1930 fun = funname; | 2052 fun = funname; |
| 1931 CHECK_SYMBOL (funname); | 2053 CHECK_SYMBOL (funname); |
| 1932 GCPRO3 (fun, funname, fundef); | 2054 GCPRO3 (fun, funname, fundef); |
| 1933 | 2055 |
| 1934 /* Preserve the match data. */ | 2056 /* Preserve the match data. */ |
| 1935 record_unwind_protect (Fset_match_data, Fmatch_data (Qnil, Qnil)); | 2057 record_unwind_save_match_data (); |
| 1936 | 2058 |
| 1937 /* Value saved here is to be restored into Vautoload_queue. */ | 2059 /* Value saved here is to be restored into Vautoload_queue. */ |
| 1938 record_unwind_protect (un_autoload, Vautoload_queue); | 2060 record_unwind_protect (un_autoload, Vautoload_queue); |
| 1939 Vautoload_queue = Qt; | 2061 Vautoload_queue = Qt; |
| 1940 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt); | 2062 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil, Qt); |
| 1941 | 2063 |
| 1942 /* Save the old autoloads, in case we ever do an unload. */ | 2064 /* Save the old autoloads, in case we ever do an unload. */ |
| 1943 queue = Vautoload_queue; | 2065 queue = Vautoload_queue; |
| 1944 while (CONSP (queue)) | 2066 while (CONSP (queue)) |
| 1945 { | 2067 { |
| 1946 first = Fcar (queue); | 2068 first = XCAR (queue); |
| 1947 second = Fcdr (first); | 2069 second = Fcdr (first); |
| 1948 first = Fcar (first); | 2070 first = Fcar (first); |
| 1949 | 2071 |
| 1950 /* Note: This test is subtle. The cdr of an autoload-queue entry | 2072 if (SYMBOLP (first) && CONSP (second) && EQ (XCAR (second), Qautoload)) |
| 1951 may be an atom if the autoload entry was generated by a defalias | 2073 Fput (first, Qautoload, (XCDR (second))); |
| 1952 or fset. */ | 2074 |
| 1953 if (CONSP (second)) | 2075 queue = XCDR (queue); |
| 1954 Fput (first, Qautoload, (Fcdr (second))); | |
| 1955 | |
| 1956 queue = Fcdr (queue); | |
| 1957 } | 2076 } |
| 1958 | 2077 |
| 1959 /* Once loading finishes, don't undo it. */ | 2078 /* Once loading finishes, don't undo it. */ |
| 1960 Vautoload_queue = Qt; | 2079 Vautoload_queue = Qt; |
| 1961 unbind_to (count, Qnil); | 2080 unbind_to (count, Qnil); |
| 1986 return Fsymbol_value (form); | 2105 return Fsymbol_value (form); |
| 1987 if (!CONSP (form)) | 2106 if (!CONSP (form)) |
| 1988 return form; | 2107 return form; |
| 1989 | 2108 |
| 1990 QUIT; | 2109 QUIT; |
| 1991 if (consing_since_gc > gc_cons_threshold) | 2110 if ((consing_since_gc > gc_cons_threshold |
| 2111 && consing_since_gc > gc_relative_threshold) | |
| 2112 || | |
| 2113 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold)) | |
| 1992 { | 2114 { |
| 1993 GCPRO1 (form); | 2115 GCPRO1 (form); |
| 1994 Fgarbage_collect (); | 2116 Fgarbage_collect (); |
| 1995 UNGCPRO; | 2117 UNGCPRO; |
| 1996 } | 2118 } |
| 1998 if (++lisp_eval_depth > max_lisp_eval_depth) | 2120 if (++lisp_eval_depth > max_lisp_eval_depth) |
| 1999 { | 2121 { |
| 2000 if (max_lisp_eval_depth < 100) | 2122 if (max_lisp_eval_depth < 100) |
| 2001 max_lisp_eval_depth = 100; | 2123 max_lisp_eval_depth = 100; |
| 2002 if (lisp_eval_depth > max_lisp_eval_depth) | 2124 if (lisp_eval_depth > max_lisp_eval_depth) |
| 2003 error ("Lisp nesting exceeds max-lisp-eval-depth"); | 2125 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); |
| 2004 } | 2126 } |
| 2005 | 2127 |
| 2006 original_fun = Fcar (form); | 2128 original_fun = Fcar (form); |
| 2007 original_args = Fcdr (form); | 2129 original_args = Fcdr (form); |
| 2008 | 2130 |
| 2029 Lisp_Object args_left; | 2151 Lisp_Object args_left; |
| 2030 register int i, maxargs; | 2152 register int i, maxargs; |
| 2031 | 2153 |
| 2032 args_left = original_args; | 2154 args_left = original_args; |
| 2033 numargs = Flength (args_left); | 2155 numargs = Flength (args_left); |
| 2156 | |
| 2157 CHECK_CONS_LIST (); | |
| 2034 | 2158 |
| 2035 if (XINT (numargs) < XSUBR (fun)->min_args || | 2159 if (XINT (numargs) < XSUBR (fun)->min_args || |
| 2036 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs))) | 2160 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs))) |
| 2037 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | 2161 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); |
| 2038 | 2162 |
| 2153 val = apply_lambda (fun, original_args, 1); | 2277 val = apply_lambda (fun, original_args, 1); |
| 2154 else | 2278 else |
| 2155 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | 2279 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); |
| 2156 } | 2280 } |
| 2157 done: | 2281 done: |
| 2282 CHECK_CONS_LIST (); | |
| 2283 | |
| 2158 lisp_eval_depth--; | 2284 lisp_eval_depth--; |
| 2159 if (backtrace.debug_on_exit) | 2285 if (backtrace.debug_on_exit) |
| 2160 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); | 2286 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); |
| 2161 backtrace_list = backtrace.next; | 2287 backtrace_list = backtrace.next; |
| 2162 | 2288 |
| 2163 #ifdef HAVE_CARBON | |
| 2164 mac_check_for_quit_char(); | |
| 2165 #endif | |
| 2166 return val; | 2289 return val; |
| 2167 } | 2290 } |
| 2168 | 2291 |
| 2169 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0, | 2292 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0, |
| 2170 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args. | 2293 doc: /* Call FUNCTION with our remaining args, using our last arg as list of args. |
| 2242 { | 2365 { |
| 2243 funcall_args [i++] = XCAR (spread_arg); | 2366 funcall_args [i++] = XCAR (spread_arg); |
| 2244 spread_arg = XCDR (spread_arg); | 2367 spread_arg = XCDR (spread_arg); |
| 2245 } | 2368 } |
| 2246 | 2369 |
| 2370 /* By convention, the caller needs to gcpro Ffuncall's args. */ | |
| 2247 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); | 2371 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); |
| 2248 } | 2372 } |
| 2249 | 2373 |
| 2250 /* Run hook variables in various ways. */ | 2374 /* Run hook variables in various ways. */ |
| 2251 | 2375 |
| 2252 enum run_hooks_condition {to_completion, until_success, until_failure}; | 2376 enum run_hooks_condition {to_completion, until_success, until_failure}; |
| 2253 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *, | 2377 static Lisp_Object run_hook_with_args P_ ((int, Lisp_Object *, |
| 2254 enum run_hooks_condition)); | 2378 enum run_hooks_condition)); |
| 2255 | 2379 |
| 2256 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0, | 2380 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0, |
| 2257 doc: /* Run each hook in HOOKS. Major mode functions use this. | 2381 doc: /* Run each hook in HOOKS. |
| 2258 Each argument should be a symbol, a hook variable. | 2382 Each argument should be a symbol, a hook variable. |
| 2259 These symbols are processed in the order specified. | 2383 These symbols are processed in the order specified. |
| 2260 If a hook symbol has a non-nil value, that value may be a function | 2384 If a hook symbol has a non-nil value, that value may be a function |
| 2261 or a list of functions to be called to run the hook. | 2385 or a list of functions to be called to run the hook. |
| 2262 If the value is a function, it is called with no arguments. | 2386 If the value is a function, it is called with no arguments. |
| 2263 If it is a list, the elements are called, in order, with no arguments. | 2387 If it is a list, the elements are called, in order, with no arguments. |
| 2388 | |
| 2389 Major modes should not use this function directly to run their mode | |
| 2390 hook; they should use `run-mode-hooks' instead. | |
| 2264 | 2391 |
| 2265 Do not use `make-local-variable' to make a hook variable buffer-local. | 2392 Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2266 Instead, use `add-hook' and specify t for the LOCAL argument. | 2393 Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2267 usage: (run-hooks &rest HOOKS) */) | 2394 usage: (run-hooks &rest HOOKS) */) |
| 2268 (nargs, args) | 2395 (nargs, args) |
| 2288 value, that value may be a function or a list of functions to be | 2415 value, that value may be a function or a list of functions to be |
| 2289 called to run the hook. If the value is a function, it is called with | 2416 called to run the hook. If the value is a function, it is called with |
| 2290 the given arguments and its return value is returned. If it is a list | 2417 the given arguments and its return value is returned. If it is a list |
| 2291 of functions, those functions are called, in order, | 2418 of functions, those functions are called, in order, |
| 2292 with the given arguments ARGS. | 2419 with the given arguments ARGS. |
| 2293 It is best not to depend on the value return by `run-hook-with-args', | 2420 It is best not to depend on the value returned by `run-hook-with-args', |
| 2294 as that may change. | 2421 as that may change. |
| 2295 | 2422 |
| 2296 Do not use `make-local-variable' to make a hook variable buffer-local. | 2423 Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2297 Instead, use `add-hook' and specify t for the LOCAL argument. | 2424 Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2298 usage: (run-hook-with-args HOOK &rest ARGS) */) | 2425 usage: (run-hook-with-args HOOK &rest ARGS) */) |
| 2304 } | 2431 } |
| 2305 | 2432 |
| 2306 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, | 2433 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, |
| 2307 Srun_hook_with_args_until_success, 1, MANY, 0, | 2434 Srun_hook_with_args_until_success, 1, MANY, 0, |
| 2308 doc: /* Run HOOK with the specified arguments ARGS. | 2435 doc: /* Run HOOK with the specified arguments ARGS. |
| 2309 HOOK should be a symbol, a hook variable. Its value should | 2436 HOOK should be a symbol, a hook variable. If HOOK has a non-nil |
| 2310 be a list of functions. We call those functions, one by one, | 2437 value, that value may be a function or a list of functions to be |
| 2311 passing arguments ARGS to each of them, until one of them | 2438 called to run the hook. If the value is a function, it is called with |
| 2439 the given arguments and its return value is returned. | |
| 2440 If it is a list of functions, those functions are called, in order, | |
| 2441 with the given arguments ARGS, until one of them | |
| 2312 returns a non-nil value. Then we return that value. | 2442 returns a non-nil value. Then we return that value. |
| 2313 If all the functions return nil, we return nil. | 2443 However, if they all return nil, we return nil. |
| 2314 | 2444 |
| 2315 Do not use `make-local-variable' to make a hook variable buffer-local. | 2445 Do not use `make-local-variable' to make a hook variable buffer-local. |
| 2316 Instead, use `add-hook' and specify t for the LOCAL argument. | 2446 Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2317 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */) | 2447 usage: (run-hook-with-args-until-success HOOK &rest ARGS) */) |
| 2318 (nargs, args) | 2448 (nargs, args) |
| 2323 } | 2453 } |
| 2324 | 2454 |
| 2325 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, | 2455 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, |
| 2326 Srun_hook_with_args_until_failure, 1, MANY, 0, | 2456 Srun_hook_with_args_until_failure, 1, MANY, 0, |
| 2327 doc: /* Run HOOK with the specified arguments ARGS. | 2457 doc: /* Run HOOK with the specified arguments ARGS. |
| 2328 HOOK should be a symbol, a hook variable. Its value should | 2458 HOOK should be a symbol, a hook variable. If HOOK has a non-nil |
| 2329 be a list of functions. We call those functions, one by one, | 2459 value, that value may be a function or a list of functions to be |
| 2330 passing arguments ARGS to each of them, until one of them | 2460 called to run the hook. If the value is a function, it is called with |
| 2331 returns nil. Then we return nil. | 2461 the given arguments and its return value is returned. |
| 2332 If all the functions return non-nil, we return non-nil. | 2462 If it is a list of functions, those functions are called, in order, |
| 2463 with the given arguments ARGS, until one of them returns nil. | |
| 2464 Then we return nil. However, if they all return non-nil, we return non-nil. | |
| 2333 | 2465 |
| 2334 Do not use `make-local-variable' to make a hook variable buffer-local. | 2466 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. | 2467 Instead, use `add-hook' and specify t for the LOCAL argument. |
| 2336 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */) | 2468 usage: (run-hook-with-args-until-failure HOOK &rest ARGS) */) |
| 2337 (nargs, args) | 2469 (nargs, args) |
| 2655 gcpro1.nvars = 7; | 2787 gcpro1.nvars = 7; |
| 2656 RETURN_UNGCPRO (Ffuncall (7, &fn)); | 2788 RETURN_UNGCPRO (Ffuncall (7, &fn)); |
| 2657 #endif /* not NO_ARG_ARRAY */ | 2789 #endif /* not NO_ARG_ARRAY */ |
| 2658 } | 2790 } |
| 2659 | 2791 |
| 2792 /* The caller should GCPRO all the elements of ARGS. */ | |
| 2793 | |
| 2660 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0, | 2794 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0, |
| 2661 doc: /* Call first argument as a function, passing remaining arguments to it. | 2795 doc: /* Call first argument as a function, passing remaining arguments to it. |
| 2662 Return the value that function returns. | 2796 Return the value that function returns. |
| 2663 Thus, (funcall 'cons 'x 'y) returns (x . y). | 2797 Thus, (funcall 'cons 'x 'y) returns (x . y). |
| 2664 usage: (funcall FUNCTION &rest ARGUMENTS) */) | 2798 usage: (funcall FUNCTION &rest ARGUMENTS) */) |
| 2674 struct backtrace backtrace; | 2808 struct backtrace backtrace; |
| 2675 register Lisp_Object *internal_args; | 2809 register Lisp_Object *internal_args; |
| 2676 register int i; | 2810 register int i; |
| 2677 | 2811 |
| 2678 QUIT; | 2812 QUIT; |
| 2679 if (consing_since_gc > gc_cons_threshold) | 2813 if ((consing_since_gc > gc_cons_threshold |
| 2814 && consing_since_gc > gc_relative_threshold) | |
| 2815 || | |
| 2816 (!NILP (Vmemory_full) && consing_since_gc > memory_full_cons_threshold)) | |
| 2680 Fgarbage_collect (); | 2817 Fgarbage_collect (); |
| 2681 | 2818 |
| 2682 if (++lisp_eval_depth > max_lisp_eval_depth) | 2819 if (++lisp_eval_depth > max_lisp_eval_depth) |
| 2683 { | 2820 { |
| 2684 if (max_lisp_eval_depth < 100) | 2821 if (max_lisp_eval_depth < 100) |
| 2685 max_lisp_eval_depth = 100; | 2822 max_lisp_eval_depth = 100; |
| 2686 if (lisp_eval_depth > max_lisp_eval_depth) | 2823 if (lisp_eval_depth > max_lisp_eval_depth) |
| 2687 error ("Lisp nesting exceeds max-lisp-eval-depth"); | 2824 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); |
| 2688 } | 2825 } |
| 2689 | 2826 |
| 2690 backtrace.next = backtrace_list; | 2827 backtrace.next = backtrace_list; |
| 2691 backtrace_list = &backtrace; | 2828 backtrace_list = &backtrace; |
| 2692 backtrace.function = &args[0]; | 2829 backtrace.function = &args[0]; |
| 2696 backtrace.debug_on_exit = 0; | 2833 backtrace.debug_on_exit = 0; |
| 2697 | 2834 |
| 2698 if (debug_on_next_call) | 2835 if (debug_on_next_call) |
| 2699 do_debug_on_call (Qlambda); | 2836 do_debug_on_call (Qlambda); |
| 2700 | 2837 |
| 2838 CHECK_CONS_LIST (); | |
| 2839 | |
| 2701 retry: | 2840 retry: |
| 2702 | 2841 |
| 2703 fun = args[0]; | 2842 fun = args[0]; |
| 2704 | 2843 |
| 2705 fun = Findirect_function (fun); | 2844 fun = Findirect_function (fun); |
| 2706 | 2845 |
| 2707 if (SUBRP (fun)) | 2846 if (SUBRP (fun)) |
| 2708 { | 2847 { |
| 2709 if (numargs < XSUBR (fun)->min_args | 2848 if (numargs < XSUBR (fun)->min_args |
| 2710 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) | 2849 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) |
| 2711 { | 2850 { |
| 2712 XSETFASTINT (lisp_numargs, numargs); | 2851 XSETFASTINT (lisp_numargs, numargs); |
| 2713 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil))); | 2852 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil))); |
| 2714 } | 2853 } |
| 2738 goto done; | 2877 goto done; |
| 2739 case 1: | 2878 case 1: |
| 2740 val = (*XSUBR (fun)->function) (internal_args[0]); | 2879 val = (*XSUBR (fun)->function) (internal_args[0]); |
| 2741 goto done; | 2880 goto done; |
| 2742 case 2: | 2881 case 2: |
| 2743 val = (*XSUBR (fun)->function) (internal_args[0], | 2882 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1]); |
| 2744 internal_args[1]); | |
| 2745 goto done; | 2883 goto done; |
| 2746 case 3: | 2884 case 3: |
| 2747 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | 2885 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], |
| 2748 internal_args[2]); | 2886 internal_args[2]); |
| 2749 goto done; | 2887 goto done; |
| 2750 case 4: | 2888 case 4: |
| 2751 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | 2889 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], |
| 2752 internal_args[2], | 2890 internal_args[2], internal_args[3]); |
| 2753 internal_args[3]); | |
| 2754 goto done; | 2891 goto done; |
| 2755 case 5: | 2892 case 5: |
| 2756 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | 2893 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], |
| 2757 internal_args[2], internal_args[3], | 2894 internal_args[2], internal_args[3], |
| 2758 internal_args[4]); | 2895 internal_args[4]); |
| 2796 if (EQ (funcar, Qlambda)) | 2933 if (EQ (funcar, Qlambda)) |
| 2797 val = funcall_lambda (fun, numargs, args + 1); | 2934 val = funcall_lambda (fun, numargs, args + 1); |
| 2798 else if (EQ (funcar, Qautoload)) | 2935 else if (EQ (funcar, Qautoload)) |
| 2799 { | 2936 { |
| 2800 do_autoload (fun, args[0]); | 2937 do_autoload (fun, args[0]); |
| 2938 CHECK_CONS_LIST (); | |
| 2801 goto retry; | 2939 goto retry; |
| 2802 } | 2940 } |
| 2803 else | 2941 else |
| 2804 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | 2942 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); |
| 2805 } | 2943 } |
| 2806 done: | 2944 done: |
| 2945 CHECK_CONS_LIST (); | |
| 2807 lisp_eval_depth--; | 2946 lisp_eval_depth--; |
| 2808 if (backtrace.debug_on_exit) | 2947 if (backtrace.debug_on_exit) |
| 2809 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); | 2948 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); |
| 2810 backtrace_list = backtrace.next; | 2949 backtrace_list = backtrace.next; |
| 2811 return val; | 2950 return val; |
| 2964 if (specpdl_size >= max_specpdl_size) | 3103 if (specpdl_size >= max_specpdl_size) |
| 2965 { | 3104 { |
| 2966 if (max_specpdl_size < 400) | 3105 if (max_specpdl_size < 400) |
| 2967 max_specpdl_size = 400; | 3106 max_specpdl_size = 400; |
| 2968 if (specpdl_size >= max_specpdl_size) | 3107 if (specpdl_size >= max_specpdl_size) |
| 2969 { | 3108 Fsignal (Qerror, |
| 2970 if (!NILP (Vdebug_on_error)) | 3109 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil)); |
| 2971 /* Leave room for some specpdl in the debugger. */ | |
| 2972 max_specpdl_size = specpdl_size + 100; | |
| 2973 Fsignal (Qerror, | |
| 2974 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil)); | |
| 2975 } | |
| 2976 } | 3110 } |
| 2977 specpdl_size *= 2; | 3111 specpdl_size *= 2; |
| 2978 if (specpdl_size > max_specpdl_size) | 3112 if (specpdl_size > max_specpdl_size) |
| 2979 specpdl_size = max_specpdl_size; | 3113 specpdl_size = max_specpdl_size; |
| 2980 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding)); | 3114 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding)); |
| 3076 Lisp_Object | 3210 Lisp_Object |
| 3077 unbind_to (count, value) | 3211 unbind_to (count, value) |
| 3078 int count; | 3212 int count; |
| 3079 Lisp_Object value; | 3213 Lisp_Object value; |
| 3080 { | 3214 { |
| 3081 int quitf = !NILP (Vquit_flag); | 3215 Lisp_Object quitf = Vquit_flag; |
| 3082 struct gcpro gcpro1; | 3216 struct gcpro gcpro1, gcpro2; |
| 3083 | 3217 |
| 3084 GCPRO1 (value); | 3218 GCPRO2 (value, quitf); |
| 3085 Vquit_flag = Qnil; | 3219 Vquit_flag = Qnil; |
| 3086 | 3220 |
| 3087 while (specpdl_ptr != specpdl + count) | 3221 while (specpdl_ptr != specpdl + count) |
| 3088 { | 3222 { |
| 3089 --specpdl_ptr; | 3223 /* Copy the binding, and decrement specpdl_ptr, before we do |
| 3090 | 3224 the work to unbind it. We decrement first |
| 3091 if (specpdl_ptr->func != 0) | 3225 so that an error in unbinding won't try to unbind |
| 3092 (*specpdl_ptr->func) (specpdl_ptr->old_value); | 3226 the same entry again, and we copy the binding first |
| 3093 /* Note that a "binding" of nil is really an unwind protect, | 3227 in case more bindings are made during some of the code we run. */ |
| 3094 so in that case the "old value" is a list of forms to evaluate. */ | 3228 |
| 3095 else if (NILP (specpdl_ptr->symbol)) | 3229 struct specbinding this_binding; |
| 3096 Fprogn (specpdl_ptr->old_value); | 3230 this_binding = *--specpdl_ptr; |
| 3231 | |
| 3232 if (this_binding.func != 0) | |
| 3233 (*this_binding.func) (this_binding.old_value); | |
| 3097 /* If the symbol is a list, it is really (SYMBOL WHERE | 3234 /* If the symbol is a list, it is really (SYMBOL WHERE |
| 3098 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a | 3235 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a |
| 3099 frame. If WHERE is a buffer or frame, this indicates we | 3236 frame. If WHERE is a buffer or frame, this indicates we |
| 3100 bound a variable that had a buffer-local or frame-local | 3237 bound a variable that had a buffer-local or frame-local |
| 3101 binding. WHERE nil means that the variable had the default | 3238 binding. WHERE nil means that the variable had the default |
| 3102 value when it was bound. CURRENT-BUFFER is the buffer that | 3239 value when it was bound. CURRENT-BUFFER is the buffer that |
| 3103 was current when the variable was bound. */ | 3240 was current when the variable was bound. */ |
| 3104 else if (CONSP (specpdl_ptr->symbol)) | 3241 else if (CONSP (this_binding.symbol)) |
| 3105 { | 3242 { |
| 3106 Lisp_Object symbol, where; | 3243 Lisp_Object symbol, where; |
| 3107 | 3244 |
| 3108 symbol = XCAR (specpdl_ptr->symbol); | 3245 symbol = XCAR (this_binding.symbol); |
| 3109 where = XCAR (XCDR (specpdl_ptr->symbol)); | 3246 where = XCAR (XCDR (this_binding.symbol)); |
| 3110 | 3247 |
| 3111 if (NILP (where)) | 3248 if (NILP (where)) |
| 3112 Fset_default (symbol, specpdl_ptr->old_value); | 3249 Fset_default (symbol, this_binding.old_value); |
| 3113 else if (BUFFERP (where)) | 3250 else if (BUFFERP (where)) |
| 3114 set_internal (symbol, specpdl_ptr->old_value, XBUFFER (where), 1); | 3251 set_internal (symbol, this_binding.old_value, XBUFFER (where), 1); |
| 3115 else | 3252 else |
| 3116 set_internal (symbol, specpdl_ptr->old_value, NULL, 1); | 3253 set_internal (symbol, this_binding.old_value, NULL, 1); |
| 3117 } | 3254 } |
| 3118 else | 3255 else |
| 3119 { | 3256 { |
| 3120 /* If variable has a trivial value (no forwarding), we can | 3257 /* If variable has a trivial value (no forwarding), we can |
| 3121 just set it. No need to check for constant symbols here, | 3258 just set it. No need to check for constant symbols here, |
| 3122 since that was already done by specbind. */ | 3259 since that was already done by specbind. */ |
| 3123 if (!MISCP (SYMBOL_VALUE (specpdl_ptr->symbol))) | 3260 if (!MISCP (SYMBOL_VALUE (this_binding.symbol))) |
| 3124 SET_SYMBOL_VALUE (specpdl_ptr->symbol, specpdl_ptr->old_value); | 3261 SET_SYMBOL_VALUE (this_binding.symbol, this_binding.old_value); |
| 3125 else | 3262 else |
| 3126 set_internal (specpdl_ptr->symbol, specpdl_ptr->old_value, 0, 1); | 3263 set_internal (this_binding.symbol, this_binding.old_value, 0, 1); |
| 3127 } | 3264 } |
| 3128 } | 3265 } |
| 3129 | 3266 |
| 3130 if (NILP (Vquit_flag) && quitf) | 3267 if (NILP (Vquit_flag) && !NILP (quitf)) |
| 3131 Vquit_flag = Qt; | 3268 Vquit_flag = quitf; |
| 3132 | 3269 |
| 3133 UNGCPRO; | 3270 UNGCPRO; |
| 3134 return value; | 3271 return value; |
| 3135 } | 3272 } |
| 3136 | 3273 |
| 3252 } | 3389 } |
| 3253 } | 3390 } |
| 3254 | 3391 |
| 3255 | 3392 |
| 3256 void | 3393 void |
| 3394 mark_backtrace () | |
| 3395 { | |
| 3396 register struct backtrace *backlist; | |
| 3397 register int i; | |
| 3398 | |
| 3399 for (backlist = backtrace_list; backlist; backlist = backlist->next) | |
| 3400 { | |
| 3401 mark_object (*backlist->function); | |
| 3402 | |
| 3403 if (backlist->nargs == UNEVALLED || backlist->nargs == MANY) | |
| 3404 i = 0; | |
| 3405 else | |
| 3406 i = backlist->nargs - 1; | |
| 3407 for (; i >= 0; i--) | |
| 3408 mark_object (backlist->args[i]); | |
| 3409 } | |
| 3410 } | |
| 3411 | |
| 3412 void | |
| 3257 syms_of_eval () | 3413 syms_of_eval () |
| 3258 { | 3414 { |
| 3259 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size, | 3415 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size, |
| 3260 doc: /* *Limit on number of Lisp variable bindings & unwind-protects. | 3416 doc: /* *Limit on number of Lisp variable bindings and `unwind-protect's. |
| 3261 If Lisp code tries to make more than this many at once, | 3417 If Lisp code tries to increase the total number past this amount, |
| 3262 an error is signaled. | 3418 an error is signaled. |
| 3263 You can safely use a value considerably larger than the default value, | 3419 You can safely use a value considerably larger than the default value, |
| 3264 if that proves inconveniently small. However, if you increase it too far, | 3420 if that proves inconveniently small. However, if you increase it too far, |
| 3265 Emacs could run out of memory trying to make the stack bigger. */); | 3421 Emacs could run out of memory trying to make the stack bigger. */); |
| 3266 | 3422 |
| 3273 if that proves inconveniently small. However, if you increase it too far, | 3429 if that proves inconveniently small. However, if you increase it too far, |
| 3274 Emacs could overflow the real C stack, and crash. */); | 3430 Emacs could overflow the real C stack, and crash. */); |
| 3275 | 3431 |
| 3276 DEFVAR_LISP ("quit-flag", &Vquit_flag, | 3432 DEFVAR_LISP ("quit-flag", &Vquit_flag, |
| 3277 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil. | 3433 doc: /* Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil. |
| 3278 Typing C-g sets `quit-flag' non-nil, regardless of `inhibit-quit'. */); | 3434 If the value is t, that means do an ordinary quit. |
| 3435 If the value equals `throw-on-input', that means quit by throwing | |
| 3436 to the tag specified in `throw-on-input'; it's for handling `while-no-input'. | |
| 3437 Typing C-g sets `quit-flag' to t, regardless of `inhibit-quit', | |
| 3438 but `inhibit-quit' non-nil prevents anything from taking notice of that. */); | |
| 3279 Vquit_flag = Qnil; | 3439 Vquit_flag = Qnil; |
| 3280 | 3440 |
| 3281 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit, | 3441 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit, |
| 3282 doc: /* Non-nil inhibits C-g quitting from happening immediately. | 3442 doc: /* Non-nil inhibits C-g quitting from happening immediately. |
| 3283 Note that `quit-flag' will still be set by typing C-g, | 3443 Note that `quit-flag' will still be set by typing C-g, |
| 3312 Qcommandp = intern ("commandp"); | 3472 Qcommandp = intern ("commandp"); |
| 3313 staticpro (&Qcommandp); | 3473 staticpro (&Qcommandp); |
| 3314 | 3474 |
| 3315 Qdefun = intern ("defun"); | 3475 Qdefun = intern ("defun"); |
| 3316 staticpro (&Qdefun); | 3476 staticpro (&Qdefun); |
| 3317 | |
| 3318 Qdefvar = intern ("defvar"); | |
| 3319 staticpro (&Qdefvar); | |
| 3320 | 3477 |
| 3321 Qand_rest = intern ("&rest"); | 3478 Qand_rest = intern ("&rest"); |
| 3322 staticpro (&Qand_rest); | 3479 staticpro (&Qand_rest); |
| 3323 | 3480 |
| 3324 Qand_optional = intern ("&optional"); | 3481 Qand_optional = intern ("&optional"); |
| 3351 This overrides the variable `debug-on-error'. | 3508 This overrides the variable `debug-on-error'. |
| 3352 It does not apply to errors handled by `condition-case'. */); | 3509 It does not apply to errors handled by `condition-case'. */); |
| 3353 Vdebug_ignored_errors = Qnil; | 3510 Vdebug_ignored_errors = Qnil; |
| 3354 | 3511 |
| 3355 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit, | 3512 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit, |
| 3356 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example). | 3513 doc: /* *Non-nil means enter debugger if quit is signaled (C-g, for example). |
| 3357 Does not apply if quit is handled by a `condition-case'. | 3514 Does not apply if quit is handled by a `condition-case'. */); |
| 3358 When you evaluate an expression interactively, this variable | |
| 3359 is temporarily non-nil if `eval-expression-debug-on-quit' is non-nil. */); | |
| 3360 debug_on_quit = 0; | 3515 debug_on_quit = 0; |
| 3361 | 3516 |
| 3362 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call, | 3517 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call, |
| 3363 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */); | 3518 doc: /* Non-nil means enter debugger before next `eval', `apply' or `funcall'. */); |
| 3364 | 3519 |
| 3429 defsubr (&Sthrow); | 3584 defsubr (&Sthrow); |
| 3430 defsubr (&Sunwind_protect); | 3585 defsubr (&Sunwind_protect); |
| 3431 defsubr (&Scondition_case); | 3586 defsubr (&Scondition_case); |
| 3432 defsubr (&Ssignal); | 3587 defsubr (&Ssignal); |
| 3433 defsubr (&Sinteractive_p); | 3588 defsubr (&Sinteractive_p); |
| 3589 defsubr (&Scalled_interactively_p); | |
| 3434 defsubr (&Scommandp); | 3590 defsubr (&Scommandp); |
| 3435 defsubr (&Sautoload); | 3591 defsubr (&Sautoload); |
| 3436 defsubr (&Seval); | 3592 defsubr (&Seval); |
| 3437 defsubr (&Sapply); | 3593 defsubr (&Sapply); |
| 3438 defsubr (&Sfuncall); | 3594 defsubr (&Sfuncall); |
| 3443 defsubr (&Sfetch_bytecode); | 3599 defsubr (&Sfetch_bytecode); |
| 3444 defsubr (&Sbacktrace_debug); | 3600 defsubr (&Sbacktrace_debug); |
| 3445 defsubr (&Sbacktrace); | 3601 defsubr (&Sbacktrace); |
| 3446 defsubr (&Sbacktrace_frame); | 3602 defsubr (&Sbacktrace_frame); |
| 3447 } | 3603 } |
| 3604 | |
| 3605 /* arch-tag: 014a07aa-33ab-4a8f-a3d2-ee8a4a9ff7fb | |
| 3606 (do not change this comment) */ |
