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 -Re
this 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.
- 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 imports
SomeClassfrom subpackage, then you are really meant to import
from package import SomeClass
and not like
from package.somepackage import SomeClass
Certainly the former is shorter and simpler.
- 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
- 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, type
- Also be sure to check out
For *ahem* vim users *ahem*, there is a vim plugin for ctags found here: http://www.vim.org/scripts/script.php?script_id=273