Add +prescient option for :completion ivy

This provides an alternative backend for filtering and sorting ivy
searches. Uses prescient instead of flx for fuzzy completion when both
+prescient and +fuzzy are selected.
This commit is contained in:
Andrew Whatson 2019-05-29 00:01:45 +10:00
parent febeed2526
commit 2a511a6576
4 changed files with 37 additions and 4 deletions

View file

@ -294,7 +294,8 @@ immediately runs it on the current candidate (ending the ivy session)."
(def-package! flx
:when (featurep! +fuzzy)
:when (and (featurep! +fuzzy)
(not (featurep! +prescient)))
:defer t ; is loaded by ivy
:init
(setq ivy-re-builders-alist
@ -307,6 +308,33 @@ immediately runs it on the current candidate (ending the ivy session)."
ivy-initial-inputs-alist nil))
(def-package! ivy-prescient
:hook (ivy-mode . ivy-prescient-mode)
:when (featurep! +prescient)
:init
(setq prescient-filter-method (if (featurep! +fuzzy)
'(literal regexp initialism fuzzy)
'(literal regexp initialism))
ivy-prescient-enable-filtering nil ;; we do this ourselves
ivy-initial-inputs-alist nil
ivy-re-builders-alist
'((counsel-ag . +ivy-prescient-non-fuzzy)
(counsel-rg . +ivy-prescient-non-fuzzy)
(counsel-grep . +ivy-prescient-non-fuzzy)
(swiper . +ivy-prescient-non-fuzzy)
(swiper-isearch . +ivy-prescient-non-fuzzy)
(t . ivy-prescient-re-builder)))
:config
(defun +ivy-prescient-non-fuzzy (str)
(let ((prescient-filter-method '(literal regexp)))
(ivy-prescient-re-builder str)))
;; NOTE prescient config duplicated with `company'
(setq prescient-save-file (concat doom-cache-dir "prescient-save.el"))
(prescient-persist-mode +1))
;; Used by `counsel-M-x'
(setq amx-save-file (concat doom-cache-dir "amx-items"))