From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Le Wang Newsgroups: gmane.emacs.help Subject: Re: called-interactively-p and edebug Date: Thu, 3 Feb 2011 11:58:13 +0800 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=00248c0ef0dc5a8634049b58c6be X-Trace: dough.gmane.org 1296705528 26354 80.91.229.12 (3 Feb 2011 03:58:48 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 3 Feb 2011 03:58:48 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: Stefan Monnier Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Feb 03 04:58:44 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1PkqLA-0001vn-U2 for geh-help-gnu-emacs@m.gmane.org; Thu, 03 Feb 2011 04:58:41 +0100 Original-Received: from localhost ([127.0.0.1]:41346 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkqLA-0006A2-8M for geh-help-gnu-emacs@m.gmane.org; Wed, 02 Feb 2011 22:58:40 -0500 Original-Received: from [140.186.70.92] (port=38339 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PkqKn-00069n-8I for help-gnu-emacs@gnu.org; Wed, 02 Feb 2011 22:58:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PkqKl-00024t-UN for help-gnu-emacs@gnu.org; Wed, 02 Feb 2011 22:58:17 -0500 Original-Received: from mail-ew0-f41.google.com ([209.85.215.41]:42394) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PkqKl-00024p-KC for help-gnu-emacs@gnu.org; Wed, 02 Feb 2011 22:58:15 -0500 Original-Received: by ewy27 with SMTP id 27so447832ewy.0 for ; Wed, 02 Feb 2011 19:58:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=TsHPIAo4GZ5zp3X1Nf8LABbaQqPT9Bi2bFRJdp49Ojo=; b=DuAgo9pGNXprKWxrnrOcITbKMjjUAk79TS2sxrYNwJg6ssSxvzJ1II9O90ev4mukrm sPOV/8uGbY43+rIw9gVnx9b1niPYR5+QGagRk27g7nePYDjS7+1pV70Jyg+OqeR1xW8V obUudGHcITYVgpdCcpYnx8V6GKvoZK6L20kK4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=dQ7rybM7biyTOJBhFIX3oQ81OkwBQQlE+AtvUG0+Sj7oDSRTr4h2s4/uSP3O1/PTZZ CHka3bDuwgXpGcgz6eyRvq+m5pgvaKnG4GnqnVRp+1ak7zzlYT+q9r4SyUZ9w4GyyM2g M2aCR6OcgS/OrDOOIki4V8PtHcI/CiBOV2Q6o= Original-Received: by 10.14.127.1 with SMTP id c1mr1580241eei.3.1296705494090; Wed, 02 Feb 2011 19:58:14 -0800 (PST) Original-Received: by 10.14.119.11 with HTTP; Wed, 2 Feb 2011 19:58:13 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.215.41 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:78945 Archived-At: --00248c0ef0dc5a8634049b58c6be Content-Type: text/plain; charset=ISO-8859-1 I should add for posterity's sake that interactive forms do work in defadvice: (defun foo (beg end) (interactive "r") (message "%s %s" beg end)) (defadvice foo (around foo-adv activate) (interactive (list (point-min) (point-max))) ad-do-it) On Wed, Feb 2, 2011 at 9:14 AM, Le Wang wrote: > Thanks Stefan, I discovered this in a defadvice, but reported it using the > simplest repro I could find. I'll keep your tip about preferring > interactive forms in mind. > > > On Wed, Feb 2, 2011 at 1:00 AM, Stefan Monnier wrote: > >> > When I step through this function: >> >> > (defun foo () >> > (interactive) >> > (when (called-interactively-p 'any) >> > (message "Interactive!") >> > 'foo-called-interactively)) >> >> > (called-interactively-p 'any) is nil even when called interactively. Is >> > this a bug? >> >> Yes, it's a known bug: stepping through a function with Edebug is done >> by rewriting the function, and called-interactively-p is a hackish >> function that doesn't have a clean enough semantics to survive >> this rewrite. >> That's one of the reasons the docstring says: >> >> 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)). >> >> So I'd recommend you use the interactive spec instead, as in: >> >> (defun foo (am-i-interactive) >> (interactive "p") >> (when am-i-interactive >> (message "Interactive!") >> 'foo-called-interactively)) >> >> >> -- Stefan >> > > > > -- > Le > -- Le --00248c0ef0dc5a8634049b58c6be Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable I should add for posterity's sake that interactive forms do work in def= advice:

(defun foo (beg end)
=A0=A0(inter= active "r")
=A0=A0(message "%s %s" beg end))<= /div>

(defadvice foo (around foo-adv activate)
=A0= =A0(interactive
=A0=A0 (list (point-min) (point-max)))
= =A0=A0ad-do-it)

On Wed, Feb 2, 2011 at = 9:14 AM, Le Wang <l26wang@gmail.com> wrote:
Thanks Stefan, I discovered this in a defad= vice, but reported it using the simplest repro I could find. =A0I'll ke= ep your tip about preferring interactive forms in mind.


On Wed, Feb= 2, 2011 at 1:00 AM, Stefan Monnier <monnier@iro.umontreal.ca&g= t; wrote:
> When I step throug= h this function:

> (defun foo ()
> =A0 (interactive)
> =A0 (when (called-interactively-p 'any)
> =A0 =A0 (message "Interactive!")
> =A0 =A0 'foo-called-interactively))

> (called-interactively-p 'any) is nil even when called interactivel= y. =A0Is
> this a bug?

Yes, it's a known bug: stepping through a function with Ede= bug is done
by rewriting the function, and called-interactively-p is a hackish
function that doesn't have a clean enough semantics to survive
this rewrite.
That's one of the reasons the docstring says:

=A0 This function is meant for implementing advice and other
=A0 function-modifying features. =A0Instead of using this, it is sometimes=
=A0 cleaner to give your function an extra optional argument whose
=A0 `interactive' spec specifies non-nil unconditionally ("p"= ; is a good
=A0 way to do this), or via (not (or executing-kbd-macro noninteractive)).=

So I'd recommend you use the interactive spec instead, as in:

=A0(defun foo (am-i-interactive)
=A0 =A0(interactive "p")
=A0 =A0(when am-i-interactive
=A0 =A0 =A0(message "Interactive!")
=A0 =A0 =A0'foo-called-interactively))


-- Stefan



--
Le



--
Le
--00248c0ef0dc5a8634049b58c6be--