Sarcastify Region of Text in Emacs
Posted on 14th of November 2026Every now and then, someone says something so profoundly obvious, unexpected, or completely detached from reality that there is really only one appropriate response: repeat exactly what they said, but in a more sarcastic tone.
The problem is that once you start noticing these sentences, they seem to be everywhere. One absurd statement leads to another, then another, until eventually you find yourself surrounded by an endless stream of things that are technically sentences but somehow seem to exist in defiance of everything you know about politics, society, and human nature.
Instead of:
“Politicians always put the public interest before their own.”
You simply respond:
“pOlItIcIaNs AlWaYs PuT tHe PuBlIc InTeReSt BeFoRe ThEiR oWn.”
Naturally, doing this manually is tedious. So I wrote a tiny function that transforms the selected region into alternating lowercase and uppercase text, while leaving punctuation, whitespace, and everything else alone.
(defun sarcastify-region (beg end)
"Convert region to alternating-case."
(interactive "r")
(let ((text (buffer-substring-no-properties beg end))
(upper t))
(delete-region beg end)
(insert
(mapconcat
(lambda (char)
(if (string-match-p "[[:alpha:]]" (char-to-string char))
(progn
(setq upper (not upper))
(char-to-string
(if upper
(upcase char)
(downcase char))))
(char-to-string char)))
text
""))))Select some text, invoke sarcastify-region, and you’re good to go!