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

regexps ending with $ #71

Closed
MarkWeberMaths opened this issue Jul 24, 2021 · 2 comments
Closed

regexps ending with $ #71

MarkWeberMaths opened this issue Jul 24, 2021 · 2 comments

Comments

@MarkWeberMaths
Copy link

Hello. Thanks for this package.

I have experienced some strange behaviour when trying to narrow my search using $ at the end of a regexp. For instance if I have a bunch of .ts and .tsx files open, and when using consult-buffer, I'd like to narrow my search to buffer names ending in 'ts' by typing 'ts$' in the search interface. For me this gives no matches. However I experience no problems using ^ at the beginning of a regexp, in such cases search narrowing works as you'd expect. When experimenting with more examples I get inconsistent behaviours -- all of the following regexps should narrow to buffers whose names end in 'ts' -- 'ts$', '[t]s$', 'ts[^x]$', 'ts[^y]$', '[t]s[^z]$ -- but for me, the first 2 give no matches, but the last 3 do successfully match the buffer names ending in 'ts'.

@oantolin
Copy link
Owner

oantolin commented Jul 24, 2021

This is actually not a bug in orderless at all, but something caused by an implementation detail in consult-buffer: it appends an invisible character to the end of the candidates for disambiguation. So if you have a buffer called heap.ts the consult-buffer candidate is actually called something like heap.ts# where the # stands for some weird unicode character which consult arranges to be invisible using Emacs display properties. Knowing this you can easily see why ts$ and [t]s$ don't match but the regexps like ts[^x]$ do:

  • ts$ and [t]s$ match strings that end in ts, so they do not match strings ending in weird character I'm denoting #.
  • ts[^x]$ does match, because [^x] matches the # character.

(Note that you said ts[^x]$ should match names ending in ts, but that of course is not true, because if a name ends in ts, then its last character, namely s, does match [^x]; but the previous one ,t, does not match s.)

The simplest work around is to use a . to match the invisible character added by consult-buffer: the regexp ts.$ matches your buffers. More sophisticated workarounds are documented in the consult wiki.

@MarkWeberMaths
Copy link
Author

Great! Thanks for the explanation. Might I suggest adding something about this in the orderless documentation, since from the user's prespective this does look at first glance like a bug in orderless? For instance, when reaching the orderless github page in my browser, it would be good if searching on '$' would bring me to this information.

Thanks again.

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