Function: evil-execute-macro

evil-execute-macro is an interactive and byte-compiled function defined in evil-commands.el.

Signature

(evil-execute-macro COUNT MACRO)

Documentation

Execute keyboard macro MACRO, COUNT times.

When called with a non-numerical prefix (such as C-u (universal-argument)), COUNT is infinite. MACRO is read from a register when called interactively.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-commands.el
(evil-define-command evil-execute-macro (count macro)
  "Execute keyboard macro MACRO, COUNT times.
When called with a non-numerical prefix \
\(such as \\[universal-argument]),
COUNT is infinite. MACRO is read from a register
when called interactively."
  :keep-visual t
  :suppress-operator t
  :repeat evil-repeat-execute-macro
  (interactive
   (let (count macro register)
     (setq count (cond ((null current-prefix-arg) 1)
                       ((numberp current-prefix-arg) current-prefix-arg)
                       (t 0))
           register (or evil-this-register (read-char)))
     (cond
      ((or (eq register ?:)
           (and (eq register ?@) (eq evil-last-register ?:)))
       (setq macro #'evil-ex-repeat
             evil-last-register ?:))
      ((eq register ?@)
       (unless evil-last-register
         (user-error "No previously executed keyboard macro."))
       (setq macro (evil-get-register evil-last-register t)))
      (t
       (setq macro (evil-get-register register t)
             evil-last-register register)))
     (list count macro)))
  (cond
   ((functionp macro)
    (evil-repeat-abort)
    (if (zerop count)
        (while t (funcall macro))
      (dotimes (_ (or count 1)) (funcall macro))))
   ((or (and (not (stringp macro))
             (not (vectorp macro)))
        (member macro '("" [])))
    ;; allow references to currently empty registers
    ;; when defining macro
    (unless evil-this-macro (user-error "No previous macro")))
   (t
    (condition-case err
        (evil-with-single-undo
          (let (pre-command-hook post-command-hook) ; For performance
            (combine-after-change-calls
              (execute-kbd-macro macro count)
              (setq this-command 'evil-execute-macro)))) ; For repeatability
      ;; enter Normal state if the macro fails
      (error
       (evil-normal-state)
       (signal (car err) (cdr err)))))))