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

Trouble defining new filtering rules with diacritics #69

Closed
hieutkt opened this issue Jul 18, 2021 · 2 comments
Closed

Trouble defining new filtering rules with diacritics #69

hieutkt opened this issue Jul 18, 2021 · 2 comments

Comments

@hieutkt
Copy link

hieutkt commented Jul 18, 2021

I am trying to make a new "matching style" (not sure if I'm using the correct jargon) to make filtering in orderless behaves well with diacritics. For example typing resume would match résumé, etc...

I have written a small function that would convert résumé to resume, using the built-in ucs-normalize.el:

(defun remove-diacritics (s)
    (replace-regexp-in-string
     ucs-normalize-nfd-quick-check-regexp ""
     (ucs-normalize-NFD-string s)))

However, adding this function to either orderless-matching-styles or orderless-style-dispatchers doesn't seem to work. I read the README but haven't been able to wrap my head around this. Any help is appreciated. Thanks!

@oantolin
Copy link
Owner

oantolin commented Jul 18, 2021

You may be thinking backwards about how to do this. A matching style gets called on the pattern you type to turn it into a regexp. So here's what happens with the remove-diacritics matching style: say you have "résumé" among the candidates and you type "resume" at the prompt, then remove-diacritics gets called with the pattern you typed, namely "resume", and turns it into the regexp "resume" which, of course, does not match "résumé".

What you need instead of remove-diacritics is a function that turns "resume" into some regexp that does match "résumé". The built-in function char-fold-to-regexp fits the bill, so you can delete your remove-diacritics and add char-fold-to-regexp directly to orderless-matching-styles.

@hieutkt
Copy link
Author

hieutkt commented Jul 18, 2021

Perfect! char-fold-to-regexp solves some of the other edge-cases that I'm thinking about, too!

Thanks a lot. I'm closing this issue.

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