aboutsummaryrefslogtreecommitdiff
path: root/.config/emacs/completion-sorting.el
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2026-07-31 17:17:22 -0400
committerJack Jamison <jackqjamison@gmail.com>2026-07-31 17:17:22 -0400
commit8c420239c924dc48a6c38145a2dad4fc18477e9e (patch)
treebce6d4da4dd957b4fc2a1d5b529ee27131d69a0d /.config/emacs/completion-sorting.el
parent67a0d2382be64c5c3dc7c41b016cda7d598f70bd (diff)
better completion sorting and fixesHEADmain
Diffstat (limited to '.config/emacs/completion-sorting.el')
-rw-r--r--.config/emacs/completion-sorting.el57
1 files changed, 57 insertions, 0 deletions
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)))))