Function: kmacro

kmacro is an autoloaded and byte-compiled function defined in kmacro.el.gz.

Signature

(kmacro KEYS &optional COUNTER FORMAT)

Documentation

Create a kmacro for macro bound to symbol or key.

KEYS should be a vector or a string that obeys key-valid-p.

Probably introduced at or before Emacs version 29.1.

Source Code

;; Defined in /usr/src/emacs/lisp/kmacro.el.gz
;;; Misc. commands

;; An idea for macro bindings:
;; Create a separate keymap installed as a minor-mode keymap (e.g. in
;; the emulation-mode-map-alists) in which macro bindings are made
;; independent of any other bindings.  When first binding is made,
;; the keymap is created, installed, and enabled.  Key seq. C-x C-k +
;; can then be used to toggle the use of this keymap on and off.
;; This means that it would be safe(r) to bind ordinary keys like
;; letters and digits, provided that we inhibit the keymap while
;; executing the macro later on (but that's controversial...)

;;;###autoload
(defun kmacro (keys &optional counter format)
  "Create a `kmacro' for macro bound to symbol or key.
KEYS should be a vector or a string that obeys `key-valid-p'."
  (oclosure-lambda (kmacro (keys (if (stringp keys) (key-parse keys) keys))
                           (counter (or counter 0))
                           (format (or format "%d")))
      (&optional arg)
    ;; Use counter and format specific to the macro on the ring!
    (let ((kmacro-counter counter)
	  (kmacro-counter-format-start format))
      (execute-kbd-macro keys arg #'kmacro-loop-setup-function)
      (setq counter kmacro-counter))))