Click here to Skip to main content
15,891,748 members
Articles / Programming Languages / C++
Article

Adding tags support to Visual Studio

Rate me:
Please Sign up or sign in to vote.
4.20/5 (2 votes)
20 Aug 2001CPOL 91.2K   408   16   14
Visual Studio Macro to provide tags support

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United Kingdom United Kingdom
Originally from an electronics background, I moved into software in 1996, partly as a result of being made redundant, and partly because I was very much enjoying the small amount of coding (in-at-the-deep-end-C) that I had been doing!

I swiftly moved from C to C++, and learned MFC, and then went on to real-time C on Unix. After this I moved to the company for which I currently work, which specialises in Configuration Management software, and currently program mainly in C/C++, for Windows. I have been gradually moving their legacy C code over to use C++ (with STL, MFC, ATL, and WTL). I have pulled in other technologies (Java, C#, VB, COM, SOAP) where appropriate, especially when integrating with third-party products.

In addition to that, I have overseen the technical side of the company website (ASP, VBScript, JavaScript, HTML, CSS), and have also worked closely with colleagues working on other products (Web-based, C#, ASP.NET, SQL, etc).

For developing, I mainly use Visual Studio 2010, along with an in-house-designed editor based on Andrei Stcherbatchenko's syntax parsing classes, and various (mostly freeware) tools. For website design, I use Dreaweaver CS3.

When not developing software, I enjoy listening to and playing music, playing electric and acoustic guitars and mandolin.

Comments and Discussions

 
GeneralExternal compiler error messages Pin
Adam Honeybell16-Sep-03 22:09
Adam Honeybell16-Sep-03 22:09 
GeneralRe: External compiler error messages Pin
Paul Vickery18-Sep-03 3:52
professionalPaul Vickery18-Sep-03 3:52 
GeneralUsing VI in VS.Net Pin
29-May-02 6:22
suss29-May-02 6:22 
GeneralBrowse info - pros and cons Pin
Peter Andersson16-Mar-01 3:12
Peter Andersson16-Mar-01 3:12 
GeneralFilesystemobject Problem in using the macro Pin
7-Mar-01 19:40
suss7-Mar-01 19:40 
QuestionBuilt-in Browser Info with stack? Pin
David Defoort7-Mar-01 17:22
David Defoort7-Mar-01 17:22 
AnswerRe: Built-in Browser Info with stack? Pin
Paul Vickery7-Mar-01 22:41
professionalPaul Vickery7-Mar-01 22:41 
GeneralRe: Built-in Browser Info with stack? Pin
David Defoort8-Mar-01 15:35
David Defoort8-Mar-01 15:35 
GeneralRe: Built-in Browser Info with stack? Pin
Bilby12-Mar-01 21:45
Bilby12-Mar-01 21:45 
GeneralRe: Built-in Browser Info with stack? Pin
16-Mar-01 3:20
suss16-Mar-01 3:20 
GeneralFor a more complete tool. Pin
Marc Brooks7-Mar-01 13:22
Marc Brooks7-Mar-01 13:22 
QuestionDoesn't Workspace Whiz do this? Pin
6-Mar-01 15:10
suss6-Mar-01 15:10 
AnswerRe: Doesn't Workspace Whiz do this? Pin
Paul Vickery7-Mar-01 6:05
professionalPaul Vickery7-Mar-01 6:05 
GeneralRe: Doesn't Workspace Whiz do this? Pin
Joshua Jensen7-Mar-01 9:48
Joshua Jensen7-Mar-01 9:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.