From 8c420239c924dc48a6c38145a2dad4fc18477e9e Mon Sep 17 00:00:00 2001 From: Jack Jamison Date: Fri, 31 Jul 2026 17:17:22 -0400 Subject: better completion sorting and fixes --- .config/emacs/completion-sorting.el | 57 +++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 .config/emacs/completion-sorting.el (limited to '.config/emacs/completion-sorting.el') diff --git a/.config/emacs/completion-sorting.el b/.config/emacs/completion-sorting.el new file mode 100644 index 0000000..c5c714a --- /dev/null +++ b/.config/emacs/completion-sorting.el @@ -0,0 +1,57 @@ + +;; https://kristofferbalintona.me/articles/complement-corfu-vertico-and-completion-preview-with-prescientel-sorting/ + +(use-package prescient + :ensure t + :custom + (prescient-aggressive-file-save t) + (prescient-sort-length-enable t) ; testing this out + (prescient-sort-full-matches-first t) + (prescient-history-length 200) + (prescient-frequency-decay 0.997) + (prescient-frequency-threshold 0.05) + :config + (prescient-persist-mode 1)) + +;; Integration with corfu +(use-package corfu-prescient + :ensure t + :demand t + :after corfu prescient + :custom + (corfu-prescient-enable-sorting t) + (corfu-prescient-override-sorting nil) ; Don't override `display-sort-function' + (corfu-prescient-enable-filtering nil) ; We want orderless to do the filtering + :config + (corfu-prescient-mode 1)) + +;; Integration with vertico +(use-package vertico-prescient + :ensure t + :demand t + :after vertico prescient + :custom + (vertico-prescient-enable-sorting t) + (vertico-prescient-override-sorting nil) + (vertico-prescient-enable-filtering nil) ; We want orderless to do the filtering + :config + (vertico-prescient-mode 1)) + +;; Have `completion-preview-mode' use prescient's sorting algorithm +(with-eval-after-load 'prescient + (setopt completion-preview-sort-function #'prescient-completion-sort)) + +(add-variable-watcher 'corfu-sort-function + (lambda (_symbol newval operation where) + "Match the value of `completion-preview-sort-function' to `corfu-sort-function'. +If `corfu-sort-function' is set buffer-locally, also set +`completion-preview-sort-function' buffer-locally. Otherwise, change +the default value of `completion-preview-sort-function' accordingly. + +This action only applies when the value of `corfu-sort-function' is +set (i.e., OPERATION is \\='set). This excludes, e.g., let bindings." + (when (equal operation 'set) + (if where + (with-current-buffer where + (setq-local completion-preview-sort-function newval)) + (setopt completion-preview-sort-function newval))))) -- cgit v1.2.3