This is a package to provide a completion-style
to Emacs that leverages flx.
- Get the package, either from MELPA (soon to come):
M-x package-install RET flx-completion RET
Or clone / download this repository and modify your
load-path
:(add-to-list 'load-path (expand-file-name "/path/to/flx-collection/" user-emacs-directory))
(use-package flx
:ensure t :straight t
:config
(set-face-attribute
'flx-highlight-face nil
:inherit 'match
:underline t
:overline nil
:weight 'bold))
(use-package flx-completion
:ensure t
:straight
(flx-completion :type git :host github :repo "jojojames/flx-completion")
:after flx
:config
(setq completion-styles '(flx)
;; For example, project-find-file uses 'project-files which uses
;; substring completion by default. Set to nil to make sure it's using
;; flx.
completion-category-defaults nil
completion-category-overrides
'((file (styles basic partial-completion)))))
We can leverage flx-rs to achieve faster scoring by using Rust.
(use-package flx-rs
:ensure t
:straight
(flx-rs
:repo "jcs-elpa/flx-rs"
:fetcher github
:files (:defaults "bin"))
;; Manual steps:
;; Install Rust
;; $ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
;; Update rustup
;; $ rustup update
;; Build flx-rs.
;; $ cargo build ~/.emacs.d/straight/repos/flx-rs/core
;; Symlink to Straight BUILD directory.
;; $ ln -s ~/.emacs.d/straight/repos/flx-rs/bin ~/.emacs.d/straight/build/flx-rs/bin
:config
(flx-rs-load-dyn)
;; This is not necessary since `flx-all-completions' already checks for this
;; function. It'll still help other libraries that call `flx-score' though.
(advice-add 'flx-score :override #'flx-rs-score))
flx may or may not be too slow when completing with company-mode.
For this, we can advise company-capf
to use basic completions.
(defconst OG-COMPLETION-STYLES completion-styles
"Original `completion-styles' Emacs comes with.")
(defun company-capf-with-og-completion-styles (f &rest args)
"Set `completion-styles' to be the default Emacs `completion-styles'
while `company-capf' runs."
(let ((completion-styles OG-COMPLETION-STYLES))
(apply f args))
;; (let ((completion-styles
;; (if (or (length< company-prefix
;; (if (and
;; (fboundp 'native-comp-available-p)
;; (native-comp-available-p))
;; 3
;; 5)))
;; j-backup-completion-styles
;; `(,(if (featurep 'orderless)
;; 'orderless
;; 'flex) ))))
;; (apply f args))
)
(advice-add 'company-capf :around 'company-capf-with-og-completion-styles)