Skip to content

integrating with flx #207

@bling

Description

@bling

i did some hacking and was able to get a prototype working with flx. here's what it looks like so far:

  (setq ivy-sort-functions-alist '((t . nil)))
  (setq my-ivy-cache (flx-make-string-cache))
  (defun ivy--filter (name candidates)
    (if (> (length name) 0)
        (let ((scores))
          (setq scores (mapcar (lambda (e)
                                 (let ((score (flx-score e ivy-text my-ivy-cache)))
                                   `(,e . ,score))) candidates))
          (setq scores (cl-delete-if-not (lambda (e) (cdr e)) scores))
          (setq scores (cl-sort scores (lambda (a b)
                                         (let ((score1 (cdr a))
                                               (score2 (cdr b)))
                                           (> (car score1) (car score2))))))
          (mapcar (lambda (e) (car e)) scores))
      candidates))

what i did was a brute-force approach...and it will break other functionality like auto-selecting the previous selection. i'm curious to see how to better integrate into ivy. worthy of note is that there is a (flx-make-filename-cache) which is optimized for files, so the algorithm would need to be applied differently depending on the source.

any help is appreciated. thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions