Function: evil-keypress-parser

evil-keypress-parser is a byte-compiled function defined in evil-common.el.

Signature

(evil-keypress-parser &optional INPUT)

Documentation

Read from keyboard or INPUT and build a command description.

Return (CMD COUNT), where COUNT is the numeric prefix argument. Both COUNT and CMD may be nil.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-common.el
;;; Key sequences

(defun evil-keypress-parser (&optional input)
  "Read from keyboard or INPUT and build a command description.
Return (CMD COUNT), where COUNT is the numeric prefix argument.
Both COUNT and CMD may be nil."
  (when input (setq unread-command-events (append input unread-command-events)))
  (let (count negative)
    (catch 'done
      (while t
        (let ((seq (read-key-sequence "")))
          (when seq
            (let ((cmd (key-binding seq)))
              (cond
               ((null cmd) (throw 'done (list nil nil)))
               ((arrayp cmd) ; keyboard macro, recursive call
                (let ((cmd (evil-keypress-parser cmd)))
                  (throw 'done
                         (list (car cmd)
                               (if (or count (cadr cmd))
                                   (list (car cmd) (* (or count 1)
                                                      (or (cadr cmd) 1))))))))
               ((or (eq cmd #'digit-argument)
                    (and (equal seq "0") count))
                (let* ((event (aref seq (1- (length seq))))
                       (char (or (when (characterp event) event)
                                 (when (symbolp event)
                                   (get event 'ascii-character))))
                       (digit (when (integerp char) (- (logand char ?\177) ?0))))
                  (setq count (+ (* 10 (or count 0)) digit))))
               ((eq cmd #'negative-argument)
                (setq negative (not negative)))
               (t
                (throw 'done (list cmd
                                   (and count
                                        (* count
                                           (if negative -1 1))))))))))))))