Function: viper-find-best-matching-macro

viper-find-best-matching-macro is a byte-compiled function defined in viper-macs.el.gz.

Signature

(viper-find-best-matching-macro ALIST STR)

Source Code

;; Defined in /usr/src/emacs/lisp/emulation/viper-macs.el.gz
;; alist is the alist of macros
;; str is the fast key sequence entered
;; returns: (matching-macro-def . unmatched-suffix-start-index)
(defun viper-find-best-matching-macro (alist str)
  (let ((lis alist)
	(def-len 0)
	(str-len (length str))
	match unmatched-start-idx found macro-def)
    (while (and (not found) lis)
      (setq macro-def (car lis)
	    def-len (length (car macro-def)))
      (if (and (>= str-len def-len)
               (equal (car macro-def) (cl-subseq str 0 def-len)))
	  (if (or (viper-kbd-buf-definition macro-def)
		  (viper-kbd-mode-definition macro-def)
		  (viper-kbd-global-definition macro-def))
	      (setq found t))
	)
      (setq lis (cdr lis)))

    (if found
	(setq match macro-def
	      unmatched-start-idx def-len)
      (setq match nil
	    unmatched-start-idx 0))

    (cons match unmatched-start-idx)))