From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: defadvice and called-interactively-p Date: Wed, 06 Jun 2012 15:26:44 +0800 Message-ID: <874nqozyrv.fsf@ericabrahamsen.net> References: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1338967632 589 80.91.229.3 (6 Jun 2012 07:27:12 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Jun 2012 07:27:12 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Jun 06 09:27:11 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1ScAe5-0002D3-Pn for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jun 2012 09:27:09 +0200 Original-Received: from localhost ([::1]:56962 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScAe5-0004sH-Ih for geh-help-gnu-emacs@m.gmane.org; Wed, 06 Jun 2012 03:27:09 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:39547) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScAdy-0004qd-93 for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 03:27:03 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ScAdt-00055o-FB for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 03:27:01 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:58488) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ScAdt-00055c-8X for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 03:26:57 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1ScAdp-0001h1-SO for help-gnu-emacs@gnu.org; Wed, 06 Jun 2012 09:26:53 +0200 Original-Received: from 114.250.121.87 ([114.250.121.87]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 06 Jun 2012 09:26:53 +0200 Original-Received: from eric by 114.250.121.87 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 06 Jun 2012 09:26:53 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 63 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 114.250.121.87 X-Pgp-Key: http://pgp.mit.edu:11371/pks/lookup?op=vindex&search=0xC98BAE7B99D0D373 X-Pgp-Fingerprint: 8E19 28A9 2B51 0C67 565D DB34 C98B AE7B 99D0 D373 User-Agent: Gnus/5.130006 (Ma Gnus v0.6) Emacs/24.1.50 (gnu/linux) Cancel-Lock: sha1:b0L0Fn2GEGziB89ZtGQT8kNAox0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:85127 Archived-At: 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