The Code Project View our sponsorsCodejock Software - Serious GUI CodeAdvertise on the CodeProject
Home >> Macros and Add-ins >> Unedited Reader Contributions

Adding tags support to Visual Studio
By Paul S. Vickery

Visual Studio Macro to provide tags support 
 Beginner
 VC 4-6, Win95-98, NT4, W2K
 Posted 6 Mar 2001
Articles by this author
Send to a friend
Printer friendly version
[This is an unedited reader contribution] [Modify this article] [Delete this article]
Home Latest updates Submit your article About Us Advertise on the Code Project Contact us Discussion Forums
Navigation bar
5 users have rated this article. result:
3.4 out of 5.
  • Download source files - 2.49 Kb
  • 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.
    [Top] Sign in to vote for this article:     PoorExcellent  

    View our sponsorsClick here for Dundas Software's TCP/IP Development KitAdvertise on the CodeProject

    Hint: For improved responsiveness, use Internet Explorer 4 (or above) with Javascript enabled, choose 'Use DHTML' from the View dropdown and hit 'Set Options'.
     Keyword Filter
     View   Per page   Messages since
    New threadMessages 1 to 11 of 11 (Total: 11)[First] [Prev] [Next] [Last]
    Subject 
    Author 
    Date 
      Browse info - pros and cons
    Unconfirmed/Anonymous posting Peter Andersson 9:12 16 Mar 01 
      Filesystemobject Problem in using the macro
    Unconfirmed/Anonymous posting Anonymous 1:40 8 Mar 01 
      Built-in Browser Info with stack?
     David Defoort 23:22 7 Mar 01 
      Re: Built-in Browser Info with stack?
     Paul S. Vickery 4:41 8 Mar 01 
      Re: Built-in Browser Info with stack?
     David Defoort 21:35 8 Mar 01 
      Re: Built-in Browser Info with stack?
     Bilby 3:45 13 Mar 01 
      Re: Built-in Browser Info with stack?
    Unconfirmed/Anonymous posting Anonymous 9:20 16 Mar 01 
      For a more complete tool.
    Unconfirmed/Anonymous posting Marc Brooks 19:22 7 Mar 01 
      Doesn't Workspace Whiz do this?
    Unconfirmed/Anonymous posting Anonymous 21:10 6 Mar 01 
      Re: Doesn't Workspace Whiz do this?
     Paul S. Vickery 12:05 7 Mar 01 
      Re: Doesn't Workspace Whiz do this?
     Joshua Jensen 15:48 7 Mar 01 
    Last Visit: 12:00 Friday 1st January, 1999[First] [Prev] [Next] [Last]
    Home >> Macros and Add-ins >> Unedited Reader Contributions
    Advertise on The Code Project
    Article content copyright Paul S. Vickery, 2001
    everything else © CodeProject, 1999-2001.