I am trying to replicate emacs standard behavior when it comes to 'q', i.e. when in a buffer where insert mode does not make sense 'q' closes it. So I defined the following function

(defun evil-new-record-macro ()
     (buffer-read-only (quit-window))
     (t (evil-record-macro ?0))

But (evil-record-macro ?0) is a bad idea since it assumes a '0' as an argument and I don't know how to use without a pre-specified register.

The question is the following:

Whats a more correct/better way to approach the letter 'q' behavior, macros when it makes sense and quit when it does not.

BONUS: How I can fix the function so it does not need a register to be pre specified.

assume that I am always in normal state and switching to emacs or motion is not an option. I also use general.el to bind keys.

1 Answer 1


To call an interactive command, use call-interactively. I've taken the liberty to simplify your code a bit:

(defun my-evil-record-macro ()
  (if buffer-read-only
    (call-interactively 'evil-record-macro)))

(with-eval-after-load 'evil-maps
  (define-key evil-normal-state-map (kbd "q") 'my-evil-record-macro))
  • Worked like a charm, I am still testing it to be sure it does exactly what I want context wise, It seems it is the case. Commented Jan 26, 2018 at 12:11

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.