In some situations a command will use timers or hooks in a way that doesn't work when repeating as a keyboard macro.
How can I detect if a function is running as part of a keyboard macro that is being repeated?
This can be checked using (not (or executing-kbd-macro noninteractive))
The documentation for called-interactively-p
states:
Instead of using this function, it is cleaner and more reliable 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)).
However I couldn't figure out how that was supposed to work.