让 ctags 在 Erlang 代码的标签文件中包含模块限定符

发布于 2024-08-05 05:19:40 字数 179 浏览 2 评论 0原文

我正在使用 Exuberant ctags 来索引 Erlang 文件。

“tags”文件包含函数,但它们没有模块限定符;所以 我无法搜索“module:function”,只能搜索“function”,这可能会给出几个 结果。

您知道如何让 ctags 在标签文件中包含模块限定符吗?

谢谢。

I'm using Exuberant ctags to index Erlang files.

The "tags" file contains functions, but they do not have module qualifiers; so
I can't search for "module:function", only "function", which may give several
results.

Do you know a way to get ctags to include module qualifiers in the tags file?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

幸福%小乖 2024-08-12 05:19:40

就像 lht 所写的那样,Exuberant Ctags 5.8 已经将函数的模块存储在标签文件中。至少在最新版本的 Vim (7.4) 中可以访问此信息。然后可以使用自定义“标签”函数查找“模块:函数”,例如:

function! ErlangTag()
    let isk_orig = &isk
    set isk+=:
    let keyword = expand('<cword>')
    let &isk = isk_orig
    let parts = split(keyword, ':')
    if len(parts) == 1
        execute 'tag' parts[0]
    elseif len(parts) == 2
        let [mod, fun] = parts
        let i = 1
        let fun_taglist = taglist('^' . fun . '
)
        for item in fun_taglist
           if item.kind == 'f' && item.module == mod
               silent execute i . 'tag' fnameescape(item.name)
               break
           endif
           let i += 1
        endfor
    endif
endfunction

nnoremap <buffer> <c-]>    :call ErlangTag()<cr>

Like lht wrote, Exuberant Ctags 5.8 already stores the module of the function in the tags file. At least with recent versions of Vim (7.4) this information can be accessed. It is then possible to look up "module:function" using a custom "tag" function, e.g.:

function! ErlangTag()
    let isk_orig = &isk
    set isk+=:
    let keyword = expand('<cword>')
    let &isk = isk_orig
    let parts = split(keyword, ':')
    if len(parts) == 1
        execute 'tag' parts[0]
    elseif len(parts) == 2
        let [mod, fun] = parts
        let i = 1
        let fun_taglist = taglist('^' . fun . '
)
        for item in fun_taglist
           if item.kind == 'f' && item.module == mod
               silent execute i . 'tag' fnameescape(item.name)
               break
           endif
           let i += 1
        endfor
    endif
endfunction

nnoremap <buffer> <c-]>    :call ErlangTag()<cr>
×眷恋的温暖 2024-08-12 05:19:40

Exuberant ctags 已经支持 Erlang 的 标签字段“模块”。

$ /usr/bin/ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Aug 17 2010, 17:33:33
  Addresses: <[email protected]>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex
$ /usr/bin/ctags xref_parser.erl

带有名为“module”的标签字段的典型标签行如下所示:

yeccgoto_const  xref_parser.erl /^yeccgoto_const(24=_S, Cat, Ss, Stack, T, Ts, Tzr) ->$/;"      f       module:xref_parser

实际上,VIM 目前还不支持此标签字段。来自 VIM 文档

{field} ..  A list of optional fields.  Each field has the form:

            <Tab>{fieldname}:{value}

        The {fieldname} identifies the field, and can only contain
        alphabetical characters [a-zA-Z].
        The {value} is any string, but cannot contain a <Tab>.

        There is one field that doesn't have a ':'.  This is the kind
        of the tag.  It is handled like it was preceded with "kind:".
        See the documentation of ctags for the kinds it produces.

        The only other field currently recognized by Vim is "file:"
        (with an empty value).  It is used for a static tag.

就是这样。仅支持“kind”和“file”标记字段名称。

Exuberant ctags already supports tag field "module" for Erlang.

$ /usr/bin/ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Aug 17 2010, 17:33:33
  Addresses: <[email protected]>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex
$ /usr/bin/ctags xref_parser.erl

A typical tag line with a tag field named "module" looks like:

yeccgoto_const  xref_parser.erl /^yeccgoto_const(24=_S, Cat, Ss, Stack, T, Ts, Tzr) ->$/;"      f       module:xref_parser

Actually, it is VIM which doesn't support this tag field as for now. From VIM doc:

{field} ..  A list of optional fields.  Each field has the form:

            <Tab>{fieldname}:{value}

        The {fieldname} identifies the field, and can only contain
        alphabetical characters [a-zA-Z].
        The {value} is any string, but cannot contain a <Tab>.

        There is one field that doesn't have a ':'.  This is the kind
        of the tag.  It is handled like it was preceded with "kind:".
        See the documentation of ctags for the kinds it produces.

        The only other field currently recognized by Vim is "file:"
        (with an empty value).  It is used for a static tag.

That's it. Only "kind" and "file" are supported tag field names.

绾颜 2024-08-12 05:19:40

听起来您没有使用 Erlang etags 模块:从 Erlang 源文件生成 Emacs TAGS 文件

It sounds like you are not using the Erlang etags module: Generate Emacs TAGS file from Erlang source files.

未蓝澄海的烟 2024-08-12 05:19:40

我是 sublime 2 文本用户,发现 ctags 在我的计算机上工作正常。我在 sublime 2 中使用 ctags 插件


->ctags --version

Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Jul 24 2012, 11:45:55
Addresses: <[email protected]>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex

i'm a sublime 2 text user and find ctags works correctly in my computer. and i use ctags plugin for sublime 2.


->ctags --version

Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Jul 24 2012, 11:45:55
Addresses: <[email protected]>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文