notes from /dev/null

by Charles Choi 최민수


Emacs Regexps: The Small Print

18 Jul 2024  Charles Choi

With my recent work with Casual RE-Builder, I found to my surprise that not all Emacs regexp commands take an Emacs-style regexp. 🤯

Apparently some commands take a grep-style of regex like dired-do-find-regexp and dired-do-find-regexp-and-replace. For such commands, the regexp syntax is dependent on the type of grep that is installed and configured for use by Emacs. If you are using GNU grep, the good news is that the regexp syntax is largely the same as Emacs.

I qualify this as largely because with interactive commands, the escaping rules are different between Emacs and grep-style regexps. I suspect this has only added to the frustration of using plain RE-Builder which only provides export for a Emacs-style regexp to be used in code.

To alleviate this, Casual RE-Builder now has a new command to export specifically to interactive grep-style regex commands. This presumes that the GNU grep is being called.

Also the search & replace menu in Casual Dired has been modified to highlight such grep-style regex commands.

One last note: While I’ve taken effort to verify that this new command is doing all the right escaping, I would not be surprised if it has bugs. Because Elisp does not have support for raw strings like Python and Swift, I’m at a loss to know how to write a unit-test to automate its verification. For now I’m doing it manually, with test regexps that hopefully cover enough escaping behavior. If you find a bug, please report an issue with your regexp and the target text so I can troubleshoot. I’d also qualify that my knowledge of Elisp regexps is not that deep. I’d be happy to get guidance from more enlightened readers.

With all that said, I invite you to try this new feature out in Casual RE-Builder. I think you’ll be delighted that you did.

emacs

 

About • Mastodon • Instagram • GitHub

Feeds & Tags • Get Captee for macOS •

Powered by Pelican