Orderless is a package that provides completion-styles
for Emacs. It’s really nice in its simplicity, like Helm to enable nice filtering of candidates we just need to add it to the completion-styles
list.
It’s pretty nice to use at least with selectrum, and it has a nice API to play with, in order to change completion style dynamically (extract from the README; a “component” is a substring, “mo lan org” is 3 components, mo
, lan
, and org
)
As an example, say you wanted the following setup:
- you normally want components to match as regexps,
- except for the first component, which should always match as an initialism —this is pretty useful for, say,
execute-extended-command
(M-x
) ordescribe-function
(C-h f
),- later components ending in
~
should match (the characters other than the final~
) in the flex style, and- later components starting with
!
should indicate the rest of the component is a literal string not contained in the candidate.You can achieve this with the following configuration:
(defun flex-if-twiddle (pattern _index _total) (when (string-suffix-p "~" pattern) `(orderless-flex . ,(substring pattern 0 -1)))) (defun first-initialism (pattern index _total) (if (= index 0) 'orderless-initialism)) (defun without-if-bang (pattern _index _total) (when (string-prefix-p "!" pattern) `(orderless-without-literal . ,(substring pattern 1)))) (setq orderless-matching-styles '(orderless-regexp) orderless-style-dispatchers '(first-initialism flex-if-twiddle without-if-bang))
Just as Consult, I think this would be nice to keep an eye on as it’s another component that seems to answer most of the use cases while being more isolated. But this still seems a little unstable.
One (possibly big) disadvantage is that, unlike prescient, orderless does not do sorting, only filtering, and expect the candidate producer to do the sorting. Ivy/selectrum don’t seem to implement “smart sorting” by default, as the fuzzy matchers/prescient tend to provide both filtering and sorting (you need to score the filtered fuzzy results and order by score).