all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eric Abrahamsen <eric@ericabrahamsen.net>
To: help-gnu-emacs@gnu.org
Subject: Re: defadvice and called-interactively-p
Date: Wed, 06 Jun 2012 15:26:44 +0800	[thread overview]
Message-ID: <874nqozyrv.fsf@ericabrahamsen.net> (raw)
In-Reply-To: jqmvb8$mfr$1@dough.gmane.org

On Wed, Jun 06 2012, Frank Fischer wrote:

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

While you're waiting for an answer from someone who really understand
how all this works, I've found that I need to add an (interactive)
statement to the defadvice form as well, in order to preserve
interactive state. Give it a shot, anyway!

Eric

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

-- 
GNU Emacs 24.1.50.1 (i686-pc-linux-gnu, GTK+ Version 2.24.10)
 of 2012-06-06 on pellet




  reply	other threads:[~2012-06-06  7:26 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06  7:03 defadvice and called-interactively-p Frank Fischer
2012-06-06  7:26 ` Eric Abrahamsen [this message]
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

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=874nqozyrv.fsf@ericabrahamsen.net \
    --to=eric@ericabrahamsen.net \
    --cc=help-gnu-emacs@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.