Generating emacs tags file for a Ruby on Rails project
Asked Answered
D

4

19

I am generating a tags file for emacs for my Ruby on Rails project with the following command:

ctags -f TAGS --extra=-f --languages=-javascript --exclude=.git --exclude=log -e -R . $(rvm gemdir)/gems/

When I try to find tags (Using M-.) some tags are working fine, but with lots of other tags I get errors like:

tag-find-file-of-tag-noselect: File /Users/simao/Documents/sp/ofe/° ¡ not found

etags-goto-tag-location: Rerun etags: `^class Tools::FilteringSteps' not found in /Users/simao/Documents/sp/ofe/lib/geo_db.rb

How are you generating tags for your RoR projects with emacs? Did you ever see this problem before?

This is the output of ctags --version

Exuberant Ctags 5.8, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Mar  9 2012, 15:47:35
Addresses: <[email protected]>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex

My emacs version:

GNU Emacs 24.0.95.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2012-04-02
Diction answered 12/4, 2012 at 9:16 Comment(5)
Just for clarity, is ^class Tools::FilteringSteps in /Users/simao/Documents/sp/ofe/lib/geo_db.rb ?Melendez
So you're saying that etags has incorrectly indexed your project, and the TAGS file thinks that class/method is in a different file to where it actually lives? (Where does it actually live?)Melendez
Yes it thinks it's on a different file and also introduces weird chars in the filenamesDiction
Which version of ctags are you running?Melendez
I updated my answer with ctags --version. ThanksDiction
A
9

Yeah, yeah, yeah. ;-)

Why would you care about not using ctags in the first place? Ctags is a great project and it does support many (like 50) languages. But Ruby support is very weak, the parser is not in good condition and it has not been changed 4 years now.

  • Ctags doesn't deal with: module A::B
  • Ctags doesn't tag (at least some of) the operator methods like ==
  • Ctags doesn't support qualified tags, -type=+
  • Ctags doesn't output tags for constants or attributes.

Unfortunately all the others (I found 2) Ruby ctags generators are either outdated (no Ruby 1.9+ support) or very slow. But there is a solution! It is called ripper-tags. https://github.com/tmm1/ripper-tags

gem install ripper-tags
cd your_project/
ripper-tags -R # for vim
ripper-tags -R -f TAGS # for emacs

This project leverages built-in Ruby parser API called Ripper. It is fast and it works as expected. It is almost as fast as ctags, but giving the most accurate results. Warning: It does NOT support Ruby 1.8.

If you like ripper-tags and you want to have all tags generated automatically upon gem installation, you can check out my gem-ripper-tags which does that. Unfortunately it does not support Emacs at the moment (patch accepted - quite easy to do). More info at: https://github.com/lzap/gem-ripper-tags

Aras answered 12/8, 2013 at 10:57 Comment(0)
M
0

This seems like it might be relevant:

Particularly note the comment in the second link, suggesting this bug has existed since Emacs 22.

Assuming you're not running Emacs 24, it sounds like you should apply that patch to etags.el (and byte-recompile).

(If you are using a version of Emacs 24 which contained this bug, you should obviously update to the latest pretest release.)

Melendez answered 13/4, 2012 at 9:48 Comment(2)
I am using GNU Emacs 24.0.95.1 (x86_64-apple-darwin, NS apple-appkit-1038.36) of 2012-04-02 and I still have this problem.Diction
Ah, I'm out of ideas then. You should add your Emacs version to the question. I'll leave this answer in case it's helpful to anyone else. Good luck.Melendez
H
0

I use rtags. For me, it worked better with Ruby than ctags.

Hexone answered 8/4, 2013 at 12:14 Comment(0)
D
0

If you are using Git, I recommend you follow this setup from Effortless CTags to auto build your tag files when you perform git operations:

http://tbaggery.com/2011/08/08/effortless-ctags-with-git.html

Even if you are not using Git, you may be able to try his command for building the CTags:

ctags --tag-relative -Rf.git/tags.$$ --exclude=.git --languages=-javascript,sql

Also, I recommend you setup an alias for bundle install to specify a path so your gems get bundled into subdirectory of your project, such as:

alias bi='bundle install --path vendor'

(Note: be sure to .gitignore that directory). This will allow you to also jump directly into the source of each of your gems, and prevent your tag file from being bloated with all gems in your system.

Dib answered 25/7, 2013 at 21:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.