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?

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.