January 24, 2007 — jao

imenu is a very handy command i learnt not long ago. Just type M-x imenu in a source code buffer (an Elisp one, for instance) and start typing the name of a variable or function (or simply TAB for name completion). There you go: instant access to definitions in the buffer.

You can also get the list of completions in a menu item calling imenu-add-menubar-index . Or, if you want the menu to be automatically created for, say, all your C files, you can put something like

(add-hook 'c-mode-hook 'imenu-add-menubar-index)

in your initialisation files.

You can read more about imenu (which has obsoleted speedbar in my workflow) in the Emacs Wiki, including how to adapt it to your favorite language (if it’s not yet supported).

Oh, and the workaround: if you’re using Emacs 22 on Mac OS X, you may need to add this dummy definition to your .emacs to make imenu work:

(defun imenu-progress-message (a &optional c d))

(otherwise, you’ll get an error about imenu-progress-message being an invalid function).