Downcasing Every Occurrence of a Word in a Buffer

Marcin Borkowski (mbork) has an instructive post based on a question in the emacs-humanities mailing list. The question that Borkowski addresses is how to replace every occurrence of a word in a buffer with its downcased version without typing the word twice. Borkowski solves this problem by writing a bit of Elisp.

In a sense, his solution is silly—as even he admits—because there are pretty easy ways of doing this with built-in commands as a couple of the respondents replied. Still, Borkowski’s solution serves as a nice example of writing a bit of Elisp to solve a simple problem.

As usual, Borkowski shows us the scaffolding. By that I mean that he doesn’t just show us a solution but the steps—and missteps—he took arriving at it. That’s why it’s an instructive post. The main thing you learn from the post is how to search through a buffer for a given regex and replace it with something else. That’s basically the interactive query-replace-regexp but you’re not supposed to call that directly from Elisp for various reasons.

Borkowski gives us the template for this sort of operation and makes it obvious how to change the operation on the target or add other steps. It’s a nice post and worth reading even if you’re already conversant with Elisp.

This entry was posted in General and tagged . Bookmark the permalink.