When I am defining keyboard macro with kmacro-start-macro and I press C-g (for example to deactivate mark or I press it accidentally), macro definition is aborted and I have to start over. Is there any way to disable this behavior?

1 Answer 1


You could write some function like this, to only run keyboard-quit if no macro is running, and bind to C-g:

(defun keyboard-quit-only-if-no-macro ()
  (if defining-kbd-macro
        (if (region-active-p)
          (message "Macro running. Can't quit.")))


(define-key global-map (kbd "C-g") 'keyboard-quit-only-if-no-macro)
  • I was hoping there would be some variable to set to make this simpler. It seems that it's very basic and should be customizable but I looked at definition at keyboard-quit and quitting macros is hardcoded there.
    – mkcms
    Mar 16, 2018 at 21:44

Your Answer

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

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