unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* defadvice and called-interactively-p
@ 2012-06-06  7:03 Frank Fischer
  2012-06-06  7:26 ` Eric Abrahamsen
  0 siblings, 1 reply; 8+ messages in thread
From: Frank Fischer @ 2012-06-06  7:03 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I have a problem when advising a function/command that uses
`called-interactively-p' but I have not been able to find a solution.

Suppose you have a command calling `called-interactively-p'

(defun myfunc ()
  (interactive)
  (message "MYFUNC %s" (called-interactively-p 'any)))

Now, when executing M-x myfunc RET the message line shows "MYFUNC t"
as expected. But when that function is advised

(defadvice myfunc (around around-myfunc activate)
  ad-do-it)

executing M-x myfunc RET again shows "MYFUNC nil" this time. The
disassembled code of the advised function reads

0            constant  nil
1            varbind     ad-return-value
2            constant  ad-Orig-myfunc
3            call        0
4            dup
5            varset       ad-return-value
6            unbind         1
7            return

If I interpret that code correctly (I'm not sure) then the original
definition of `myfunc' is called in line 3 using something similar to
(funcall 'ad-Orig-myfunc) where `ad-Orig-myfunc' is the renamed
original function. This would explain (IMO) why
`called-interactivly-p' returns nil -- the original body has *not*
been called interactively but using a usual non-interactive function
call.

But of course, if the (interactive) behavior of `myfunc' depends on
the return value of `called-interactively-p' this would make the
advised function unusable in interactive calls.

Is there some way to make `called-interactively-p' behave "correctly"
in the advised body?

Thanks is advance,
Frank





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

end of thread, other threads:[~2012-06-08  7:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-06  7:03 defadvice and called-interactively-p Frank Fischer
2012-06-06  7:26 ` Eric Abrahamsen
2012-06-06  7:35   ` Frank Fischer
2012-06-06  7:55     ` Eric Abrahamsen
2012-06-06  8:11       ` Frank Fischer
2012-06-08  0:03         ` Juanma Barranquero
2012-06-08  6:45           ` Frank Fischer
2012-06-08  7:02             ` Juanma Barranquero

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