unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* called-interactively-p and edebug
@ 2011-02-01  8:43 Le Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Le Wang @ 2011-02-01  8:43 UTC (permalink / raw)
  To: help-gnu-emacs

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

Hi

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?


-- 
Le

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

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

* Re: called-interactively-p and edebug
       [not found] <mailman.1.1296549798.22589.help-gnu-emacs@gnu.org>
@ 2011-02-01 17:00 ` Stefan Monnier
  2011-02-02  1:14   ` Le Wang
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2011-02-01 17:00 UTC (permalink / raw)
  To: help-gnu-emacs

> 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


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

* Re: called-interactively-p and edebug
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Le Wang @ 2011-02-02  1:14 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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

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

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

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

* Re: called-interactively-p and edebug
  2011-02-02  1:14   ` Le Wang
@ 2011-02-03  3:58     ` Le Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Le Wang @ 2011-02-03  3:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs

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

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

end of thread, other threads:[~2011-02-03  3:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [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
2011-02-01  8:43 Le Wang

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