From 2a511a65767aaae2a2d4e5307f1b3e8e7acee077 Mon Sep 17 00:00:00 2001 From: Andrew Whatson Date: Wed, 29 May 2019 00:01:45 +1000 Subject: [PATCH] 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. --- modules/completion/company/config.el | 1 + modules/completion/ivy/README.org | 4 +++- modules/completion/ivy/config.el | 30 +++++++++++++++++++++++++++- modules/completion/ivy/packages.el | 6 ++++-- 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/modules/completion/company/config.el b/modules/completion/company/config.el index 3e582e242..226b64ee9 100644 --- a/modules/completion/company/config.el +++ b/modules/completion/company/config.el @@ -47,6 +47,7 @@ (def-package! company-prescient :hook (company-mode . company-prescient-mode) :config + ;; NOTE prescient config duplicated with `ivy' (setq prescient-save-file (concat doom-cache-dir "prescient-save.el")) (prescient-persist-mode +1)) diff --git a/modules/completion/ivy/README.org b/modules/completion/ivy/README.org index 9feb2af27..ab34d25b5 100644 --- a/modules/completion/ivy/README.org +++ b/modules/completion/ivy/README.org @@ -37,7 +37,8 @@ lighter, simpler and faster in many cases. #+end_quote ** Module Flags -+ =+fuzzy= Enables the fuzzy method for ivy searches. ++ =+fuzzy= Enables fuzzy completion for Ivy searches. ++ =+prescient= Enables prescient filtering and sorting for Ivy searches. + =+childframe= Causes Ivy to display in a floating child frame, above Emacs. *This requires GUI Emacs 26.1+* + =+icons= Enables file icons for switch-{buffer,project}/find-file counsel @@ -53,6 +54,7 @@ lighter, simpler and faster in many cases. + [[https://github.com/mhayashi1120/Emacs-wgrep][wgrep]] + [[https://github.com/DarwinAwardWinner/amx][amx]] + [[https://github.com/lewang/flx][flx]]* (=+fuzzy=) ++ [[https://github.com/raxod502/prescient.el][prescient]]* (=+prescient=) + [[https://github.com/tumashu/ivy-posframe][ivy-posframe]]* (=+childframe=) + [[https://github.com/asok/all-the-icons-ivy][all-the-icons-ivy]]* (=+icons=) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 032943a3d..677c5a77e 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -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")) diff --git a/modules/completion/ivy/packages.el b/modules/completion/ivy/packages.el index a61af857e..e804e9ead 100644 --- a/modules/completion/ivy/packages.el +++ b/modules/completion/ivy/packages.el @@ -10,8 +10,10 @@ (package! ivy-rich) (package! wgrep) -(when (featurep! +fuzzy) - (package! flx)) +(if (featurep! +prescient) + (package! ivy-prescient) + (when (featurep! +fuzzy) + (package! flx))) (when (and EMACS26+ (featurep! +childframe)) (package! ivy-posframe))