(or (funcall func defp)
(setq completions--only-exceptional-candidates
(funcall func pred))))
- (t (funcall func pred))))
- (adjust-fn (get (cdr result-and-style) 'completion--adjust-metadata)))
+ (t (funcall func pred)))))
(setq completion--matching-style (cdr result-and-style))
- (when (and adjust-fn metadata)
- (setcdr metadata (cdr (funcall adjust-fn metadata))))
(if requote
(funcall requote (car result-and-style) n)
(car result-and-style))))
:version "27.1"
:type 'boolean)
-(put 'flex 'completion--adjust-metadata 'completion--flex-adjust-metadata)
-
-(defun completion--flex-adjust-metadata (metadata)
- "If `flex' is actually doing filtering, adjust sorting."
- (let ((flex-is-filtering-p completion-pcm--regexp)
- (existing-sf (completion-metadata-get metadata 'sort-function)))
- (cl-flet
- ((compose-flex-sort-fn (existing-sort-fn)
- (lambda (completions)
- (let* ((sorted (sort
- (mapcar
- (lambda (str)
- (cons
- (- (completion--flex-score
- (or (get-text-property
- 0 'completion--unquoted str)
- str)
- completion-pcm--regexp))
- str))
- (if existing-sort-fn
- (funcall existing-sort-fn completions)
- completions))
- #'car-less-than-car))
- (cell sorted))
- ;; Reuse the list
- (while cell
- (setcar cell (cdar cell))
- (pop cell))
- sorted))))
- `(metadata
- ,@(and flex-is-filtering-p
- `((sort-function . ,(compose-flex-sort-fn existing-sf))))
- ,@(cdr metadata)))))
-
(defun completion-flex--make-flex-pattern (pattern)
"Convert PCM-style PATTERN into PCM-style flex pattern.