exuberant-ctags + emacs!
Here is rule number one for any python development with Zope3: use ctags.
ctags is a program that goes through an entire source tree and creates a database of where all functions and class definitions are located. This way programs that support ctags can do really fast lookups and give you the location of some function or class definition. You will no longer have to sheepishly ask on irc where such and such Interface or Class is located – and frankly no one else knows and everyone just uses ctags. Here are the steps involved in setting up and using ctags with emacs on ubuntu.
- Install ctags
$ sudo apt-get install exuberant-ctags - Go to the root of your source tree and type at the command line:
$ ctags -Rethis will create a file called
TAGSin the local directory - Use emacs. To do a tag lookup type in any emacs buffer
M-.(that is Alt-. for those of you who don’t know emacs command syntax) - Type in the name of the tag you are looking for. If you don’t know the whole name, emacs supports tab completion in this area. After typing the word hit Enter/Return
- The first time you do this, it will ask you to specify the location of the TAGS file, so just enter it in (it is in the root of your source directory) and hit enter.
- You should now be looking at the definition of the class/interface you were looking for and the file you are in specifies the path.
- Catch-22s:
- Occasionally, due to polymorphism, functions and classes in different packages can have the same name and the tags will go to the first one it finds. So searching for __init__ doesn’t really do any good
- Sometimes the location where something is defined is not where you should be importing from. For example, if there is a class
SomeClassdefined in package/subpackage.py, and package/__init__.py importsSomeClassfrom subpackage, then you are really meant to importSomeClasslikefrom package import SomeClassand not like
from package.somepackage import SomeClassCertainly the former is shorter and simpler.
- Other Tips:
- If you are working in multiple source trees on multiple projects and you want to switch which TAGS database is being loaded, then you can type
M-x tags-reset-tags-tables - If you want to search for every place where a tag is used in your source (like every time someFunction() is called) you can type
M-x tags-searchand enter in the search string. To get to the next result, typeM-,. - Also be sure to check out
M-x tags-aproposandtags-query-replace.
- If you are working in multiple source trees on multiple projects and you want to switch which TAGS database is being loaded, then you can type
For *ahem* vim users *ahem*, there is a vim plugin for ctags found here: http://www.vim.org/scripts/script.php?script_id=273
Heh, I use Wing IDE, which has auto-completion (python code analysis based) built right in. The right methods with the right classes, not the big pot ctags creates. :) The Zope3 debugger integration is mine, btw..
As for VIM: it supports ctags out-of-the-box, the plugin you link to uses ctags to create a more detailed source-code overview. And Wing has both an emacs and a vi mode, so any old unix coder should feel right at home.. ;)