Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rank prefix-matches higher than orderless-literal and orderless-regexp #188

Closed
benma opened this issue Mar 17, 2025 · 4 comments
Closed

Comments

@benma
Copy link

benma commented Mar 17, 2025

Hi

Can i configure orderless so that the items that match my input at the beginning are ranked higher and shown above other matches, but still show all other matches?

E.g. if there are three candidates

foo-bar
bar-foo
goo

and i type bar, then bar-foo should appear above foo-bar, even though both are matched.

I tried

(orderless-matching-styles (list #'orderless-literal #'orderless-regexp  #'orderless-literal-prefix))

but it seems the order of the styles in this list is not considered in the final ranking.

@oantolin
Copy link
Owner

Orderless does no candidate ordering at all! I consider it out of scope for orderless.

In Emacs there are too many places where completion candidates can be ordered: (1) the candidates are usually put into a list or alist which of course has an ordering, (2) then the completion metadata can specify an ordering function, (3) a completion style can reorder matches, (4) the completion UI can displays candidates in any order it wants.

Even if orderless did reorder its candidates, there is no guarantee you'd ever see the order, since a completion UI can later reorder them however it wants. In practice, I don't think completion styles usually reorder matches; I am only aware of one built-in completion style that does this, namely flex, and I think maybe a couple of third-party ones implementing some kind of fuzzy matching do too, like hotfuzz.

@benma
Copy link
Author

benma commented Mar 17, 2025

Thanks for the response. I am using orderless in combination with vertico. Do you maybe have a hint where to look to fix my problem? I like the matching of orderless, but often I prefer the literal prefix matches to be at the top as they are the most likely candidates. And it's strange to see candidates appear on top that have my input somewhere in the middle or near the end rank higher than literal prefixes.

Edit: just found vertico-sort-function, maybe I can figure it out with that.

@benma benma closed this as completed Mar 17, 2025
@oantolin
Copy link
Owner

oantolin commented Mar 17, 2025

Be careful when modifying the sorting of candidates, you probably only want to do it sometimes. For example, if you use consult-line you probably always want the lines in the order they appear in the buffer.

@benma
Copy link
Author

benma commented Mar 17, 2025

Thanks. I also just realized that vertico combined with savehist (rank more recent picks higher) is not really compatible with what I want here. So maybe I'll just settle on using the ^ affix dispatch workaround if I know I want to look for a prefix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants