-
-
Notifications
You must be signed in to change notification settings - Fork 338
Open
Labels
enhancementSuggestion to improve or extend existing behaviorSuggestion to improve or extend existing behavior
Description
The default fuzzy speed seems to be a little slow when I compare it with evaling this snippet from
(with-eval-after-load 'ivy
(require 'flx)
(defvar my/ivy-cache (flx-make-string-cache))
(defvar my/ivy-flx-limit 500)
(defun nadvice/ivy--filter (name candidates)
(if (or (= (length name) 0)
(string= name "^"))
candidates
(let* (;; an optimized regex for fuzzy matching
;; "abc" → "\\`[^a]*a[^b]*b[^c]*c"
(fuzzy-regex (if (= (elt name 0) ?^)
(concat "^"
(regexp-quote (substring name 1 2))
(mapconcat
(lambda (x)
(setq x (string x))
(concat "[^" x "]*" (regexp-quote x)))
(substring name 2)
""))
(concat "^"
(mapconcat
(lambda (x)
(setq x (string x))
(concat "[^" x "]*" (regexp-quote x)))
name
""))))
(flx-name (if (= (elt name 0) ?^)
(substring name 1)
name))
;; disable side-effects of string-match
(inhibit-changing-match-data t)
(cands-left)
(cands-to-sort))
;; filter out non-matching candidates
(dolist (cand candidates)
(when (string-match fuzzy-regex cand)
(push cand cands-left)))
;; pre-sort the candidates by length before partitioning
(setq cands-left (sort cands-left
(lambda (c1 c2)
(< (length c1)
(length c2)))))
;; partition the candidates into sorted and unsorted groups
(dotimes (_n (min (length cands-left) my/ivy-flx-limit))
(push (pop cands-left) cands-to-sort))
(append
;; compute all of the flx scores in one pass and sort
(mapcar #'car
(sort (mapcar
(lambda (cand)
(cons cand
(car (flx-score cand
flx-name
my/ivy-cache))))
cands-to-sort)
(lambda (c1 c2)
(> (cdr c1)
(cdr c2)))))
;; add the unsorted candidates
cands-left))))
(advice-add 'ivy--filter :override #'nadvice/ivy--filter))
I included a video here.
https://dl.dropboxusercontent.com/u/11400324/Untitled.m4v
When I type 'adengine' with the default ivy fuzzy, it has a noticeable 1-2 second pause before going through with the search. With the eval'd code, I can get through the entire adengine text with only minor pauses.
Using ivy-20170105.711
My own ivy config
(use-package ivy
:ensure t)
(use-package counsel
:ensure t
:config
;; Disable for now while trying grizzl.
(global-set-key (kbd "M-x") 'counsel-M-x)
(global-set-key (kbd "s-x") 'counsel-M-x))
(use-package swiper
:ensure t
:diminish ivy-mode
:config
(if (jojo/imac-p)
(setq ivy-flx-limit 100)
(setq ivy-flx-limit 500))
;; (ivy-mode)
(setq ivy-re-builders-alist
'((t . ivy--regex-fuzzy)))
(setq ivy-initial-inputs-alist nil)
;; swapping behavior
(define-key ivy-minibuffer-map (kbd "RET") 'ivy-alt-done)
(define-key ivy-minibuffer-map (kbd "C-j") 'ivy-done)
;; default: "ag --nocolor --nogroup %s -- ."
(setq counsel-ag-base-command "ag -U --nocolor --nogroup %s -- .")
(setq ivy-count-format "")
(setq ivy-height 15))
Metadata
Metadata
Assignees
Labels
enhancementSuggestion to improve or extend existing behaviorSuggestion to improve or extend existing behavior