views:

125

answers:

2

Is there an equivalent of slime for python?

For example, if I position the cursor on foo() and do M-. (jump to definition) I would like to see the source definition of the function foo

This should work regardless of whether foo is in

1) the local project directory

2) in some ~/.virtualenvs/bar/lib/site-packages

3) in some other python-path

4) virtual env is in use (ie, it should look in my current virtualenv)

Does the pymacs/ropemacs combination do any of this?

+2  A: 

M-. normally runs the "find-tag" function. You should create a TAGS file of your python source files. Then you "visit-tags-table" before doing a M-. That way, Emacs will jump to all the definitions of the tag. Type C-u M-. to jump the next definition of your tag. See find-tag documentation for help. Consult Emacs help to know how to create a TAGS file from python source files.

You can for example use Exuberant Ctags for creating the TAGS file.

Go to the root directory of your python files and do this :

ctags -e -R .

A TAGS file is normally created at the root directory of the project.

Jérôme Radix
I recommend looking at http://www.emacswiki.org/emacs/EtagsSelect as well, which provides a nicer interface if you bind `M-.` to `etags-select-find-tag`
phils
With an etags in root, and several projects wouldn't it get confused between different installs of the same package (multiple site-packages?). Or at least, each time it'd pop up a buffer asking me *which* source defn I wanted to go to?
nunb
You create a TAGS file for each of your project at their respective root directory (not the root directory / of the system). Then you use 'visit-tags-table' on each TAGS file that interest you. All TAGS files reference are appended to 'tags-table-list' variable. Then, using M-. , emacs search for the keyword in all TAGS files referenced in 'tags-table-list'.
Jérôme Radix
+1  A: 

To avoid the -e you can use etags and with a find you recursively add the py file:

find . -type f -name '*.py' | xargs etags
mathk
Yeah, but the relevant .py files are not in a subdirectory of my code, they are in ~/.virtualenv whereas I work in ~/src/project/foo
nunb
With find you can use any directory you want: `find ~/.virtualenv -type f -name '*.py' | xargs etags`
mathk
I guess this calls for a virtualenv hook then, so that the tags can automatically be generated for whatever working directory + virtualenv combo the user is in.
nunb
@nunb sorry I don't get what you said. What I wrote to you is the shell command to generate the TAGS file.
mathk