unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11747: 24.1.50; called-interactively-p vs. advice
@ 2012-06-19 18:21 Michael Heerdegen
  2012-06-25  1:14 ` Glenn Morris
  2013-02-08 22:41 ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Michael Heerdegen @ 2012-06-19 18:21 UTC (permalink / raw)
  To: 11747

Hi,

`called-interactively-p' returns wrong values when called inside
commands that are adviced.

Example:

(defun interactive-test ()
  (interactive)
  (message "Called %sinteractively"
           (if (called-interactively-p 'any) "" "non-")))

M-x interactive-test

  ==>

  Called interactively

M-: (interactive-test)

  ==>

  Called non-interactively


Now eval e.g. this:

(defadvice interactive-test (before foo activate)
  (sleep-for 1))

Then:

M-x interactive-test

  ==>

  Called non-interactively


This is quite surprising, and may cause surprising effects if the user
decides to advice such a command.

I found nothing in the doc about his behavior.  If this is not a bug,
maybe explain this behavior somewhere.


This last paragraph in the docstring of `called-interactively-p' seems
somewhat (but not directly) related:

| This function is meant for implementing advice and other
| function-modifying features.  Instead of using this, it is sometimes
| cleaner 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)). 

It seems a bit confusing - is there a "not" missing in the first
sentence?


Thanks,

Michael.


In GNU Emacs 24.1.50.1 (i486-pc-linux-gnu, GTK+ Version 3.4.2)
 of 2012-06-15 on zelenka, modified by Debian
 (emacs-snapshot package, version 2:20120615-1)
Windowing system distributor `The X.Org Foundation', version 11.0.11201902
Configured using:
 `configure '--build' 'i486-linux-gnu' '--host' 'i486-linux-gnu'
 '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
 '--localstatedir=/var' '--infodir=/usr/share/info'
 '--mandir=/usr/share/man' '--with-pop=yes'
 '--enable-locallisppath=/etc/emacs-snapshot:/etc/emacs:/usr/local/share/emacs/24.1.50/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.1.50/site-lisp:/usr/share/emacs/site-lisp'
 '--without-compress-info' '--with-crt-dir=/usr/lib/i386-linux-gnu/'
 '--with-x=yes' '--with-x-toolkit=gtk3' '--with-imagemagick=yes'
 'build_alias=i486-linux-gnu' 'host_alias=i486-linux-gnu'
 'CFLAGS=-DDEBIAN -DSITELOAD_PURESIZE_EXTRA=5000 -g -O2' 'LDFLAGS=-g
 -Wl,--as-needed -znocombreloc' 'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
  value of $LC_ALL: de_DE.utf8
  value of $LC_TIME: C
  value of $LANG: de_DE.utf8
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t






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

* bug#11747: 24.1.50; called-interactively-p vs. advice
  2012-06-19 18:21 bug#11747: 24.1.50; called-interactively-p vs. advice Michael Heerdegen
@ 2012-06-25  1:14 ` Glenn Morris
  2012-06-25 17:54   ` Michael Heerdegen
  2013-02-08 22:41 ` Stefan Monnier
  1 sibling, 1 reply; 5+ messages in thread
From: Glenn Morris @ 2012-06-25  1:14 UTC (permalink / raw)
  To: michael_heerdegen; +Cc: 11747

Michael Heerdegen wrote:

> `called-interactively-p' returns wrong values when called inside
> commands that are adviced.

Old "interactive-p" had the same issue, though maybe that mattered less.
It's to do with the way advice is implemented. It actually goes out of
its way to avoid using call-interactively unless it has to (subrs).
See comments in advice.el header.





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

* bug#11747: 24.1.50; called-interactively-p vs. advice
  2012-06-25  1:14 ` Glenn Morris
@ 2012-06-25 17:54   ` Michael Heerdegen
  2012-06-25 23:40     ` Glenn Morris
  0 siblings, 1 reply; 5+ messages in thread
From: Michael Heerdegen @ 2012-06-25 17:54 UTC (permalink / raw)
  To: Glenn Morris; +Cc: 11747

Glenn Morris <rgm@gnu.org> writes:

> > `called-interactively-p' returns wrong values when called inside
> > commands that are adviced.
>
> Old "interactive-p" had the same issue, though maybe that mattered less.
> It's to do with the way advice is implemented. It actually goes out of
> its way to avoid using call-interactively unless it has to (subrs).
> See comments in advice.el header.

So, do you mean this can't be fixed?  Too bad, but ok, that's what I
thought.

But then, we IMHO should improve the docstring of `called-interactively':

1.  This sentence:

   This function is meant for implementing advice and other
   function-modifying features.

Is there a "not" missing?

2.  Explicitly say that `called-interactively' will not work when used
in an adviced function.

This is something completely different than 1.  1. is about implementing
advice via `called-interactively'.  2. says that if you advice any
function that already uses it, it will stop working.  

So, my wish is to improve the docstring of `called-interactively' a bit.
Then, this report can be closed.


Michael.





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

* bug#11747: 24.1.50; called-interactively-p vs. advice
  2012-06-25 17:54   ` Michael Heerdegen
@ 2012-06-25 23:40     ` Glenn Morris
  0 siblings, 0 replies; 5+ messages in thread
From: Glenn Morris @ 2012-06-25 23:40 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 11747

Michael Heerdegen wrote:

> So, do you mean this can't be fixed? 

No, just that I personally don't see how to fix it. Hopefully someone
else does.

>    This function is meant for implementing advice and other
>    function-modifying features.
>
> Is there a "not" missing?

I'm not sure. I cannot tell what the sentence is supposed to mean under
either reading. I think it could just as well be removed.

> 2.  Explicitly say that `called-interactively' will not work when used
> in an adviced function.

Sure, if no-one fixes it.





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

* bug#11747: 24.1.50; called-interactively-p vs. advice
  2012-06-19 18:21 bug#11747: 24.1.50; called-interactively-p vs. advice Michael Heerdegen
  2012-06-25  1:14 ` Glenn Morris
@ 2013-02-08 22:41 ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2013-02-08 22:41 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: 11747

> | This function is meant for implementing advice and other
> | function-modifying features.  Instead of using this, it is sometimes
> | cleaner 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)). 
> It seems a bit confusing - is there a "not" missing in the first
> sentence?

No, called-interactively-p is indeed specifically useful when writing
advice (i.e. for use in the advice itself, not in the function that is
advised).
For normal functions, it is usually better (and always more reliable) to
provide an appropriate argument from the `interactive' spec, but doing
that in an advice is a lot more difficult, since it requires modifying
the `interactive' spec, which defadvice does not really let you do (it
lets you override it with another spec, but not modify the existing
spec).


        Stefan





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

end of thread, other threads:[~2013-02-08 22:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-19 18:21 bug#11747: 24.1.50; called-interactively-p vs. advice Michael Heerdegen
2012-06-25  1:14 ` Glenn Morris
2012-06-25 17:54   ` Michael Heerdegen
2012-06-25 23:40     ` Glenn Morris
2013-02-08 22:41 ` Stefan Monnier

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