   Visual Studio Macros for the Game Programmer
  Comments for the article Visual Studio Macros for the Game Programmer
  Excellent article, very useful and inspiring. Thank you!   ;  Nice introduction to Visual Studio Macros. I've never done anything with them before but I'm really planning to after reading this article.I just tried your example:Sub Signature()  Dim sel As TextSelection = DTE.ActiveDocument.Selection  sel.Insert("MikeCline ")  sel.Insert(Format(Date.Today, "MMM dd yyyy"))  sel.Insert(".")End SubI noticed that when you want to undo this, VS will undo every Insert call and not undo it at once. So my tip is that you probably want to insert that text at once so it's easy to undo.Sub Signature()  Dim sel As TextSelection = DTE.ActiveDocument.Selection  Dim str As String  str = "MikeCline " + Format(Date.Today, "MMM dd yyyy") + "."  sel.Insert(str)End SubNice article.   ;Quote:Original post by WalterTamboerNice introduction to Visual Studio Macros. I've never done anything with them before but I'm really planning to after reading this article.I just tried your example:*** Source Snippet Removed ***I noticed that when you want to undo this, VS will undo every Insert call and not undo it at once. So my tip is that you probably want to insert that text at once so it's easy to undo.*** Source Snippet Removed ***Nice article.Thats a good tip. I found the same problem with macros that someone else has written.   ;  Amazing... I never thought of doing any of this, great article.   ;Quote:Original post by DaveQuote:Original post by WalterTamboerNice introduction to Visual Studio Macros. I've never done anything with them before but I'm really planning to after reading this article.I just tried your example:*** Source Snippet Removed ***I noticed that when you want to undo this, VS will undo every Insert call and not undo it at once. So my tip is that you probably want to insert that text at once so it's easy to undo.*** Source Snippet Removed ***Nice article.Thats a good tip. I found the same problem with macros that someone else has written.If you want to have the undo feature remove the changes your macro made all at once, you can open an UndoContext around your macro changes, then close the UndoContext afterwards. Then, when you perform an undo, it will remove everything at once. Like so:    Public Sub InsertLineComment()   Dim name As String = "KJF"   Dim selection As TextSelection   selection = CType(DTE.ActiveDocument.Selection, TextSelection)   If (Not DTE.UndoContext.IsOpen()) Then  DTE.UndoContext.Open("KJF Insert Line Comment")   End If   selection.EndOfLine()   ' Go to the end of the line to insert the comment   Dim comment As String   comment = "//" + name + " " + Date.Now.ToString("dd-MM-yyyy") + " - "   selection.Insert(comment)   If (DTE.UndoContext.IsOpen()) Then  DTE.UndoContext.Close()   End If    End Sub;Quote:Original post by DorvoThen, when you perform an undo, it will remove everything at once.Ah :) That's even better! Thnx.   ;  Another thumbs up for this informative article :-) Definitely I can find some use for them.I also have a snippet here to share, for trimming of trailing whitespaces, which is missing from VS. It is basically just a replace all using regexp.Dim textDocObj As TextDocument = DTE.ActiveDocument.ObjecttextDocObj.ReplacePattern(    "[ \t]+\n",    ControlChars.NewLine,    vsFindOptions.vsFindOptionsRegularExpression)I've the full macro implementation on my page if anyone's interested.   ;  Great article! opened a door I hadn't even considered. Thank you.   ;  Nice job. But your first example, switching between header and source file, is sort of built in. Visual C++ 2005 express, no add-ins that I remember, and if I right click on a source file there is a Go To Header File option. There doesn't seem to be an equivalent for going from header to source though.   