all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Richard Stallman <rms@gnu.org>
To: Dmitri Paduchikh <dpaduchikh@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Brittleness of called-interactively-p
Date: Sun, 12 Jul 2015 17:59:22 -0400	[thread overview]
Message-ID: <E1ZEPHO-0003iL-5p@fencepost.gnu.org> (raw)
In-Reply-To: <871tgeufzt.fsf@gmail.com> (message from Dmitri Paduchikh on Sun,  12 Jul 2015 10:00:54 +0500)

[[[ To any NSA and FBI agents reading my email: please consider    ]]]
[[[ whether defending the US Constitution against all enemies,     ]]]
[[[ foreign or domestic, requires you to follow Snowden's example. ]]]

  > 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.

This is simply a bug.  We should fix it to work with the debugger,
and programs that advise or instrument code should have a documented
way to arrange for 'called-interactively-p' to keep working.

  > I would like to make a suggestion. All these problems can be resolved by
  > introducing a special (dynamically bound) variable. Each call -- not only
  > interactive -- to an interactive function would rebind it to the value
  > providing all the necessary information about interactiveness of this call.

This could work, but it would use the specpdl in an inefficient way,
making many bindings that will never be used.

There is also a speed issue: every function call would need to check
whether the called function has an interactive spec.  But maybe it won't
be very bad.

Here's another approach: give 'interactive' a way to specify a
variable to bind for this purpose.  That way, the variable would be
bound only in functions that want it, and it would not interfere with
the function's calling interface.

The variable could be written as the second argument of 'interactive'.

If we want to preserve the principle that 'interactive' has no effect
on actual execution of a call to the function, we could make a new
name so that (was-interactive foo) in the function body binds foo to a
suitable value for the rest of the function body.

To get the right results when advising or instrumenting code, we could
define (advised-interactive foo) as an alternative to use in wrappers.

(defun foo (y)
  (interactive)
  (was-interactive in-foo)
  ...)

(lambda (x) (advised-interactive in-foo) (message "I am at foo") (foo x))

When the lambda gets called, 'advised-interactive' will bind 'in-foo'
to say whether the call was interactive, and it will suppress the
'was-interactive' form in 'foo' from binding 'in-foo' (because they
bind the same variable).

We could also write them as

  (was-interactive (VAR) BODY...)
  (advised-interactive (VAR) BODY...)

This is cleaner in that the scope of VAR is shown explicitly,
but people would be surprised that these don't work when
nested inside any other construct.

-- 
Dr Richard Stallman
President, Free Software Foundation (gnu.org, fsf.org)
Internet Hall-of-Famer (internethalloffame.org)
Skype: No way! See stallman.org/skype.html.




  parent reply	other threads:[~2015-07-12 21:59 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-12  5:00 Brittleness of called-interactively-p Dmitri Paduchikh
2015-07-12 13:53 ` Stefan Monnier
2015-07-12 15:17   ` Dmitri Paduchikh
2015-07-12 23:26     ` Stefan Monnier
2015-07-13 15:17       ` Dmitri Paduchikh
2015-07-14 23:24         ` Stefan Monnier
2015-07-16 15:57           ` raman
2015-07-16 17:36             ` Drew Adams
2015-07-16 17:58               ` T.V Raman
2015-07-17  1:55                 ` Richard Stallman
2015-07-17  4:52                   ` Dmitri Paduchikh
2015-07-17 13:36                     ` Dmitri Paduchikh
     [not found]                       ` <jwvpp3qp9dn.fsf-monnier+emacs@gnu.org>
2015-07-18  5:16                         ` Dmitri Paduchikh
2015-07-17 18:15                     ` raman
2015-07-17 18:14                   ` raman
2015-07-17 19:31                     ` Drew Adams
2015-07-17 23:25                       ` raman
2015-07-18  1:47                         ` Drew Adams
2015-07-20 12:19                       ` Andreas Röhler
2015-07-16 22:55             ` Stefan Monnier
2015-07-17 18:10               ` raman
2015-07-18  0:57                 ` Stefan Monnier
2015-07-18  4:39               ` Dmitri Paduchikh
2015-07-20 12:22                 ` Andreas Röhler
2015-07-20 22:23                 ` Stefan Monnier
2015-08-06 22:30         ` Stefan Monnier
2015-08-06 22:33         ` Stefan Monnier
2015-08-07 13:35           ` Dmitri Paduchikh
2015-08-07 17:18             ` Stefan Monnier
2015-07-18 22:29   ` raman
2015-07-12 21:59 ` Richard Stallman [this message]
2015-07-13 15:17   ` Dmitri Paduchikh
2015-07-13 23:03     ` Richard Stallman
2015-08-06 22:36     ` Stefan Monnier
2015-07-17 20:35 ` Przemysław Wojnowski

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

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

  git send-email \
    --in-reply-to=E1ZEPHO-0003iL-5p@fencepost.gnu.org \
    --to=rms@gnu.org \
    --cc=dpaduchikh@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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 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.