emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

interactive-p and called-interactively-p


From: Luc Teirlinck
Subject: interactive-p and called-interactively-p
Date: Wed, 1 Dec 2004 20:16:17 -0600 (CST)

I know what the difference between interactive-p and
called-interactively-p is _supposed_ to be.  However is something
completely escaping me or are these two functions identical except for
their docstrings?

DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
       doc: /* Return t if the function was run directly by user
       input.
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),
and Emacs is not running in batch mode (`noninteractive' is nil).

The only known proper use of `interactive-p' is in deciding whether to
display a helpful message, or how to display it.  If you're thinking
of using it for any other purpose, it is quite likely that you're
making a mistake.  Think: what do you want to do when the command is
called from a keyboard macro?

If you want to test whether your function was called with
`call-interactively', the way to do that is by adding an extra
optional argument, and making the `interactive' spec specify non-nil
unconditionally for that argument.  (`p' is a good way to do this.)
*/)
     ()
{
  return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
}


DEFUN ("called-interactively-p", Fcalled_interactively_p,
Scalled_interactively_p, 0, 0, 0,
       doc: /* Return t if the function using this was called with
call-interactively.
This is used for implementing advice and other function-modifying
features of Emacs.

The cleanest way to test whether your function was called with
`call-interactively', the way to do that is by adding an extra
optional argument, and making the `interactive' spec specify non-nil
unconditionally for that argument.  (`p' is a good way to do this.)
*/)
     ()
{
  return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]