help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: called-interactively-p and edebug


From: Stefan Monnier
Subject: Re: called-interactively-p and edebug
Date: Tue, 01 Feb 2011 12:00:55 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]