all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Le Wang <l26wang@gmail.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: help-gnu-emacs@gnu.org
Subject: Re: called-interactively-p and edebug
Date: Thu, 3 Feb 2011 11:58:13 +0800	[thread overview]
Message-ID: <AANLkTikgsaXy69HWs+BwUpb_PQ6DTkYJHR3QKafXgRE6@mail.gmail.com> (raw)
In-Reply-To: <AANLkTimUxnuxtKBAUGxkxvwuTE3SuQ32Ww=H6mZHd_+_@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1793 bytes --]

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 <l26wang@gmail.com> 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 <monnier@iro.umontreal.ca>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

[-- Attachment #2: Type: text/html, Size: 2793 bytes --]

  reply	other threads:[~2011-02-03  3:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1.1296549798.22589.help-gnu-emacs@gnu.org>
2011-02-01 17:00 ` called-interactively-p and edebug Stefan Monnier
2011-02-02  1:14   ` Le Wang
2011-02-03  3:58     ` Le Wang [this message]
2011-02-01  8:43 Le Wang

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=AANLkTikgsaXy69HWs+BwUpb_PQ6DTkYJHR3QKafXgRE6@mail.gmail.com \
    --to=l26wang@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.