In Emacs, how can I jump between functions in the current file?
Asked Answered
G

9

21

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.

Grantley answered 25/1, 2010 at 4:34 Comment(0)
W
36

Just to jump around functions in the current file? Use imenu. It's the simplest and lightest of all the alternatives listed so far and might be enough for what you want. It's also built into Emacs and has minimum setup hassle. It features graphical and textual interfaces. Anything extra and you'll be better off using one of the other excellent suggestions made here.

Woosley answered 25/1, 2010 at 6:23 Comment(2)
What languages are supported? C-family and Elisp, what else?Keslie
I think most of the inbuilt modes work fine with imenu. It's pretty easy to add imenu support to a mode as well. It works for Python and in Cperl mode. I've used those.Woosley
P
2

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.

Palladium answered 25/1, 2010 at 5:15 Comment(0)
F
2

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

Fideism answered 25/1, 2010 at 12:21 Comment(0)
S
0

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.

Subalpine answered 25/1, 2010 at 4:57 Comment(0)
R
0

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.

Renee answered 25/1, 2010 at 5:5 Comment(1)
Semantic also has nice integration with Anything, and the anything-c-source-semantic source gives a list of everything found by semantic.Erudition
J
0

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

Jansenism answered 25/1, 2010 at 5:23 Comment(0)
T
0

global gtags is very good

Tourniquet answered 26/1, 2010 at 8:40 Comment(0)
S
0

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.

Splat answered 21/8, 2011 at 23:4 Comment(0)
S
0

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.

Squatness answered 4/2, 2022 at 15:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.