I'm using Vim to edit Erlang source files. As function names in Erlang are only unique within a module (unlike in C), the tags support "out of the box" is not perfect (for example there are more than 200 function clauses called encode in the dependencies of my project and in the standard library). I tried to create a tagfunc that will filter the results by module name:

function! ErlangTag(pattern, flags, info)
  let l:funcname = expand("<cword>")
  let l:line = getline(".")
  let l:match_res = matchlist(line, "[a-zA-Z0-9'_]*:" . l:funcname)
  if len(l:match_res) > 0
    let [l:mod, l:fun] = split(l:match_res[0], ":")
    return filter(taglist(a:pattern), 'v:val.module ==' . l:mod)
    return taglist(a:pattern)

but when I type g-] on the jsx:encode call (when the cursor is over encode), I get this error message:

Error detected while processing function ErlangTag:
line    6:
E121: Undefined variable: jsx
Error detected while processing function ErlangTag:
line    6:
E15: Invalid expression: v:val.module ==jsx 

How do I pass the module name to the filter expression? I also tried this line:

    return filter(taglist(a:pattern), 'v:val.module == l:mod')

but got a different error:

Error detected while processing function ErlangTag:
line    6:
E716: Key not present in Dictionary: module == l:mod

1 Answer 1


"module" is optionally present in tags. The correct form of the filter is:

return filter(taglist(a:pattern), 'get(v:val, "module", "") ==# l:mod')

Using get() to compensate for the possibly missing field and using ==# meaning case sensitive string equality.

  • 1
    One example where dealing with lambdas instead of strings might be easier
    – D. Ben Knoble
    Aug 21, 2021 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.