Endless Parentheses

Ramblings on productivity and technical subjects.

profile for Malabarba on Stack Exchange

New in Emacs 25.1: Easily search for non-ASCII characters

Since last week’s post was about Unicode characters, it makes sense to continue that trend today. This feature might go unnoticed by a lot of people who live in an ASCII world, but it will probably jump out at everyone else at one point or another. The name, if a bit odd, is “character-folding search”.

In Emacs 25, Isearch can find a wide range of Unicode characters (like á, ⓐ, or 𝒶) when you search for ASCII characters (a in this example). To enable this feature, set the variable search-default-mode to char-fold-to-regexp.

(setq search-default-mode #'char-fold-to-regexp)

This first came up due to a new feature of a recent version of Texinfo, where some markup styles are exported in “round quotes” when generating the info manual. This is a nice improvement in readability, but when you’re trying to search for something with C-s, things can get a little difficult if your keyboard can’t type some of the characters.

With char-folding, when you hit C-s and search for ", Emacs will also search for a variety of double quotes, from the aforementioned “” to many others like «» and ❝❞. The same goes for the single quote, and for pretty much any other ASCII character.

You could always type any Unicode character by name with C-x 8 RET, and many of them even have their own shortcuts under C-x 8, but not having to type them can be a significant convenience when it comes up. As any Brazilian, I am a daily user of diacritical marks (ó, ã, ê, and the likes), and even though my keyboard can type these characters, I still enjoy the simplicity of not having to.

Finally, you can extend this feature to the query-replace command, which is also as easy as setting a variable.

(setq replace-char-fold t)
comments powered by Disqus