notes from /dev/null

by Charles Choi 최민수


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
(add-hook 'prog-mode-hook
          (lambda nil
            (condition-case err (imenu-add-menubar-index)
              (imenu-unavailable
               (let ((inhibit-message t))
                 (message "Warning: %s" (error-message-string err)))))))

A couple of observations:

  • The error handler is opportunistic in applying imenu-add-menubar-index to a mode derived from prog-mode.
  • If the error imenu-unavailable is caught, then a warning message is logged but not messaged to the mini-buffer.
    • The variable inhibit-message is 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.)

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.

emacs

 

AboutMastodonBlueskyGitHub

Feeds & Tags
Get Scrim for macOSGet Captee for macOS

Powered by Pelican