Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Commenting out things like $selected$ in Snippets?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kennyl
Ketchup Master

50 Posts

Posted - Apr 06 2011 :  03:06:18 AM  Show Profile  Reply with Quote
When modify code, our company requires us to add some sort of "Code Mark" and have the original code commented out instead of directly remove/modify them.

For example, original code:

*pRetNumber1 = nResult1;   // validity checking missed
*pRetNumber2 = nResult1;   // bad Copy & Paste here


Updated code:

//-- CODE_MARK_BEGIN, date here, author's name here, ...
//*pRetNumber1 = nResult1;
//*pRetNumber2 = nResult1;
if (pRetNumber1)
    *pRetNumber1 = nResult1;
if (pRetNumber2)
    *pRetNumber2 = nResult2;
//-- CODE_MARK_END


To do this job I will have to:
1. Select the code block.
2. Comment out the original code.
3. Select the code block again.
4. Either press a key or use VA's menu to add "Code Mark" by VA Snippets.
5. Add modified code.

So, I wonder if VA could provide a way to comment out things like $selected$ in VA Snippets, like this:

//-- CODE_MARK_BEGIN, $DATE$, Kenny
{CmtBegin} $selected$ {CmtEnd}
//-- CODE_MARK_END


{CmtBegin} and {CmtEnd} here are tags to indicate what to be commented out, and also it'd be better if VA could use single line (C++) / multi-line comment (C) base on the number of lines of $selected$.

Regards,
Kenny

Edited by - kennyl on Apr 06 2011 03:14:39 AM

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Apr 07 2011 :  10:11:32 AM  Show Profile  Reply with Quote
The VA Snippet:

//-- CODE_MARK_BEGIN, $DATE$, %USERNAME%
/* $selected$ */
//-- CODE_MARK_END

seems to do what you want. Just select the code to mark, and tell VA to use a Snippet on the selected code. This can be done via the right click menu or by pressing the VA toolbar button "Insert VA Snippet".

zen is the art of being at one with the two'ness
Go to Top of Page

kennyl
Ketchup Master

50 Posts

Posted - Apr 07 2011 :  9:51:42 PM  Show Profile  Reply with Quote
quote:
Originally posted by feline

The VA Snippet:

//-- CODE_MARK_BEGIN, $DATE$, %USERNAME%
/* $selected$ */
//-- CODE_MARK_END

seems to do what you want. Just select the code to mark, and tell VA to use a Snippet on the selected code. This can be done via the right click menu or by pressing the VA toolbar button "Insert VA Snippet".



The $selected$ code might contain comment, so /*...*/ might not work in that case, and second, I'd still prefer VA to decide single line comment or multi-line comment style base on the number of code.

Thank you for your reply though.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Apr 11 2011 :  10:58:47 AM  Show Profile  Reply with Quote
You can make an IDE macro do most of this. I am not sure about getting the user name in a macro, but you should be able to pick up the current date and time in VBScript using the standard functions.

A simple IDE macro to comment out the block using either // or /* */ comments, based on the number of lines with text on them is:

    ' select a block of text then trigger this macro
    Public Sub TurnSelectionIntoMarkedBlock()
        Dim objTxtSel As TextSelection = DTE.ActiveDocument.Selection
        Dim colRanges As TextRanges = objTxtSel.TextRanges
        Dim objRange As TextRange
        Dim nTotalLines As Integer = 0      ' the number of selected lines that contain text

        ' count the number of lines that actually have text in them
        For Each objRange In colRanges
            Dim nLineLength As Integer = objRange.EndPoint.AbsoluteCharOffset - objRange.StartPoint.AbsoluteCharOffset
            If nLineLength > 0 Then
                nTotalLines = nTotalLines + 1
            End If
        Next
        If nTotalLines > 1 Then
            DTE.ExecuteCommand("VAssistX.SelectionBlockComment")
        Else
            DTE.ExecuteCommand("VAssistX.SelectionLineComment")
        End If
    End Sub

since this is using VA to do the commenting, when VA does a block comment, /* */, VA will handle any existing /* */ comments inside the selected lines as normal.

This just leaves you needing to move up and down, add a line, and type any start and end marker comments you want.

I hope this helps to get you started.

zen is the art of being at one with the two'ness
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000