Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 Commenting out things like $selected$ in Snippets?

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
kennyl Posted - Apr 06 2011 : 03:06:18 AM
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
3   L A T E S T    R E P L I E S    (Newest First)
feline Posted - Apr 11 2011 : 10:58:47 AM
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.
kennyl Posted - Apr 07 2011 : 9:51:42 PM
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.
feline Posted - Apr 07 2011 : 10:11:32 AM
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".

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000