reddit / emacs

question on vertico + orderless

whudwl · 2022-06-27 10:51
I'm trying out vertico + orderless, something I find very strange is that when I use `switch-to-buffer` and type in `scratch`, if I have a file `scratch.txt` open, then only `scratch.txt` is shown, `*scratch*` is not shown. However if there is no such `scratch.txt` buffer, typing `scratch` will match `*scratch*`. why is it like this? How can I configure it/them so that typing `scratch` will always match both buffers? I'm doing this on an empty config with pretty much only vertico and orderless installed, and I'm using sample configuration from their Readme.
0xMii · 2022-06-27 11:17
orderless has different completion styles. The default one is that it matches beginning of words. So `scratch` does not match `*scratch*` because the latter expects the asterisk there to match. You can change that or add multiple in the settings so that certain matches get prioritized over others. You probably want `orderless-literal`. That one matches what you type anywhere in the result. The full list and how to set those up is in the [Readme](https://github.com/oantolin/orderless).
whudwl · 2022-06-27 12:41
By default orderless-matching-styples is (orderless-literal orderless-regexp), which shouldn't be a problem I think? What is causing the unexpected behaviour seems to be completion-category-defaults ? whose default value looks something like this: ((email (styles substring partial-completion)) (buffer (styles basic substring)) (unicode-name (styles basic substring)) (project-file (styles substring)) (xref-location (styles substring)) (info-menu (styles basic substring)) (symbol-help (styles basic shorthand substring))) Setting it to nil seems to eliminate the strange behavior I described.
0xMii · 2022-06-27 13:22
Interesting. I didn’t set any of this and it works for me with just `orderless-matching-styles` set to `’(orderless-literal orderless-prefixes orderless-initialism)`, which is the only config I’ve put into orderless whatsoever.
bdarcus · 2022-06-27 15:11
I tried this with emacs -Q, and default `orderless` config. What I see: * if I do `M-x switch-to-buffer`, I see both the file `scratch.txt` and the buffer `*scratch*` * if then type `sc`, I only see the file * if I type `*sc`, I only see `*scratch*`
graduale · 2022-06-27 17:31
I believe the matching styles are tried in order. If using one of them you get a match, you don’t see what you would’ve seen with the other styles. But if the first style yields no matches, you see the matches that result from using the next style. So, while `*scratch*` is a match for the `substring` style, that match shows up only if `basic` yields no results.
whudwl · 2022-06-27 22:58
This is the exact same behavior I saw. I find it strange that when I type sc I only see the file. I would definitely want to see both when typing `sc`
oantolin · 2022-06-28 04:28
I'm late to the party: this is the answer. As a little trick, even if you do have some completion-category-defaults or completion-category-overrides, you can usually get ordereless to match by adding a space to your input (which usually causes other completion styles to stop matching).
bdarcus · 2022-06-28 11:16
I don't really have an opinion. Anything to add /u/oantolin?
oantolin · 2022-06-28 18:49
This sounds like some other completion style is doing the matching instead of `orderless`. The completion styles you have configured are tried in order and the first one that matches anything at all gets used. Which completion styles are tried are controled by 3 variables: - `completion-styles` - `completion-category-overrides` - `completion-category-defaults` Check the alist entry for `buffer` in the last two variables, to see which completion styles are being tried. The behavior you describe sounds like `basic`. Even without changing the configuration you can usually get `orderless` to be used by adding spaces to your input, which usually causes the other completion styles to stop matching.
whudwl · 2022-06-29 06:19
Yes it is basic. just did a `emacs -Q` and checked `completion-category-defaults`, here is its value: ((buffer (styles basic substring)) (unicode-name (styles basic substring)) (project-file (styles substring)) (xref-location (styles substring)) (info-menu (styles basic substring)) (symbol-help (styles basic shorthand substring)))