FlexIsearch

BitBucket repo

This is a minor mode that modifies isearch-mode. If the search fails, the search string is transformed into a regular expression that matches the original and similar strings. The resulting regexp is similar to the way ido flex matching works (see InteractivelyDoThings). You can customize the transformation by redefining the function flex-isearch-compile-regexp. This was originally based off of fuzzy.el by Tomohiro Matsuyama of AutoComplete fame.

Example:

Say you have:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

And search for “lrm”. Isearch will initially fail, and then flex isearch takes over, matching “Lorem” and “laborum”.

Discussion

Nice idea, my only problem with it I can’t use the flex matching conveniently. If I set flex matching to “always” then it is often matches something I don’t want. If I set it to “fail” then I have to press C-s twice until isearch wraps around and fails twice and it switches to flex matching.

How about adding a third option which would use a control character at the beginning of the pattern to switch on flex matching? For example, if I search for “test” then it uses normal isearch matching. If I search for “,test” then it uses flex matching. This would make it very easy to turn on flex matching when I need it. (I used comma as the control character, because I usually don’t use this character as the first char of the search pattern, but the control character should be configurable, so anyone could choose a character he prefers.)

this seems like a perfect use of prefix args? Since current isearch uses a prefix to mean “do regexp search” flex search could use one C-u to mean “regexp” and two C-u’s to mean “flex”, maybe. Eliminate the need for a first-character thing, anyway.

Excellent idea. I’ve updated it to advise normal isearch commands so that a double prefix activates flex searching, and also added some commands that work like the regular isearch commands except they force flex searching. Also, I’ve set the default to not automatically activate flex searching when isearch fails.