# HG changeset patch # User Gerd Moellmann # Date 980952511 0 # Node ID efc51d1a7b604365f10963d17a0fbc674ac9b79d # Parent 04bb0b45e18c145874a4cc39119201a23620e90a (interactive_p): New function. (Finteractive_p): Use it. diff -r 04bb0b45e18c -r efc51d1a7b60 src/eval.c --- a/src/eval.c Wed Jan 31 14:48:07 2001 +0000 +++ b/src/eval.c Wed Jan 31 14:48:31 2001 +0000 @@ -1,5 +1,5 @@ /* Evaluator for GNU Emacs Lisp interpreter. - Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000 + Copyright (C) 1985, 86, 87, 93, 94, 95, 99, 2000, 2001 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -551,6 +551,7 @@ return Fcar (args); } + DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0, "Return t if function in which this appears was called interactively.\n\ This means that the function was called with call-interactively (which\n\ @@ -558,16 +559,33 @@ and input is currently coming from the keyboard (not in keyboard macro).") () { - register struct backtrace *btp; - register Lisp_Object fun; + return interactive_p (1) ? Qt : Qnil; +} + + +/* Return 1 if function in which this appears was called + interactively. This means that the function was called with + call-interactively (which includes being called as the binding of + a key) and input is currently coming from the keyboard (not in + keyboard macro). + + EXCLUDE_SUBRS_P non-zero means always return 0 if the function + called is a built-in. */ + +int +interactive_p (exclude_subrs_p) + int exclude_subrs_p; +{ + struct backtrace *btp; + Lisp_Object fun; if (!INTERACTIVE) - return Qnil; + return 0; btp = backtrace_list; /* If this isn't a byte-compiled function, there may be a frame at - the top for Finteractive_p itself. If so, skip it. */ + the top for Finteractive_p. If so, skip it. */ fun = Findirect_function (*btp->function); if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p) btp = btp->next; @@ -591,15 +609,17 @@ Fbytecode at the top. If this frame is for a built-in function (such as load or eval-region) return nil. */ fun = Findirect_function (*btp->function); - if (SUBRP (fun)) - return Qnil; + if (exclude_subrs_p && SUBRP (fun)) + return 0; + /* btp points to the frame of a Lisp function that called interactive-p. Return t if that function was called interactively. */ if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively)) - return Qt; - return Qnil; + return 1; + return 0; } + DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0, "Define NAME as a function.\n\ The definition is (lambda ARGLIST [DOCSTRING] BODY...).\n\