views:

278

answers:

2

Has anyone managed successfully using cscope with Python code? I have VIM 7.2 and the latest version of cscope installed, however it doesn't get my code's tags correctly (always off by a couple of lines). I tried the pycscope script but its output isn't supported by the modern version of cscope.

Any ideas? Or an alternative for browsing Python code with VIM? (I'm specifically interested in the extra features cscope offers beyond the simple tags of ctags)

+2  A: 

EDIT: I'm going to run through the process step by step:

Preparing the sources:

exhuberant ctags, has an option: -x

   Alternatively,  ctags  can generate a cross reference file which lists,
   in human readable form, information about the  various  source  objects
   found in a set of language files.

This is the key to the problem:

 ctags -x $(ls **/*.py);                  # replace with find if no zsh

will give you your database of source objects in a known, format, described under

 man ctags;                               # make sure you use exuberant ctags!

Gnu Global is not limited to only the "out of the box" type of files. Any regular file format will serve.

Also, you can use gtags-cscope, which comes with global as mentioned in section 3.7 of the manual, for a possible shortcut using gtags. You'll end up with an input of a ctags tabular file which Global/gtags can parse to get your objects, or you can use the source for pycscope together with your ctags file of known format to get an input for the vim cscope commands in

if_cscope.txt.

Either way it's quite doable.

Perhaps you'd prefer idutils?

Definintely possible since

z3c.recipe.tags

on pypi makes use of both ctags and idutils to create tag files for a buildout, which is a method I shall investigate in short while.

Of course, you could always use the greputils script below, it has support for idutils , we know idutils works with python, and if that fails, there is also something called vimentry from this year that also uses python, idutils and vim.

Reference links ( not complete list ):

http://www.vim.org/scripts/script.php?script_id=893 ( Gnu global, updated 2008 )

http://www.vim.org/scripts/script.php?script_id=1062 ( greputils, contains support for the *id idutils, 2005 )

http://www.vim.org/scripts/script.php?script_id=251 ( Ancient, but this guy is pretty good, his tag and buffer howtos are amazing 2002 )

http://code.google.com/p/python-on-a-chip/source/browse/trunk/src/tools/pycscope.py?r=503 ( 2009, seems to be updates to pycscope)

Hopefully this helps you with your problem, I certainly helped me. I would have been quite sad tonight with a maggoty pycscope.

chiggsy
gnu global doesn't support Python, grep utils obviously isn't what I'm looking for... why do you link to pycscope's source code?
Eli Bendersky
I've edited my answer to be more precise above.
chiggsy
Why do you use `$(ls **/*.py)` instead of `**/*.py` on its own? AFAIK in zsh they are equivalent, and will both expand to the list of matching files in all subdirectories.
Dave Kirby
@Dave, not on my system.
chiggsy
I've decided to grant you the bounty since you've done a solid amount of research trying to help me solve the problem. Keep up the good work on SO
Eli Bendersky
+1  A: 
  1. From a correspondence with the maintainer of cscope, this tool isn't designed to work with Python, and there are no plans to implement that compatibility. Whatever works now, apparently works by mistake, and there is no promise whatsoever that it will keep working.
  2. It appears I've been using an out-of-date version of pycscope. The latest version 0.3 is supported by the cscope DB. The author of pycscope told me that he figured out the output format for the cscope DB from reading the source code of cscope. That format isn't documented, on purpose, but nevertheless it currently works with pycsope 0.3, which is the solution I'll be using.

I'm going to accept this answer since unfortunately no other answer provided help even after bounty was declared. No answers are upvoted, so I honestly have no idea where the bounty will go.

Eli Bendersky
*shrugs* You wanted an alternative to cscope, which would be idutils. They perform similar tasks.
chiggsy
@chiggsy: AFAIU idutils is more a replacement for `grep` than for `cscope`
Eli Bendersky