Ctags is the most famous tags tools. However, there are some disadvantages of ctags, and there are some better choices vary from target languages to languages.
For example, for Ruby, I prefer to use ripper-tags. And for JavaScript, people often use jsctags. There is also something like CoffeeTags, too.
So, my question is, how to integrate or combine these tools?
Is it possible to write a shell script (or something else), for example: omni-tags
, so that I can use omni-tags
for all kind of files. And it will automatically invoke different tags tools depends on file types?
Sometimes there are more than one file types in a projects, so it will be more convenient if we can use a unified tool to generate tags.
Thanks.
Your hypothetical omni-tags
command would be easy to implement in shell or any scripting language (Perl, Python, Ruby, whatever) assuming you were only dealing with projects with one particular kind of source code. Just recursively scan a project directory, look for the predominant type of file within it (by matching file extensions, or using the Unix file
program) and then run the tags-generation program associated with that particular kind of source file.
This would get more difficult, but not impossible, if you have a project containing code in multiple languages. One example would be a Ruby gem containing both Ruby .rb
source files and some .c
and .h
files implementing a native C extension. In this case the Ruby and C files are usually fairly cleanly separated--i.e., one directory tree under the root directory of the gem is all Ruby, and another is all C. So omni-tags
could probably be written to recognize this case and run ctags
on the .c
and .h
files and ripper-tags
on the .rb
files. Since most editors can integrate multiple tags files per project (at least, I know Emacs can), you would then be able to navigate between a symbol defined in the C source and used in the Ruby source (for example).
The trickiest part would be how to deal with code bases where multiple languages are intermingled that you want to tag. For your JavaScript example, are you likely to have a directory containing both JavaScript and CoffeeScript files, for instance? In this case omni-tags
needs to run the tool appropriate to each language on each source file. If the tags-generating tools are written to ignore any file not of the right type, you could just run each from the root directory of your project and then, again, use an editor that integrates multiple tags files. If the tools need to be fed only the right kind of files, then omni-tags
needs to build an index of the files in question and then feed the names of only the correct files to each tool. It's not impossible, but would require a bit more work (in contrast to the simplest case described in the first paragraph, which would probably be doable in about 10 lines of Python or Ruby).