0

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 ()
  (interactive)
    (cond
     (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

2

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

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

(with-eval-after-load 'evil-maps
  (define-key evil-normal-state-map (kbd "q") 'my-evil-record-macro))
1
  • 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. Jan 26, 2018 at 12:11

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.