I've been working in a large Ruby project using Vim with ctags. I have a git hook that generates an up-to-date tags file whenever I commit/pull/etc.

It basically boils down to

git ls-files | \
  ctags --tag-relative=yes -L - -f ".git/tags" --languages=-javascript,sql

It takes about 1 second to run, and results in a 7MB tags file.

I'd like to start using Emacs for this project, but generating etags takes well over a minute and outputs an 8GB TAGS file. Here's the command I'm using to generate etags (only differences from the previous command are the -e flag and the TAGS filename:

git ls-files | \
  ctags --tag-relative=yes -L - -e -f ".git/TAGS" --languages=-javascript,sql

Why is it such a huge file, and is there a better tags solution I can try?

  • 2
    Have you tried the etags program that comes with Emacs? In 25.1, it's been much improved for Ruby code. – Dmitry Dec 17 '16 at 23:20
  • 1
    @Dmitry Wow, what a difference! I'll have to tweak my script a bit since etags doesn't have the same command line options, but that runs much faster and the output file is actually smaller than the 7MB ctags file. Really makes me wonder what's going on with ctags -e, but so long as I have another working option, I'm happy. Thanks! – ivan Dec 18 '16 at 1:24
  • 1
    Happy to help! I'll move the commend into an answer, then, with some extra info. – Dmitry Dec 18 '16 at 10:59

The etags program that comes with Emacs is a solid option. In 25.1, Eli added Ruby support, as well as fixed some parsing problems that are still present in the commonly used version of ctags.

"Why 8GB" is a good question, though. To try to answer it, you can open the generated file and look inside. The contents are mostly human-readable. Does it have ridiculously long lines or simply garbage entries (that don't correspond to any symbols)? Does it have duplicates?

If you find the problem, it would be good to report it to https://github.com/universal-ctags/ctags/, which is the new project home. You might want to build and try their version first, though, there are quite a few fixes there that still haven't found their way into the popular GNU/Linux distributions.

| improve this answer | |
  • 1
    Turns out it was mostly because of a large json file that was getting tagged, as universal-ctags added support for json. I got some good help at the universal-ctags project as well: github.com/universal-ctags/ctags/issues/1247 – ivan Dec 19 '16 at 13:39
  • 1
    Ah yes, and that also happens when you get minified files tagged by mistake. universal-ctags should probably blacklist extensions like .min.css and .min.js by default. – Dmitry Dec 19 '16 at 14:52

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.