Getting ctags to include module qualifiers in the tags file for Erlang code
Asked Answered
W

4

6

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.

Wakeful answered 24/9, 2009 at 12:18 Comment(0)
M
4

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.

Mortenson answered 25/9, 2010 at 15:24 Comment(1)
This tool generates module:function tags for Erlang files in a way that Vim can use them: github.com/vim-erlang/vim-erlang-tagsWakeful
B
5

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>
Byers answered 4/11, 2013 at 22:49 Comment(0)
M
4

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.

Mortenson answered 25/9, 2010 at 15:24 Comment(1)
This tool generates module:function tags for Erlang files in a way that Vim can use them: github.com/vim-erlang/vim-erlang-tagsWakeful
S
1

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

Spina answered 24/9, 2009 at 13:18 Comment(2)
etags is for Emacs, and I use Vim.Wakeful
Correction: Vim can use etags too when compiled with the +emacs_tags feature. But etags does not seem to support module qualifiers either.Wakeful
H
0

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
Huggins answered 24/7, 2012 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.