notes from /dev/null

by Charles Choi 최민수

Highlighting with isearch

10 Jan 2024  Charles Choi

Happy New Year!

Here’s a follow-up to my last post on improving isearch usability using a Transient menu. Last December I had the opportunity to impromptu demo it online at the Emacs Berlin meetup. At that meeting, Ihor Radchenko (yantar92) made the observation that you could highlight text in a buffer from isearch. When I first heard it, to be honest I had no idea what he meant. Doesn’t isearch already highlight the matches? It was only upon further reading that I got it: isearch highlighting will keep the highlighting turned on after you left isearch mode. Two functions accomplish this:

  • isearch-highlight-regexp (default binding M-s h r)
  • isearch-highlight-lines-matching-regexp (default binding M-s h l)

Both of them have bindings which I’ll never remember, so adding them to my isearch Transient menu was both perfect and trivial. The menu now looks like this:

Emacs isearch Transient menu with highlight support

In the image above, you see that I’ve already highlighted the word “failed” in yellow and want to highlight the word “error” in the syslog buffer. Choosing h in the menu does just that. The result is shown below:

Emacs buffer syslog with highlighted strings 'failed' and 'error'.

You can remove the highlighting using unhighlight-regexp command, available from the main menu at EditRegexp HighlightingRemove Highlighting…

Being able to highlight regexp matches in a buffer is a really great feature, especially for analyzing log files. It's so great that I get wistful thinking of all the many times I could of used this feature in the past. Better late than never though - from here on out isearch highlighting will be an essential tool that I’ll grab whenever I need to look at a log file or markup any kind of text.




Feeds & TagsGet Captee for macOS

Powered by Pelican