Deburring Emacs Imenu GUI Configuration
10 Feb 2026 Charles Choi
A while back, I made a post on Emacs Imenu configuration that made an unsafe assumption that any mode derived from prog-mode would support Imenu. Turns out, that’s not always true (for example, looking at you gnuplot-mode). This post shows how to deal with this using an error handler.
One such implementation of an error handler is the lambda expression shown below using condition-case.
1 2 3 4 5 6 | |
A couple of observations:
- The error handler is opportunistic in applying
imenu-add-menubar-indexto a mode derived fromprog-mode. - If the error
imenu-unavailableis caught, then a warning message is logged but not messaged to the mini-buffer.- The variable
inhibit-messageis used to avoid sending a warning message to the minibuffer (it will still be logged in *Messages*) to avoid noise from modes that do not support Imenu. (Thanks to bpalmer for this guidance.)
- The variable
If you use Emacs and this is the first time you’ve heard of Imenu, I highly recommend that you learn what it has to offer.