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).
January 25, 2007 at 1:32 am
First let me say that this blog is awesome! As an aspiring emacs beginner this is just the sort of thing I need – my emacs learning lately has consisted of trying out whatever you blog about (plus slogging through the manual)…
My daily dev work is in PHP and I had installed php-mode (the Turadg Aleahmad version) but hadn’t ever enabled the imenu support. When I needed to see a list of functions i was using
M-x occur ^[\ \t]*function
I had previously looked around for some sort of more IDE’ish style environment and installed ECB (very nice: list of buffers open, list of files in current directory, list of important symbols in current file) but wasn’t able to get it to support PHP. Seeing your post made me check out imenu instead and once I got that working ECB automatically uses it for my function list as well. (ECB uses the Semantic Bovinator for file parsing, but it will fall back to ctags or imenu if necessary). Very nice – something I’d been meaning to fix for a while… Keep up the good work!
January 25, 2007 at 7:21 am
If you’re running a gui emacs (eg. X11) you can use imenu like a “modern” context menu under your right mouse button:
(global-set-key [mouse-3] ‘imenu)
January 25, 2007 at 7:23 am
Just in case someone gets confused by the “smart” quote:
(global-set-key [mouse-3] ‘imenu)
January 25, 2007 at 7:24 am
too smart for me…
January 25, 2007 at 11:58 am
Another gem! I’ve been using it for TCL and SQL so far.
@Mark Thanks for your tip. I hate to have to use the menubar and normally have it hidden.
January 25, 2007 at 1:49 pm
I’ve been using Emacs for three years, and I thought I knew most of the tricks. To my delight, every single entry in this blog has taught me something new. Thanks!
January 25, 2007 at 3:35 pm
Hey, FYI if someone leaves a reply, and they neglect to include Mail or Website (which are not declared to be required fields) then they will lose everything they typed 😦 which was….
————————-
Great blog!
However, is imenu really better than a simple isearch-forward? I like to type a fragment of what I’m looking for, not the whole thing, starting at the beginning. I’m not sure I want to retrain my fingers to use this special search in the 10% of cases where it would be more efficient.
BTW, I refuse to enable menus 😉
January 25, 2007 at 5:47 pm
Cool stuff.
I’m loving it; however, the tab completion seems pretty primitive to me. ido-style is much preferrable.
I tried using flet to ido-ize imenu, but it seems to not be working. Perhaps this is the wrong approach. Any ideas?
http://paste.lisp.org/display/35912
Aemon: if you can get imenu to work with ido, then you can use it by only typing the first unique fragment of what you’re looking for. Then it has all the advantages of isearch.
February 12, 2007 at 7:36 pm
imenu is pretty cool, but it does not grok Javascript files where functions are defined as
foo = function(bar) {
alert(bar + “!”);
}
It only likes the good old
function foo(bar) {
alert(bar + “!”);
}
😦
December 22, 2009 at 2:38 pm
Interesting read. There is currently quite a lot of information around this subject around and about on the net and some are most defintely better than others. You have caught the detail here just right which makes for a refreshing change – thanks.