Function: evil-extract-count

evil-extract-count is a byte-compiled function defined in evil-common.el.

Signature

(evil-extract-count KEYS)

Documentation

Split the key-sequence KEYS into prefix-argument and the rest.

Return the list (PREFIX CMD SEQ REST), where PREFIX is the prefix count, CMD the command to be executed, SEQ the subsequence calling CMD, and REST is all remaining events in the key-sequence. PREFIX and REST may be nil if they do not exist. If a command is bound to some keyboard macro, it is expanded recursively.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-common.el
(defun evil-extract-count (keys)
  "Split the key-sequence KEYS into prefix-argument and the rest.
Return the list (PREFIX CMD SEQ REST), where PREFIX is the
prefix count, CMD the command to be executed, SEQ the subsequence
calling CMD, and REST is all remaining events in the
key-sequence. PREFIX and REST may be nil if they do not exist.
If a command is bound to some keyboard macro, it is expanded
recursively."
  (catch 'done
    (let ((len (length keys))
          (beg 0)
          (end 1)
          found-prefix)
      (while (<= end len)
        (let* ((seq (substring keys beg end))
               (cmd (key-binding seq)))
          (cond
           ((memq cmd '(undefined nil))
            (user-error "No command bound to `%s'" seq))
           ((arrayp cmd) ; keyboard macro, replace command with macro
            (setq keys (vconcat (substring keys 0 beg)
                                cmd
                                (substring keys end))
                  end (1+ beg)
                  len (length keys)))
           ((functionp cmd)
            (if (or (memq cmd '(digit-argument negative-argument))
                    (and found-prefix
                         (equal (vconcat seq) (vector ?0))))
                ;; skip those commands
                (setq found-prefix t ; found at least one prefix argument
                      beg end
                      end (1+ end))
              ;; a real command, finish
              (throw 'done
                     (list (unless (zerop beg)
                             (string-to-number
                              (concat (substring keys 0 beg))))
                           cmd
                           seq
                           (when (< end len)
                             (substring keys end))))))
           (t ; append a further event
            (setq end (1+ end))))))
      (user-error "Key sequence contains no complete binding"))))