Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the short-cut key to jump to declaration in Emacs?

Tags:

emacs

Well, it's a bit more involved than that.

By default, Emacs doesn't "know" about function declarations for C or C++ code. First, obtain Exuberant Ctags. Then, use command etags (ctags for Emacs) on your source code. A file named TAGS will be generated.

Then, while editing your source code, when you want to jump to a declaration, press M-. (meta and dot, or alt and dot on modern keyboards). At first, Emacs will ask you for location of your tags file. Point it to the one you generated and afterwards navigation will be automatic.

I'd suggest reading Emacswiki article about tags for a better understanding of this functionality.

The newest version of Emacs (23.2) comes with CEDET integrated, which has more advanced features for C and C++ navigation, but it can be a bit difficult to set up right, so read more about it if you're interested.


M-. key will take you to the function definition emacs.


As others have said there is no built-in universal solution for this in emacs. That said, after having this functionality in IntelliJ I wanted it in emacs too so I made Dumb Jump.

Right now Dumb Jump has basic support for:

  • JavaScript
  • Emacs Lisp
  • Python
  • Go
  • PHP
  • Ruby
  • Faust
  • and more... (over 20 now)

It's available via MELPA and is actively being developed.


There are multiple ways to do this. As darioo mentioned, Ctags is one, but it goes to the definition by default (which might work for you). Looking further, though, you can see that prefixing M-.(ie, C-u M-.) will take you to the next tag match (which is often the declaration). There is also a --declarations option, but Exuberant Ctags doesn't seem to support it.

CEDET is another option, but in my experience, it's still not ready for production. Often times in C++ semantic-ia-fast-jump will go to forward declarations instead of the definition or the declaration.