Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I best do source code browsing inside Emacs?

Tags:

emacs

I have a workflow where I use grep and other tools in a shell for searching in different projects even though my main editor is emacs. I usually work on bug fixing and minor development of source code that is often unknown to me so searching the code is important. The langages I mostly work in are php, ruby, java, perl and sometimes python.

Is there some common IDE extension in emacs that would enable me to have functionality like "goto definition" from multiple files that span all these languages? Are there some other modules that could be useful, either code browsing or indexed search?

like image 513
grm Avatar asked Nov 01 '10 18:11

grm


2 Answers

If you want to work with lots of different languages, ctags is pretty flexible. See the EmacsWiki for instructions on integration of ctags.

like image 90
dbrown0708 Avatar answered Oct 23 '22 11:10

dbrown0708


Code browsing can mean a bunch of different things. The mode you mention of using grep implies to me you are looking for function definitions, or perhaps looking for uses of a particular function.

While CEDET supports all the languages you list (some with the ctags parser), starting fresh in a new source code area is something CEDEt isn't too good at until it has indexed the entire project for those tasks you listed. You can, however, use GNU Global or idutils. I think idutils supports more languages.

In CEDET, the `semantic-symref' and related commands will do a grep-like operation with grep, or global, or idutils (depending on what type of tag table you created.) Unlike grep style output, the symref output buffer shows which functions are using the command in question. You can then execute macros on the hits of the symbol you care about to do large refactoring operations.

CEDET also supports a tags like jump to function, though if you are already using something like ctags that works fine too. CEDET is better when it comes to handling polymorphism in some cases.

With CEDET, you can also get structured browsing via imenu, speedbar, and ECB (the emacs code browser). ECB is particularly good in that the methods buffer allows you to quickly navigate to different parts of a class. Particularly handy for classes where the pieces are spread around, like in C++. CEDET can even create cute UML diagrams of class inheritance structures which are connected to your code.

CEDET does take some learning, and some of the languages you list are not fully supported for all the tools, though the basic browsing discussed above should be ok.

like image 37
Eric Avatar answered Oct 23 '22 10:10

Eric