Home > Intelligent-Tags

Intelligent-Tags

Intelligent-Tags is a project mainly written in Vim Script, it's free.

Automated Tag creation/inclusion

This is a mirror of http://www.vim.org/scripts/script.php?script_id=3662

Project Home: https://github.com/bahejl/Intelligent_Tags

Intelligent Tags is designed to handle creating tags and setting the 'tag' option for you. Tradionally, you would run ctags on your project at regular intervals (or in a cron job), but I struggled with this approach for several reasons:

  • I'm initially not familiar with the project structure of many of the projects I work on, so I have to chase down the includes until I feel comfortable that I know where the project ends/begins before I can create a useful tags files. This is a large overhead, and prevents me from using tags
  • As I actively work on a project, updating the tags once a day, or even every hour, just doesn't cut it. I would like the tags to be updated as soon as the file is updated.

Intelligent Tags solves these problems by using two tools. First, it uses Vim's built-in options 'include', and 'includeexpr' to find any/all include files, and then searches those includes for includes, etc. The depth of this search can be set by the user to any level using the |Itags_Depth| variable. To save time, Intelligent Tags will create an .incl file for every file examined. This file is simply a cache that lets Intelligent Tags avoid re-scanning for include files unless it is necessary. In order for any of this to work properly, Vim's path option must be set correctly. You can check if it is correct by running the Vim command |:checkpath|. If you use Intelligent Tags with an incorrect path, the information stored in the cached .incl files will be incorrect, and you will need to run the |ItagsRegenIncl| command after correcting your path to correct the cached informaiton. For more information on setting your path type ':h path'.

The second tool Intelligent Tags uses is exhuberant ctags. Intelligent Tags uses exhuberant ctags' report of supported languages to automatically add a FileType autocommand for each type of supported file. I want my tags updated as soon as I make a change to a file, but if you use the tradional method of having a single tags file per project that can take quite a while -- especially for a large project. To work around that problem, Intelligent Tags creates a seperate tags file for each source file, and only updates those that are out of date.

This methodolgy begins to break down for some languages, such as C, where the following problems exist:

  • foo.c includes bar.h, followed by baz.h, so (almost magically) everything in bar.h is available to baz.h. Because Intelligent Tags works on a per-file and not per-project basis, it is impossible (as far as I can tell) for Intelligent Tags to know that bar.h's tags should be included based only on the information in baz.h.
  • foo.c includes bar.h, which contains externals defined in bar.c. Intelligent Tags works around this problem by allowing for a special |Itags_header_mapping| option. If this is defined, when Intelligent Tags finds any included file whose extension is recognized as a header, it will search for a source file of the same name and include its tags as well.

In the end, when you open any exhuberant ctags supported file, intelligent Tags will generated generate any tags files necessary and update the 'tags' option for you, and you don't have to do a thing!

Previous:lemon.vim