Function: viper-exec-mapped-kbd-macro

viper-exec-mapped-kbd-macro is an interactive and byte-compiled function defined in viper-macs.el.gz.

Signature

(viper-exec-mapped-kbd-macro COUNT)

Documentation

Dispatch kbd macro.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/emulation/viper-macs.el.gz
(defun viper-exec-mapped-kbd-macro (count)
  "Dispatch kbd macro."
  (interactive "P")
  (let* ((macro-alist (cond ((eq viper-current-state 'vi-state)
			     viper-vi-kbd-macro-alist)
			    ((memq viper-current-state
				   '(insert-state replace-state))
			     viper-insert-kbd-macro-alist)
			    (t
			     viper-emacs-kbd-macro-alist)))
	(unmatched-suffix "")
	;; Macros and keys are executed with other macros turned off
	;; For macros, this is done to avoid macro recursion
	viper-vi-kbd-minor-mode viper-insert-kbd-minor-mode
	viper-emacs-kbd-minor-mode
	next-best-match keyseq event-seq
	macro-first-char macro-alist-elt macro-body
	command)

    (setq macro-first-char last-command-event
	  event-seq (viper-read-fast-keysequence macro-first-char macro-alist)
	  keyseq (viper-events-to-macro event-seq)
	  macro-alist-elt (assoc keyseq macro-alist)
	  next-best-match (viper-find-best-matching-macro macro-alist keyseq))

    (if (null macro-alist-elt)
	(setq macro-alist-elt (car next-best-match)
              unmatched-suffix (cl-subseq event-seq (cdr next-best-match))))

    (cond ((null macro-alist-elt))
	  ((setq macro-body (viper-kbd-buf-definition macro-alist-elt)))
	  ((setq macro-body (viper-kbd-mode-definition macro-alist-elt)))
	  ((setq macro-body (viper-kbd-global-definition macro-alist-elt))))

    ;; when defining keyboard macro, don't use the macro mappings
    (if (and macro-body (not defining-kbd-macro))
	;; block cmd executed as part of a macro from entering command history
	(let ((command-history command-history))
	  (setq viper-this-kbd-macro (car macro-alist-elt))
	  (execute-kbd-macro (viper-macro-to-events macro-body) count)
	  (setq viper-this-kbd-macro nil
		viper-last-kbd-macro (car macro-alist-elt))
	  (viper-set-unread-command-events unmatched-suffix))
      ;; If not a macro, or the macro is suppressed while defining another
      ;; macro, put keyseq back on the event queue
      (viper-set-unread-command-events event-seq)
      ;; if the user typed arg, then use it if prefix arg is not set by
      ;; some other command (setting prefix arg can happen if we do, say,
      ;; 2dw and there is a macro starting with 2.  Then control will go to
      ;; this routine
      (or prefix-arg (setq  prefix-arg count))
      (setq command (key-binding (read-key-sequence nil)))
      (if (commandp command)
	  (command-execute command)
	(beep 1)))
    ))