From 2a511a65767aaae2a2d4e5307f1b3e8e7acee077 Mon Sep 17 00:00:00 2001 From: Andrew Whatson Date: Wed, 29 May 2019 00:01:45 +1000 Subject: [PATCH 1/2] 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)) From 9f4352006f7a07ad29cdcb1bd613cff5cddbb2ba Mon Sep 17 00:00:00 2001 From: Andrew Whatson Date: Wed, 29 May 2019 00:10:21 +1000 Subject: [PATCH 2/2] Increase ivy-flx-limit for improved fuzzy behavior The default setting of 200 is too low for common use-cases like `describe-function`, `describe-variable` or `counsel-projectile`. This has a performance impact, but it's barely noticeable on a fast machine. If performance is not acceptable, set `ivy-flx-limit` lower or consider disabling the `+fuzzy` feature entirely. --- modules/completion/ivy/config.el | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 677c5a77e..ce3e192f6 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -305,7 +305,8 @@ immediately runs it on the current candidate (ending the ivy session)." (swiper . ivy--regex-plus) (swiper-isearch . ivy--regex-plus) (t . ivy--regex-fuzzy)) - ivy-initial-inputs-alist nil)) + ivy-initial-inputs-alist nil + ivy-flx-limit 10000)) (def-package! ivy-prescient