开发工具 Mac OS X Lion 上 Sublime Text 2 的 CTags 出错

dumbcoder · 2012年06月29日 · 最后由 dumbcoder 回复于 2012年07月08日 · 9445 次阅读

每次一个 project,第一次 build tags 的时候,控制台就会出这个错:

Traceback (most recent call last):
  File "./sublime_plugin.py", line 362, in run_
  File "./ctagsplugin.py", line 597, in run
  File "./ctagsplugin.py", line 196, in find_top_folder
  File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/posixpath.py", line 119, in dirname
    i = p.rfind('/') + 1
AttributeError: 'NoneType' object has no attribute 'rfind'

然后,用 CTags 跳转的时候,行为怪异。。。比如我按了 3 次跳到定义处 (后两次无效),就得按 3 次跳回原位置才跳得回来,我觉得应该是按一次跳回来就可以跳得回来的。 我用的是最新的 Sublime Text 2.0 (build 2210),用 Package Control 安装的 CTags 插件。 Mac OS 的 CTags 我是用 port install ctags 安装的,不是默认的。

另外,我从 terminal 进入 python 后,发觉版本是 2.7:

$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

不知道问题在哪里。

1 楼 已删除

lion 自带的 ctags 有问题,需要用 ctags-extend, 去http://ctags.sourceforge.net/ 下一个重新编译安装下

我是先删除了 Lion 自带的 ctags,再用"sudo port install ctags" 安装的最新的 ctags for darwin.

我之前也试验了去 http://ctags.sourceforge.net/ 下一个重新编译安装。 我装的是" Source only distribution (gzipped) ctags-5.8.tar.gz " 但是发现这个版本居然不支持"ctags -R"选项。所以没用这个。 因为: /Users/MyName/Library/Application Support/Sublime Text 2/Packages/CTags/CTags.sublime-settings 这个配置文件里,可是写了要用 "-R"的。

{
    "debug"           :  false,
    "ctags_command"   :  "ctags -R -f .tags",
    "filters"         :  {
        "source.python": {"type":"^i$"}
    },
    "definition_filters": {
        "source.php": {"type":"^v$"}
    },
    "definition_current_first": true,
    "show_context_menus": true,
    "extra_tag_paths" :  [ [["source.python", "windows"], "C:\\Python27\\Lib\\tags"]],
    "extra_tag_files" : [".gemtags"]
}
brew install ctags

# bashrc / zshrc
alias ctags='`brew --prefix`/bin/ctags'

用 "brew install ctags" 安装完的 ctags 版本 (ver5.8) 还是不支持 -R:

ctags -R ctags: illegal option -- R usage: ctags [-BFadtuwvx] [-f tagsfile] file ...

这里有多少用 Mac OS Lion 的朋友?你们装 ctags 有如此折腾么...

#4 楼 @dumbcoder /usr/local/Cellar/ctags/5.8/bin/ctags

#4 楼 @dumbcoder 我是直接在项目下 ctags -Rf .tags。没遇到你说的问题。。google 木有结果吗?

谢楼上,我将配置文件 /Users/MyName/Library/Application Support/Sublime Text 2/Packages/CTags/CTags.sublime-settings 里面的 "ctags_command" 改成了绝对路径: { "debug" : false, "ctags_command" : "/usr/local/Cellar/ctags/5.8/bin/ctags -R -f .tags", "filters" : { ... ... }

然后,现在还是跟我在 1 楼说的症状一样: 每次生成 tags,都报错。然后,用 CTags 跳转的时候,行为怪异。。。比如我按了 3 次跳到定义处 (后两次无效),就得按 3 次跳回原位置才跳得回来,我觉得应该是按一次跳回来就可以跳得回来的。

我现在在想,大家在 Lion 里使用的时候,这个就是正常行为...??

我刚去试验了下直接在目录下 "/usr/local/Cellar/ctags/5.8/bin/ctags -R -f .tags"

跳转时候还是怪怪的。难道 ctags 正常就是这样的?

比如: in main.cpp call functionA() //place-1

in functionA.cpp implement functionA() {... } //place-2

我用"ctrl+alt+]" 从 place-1 跳转到 place-2 之后,如果我按了 3 次"ctrl+alt+]", 第一次会跳转到 place-2, 然后两次无效,之后,我得连按 3 次 "ctrl+alt+["才能跳回到 place-1. 难道不是应该只按一次"ctrl+alt+["就能跳回到 place-1 吗?

#8 楼 @dumbcoder 我嫌这几个快捷键太难按了自定义了下

{"keys": ["super+t"], "command": "navigate_to_definition"}, {"keys": ["super+`"], "command": "jump_back"}, 跳转到指定函数的时候如果有重名的话还得自己选,不是那么智能。但是跳回去没遇到什么问题

我试了下改快捷键,可以修改。

但是跳回去还是有我说的问题。。。 +_+ 我用来测试的 project 就是我上面说的这么简单,没有函数重名的。

还有,我发现,如果我已经在 place-2 了,再按"ctrl+alt+]"的话,sublime text 2 的 find 菜单是会高亮一下的,也就是说,这个本该无效的"ctrl+alt+]"是起效果了的,所以这个"ctrl+alt+]"就被莫名奇妙地"buffer"下来了。。。 折腾郁闷了,还是跟最开始一样的问题。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号