unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Andreas Röhler" <andreas.roehler@online.de>
To: emacs-devel@gnu.org
Cc: John Wiegley <johnw@newartisans.com>,
	bruce.connor.am@gmail.com, raman <raman@google.com>
Subject: Re: Suggest: dont declare interactive-p obsolete
Date: Thu, 19 Nov 2015 14:06:21 +0100	[thread overview]
Message-ID: <564DC94D.8010002@online.de> (raw)
In-Reply-To: <CAAdUY-+BqBmS07MxBt-V04vNTSHR6qHTW_3LnJ+THcxJzingwQ@mail.gmail.com>

  On 19.11.2015 09:39, Artur Malabarba wrote:
> 2015-11-19 4:16 GMT+00:00 John Wiegley<jwiegley@gmail.com>:
>>>>>>> raman<raman@google.com>  writes:
>>> This is a minor change -- that will let existing code run without warnings.
>>> If we turned the defun in subr.el to a defsubst and dropped the (declare
>>> (obsolete called-interactively-p "23.2")) (called-interactively-p
>>> 'interactive))
>> I don't see any downsides to this; others?
> I wasn't here when this function was made obsolete, but I can think of
> a couple of downsides:
>
> 1. Code duplication (sure, the code is already duplicated, but by
> keeping it obsolete we can hopefully remove it soon).
> 2. The name interactive-p makes it sound like it's equivalent to `(not
> noninteractive)', which determines whether Emacs itself (not the
> function) is running interactively. While `called-interactively-p' is
> more obviously about how the function was called.
>
> By my estimates, this function was made obsolete 5 years ago. And it
> _is_ obsolete.

Don't think so. Its replacement is not only hard to code, it's a monster.
The docu says all:

Return t if the containing function was called by `call-interactively'.
If KIND is `interactive', then only return t if the call was made
interactively by the user, i.e. not in `noninteractive' mode nor
when `executing-kbd-macro'.
If KIND is `any', on the other hand, it will return t for any kind of
interactive call, including being called as the binding of a key or
from a keyboard macro, even in `noninteractive' mode.

This function is very brittle, it may fail to return the intended result when
the code is debugged, advised, or instrumented in some form.  Some macros and
special forms (such as `condition-case') may also sometimes wrap their bodies
in a `lambda', so any call to `called-interactively-p' from those bodies will
indicate whether that lambda (rather than the surrounding function) was called
interactively.

Instead of using this function, it is cleaner and more reliable to give your
function an extra optional argument whose `interactive' spec specifies
non-nil unconditionally (\"p\" is a good way to do this), or via
\(not (or executing-kbd-macro noninteractive)).

The only known proper use of `interactive' for KIND 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?



> IMHO, packages that try to support Emacs releases 6 years apart (as
> noble as that is) can't expect to be able to do that without a few
> warnings. There are ways for such packages to suppress these warnings.
> But it's important to keep them to prevent this function from
> spreading.
>




  reply	other threads:[~2015-11-19 13:06 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-19  1:57 Suggest: dont declare interactive-p obsolete raman
2015-11-19  4:16 ` John Wiegley
2015-11-19  8:39   ` Artur Malabarba
2015-11-19 13:06     ` Andreas Röhler [this message]
2015-11-19 13:46       ` Dmitry Gutov
2015-11-20  7:29         ` Andreas Röhler
2015-11-19 13:44     ` Dmitry Gutov
2015-11-19 15:29   ` Eli Zaretskii
2015-11-19 16:25     ` John Wiegley
2015-11-19 17:32       ` raman
2015-11-19 17:47         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=564DC94D.8010002@online.de \
    --to=andreas.roehler@online.de \
    --cc=bruce.connor.am@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=johnw@newartisans.com \
    --cc=raman@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).