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