12

Does emacs have a function or library that can allow the user to go to the function declaration even if it was defined in another file?

If so, what languages is there support for?

The inspiration for this question, comes from the below article which talks about some of the reasons why emacs will never be able to compete with IDE's.

http://henrikwarne.com/2012/06/17/programmer-productivity-emacs-versus-intellij-idea/

  • The way emacs generally handles this is by relying on external, compiled programs (like clang) to understand the source code quickly and respond to queries passed via the command line. Check out irony-clang to this end. Did you read the comments on the article? – Sean Allred Mar 19 '15 at 2:37
  • 1
    The functionality provided by alchemist.el, for elixir, or omnisharp for C#, both of which rely on external programs for navigation/refactoring/ide-ish stuff are pretty akin to most IDEs out there. (at least for most use cases). Emacs is not in the same business as IDEs, so I don't think that's reasonable to say it will never have a competing chance. – Renan Ranelli Mar 19 '15 at 3:11
  • @RenanRanelli IDE is just the same way, except we have to do integration manually instead of someone already did it and called it an "IDE". – Tu Do Mar 19 '15 at 6:34
  • IN 2019 there is only one solution you should consider in my opinion. And that is rtags with company completion. Forget etags or the bloated, unstable CEDET. rtags uses compile-time info to provide a LIVE structure of what your project is using. global et al are awful - they are glorified "greps" that do a lot of guesswork and frequently take you to the wrong place. github.com/Andersbakken/rtags – HörmannHH Mar 10 at 14:58
14

You can jump to any definition/reference of entire project as large as Linux kernel source tree (more than 36k) in an instant. See my C/C++ guide for details. For C/C++, I suggest using GNU Global that supports C, C++, Yacc, Java, PHP4 and assembly.

The key is, if you want to have IDE features of a language, you have to install plugin of that language. Here are some packages for dynamic languages that I know of:

  • Live web development: skewer-mode.
  • Javascript: Tern. But before that, remember to install js2-mode. As for what js2-mode does, see the description; but in essence, js2-mode is a complete Javascript parser that generates an AST to do proper IDE features. If you install skewer-mode than you will have js2-mode by default, since skewer-mode depends on it.
  • Python: elpy, see the IDE features
  • Ruby: robe provides these features:
  • Jump to method definition
  • Jump to super or a constructor called at point
  • Jump to a module or class (provided it has at least one method defined)
  • Display method documentation
  • Display information about method called at point using ElDoc
  • Method and constant name completion

You can also use ctags to support vast many languages such as shell script or Tcl...

  • Any suite suggestion for javascript? – user2522280 Mar 19 '15 at 15:51
  • @BarryG There is Tern and j2-mode I edited in my answer. – Tu Do Mar 20 '15 at 6:17
  • 2
    I'd like to point our that anaconda may be a more specific solution for definition jumping in Python. – PythonNut Feb 19 '16 at 0:48
  • @TuDo You've put Robe's feature list under ESS. – Dmitry Feb 20 '16 at 12:00
  • For C++, there's also rtags and ycmd. I use ycmd, which also works with e.g. Python, C#, Go and other languages. I use dumb-jump and counsel-rg as a fall-back or to show usages or commented/doc mentions of a symbol. – unhammer Aug 21 '17 at 9:43
17

I ran into a similar issue with emacs, so I made Dumb Jump. I tried many of the solutions mentioned in the accepted answer, but I always ran into one or more of the following issues:

  • Solution only worked for a single programming language
  • Solution required an index (TAG) file or persistent process

I badly wanted a solution that "just worked" and didn't require customization or setup. That is, I wanted to clone a random repo on Github and navigate around it like any other of my own projects.

Right now Dumb Jump has basic support for:

  • JavaScript
  • Emacs Lisp
  • Python
  • Go
  • PHP
  • Ruby
  • Faust
  • R
  • Lua
  • Rust
  • ...and more

It's available via MELPA and GitHub issues and PRs are more than welcome.

4

The primary solution for this in emacs is using TAGS files, which are created by programs such as etags or gtags. I myself use (and recommend) exuberant ctags, and etags-select.el to help you narrow down destinations when the search symbol lies in multiple destinations. The supported languages are quite numerous, see the individual tools' manuals. There is even support for adding your own language, whereby you can provide a regular expression that instructs ctags how to isolate the tags you are interested in.

  • 1
    Oh! How could I forget about tagsfiles? ctags -e -R * from the root directory will set it up for you. – Sean Allred Mar 19 '15 at 3:46
  • is this an acceptable solution when your project has many dependencies (such as more recent javascript web dev projects)? – Rudolf Olah Nov 19 '15 at 16:08
  • The number of dependencies is not itself an impediment. You can either have one large tags file that aggregates many different libraries; I did this for many years, the ctags command invocation trivially does this. Or what I now recommend is to have a separate tags file per dependency; emacs is smart enough to load multiple tags files. To ease this, search out etags-table.el, which helps loading groups of tags files per project. – InHarmsWay Nov 19 '15 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.