使用 cscope 通过 VIM 浏览 Python 代码?
有没有人成功地使用 cscope
和 Python 代码进行管理?我安装了 VIM 7.2 和最新版本的 cscope
,但是它无法正确获取我的代码标签(总是偏离几行)。我尝试了 pycscope 脚本,但现代版本的 cscope 不支持其输出。
有什么想法吗?或者使用 VIM 浏览 Python 代码的替代方案? (我对 cscope
除了 ctags
的简单标签之外提供的额外功能特别感兴趣)
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
)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我有同样的问题,浏览互联网后,我找到了解决此问题的方法:
创建一个 python 脚本:
cscope_scan.py
在代码的根文件夹下执行此脚本,这将生成 < code>cscope.files 然后执行
cscope -b
我不知道我的计算机会发生什么,最后两行效果不佳,但我认为手动输入 < code>cscope -bk 是可以接受的:)I got the same question you got, after browsing the internet, I found a way to fix this:
create a python script:
cscope_scan.py
excute this script under you code's root folder, this will generate the
cscope.files
and then excutecscope -b
I don't know what happens to my computer, the last two lines aren't working well, but I think manually type acscope -bk
is acceptable:)此 hack 似乎还强制 cscope 浏览 Python 文件:
如果您接受
cscope
是 显然不适合与 Python 一起使用。超集任何语言任何工具问题:如何查找所有出现的情况Vim 中的变量?
This hack also seems to force cscope to go through Python files:
If you accept that
cscope
is apparently not designed to work with Python.Superset any language any tool question: How to find all occurrences of a variable in Vim?
编辑:我将逐步完成该过程:
准备源:
exhuberant ctags,有一个选项:-x
这是问题的关键:
将以已知的格式为您提供源对象的数据库, Gnu Global中描述的
不仅限于“开箱即用”类型的文件。任何常规文件格式都可以。
此外,您还可以使用 gtags-cscope(如手册第 3.7 节中所述,它带有全局)作为使用 gtags 的可能快捷方式。您最终将得到一个 ctags 表格文件的输入,Global/gtags 可以解析该文件以获取您的对象,或者您可以将 pycscope 的源代码与已知格式的 ctags 文件一起使用,以获取 vim cscope 命令的输入
if_cscope.txt。
不管怎样,这都是可行的。
也许您更喜欢 idutils?
绝对有可能,因为
pypi 上的z3c.recipe.tags
使用 ctags 和 idutils 来为构建创建标记文件,这是我将很快研究的一种方法。
当然,您始终可以使用下面的 greputils 脚本,它支持 idutils ,我们知道 idutils 可以与 python 一起使用,如果失败,今年还有一个名为 vimentry 的东西也使用 python、idutils 和 vim。
参考链接(不完整列表):
希望这可以帮助您解决您的问题,我当然也帮助了我。今晚如果有蛆虫望远镜的话我会感到非常难过。
EDIT: I'm going to run through the process step by step:
Preparing the sources:
exhuberant ctags, has an option: -x
This is the key to the problem:
will give you your database of source objects in a known, format, described under
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):
Hopefully this helps you with your problem, I certainly helped me. I would have been quite sad tonight with a maggoty pycscope.
这似乎对我有用:
更改为 python 代码的顶级目录。创建一个名为
cscope.files
的文件:如果未正确构建交叉引用,您可能需要首先执行
cscope -b
。This seems to work for me:
Change to the top directory of your python code. Create a file called
cscope.files
:You may need to perform a
cscope -b
first if the cross references don't get built properly.cscope
维护者的通信,该工具并非设计用于与 Python 配合使用,并且没有计划实现该兼容性。无论现在起作用的是什么,显然都是错误的,并且没有任何承诺它会继续起作用。pycscope
。cscope
DB 支持最新版本 0.3。pycscope
的作者告诉我,他通过阅读cscope
的源代码弄清楚了cscope
DB 的输出格式。该格式没有被故意记录,但它目前可以与 pycsope 0.3 一起使用,这是我将使用的解决方案。我将接受这个答案,因为不幸的是,即使在宣布赏金后也没有其他答案提供帮助。没有答案得到赞成,所以老实说我不知道赏金会去哪里。
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.pycscope
. The latest version 0.3 is supported by thecscope
DB. The author ofpycscope
told me that he figured out the output format for thecscope
DB from reading the source code ofcscope
. That format isn't documented, on purpose, but nevertheless it currently works withpycsope
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.
有一个很棒的 Python-mode-klen 插件。如果您安装了它并安装了 rod(python 重构库),那么转到特定术语的定义就像
g
或rag
一样简单> (第一个是文件类型映射,第二个是全局映射)。还有更多有用的功能,有些对我来说没用。所有这些都是可禁用的。 cscope-intro 中的问题列表中的功能:-
而不是实际的行(尽管它们指向正确的位置)。也许它会被修复。不是很多,但我不是有经验的 Ropevim 用户。
There is a wonderful Python-mode-klen plugin. If you have it and rope (python refactoring library) installed, then going to the definition of a particular term is as simple as
<C-c>g
or<C-c>rag
(first is filetype mapping, second is a global one). There are much more useful features, some useless for me. All of them are disableable. Features from list of questions found at cscope-intro:-
instead of the actual lines (though they point to the correct location). Maybe it will be fixed.Not very much, but I am not too experienced user of ropevim.