jMilton13 · 2022-12-17 07:56
I’m wanting to sort corfu candidates by string length, from shortest to longest. By default, I believe corfu does sort by string length, but it groups the candidates and restarts the sort several times in a long list of candidates (e.g., the `cape-symbol` capf) depending on several factors. I thought the below settings would get me the global sort I’m looking for, but no luck:
```
(customize-set-variable 'corfu-sort-override-function #'my/corfu--sort)
(defun my/corfu--sort (list)
"Sorting predicate which compares X and Y."
(sort list #'my/corfu--sort-predicate))
(defun my/corfu--sort-predicate (x y)
(< (length x) (length y)))
```
Does anyone have a solution? Thank you!
JDRiverRun · 2022-12-17 14:46
Are you combining results with `cape-super-capf`? Which results?
jMilton13 · 2022-12-17 18:38
In the buffer I’m testing, I’m using:
```
(setq completion-at-point-functions '(cape-symbol t))
```
So no `cape-super-capf`. If I type "corf", Corfu first groups and sorts the symbol candidates that begin with "corfu" from shortest to longest string, and then towards the end of the list Corfu begins to sort a different group of symbols: those containing "corfu" later in the string, not the beginning. I was hoping to override this so that all candidates are sorted from shortest to longest, no matter where "corfu" appears in the symbol.
It’s worth noting that I also use `Orderless` to allow completion of symbols by initials, and Corfu candidates also get grouped separately for those matching the initials of what I’ve typed from shortest to longest candidate. So it seems like Orderless and Corfu are working together to create this behavior.