Since ctags is somewhat language agnostic, this isn't really Python specific. Neither python.el nor python-mode.el do anything with tags that I can tell.
Welcome to 80's style code navigation! Ctags is a program the analyzes code and creates an index (called a TAGS file). Unlike a compiler that knows what's going on in your code, the index makes best guesses (using advanced technology such as regexes). The basic idea is that with this index in hand one can quickly navigate to the definition of a function or class. (Although it may be ancient tech, there are quite a few editors that support this old school technology, including emacs, jedit, kate, notepad++, vi and even Textmate)
I've been reading through Programming in Emacs Lisp, and in section 4.1 it talks about using TAGS files for navigation of elisp files. So I thought I'd mess around with it in Python.
One way to build a TAGS file is to use the etags command included in emacs. I used exuberant tags, a more featureful etags replacement (though I'm not really using too many features just the recurse feature (rather than find/pipe/xargs to normal etags)).
Apparently, buildout has support for creating TAG files. Since I've never used buildout, I can't comment more on that, but it looks straightforward enough for buildout users.
Another way as suggested in section 12.5 "Creating Your Own TAGS File (of the lisp intro book), is to run the command from M-x compile. (Though first you might want to M-x cd to get to the root of your project if your current python buffer isn't at the root. Then instead of running the normal compile command, you'll give something like this (note --recurse is an exuberant feature, also note that "src" should be a directory containing python modules)
etags --recurse=yes src. Note, another binary is included with exuberant called ctags. Don't use that one, as emacs will complain about an invalid tag file.
That's all there is to creating TAGS. Of course, once you edit your files, you need to recreate the TAGS file, as it will be out of date. (If I find a good way to automate that, I'll post here).
How to use tags? Well emacswiki has some suggestions for using tags. The main one is M-. (find-tag) which should take you to the definition of said tag (after you point it to the TAGS file you just created). There's also tags-search which is a little like C-s but if you follow it with M-,, it takes you to all references of a tag which includes going to other files as well. Quite handy.
If anyone has any more suggestions for tags, I'd love to hear them. I'd like to look into js/html/css support. I'll update this post as I use tags more.
I'm using a simple shell alias for generating the tags, which I typically
invoke from a top-level directory of a project:
alias update-tags='find . -type f -name '\*py'\ | xargs etags -o TAGS -a -l python'
Handy command line alias! I'm using buildout with "omelette", which creates
a symlink structure to all the libraries used. So I had to add the -L
option for traversing the symlinks:
I wrote a custom vim plugin that lets me press F5 while on top of an
identifier, looks up the file defining that name, and adds the appropriate
'from foo.bar.baz import X' at the top. Incredibly awesomely useful.
"ctags -e -R *" at the top of your tree produces an Emacs compatible TAGS
file - Exuberant Ctags 5.7 - emacs 23.1
Another useful use of tags -- again for vim, I'm not that familiar with
emacs -- is that they are used for keyword completion (vim's equivalent of
dabbrev-expand). This way you get a complete database of all identifiers
used in your project.
Hi