'In Emacs, how can I jump between functions in the current file?

I'd like to quickly move point to a function in my Emacs buffer. I'd like to run some function and get a prompt asking me for the function name, with completion provided for every function defined in the current buffer.

I generally use etags to navigate around, but sometimes I'm looking for a framework method that's been overridden in several files. In these cases, I can find the file I need but then I'd like to quickly jump to the function there. There is a similar feature in TextMate where you can select a definition from a list in the bottom right of the editor.



Solution 1:[1]

speedbar comes standard, and gives you a collapsible menu for each file in the current directory, by default middle clicking on an entry for a function definition jumps to that def. With emacs23 this was changed to the more normal leftclick.

Solution 2:[2]

You can use etags-select to select from multiple matching tags. But the answer to what you asked is imenu.

Solution 3:[3]

Icicles is probably closer to what you are looking for:

http://www.emacswiki.org/emacs/Icicles_-_Tags_Enhancements

It's an enhancement to etags and includes (among other things) the file name with the tag so you can tell if it's the one you are looking for.

Solution 4:[4]

try CEDET. It is a bit difficult to set up the first, but here is an excellent tutorial: by Alex ott

And when he gets installed, you can use semantic-complete-jump. pressed tab couple times, and it is also brings up symbol definitions.

Solution 5:[5]

If M-. brings up the wrong method, you can type C-u M-. to find the next one with the same name.

Solution 6:[6]

global gtags is very good

Solution 7:[7]

To navigate within the current file or a set of files that you select, you do not need a TAGS file. You can use Imenu. But it is better to use Icicles imenu commands.

Why? Because they let you use completion. Substring, regexp, prefix, or fuzzy completion. Combine simple patterns to match, or subtract them.

Command icicle-imenu is bound in Icicle mode to C-c =. Butyou can also look up just a command or just a non-command function (non-interactive), using command icicle-imenu-command or icicle-imenu-non-interactive-function.

These commands are multi-commands, meaning that they are actually browsers: you can trip among function definitions using keys C-RET or C-mouse-2 (direct jumps) and C-down (cycle). Hit RET or click mouse-2 to settle down at a final destination.

Solution 8:[8]

I use C-M-a and C-M-e to jump between the beginning and end of functions.

Otherwise, open up Speedbar and click the + icon next to a file name to view a list of functions contained in the file. Then click on the function names to jump to them directly.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Justin Smith
Solution 2 scottfrazer
Solution 3 Joshua Smith
Solution 4
Solution 5 offby1
Solution 6 chunhui
Solution 7 Drew
Solution 8 mrbean