ctags for scala

1 Dec 2014

It turns out there are 2 ctags binaries on OSX. One is from XCode toolchains. The other one I install it from brew.

Be careful with it.

Here's the configuration in ~/.ctags that makes ctags for Scala:

--langdef=Scala --langmap=Scala:.scala --regex-Scala=/^[[:space:]]*(([[:<:]](abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]class[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/c,classes/e --regex-Scala=/^[[:space:]]*(([[:<:]](abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]object[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/o,objects/e --regex-Scala=/^[[:space:]]*(([[:<:]](abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]trait[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/t,traits/e --regex-Scala=/^[[:space:]]*(([[:<:]](abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]case[[:space:]]+class[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/m,case-classes/e --regex-Scala=/^[[:space:]]*(([[:<:]](abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]case[[:space:]]+object[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/M,case-objects/e --regex-Scala=/^[[:space:]]*.*[[:<:]]abstract[[:>:]].*[[:<:]]class[[:space:]]+([[:<:]][[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?[[:>:]])/\1/a,abstract-classes/e --regex-Scala=/^[[:space:]]*(([[:<:]](override|abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]def[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/f,functions/e --regex-Scala=/^[[:space:]]*(([[:<:]](override|abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]val[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/V,values/e --regex-Scala=/^[[:space:]]*(([[:<:]](override|abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]var[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/v,variables/e --regex-Scala=/^[[:space:]]*(([[:<:]](override|abstract|final|sealed|implicit|lazy|private|protected)[[:>:]]|(\[[[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?\]))[[:space:]]*)*[[:<:]]type[[:space:]]+([[:alpha:]][[:alnum:]]*(_[[:alnum:][:punct:]])?)/\6/T,types/e --regex-Scala=/^[[:space:]]*[[:<:]]package[[:>:]][[:space:]]+([[:alpha:]][[:alnum:][:punct:]]*)/\1/p,packages/e

Now you can use:

ctags -R .

in order to generate ctags file for the whole project.

Vim already supports it natively, so you can just use it.

Give it a kudos