Function: completion--flex-cost
completion--flex-cost is a byte-compiled function defined in
minibuffer.el.gz.
Signature
(completion--flex-cost PAT STR &optional DONT-ERROR)
Documentation
Compute flex cost of STR matching PAT using Gotoh algorithm.
If DONT-ERROR, return nil if PAT cannot match STR. Return (NORMALIZED-COST . MATCHES) where NORMALIZED-COST is a number (lower = better) and MATCHES is a list of match positions in STR.
Source Code
;; Defined in /usr/src/emacs/lisp/minibuffer.el.gz
(cl-defun completion--flex-cost (pat str &optional dont-error)
"Compute flex cost of STR matching PAT using Gotoh algorithm.
If DONT-ERROR, return nil if PAT cannot match STR.
Return (NORMALIZED-COST . MATCHES) where NORMALIZED-COST is a
number (lower = better) and MATCHES is a list of match positions in STR."
(pcase-let ((`(,cost . ,matches)
(completion--flex-cost-gotoh pat str)))
(unless cost
(if dont-error (cl-return-from completion--flex-cost nil)
(error "Pattern %s does not match %s" pat str)))
(cons (* (1+ cost) (- (length str) (length pat))) matches)))