diff options
Diffstat (limited to 'src/eval.c')
| -rw-r--r-- | src/eval.c | 132 |
1 files changed, 17 insertions, 115 deletions
diff --git a/src/eval.c b/src/eval.c index f8a76646352..34b20f6fc8e 100644 --- a/src/eval.c +++ b/src/eval.c | |||
| @@ -114,7 +114,6 @@ Lisp_Object Vsignaling_function; | |||
| 114 | Lisp_Object inhibit_lisp_code; | 114 | Lisp_Object inhibit_lisp_code; |
| 115 | 115 | ||
| 116 | static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); | 116 | static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); |
| 117 | static bool interactive_p (void); | ||
| 118 | static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); | 117 | static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); |
| 119 | 118 | ||
| 120 | /* Functions to set Lisp_Object slots of struct specbinding. */ | 119 | /* Functions to set Lisp_Object slots of struct specbinding. */ |
| @@ -489,102 +488,6 @@ usage: (function ARG) */) | |||
| 489 | } | 488 | } |
| 490 | 489 | ||
| 491 | 490 | ||
| 492 | DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0, | ||
| 493 | doc: /* Return t if the containing function was run directly by user input. | ||
| 494 | This means that the function was called with `call-interactively' | ||
| 495 | \(which includes being called as the binding of a key) | ||
| 496 | and input is currently coming from the keyboard (not a keyboard macro), | ||
| 497 | and Emacs is not running in batch mode (`noninteractive' is nil). | ||
| 498 | |||
| 499 | The only known proper use of `interactive-p' is in deciding whether to | ||
| 500 | display a helpful message, or how to display it. If you're thinking | ||
| 501 | of using it for any other purpose, it is quite likely that you're | ||
| 502 | making a mistake. Think: what do you want to do when the command is | ||
| 503 | called from a keyboard macro? | ||
| 504 | |||
| 505 | To test whether your function was called with `call-interactively', | ||
| 506 | either (i) add an extra optional argument and give it an `interactive' | ||
| 507 | spec that specifies non-nil unconditionally (such as \"p\"); or (ii) | ||
| 508 | use `called-interactively-p'. */) | ||
| 509 | (void) | ||
| 510 | { | ||
| 511 | return (INTERACTIVE && interactive_p ()) ? Qt : Qnil; | ||
| 512 | } | ||
| 513 | |||
| 514 | |||
| 515 | DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 1, 0, | ||
| 516 | doc: /* Return t if the containing function was called by `call-interactively'. | ||
| 517 | If KIND is `interactive', then only return t if the call was made | ||
| 518 | interactively by the user, i.e. not in `noninteractive' mode nor | ||
| 519 | when `executing-kbd-macro'. | ||
| 520 | If KIND is `any', on the other hand, it will return t for any kind of | ||
| 521 | interactive call, including being called as the binding of a key, or | ||
| 522 | from a keyboard macro, or in `noninteractive' mode. | ||
| 523 | |||
| 524 | The only known proper use of `interactive' for KIND is in deciding | ||
| 525 | whether to display a helpful message, or how to display it. If you're | ||
| 526 | thinking of using it for any other purpose, it is quite likely that | ||
| 527 | you're making a mistake. Think: what do you want to do when the | ||
| 528 | command is called from a keyboard macro? | ||
| 529 | |||
| 530 | Instead of using this function, it is sometimes cleaner to give your | ||
| 531 | function an extra optional argument whose `interactive' spec specifies | ||
| 532 | non-nil unconditionally (\"p\" is a good way to do this), or via | ||
| 533 | \(not (or executing-kbd-macro noninteractive)). */) | ||
| 534 | (Lisp_Object kind) | ||
| 535 | { | ||
| 536 | return (((INTERACTIVE || !EQ (kind, intern ("interactive"))) | ||
| 537 | && interactive_p ()) | ||
| 538 | ? Qt : Qnil); | ||
| 539 | } | ||
| 540 | |||
| 541 | |||
| 542 | /* Return true if function in which this appears was called using | ||
| 543 | call-interactively and is not a built-in. */ | ||
| 544 | |||
| 545 | static bool | ||
| 546 | interactive_p (void) | ||
| 547 | { | ||
| 548 | struct backtrace *btp; | ||
| 549 | Lisp_Object fun; | ||
| 550 | |||
| 551 | btp = backtrace_list; | ||
| 552 | |||
| 553 | /* If this isn't a byte-compiled function, there may be a frame at | ||
| 554 | the top for Finteractive_p. If so, skip it. */ | ||
| 555 | fun = Findirect_function (btp->function, Qnil); | ||
| 556 | if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p | ||
| 557 | || XSUBR (fun) == &Scalled_interactively_p)) | ||
| 558 | btp = btp->next; | ||
| 559 | |||
| 560 | /* If we're running an Emacs 18-style byte-compiled function, there | ||
| 561 | may be a frame for Fbytecode at the top level. In any version of | ||
| 562 | Emacs there can be Fbytecode frames for subexpressions evaluated | ||
| 563 | inside catch and condition-case. Skip past them. | ||
| 564 | |||
| 565 | If this isn't a byte-compiled function, then we may now be | ||
| 566 | looking at several frames for special forms. Skip past them. */ | ||
| 567 | while (btp | ||
| 568 | && (EQ (btp->function, Qbytecode) | ||
| 569 | || btp->nargs == UNEVALLED)) | ||
| 570 | btp = btp->next; | ||
| 571 | |||
| 572 | /* `btp' now points at the frame of the innermost function that isn't | ||
| 573 | a special form, ignoring frames for Finteractive_p and/or | ||
| 574 | Fbytecode at the top. If this frame is for a built-in function | ||
| 575 | (such as load or eval-region) return false. */ | ||
| 576 | fun = Findirect_function (btp->function, Qnil); | ||
| 577 | if (SUBRP (fun)) | ||
| 578 | return 0; | ||
| 579 | |||
| 580 | /* `btp' points to the frame of a Lisp function that called interactive-p. | ||
| 581 | Return t if that function was called interactively. */ | ||
| 582 | if (btp && btp->next && EQ (btp->next->function, Qcall_interactively)) | ||
| 583 | return 1; | ||
| 584 | return 0; | ||
| 585 | } | ||
| 586 | |||
| 587 | |||
| 588 | DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0, | 491 | DEFUN ("defvaralias", Fdefvaralias, Sdefvaralias, 2, 3, 0, |
| 589 | doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE. | 492 | doc: /* Make NEW-ALIAS a variable alias for symbol BASE-VARIABLE. |
| 590 | Aliased variables always have the same value; setting one sets the other. | 493 | Aliased variables always have the same value; setting one sets the other. |
| @@ -696,8 +599,9 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | |||
| 696 | if (EQ ((--pdl)->symbol, sym) && !pdl->func | 599 | if (EQ ((--pdl)->symbol, sym) && !pdl->func |
| 697 | && EQ (pdl->old_value, Qunbound)) | 600 | && EQ (pdl->old_value, Qunbound)) |
| 698 | { | 601 | { |
| 699 | message_with_string ("Warning: defvar ignored because %s is let-bound", | 602 | message_with_string |
| 700 | SYMBOL_NAME (sym), 1); | 603 | ("Warning: defvar ignored because %s is let-bound", |
| 604 | SYMBOL_NAME (sym), 1); | ||
| 701 | break; | 605 | break; |
| 702 | } | 606 | } |
| 703 | } | 607 | } |
| @@ -717,8 +621,8 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) | |||
| 717 | /* A simple (defvar foo) with lexical scoping does "nothing" except | 621 | /* A simple (defvar foo) with lexical scoping does "nothing" except |
| 718 | declare that var to be dynamically scoped *locally* (i.e. within | 622 | declare that var to be dynamically scoped *locally* (i.e. within |
| 719 | the current file or let-block). */ | 623 | the current file or let-block). */ |
| 720 | Vinternal_interpreter_environment = | 624 | Vinternal_interpreter_environment |
| 721 | Fcons (sym, Vinternal_interpreter_environment); | 625 | = Fcons (sym, Vinternal_interpreter_environment); |
| 722 | else | 626 | else |
| 723 | { | 627 | { |
| 724 | /* Simple (defvar <var>) should not count as a definition at all. | 628 | /* Simple (defvar <var>) should not count as a definition at all. |
| @@ -971,7 +875,7 @@ definitions to shadow the loaded ones for use in file byte-compilation. */) | |||
| 971 | if (NILP (tem)) | 875 | if (NILP (tem)) |
| 972 | { | 876 | { |
| 973 | def = XSYMBOL (sym)->function; | 877 | def = XSYMBOL (sym)->function; |
| 974 | if (!EQ (def, Qunbound)) | 878 | if (!NILP (def)) |
| 975 | continue; | 879 | continue; |
| 976 | } | 880 | } |
| 977 | break; | 881 | break; |
| @@ -986,7 +890,7 @@ definitions to shadow the loaded ones for use in file byte-compilation. */) | |||
| 986 | GCPRO1 (form); | 890 | GCPRO1 (form); |
| 987 | def = Fautoload_do_load (def, sym, Qmacro); | 891 | def = Fautoload_do_load (def, sym, Qmacro); |
| 988 | UNGCPRO; | 892 | UNGCPRO; |
| 989 | if (EQ (def, Qunbound) || !CONSP (def)) | 893 | if (!CONSP (def)) |
| 990 | /* Not defined or definition not suitable. */ | 894 | /* Not defined or definition not suitable. */ |
| 991 | break; | 895 | break; |
| 992 | if (!EQ (XCAR (def), Qmacro)) | 896 | if (!EQ (XCAR (def), Qmacro)) |
| @@ -1811,12 +1715,12 @@ then strings and vectors are not accepted. */) | |||
| 1811 | 1715 | ||
| 1812 | fun = function; | 1716 | fun = function; |
| 1813 | 1717 | ||
| 1814 | fun = indirect_function (fun); /* Check cycles. */ | 1718 | fun = indirect_function (fun); /* Check cycles. */ |
| 1815 | if (NILP (fun) || EQ (fun, Qunbound)) | 1719 | if (NILP (fun)) |
| 1816 | return Qnil; | 1720 | return Qnil; |
| 1817 | 1721 | ||
| 1818 | /* Check an `interactive-form' property if present, analogous to the | 1722 | /* Check an `interactive-form' property if present, analogous to the |
| 1819 | function-documentation property. */ | 1723 | function-documentation property. */ |
| 1820 | fun = function; | 1724 | fun = function; |
| 1821 | while (SYMBOLP (fun)) | 1725 | while (SYMBOLP (fun)) |
| 1822 | { | 1726 | { |
| @@ -1876,7 +1780,7 @@ this does nothing and returns nil. */) | |||
| 1876 | CHECK_STRING (file); | 1780 | CHECK_STRING (file); |
| 1877 | 1781 | ||
| 1878 | /* If function is defined and not as an autoload, don't override. */ | 1782 | /* If function is defined and not as an autoload, don't override. */ |
| 1879 | if (!EQ (XSYMBOL (function)->function, Qunbound) | 1783 | if (!NILP (XSYMBOL (function)->function) |
| 1880 | && !AUTOLOADP (XSYMBOL (function)->function)) | 1784 | && !AUTOLOADP (XSYMBOL (function)->function)) |
| 1881 | return Qnil; | 1785 | return Qnil; |
| 1882 | 1786 | ||
| @@ -2055,7 +1959,7 @@ eval_sub (Lisp_Object form) | |||
| 2055 | 1959 | ||
| 2056 | /* Optimize for no indirection. */ | 1960 | /* Optimize for no indirection. */ |
| 2057 | fun = original_fun; | 1961 | fun = original_fun; |
| 2058 | if (SYMBOLP (fun) && !EQ (fun, Qunbound) | 1962 | if (SYMBOLP (fun) && !NILP (fun) |
| 2059 | && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) | 1963 | && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) |
| 2060 | fun = indirect_function (fun); | 1964 | fun = indirect_function (fun); |
| 2061 | 1965 | ||
| @@ -2177,7 +2081,7 @@ eval_sub (Lisp_Object form) | |||
| 2177 | val = apply_lambda (fun, original_args); | 2081 | val = apply_lambda (fun, original_args); |
| 2178 | else | 2082 | else |
| 2179 | { | 2083 | { |
| 2180 | if (EQ (fun, Qunbound)) | 2084 | if (NILP (fun)) |
| 2181 | xsignal1 (Qvoid_function, original_fun); | 2085 | xsignal1 (Qvoid_function, original_fun); |
| 2182 | if (!CONSP (fun)) | 2086 | if (!CONSP (fun)) |
| 2183 | xsignal1 (Qinvalid_function, original_fun); | 2087 | xsignal1 (Qinvalid_function, original_fun); |
| @@ -2251,10 +2155,10 @@ usage: (apply FUNCTION &rest ARGUMENTS) */) | |||
| 2251 | numargs += nargs - 2; | 2155 | numargs += nargs - 2; |
| 2252 | 2156 | ||
| 2253 | /* Optimize for no indirection. */ | 2157 | /* Optimize for no indirection. */ |
| 2254 | if (SYMBOLP (fun) && !EQ (fun, Qunbound) | 2158 | if (SYMBOLP (fun) && !NILP (fun) |
| 2255 | && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) | 2159 | && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) |
| 2256 | fun = indirect_function (fun); | 2160 | fun = indirect_function (fun); |
| 2257 | if (EQ (fun, Qunbound)) | 2161 | if (NILP (fun)) |
| 2258 | { | 2162 | { |
| 2259 | /* Let funcall get the error. */ | 2163 | /* Let funcall get the error. */ |
| 2260 | fun = args[0]; | 2164 | fun = args[0]; |
| @@ -2728,7 +2632,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */) | |||
| 2728 | 2632 | ||
| 2729 | /* Optimize for no indirection. */ | 2633 | /* Optimize for no indirection. */ |
| 2730 | fun = original_fun; | 2634 | fun = original_fun; |
| 2731 | if (SYMBOLP (fun) && !EQ (fun, Qunbound) | 2635 | if (SYMBOLP (fun) && !NILP (fun) |
| 2732 | && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) | 2636 | && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) |
| 2733 | fun = indirect_function (fun); | 2637 | fun = indirect_function (fun); |
| 2734 | 2638 | ||
| @@ -2816,7 +2720,7 @@ usage: (funcall FUNCTION &rest ARGUMENTS) */) | |||
| 2816 | val = funcall_lambda (fun, numargs, args + 1); | 2720 | val = funcall_lambda (fun, numargs, args + 1); |
| 2817 | else | 2721 | else |
| 2818 | { | 2722 | { |
| 2819 | if (EQ (fun, Qunbound)) | 2723 | if (NILP (fun)) |
| 2820 | xsignal1 (Qvoid_function, original_fun); | 2724 | xsignal1 (Qvoid_function, original_fun); |
| 2821 | if (!CONSP (fun)) | 2725 | if (!CONSP (fun)) |
| 2822 | xsignal1 (Qinvalid_function, original_fun); | 2726 | xsignal1 (Qinvalid_function, original_fun); |
| @@ -3551,8 +3455,6 @@ alist of active lexical bindings. */); | |||
| 3551 | defsubr (&Sunwind_protect); | 3455 | defsubr (&Sunwind_protect); |
| 3552 | defsubr (&Scondition_case); | 3456 | defsubr (&Scondition_case); |
| 3553 | defsubr (&Ssignal); | 3457 | defsubr (&Ssignal); |
| 3554 | defsubr (&Sinteractive_p); | ||
| 3555 | defsubr (&Scalled_interactively_p); | ||
| 3556 | defsubr (&Scommandp); | 3458 | defsubr (&Scommandp); |
| 3557 | defsubr (&Sautoload); | 3459 | defsubr (&Sautoload); |
| 3558 | defsubr (&Sautoload_do_load); | 3460 | defsubr (&Sautoload_do_load); |