Last year, I wrote about a few ways of highlighting things in an Emacs buffer. A few days ago I had a somewhat similar need. This time, however, I didn’t have a regex to match the things I wanted highlighted: I just needed to mark something (as in “region”), and have it permanently highlighted (“permanently” meaning that the highlighting should survive editing commands, but not actually closing the buffer).
Emacs being Emacs, it turned out to be possible (and easy). Download the highlight.el library (authored by the famous Drew Adams) and enjoy a bunch of commands under the prefix hlt-
. There are quite a few, but let me mention just two.
First, hlt-highlight-region
. It does exactly what it says on the tin, and comes with a counter-spell called (of course) hlt-unhighlight-region
.
And here is the other gem: hlt-highlighter-mouse
. Issue this command and then drag a portion of the buffer with the mouse. It acts like a highlighter pen! How cool is that? And when you no longer need the highlighting, just say hlt-eraser-mouse
and drag again. (Also, you can bind hlt-highlighter
and hlt-eraser
to drag events instead, e.g. with modifiers like super.)
Also, it is worth remembering that hlt-unhighlight-region
removes all highlighting in the region, and if the region is not active, in the buffer.
Read the linked page for more, but even these commands are quite useful!