all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* interactive-p and called-interactively-p
@ 2009-08-15 23:00 Drew Adams
  2009-08-16  5:16 ` Stefan Monnier
  0 siblings, 1 reply; 27+ messages in thread
From: Drew Adams @ 2009-08-15 23:00 UTC (permalink / raw)
  To: emacs-devel

1. The doc for these two functions is a mess - see bug #3941.

2. Beyond the doc problem, but related to it, there is a non-doc problem:
Whoever came up with the new function (in Emacs 22) `called-interactively-p' did
the wrong thing, IMO.

That function name tells nothing more nor less than the name `interactive-p'
tells. There is nothing in the _names_ that distinguishes these two functions.
Might as well have named the new function `interactive-p-2' (no, it's not a
suggestion).

This fact is a sign that the design is wrong, for if we did come up with names
that suggest the distinction, we would soon see that using two different
functions is the wrong approach. This is really one function with two minor
behavioral variants.

It would have been far better to just add an optional argument to
`interactive-p' than to create a new, similarly named function. For example:

(defun interactive-p (&optional k-macro-p)
  "Return t if the function in which this appears was called interactively.
If optional arg K-MACRO-P is non-nil, return t when called during
execution of a keyboard macro. If it is nil, return nil in that case.
...[rest of description]"

Leaving the status quo in place will bring nothing but confusion, no matter how
the doc is improved. It is better to just DTRT now.

I vote for deprecating one or the other of these two functions, combining them
by using an optional argument to express the alternative behaviors. That will go
a long way toward clarifying the intended uses.





^ permalink raw reply	[flat|nested] 27+ messages in thread
* Re: interactive-p and called-interactively-p
@ 2009-09-03 16:27 MON KEY
  0 siblings, 0 replies; 27+ messages in thread
From: MON KEY @ 2009-09-03 16:27 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> So if we obsolete interactive-p we may as well
> introduce a brand new function with a mandatory argument.  The only
> problem with it would be to find a good name for it, since
> called-interactively-p is already taken.

I've been using one these in a functions' lambda list behind &optional:
interp intrp inter-p intr-p

I think these are clear, reasonably terse,  and in keeping with the
suggestions of docstring for `interactive-p':

,----
| 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.)'
`----

s_P




^ permalink raw reply	[flat|nested] 27+ messages in thread
* interactive-p and called-interactively-p
@ 2004-12-02  2:16 Luc Teirlinck
  2004-12-03  3:41 ` Richard Stallman
  0 siblings, 1 reply; 27+ messages in thread
From: Luc Teirlinck @ 2004-12-02  2:16 UTC (permalink / raw)


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;
}

^ permalink raw reply	[flat|nested] 27+ messages in thread

end of thread, other threads:[~2009-09-04 13:11 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-15 23:00 interactive-p and called-interactively-p Drew Adams
2009-08-16  5:16 ` Stefan Monnier
2009-08-16 13:29   ` Chong Yidong
2009-08-16 14:53     ` Stefan Monnier
2009-08-16 15:51     ` Drew Adams
2009-08-16 21:23   ` Richard Stallman
2009-08-16 22:40     ` Drew Adams
2009-08-17  5:38     ` Stephen J. Turnbull
2009-08-18  4:57       ` Richard Stallman
2009-08-18  7:08         ` Stephen J. Turnbull
2009-08-29 21:54     ` Stefan Monnier
2009-08-31 22:21       ` Richard Stallman
2009-08-31 23:56         ` Stefan Monnier
2009-09-01  1:58           ` Chong Yidong
2009-09-01  5:40             ` Stefan Monnier
2009-09-01 21:20               ` Richard Stallman
2009-09-01 23:30                 ` Stefan Monnier
2009-09-03 13:48                   ` Richard Stallman
2009-09-03 14:11                     ` Stephen J. Turnbull
2009-09-03 21:17                       ` Stefan Monnier
2009-09-04  1:21                         ` Stephen J. Turnbull
2009-09-04 13:11                           ` Stefan Monnier
2009-09-04  3:04                         ` Glenn Morris
2009-09-04  4:44                           ` Stephen J. Turnbull
  -- strict thread matches above, loose matches on Subject: below --
2009-09-03 16:27 MON KEY
2004-12-02  2:16 Luc Teirlinck
2004-12-03  3:41 ` Richard Stallman

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.