Click here to Skip to main content
Email Password   helpLost your password?

Introduction

The Visual Studio 2008 C++ text editor only highlights matching braces if written the first time. Almost all text editors have the feature of highlighting matching braces if you put the cursor near to an open or close brace (even the Visual Studio C# editor). This add-in will provide this feature for C++ too. (Tested with Visual Studio 2008; for 2005, you need to change the version information in the "MatchingBraces.AddIn" file from 9.0 to 8.0).

Using the Add-in

  1. Just copy the contents of the "readyplugin" folder to "C:\Users\Username\Documents\Visual Studio 2008\Addins". Restart Visual Studio.
  2. Put the cursor on the right side of a brace (one of: '{[()]}'). If the brace has a matching one, both braces will be highlighted with a bold font.

Source Code Overview

Limitations

The add-in needs to rewrite the brace. This modifies the text as long as the cursor is near a brace. If you move the cursor away, the text is not modified anymore.

Conclusion

This is an essential feature for every text editor.

History

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralVisual Studio 2008 german
Honkoid
14:44 11 Feb '10  
Hi folks.

I've got visual studio 2008 under MSDNAA license and unfortunately I'm only able to get the german version. As for installing this plugin I have the problem that I have no "Addins"-folder and nothing similar in the german equivalent to "C:\Users\Username\Documents\Visual Studio 2008". I tried around a bit, but I don't get working brace matching. Do you have any advice for me how to install this plugin?

Thanks in advance
GeneralRe: Visual Studio 2008 german
Jochen Baier
20:28 11 Feb '10  
hi,

which version of windows ? (the language of VS do not matter).

if Vista the folder is: User\Dokumente\Visual Studio 2008\Addins
You can only see the "Dokumente" folder with explorer.
The germany folders do not exist in real, on your harddisk the folder is:
C:\Users\Username\Documents\Visual Studio 2008\Addins.

If the Addins folder do not exist create it.

Gruss

jochen
GeneralRe: Visual Studio 2008 german
Honkoid
5:55 12 Feb '10  
Win7
I already created the folder, inserted the plugin, no effect.
GeneralRe: Visual Studio 2008 german
Jochen Baier
23:46 12 Feb '10  
hi,

the plugin do not work with the Express Editon.

1. make sure the files: matchingbraces.Addin and MatchingBraces.dll are in the folder "C:\Users\username\Documents\Visual Studio 2008\Addins" (click on the adress in the explorer window to see the whole path).

2. start VS and take a look in Tools->Addin-Manager if the addin is available and
Startup is enabled.

3. open a C++ document and put the cursor behind a brace

tested on Win7 64 bit, englisch VS, but in the time of writing the addin I used a german version of VS and it works.

hope this helps, jochen
GeneralRe: Visual Studio 2008 german
Honkoid
15:50 23 Feb '10  
Sorry for the delay, had some other things to do.

Just wanted to say thanks for the VERY fast answers and now it works fine here as well Smile
I think my mistake was to make a subdirectory for the plugin in the Addins dir.

Thanks again Smile
Questionsource version
doktorekx
11:06 23 Dec '09  
I build the source version and it doesn't work when I copied dll file and AddIn file! why ?
AnswerRe: source version
Jochen Baier
11:45 23 Dec '09  
Visual Studio Express ?
GeneralRe: source version
doktorekx
12:15 23 Dec '09  
I have Professional edition.
Problem does't exist anymore, in matchingbraces.AddIn file I have changed 0 to 1 and work's great.
GeneralAwesome!
visualstudiowang
13:00 23 Oct '09  
Awesome!@
GeneralAuto-Generated End-Brace Comment
kjward
3:11 30 Sep '09  
hi jochen,

thanks for the interesting article. could you please advise as to how i could create a similar add-in that would not only find the matching end brace, but add to it a comment that relates it back to the signiture of the block it closes? i usually work in C#, so if you could use sample code in C# it would be greatly appreciated.

thanks again for sharing your expertise.

kjward

GeneralRe: Auto-Generated End-Brace Comment
Jochen Baier
5:36 2 Oct '09  
hi,

sorry didn´t used c# since programming this addin. so I have the some effort as you have. take a look on the other addin examples and look on msdn.com


jochen
GeneralModified for Visual Basic: Works in VS2008 but not VS2005
Bruce Farmer
10:27 21 Sep '09  
I modified this add-in to work for Visual Basic code files by changing the following functions:

      private bool isCPlusPlusText()
      {
         if (_applicationObject.ActiveDocument == null ||
//////      _applicationObject.ActiveDocument.Language != "C/C++")
               _applicationObject.ActiveDocument.Language != "Basic")
         {
            return false;
         }
         else
         {
            return true;
         }
      }

      public void OnStartupComplete(ref Array custom)
      {
         EnvDTE.Properties txtEdCS2 =
//////   _applicationObject.get_Properties("TextEditor", "C/C++");
         _applicationObject.get_Properties("TextEditor", "Basic");
         bool word_wrap_c = (bool)txtEdCS2.Item("WordWrap").Value;

         if (word_wrap_c != true)
         {
            MessageBox.Show("You have 'WordWrap' disabled in the Editor settings. \nYou need" +
            " to enable it for the MatchingBraces plugin to work correctly.", "MatchingBraces - AddIn",
                  MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
      }

This works in VS2008, but does not work in VS2005, even after modifying the .AddIn file from

   <HostApplication>
      <Name>Microsoft Visual Studio</Name>
      <Version>9.0</Version>
   </HostApplication>

To:

   <HostApplication>
      <Name>Microsoft Visual Studio</Name>
      <Version>8.0</Version>
   </HostApplication>

Anyone have any idea why the VB version works in VS2008 but not VS2005?
GeneralRe: Modified for Visual Basic: Works in VS2008 but not VS2005
kjward
5:18 29 Sep '09  
would it be that simple to include c# as well?

kjward

GeneralRe: Modified for Visual Basic: Works in VS2008 but not VS2005
Bruce Farmer
5:38 29 Sep '09  
It would be a little more work to support multiple languages because the macro gets the properties of the text editor (C/C++, C#, VB) on startup and makes some decisions based on that. That said, it should only be a LITTLE more work. I think that given the example of what I did with the original macro, it should be straightforward to implement this yourself.
GeneralRe: Modified for Visual Basic: Works in VS2008 but not VS2005
kjward
5:58 29 Sep '09  
thanks for the quick reply bruce.

what i'm really looking to do is simply add a comment to the end brace of a block to match it's signiture. i thought i could modify/extend your example to do this. is there a better approach to do what i want?

kjward

GeneralRe: Modified for Visual Basic: Works in VS2008 but not VS2005
Bruce Farmer
8:55 29 Sep '09  
Sorry kjward, but my knowledge of Windows add-ins is limited. I found the article by Jochen Baier and after downloading the source code I found it pretty simple to modify for my use with the VB editor. What you want to do sounds more complicated. My suggestion to you would be to download the source code, look at it and experiment with it to see if you can achieve the results you want. If not, perhaps try to contact Jochen Baier. Bottom line is that as long as you experiment on test C# source files, I don't think you can hurt anything by testing, because if your changes cause the C# files to be junked up, you can just deleted the DLL from the add-in directory and the editor will return to its normal behavior.
GeneralMy vote of 1
salocin_
4:50 2 Jul '09  
It doesn't mention it doesn't work for VS 2008 Express version...
GeneralVS2008 SP1
VEMS
3:15 30 Apr '09  
Got a message indicating word wrap was disabled and needed it enabled for this addin to work. Enabled word wrap, restart vs2008: not working.
Generalchances to get this working with visual basic in VS 2k8 as well?
tomtom1980
22:20 2 Apr '09  
Visual Basic also lacks the feature to highlight round brackets. just when you close a round bracket the first time, the corresponding bracket gets highlighted, but unlike c# not when you place the cursor next to a bracket. ctrl + ] also isn't working for visual basic.net.
would be great if you could adapt this addin to work for visual basic as well.
GeneralColor Highliight [modified]
ameliaamelia
16:57 26 Mar '09  
It is a good work.
It is possible to change the "matching advice" using the colors of
"Brace Matching (Highlight)" [<-this works] and "(Rectangle)" of "Fonts and Colors"
of Options settings ?
Thanks.

modified on Thursday, March 26, 2009 10:05 PM

GeneralVery useful
sprice86
3:50 20 Feb '09  
Thanks -- this is really useful Big Grin

Bertram

QuestionCan this work for .Net 2003? It seems not to!
Jelena Curcic
22:46 12 Feb '09  
And thanks this helps a lot...
Questionnot working in Visual C++ Express
torys
15:13 26 Oct '08  
Why does this solution not work in Visual C++ 2008 Express Ed ? :(
AnswerRe: not working in Visual C++ Express
Jochen Baier
1:51 28 Oct '08  
hi,

did you have the Microsoft .NET Framework 3.0 Redistributable Package installed ? the plugin is written in C#.

cu jochen
AnswerRe: not working in Visual C++ Express
Qwertie
10:53 11 Nov '08  
Visual Studio express editions don't officially support add-ins. Last I heard they accidentally left a hook in VS 2005... but they might have fixed it in 2008.


Last Updated 5 Nov 2008 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010