Visual Studio Tags Support

-->

Environment: VC6 (probably any VC)

What's all this then?

Having programmed on a UNIX platform, where I used the vi editor, and since then on a PC using Lemmy, I have missed the ability to use tags when using Visual Studio. The macro published here provides tags support.

To use the macro file, simply put it in the Common\MSDev98\Macros directory under where-ever your Visual Studio is installed. The macro file exposes two functions (listed below). These functions can be mapped to keys of your choice.

The functions are as follows:

PushContext: Invoking this function picks up the currently selected text, and looks for a reference to it in the tags file. If it finds it in the file, it then opens the file it is contained in and jumps to the correct line or text. The current cursor position (and file) is added to the tag stack.

PopContext: This function will take the top entry from the tag stack, and jump to the file and cursor position listed there. This enables you to jump to a definition, and then come back to where you were previously working. This works regardless of whether the tag jumped to was in the same file or a different file.

So why not use the browser facilities built-in to Visual Studio?

One of the things I like about tags that the browser info doesn't give me is the ability to stack the tags, so I jump back to where I came from.

Mmm, looks useful, but how do I generate my tags?

To generate my tags I use Exuberant Ctags, by Darren Hiebert. This is available as a free download from http://ctags.sourceforge.net/. One thing to be careful of is that if you create the tags file by specifying a directory, then the file paths are stored as relative paths in the tags file. This then causes problems, as Visual Studio may change its current directory each time you open a file.

How it works

When you first execute the PushContext function, the tags file is sought in the directory in which the current file lives. If it is found, then its contents are read in line by line, and the tag text is added to a dictionary, along with the tag information (file path, and line number or search text). (This does mean that the first time you read a tags file, there is a bit of a delay, but after that it is quite fast.)

A separate dictionary is kept for each tags file you read, and a dictionary of dictionaries is used to get back the correct dictionary. This means that different directories can use different tags files.

Before reading in a tags file, the master dictionary is searched to see if there is already a dictionary for that file. If there is, then the time stamp of the file is compared to a saved timestamp in the dictionary, to see if the tags file needs re-reading. This enables you to update your tags at any time, and still be able to use them correctly.

Limitations

If the tag text is listed in the file more than once, then the only the first occurance will be used. To avoid this causing problems, use care when creating your tags file, to ensure that the more important files are scanned first, and generate a non-sorted tags file.

Downloads

Download source - 3 Kb


Comments

  • Find the tag file in the project home dir...

    Posted by Legacy on 07/05/2002 12:00am

    Originally posted by: Matthieu

    If you prefer to have several projects and not only one tag file is to refer it from the project base directory.
    You'll need to use --tag-relative option from ctags and change the following lines from the original macro

    5,7c5
    < str = ActiveProject.FullName
    < pos = inStrRev(str, "\")
    < default_tags_path = left(str, pos)
    ---
    > const default_tags_path = "c:"
    86d83
    < file = default_tags_path + file

    Have fun !

    Matthieu

    Reply
  • Browse info - pros and cons

    Posted by Legacy on 03/14/2001 12:00am

    Originally posted by: Peter Andersson

    Hello,

    I noticed the following comment:

    "So why not use the browser facilities built-in to Visual Studio? One of the things I like about tags that the browser info doesn't give me is the ability to stack the tags, so I jump back to where I came from. "

    There is a command in MSDEV called BrowsePopContext (bound to Ctrl-* when using the classic Visual C 2.0 keys) so you CAN push and pop the context.

    I always hit F11 to check the definition, then use Ctrl-* to get back to where I were.

    I haven't used the "tags" package yet since the built-in browser info actually is very good. However, MS seems to want to want people to stay away from this functionality, by not promoting/developing it. For example, browsing info is no longer turned on by default, and the GUI hasn't changed in years.

    The downside with using the browser is:
    - BSCMAKE can take a long time to finish
    - There are NO reporting facilities, printing etc of this potentially very useful information

    You can of course use the BROWSE API, and make your own app, but so far I haven't gotten around to doing that. I'm a little bit surprised that noone else have done it either.

    /Peter

    Reply
  • Nice job

    Posted by Legacy on 03/13/2001 12:00am

    Originally posted by: Trance

    Also, for those interested, there is another tool which is not a plug in. It's called Developer's Notepad, and is available for free from http://www.relisoft.com. It operates on the same principles.

    Reply
  • www.vadaumuie.ro

    Posted by Legacy on 03/12/2001 12:00am

    Originally posted by: gigi

    Imi bag pula!

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

Most Popular Programming Stories

More for Developers

RSS Feeds