Is it possible to dispatch styles based on the command?
I like to not use the flex style for counsel-recentf (an ivy command), as it is way too slow for that command. Is there any way to dispatch on such a thing?
Sure, you can advise the command to set orderless-matching-styles to something else:
(defun no-flex-for-you! (fn &rest args)
(let ((orderless-matching-styles '(orderless-literal orderless-prefixes))) ; whatever you want
(apply fn args)))
(advice-add 'counsel-recentf :around #'no-flex-for-you!)
In that example I only set orderless-matching-styles, but of course you set any other variables you need too, to fully configure orderless for that particular use.
That's a good bandaid but a better solution would be for me to make flex fast enough to use. I'll experiment with compiling "abc" to ("a" "b" "c" "a.*b.*c") instead of just "a.*b.*c", that is, to check if all the characters appear before checking if they appear in the right order. I think that could easily be much faster.
@oantolin I think using a separate completion style is the way to go. We introduced orderless-define-style in particular for this purpose. It won't be faster for words of the form bcaaaa...? The performance problem is most relevant for long candidates for which it is more likely that all characters appear.
@oantolin Indeed, I had this idea myself after waking up.
I know that fzf can work with my set of recent files just fine, but fzf is in golang, so I am not sure how far we can push emacs. I already have an fzf wrapper which is what I am using, but because it runs fzf for each change in the query, that too is rather slow. (It's still better than orderless's flex, which does suggest that improvements here are possible.)
@oantolin I think using a separate completion style is the way to go. We introduced orderless-define-style in particular for this purpose.
I think a separate completion style is the best choice for when you are targeting some specific completion category, and then you put the bespoke completion style in completion-category-overrides. For a command that doesn't have a nice completion category you can target, this advice technique is pretty convenient. (You can of course also use Marginalia to add a completion category and then use the bespoke completion style approach too).
It won't be faster for words of the form bcaaaa...? The performance problem is most relevant for long candidates for which it is more likely that all characters appear.
True. Some benchmarking is in order.
I think this question has been adequately answered (by the technique using advice and also by the marginalia + completion-category-overrides suggestion), so I'll close.