获取ctags以在Erlang代码的标记文件中包含模块限定符

hcs*_*s42 5 erlang ctags

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

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

你知道一种方法来获取ctags在标签文件中包含模块限定符吗?

谢谢.

jmu*_*muc 5

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

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>
Run Code Online (Sandbox Code Playgroud)


lht*_*lht 4

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

$ /usr/bin/ctags --version
Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
  Compiled: Aug 17 2010, 17:33:33
  Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
  Optional compiled features: +wildcards, +regex
$ /usr/bin/ctags xref_parser.erl
Run Code Online (Sandbox Code Playgroud)

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

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

实际上,目前是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.
Run Code Online (Sandbox Code Playgroud)

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