How to auto-collapse certain comments in Visual Studio 2010?
Asked Answered
S

2

1

A colleague of mine uses a abomination text editor that routinely leaves comment blocks all over the code. Needless to say, this is driving me rather mad. The comment blocks look like this:

/* EasyCODE ) */
/* EasyCODE ( 0 
WndProc */
/* EasyCODE F */

i.e. they all start with EasyCODE and most of them span several lines. Thankfully, VS2010 can collapse comment blocks, so I don't have to see them all the time.

Is there a way to automate that? A way to automatically collapse all those horrible EasyCODE blocks would be godsent!

Scornik answered 7/9, 2010 at 6:37 Comment(5)
Is there a way to automate something that zaps your colleague every time he uses said abomination? :)Interject
If it clutters everyone's code with unreadable and useless comments, perhaps the nicer solution would be to convince your collegue to deactivate this function, or to change his editor.Kathrinkathrine
@ereOn: sadly, that editor heavily relies on those comments. It substitutes nice, human-readable code with weird, machine-readable comments.Scornik
Just out of curiosity, what is that editor ?Kathrinkathrine
@ereOn: Well, it is called EasyCODE. It is basically structure chart based programming and it structures code using those comment blocks.Scornik
S
2

Here is a macro that should do it. There are some weirder EasyCode comments that it doesn't catch but it mostly does the trick.

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a ' remove for VS2008
Imports EnvDTE100 ' remove for VS2008
Imports System.Diagnostics
Imports System.Collections.Generic

Public Module HideEasyCODEComments
    ''
    '' Collapse all EasyCODE comment blocks
    ''
    Sub ToggleSummaryCommentsOutlineExpansion()
        If (DTE.ActiveDocument Is Nothing) Then
            Exit Sub
        End If

        If (DTE.UndoContext.IsOpen) Then
            DTE.UndoContext.Close()
        End If

        DTE.SuppressUI = True

        Try
            DTE.UndoContext.Open("ToggleSummaryCommentsOutline")
        Catch
        End Try

        Dim objSelection As TextSelection = DTE.ActiveDocument.Selection
        Dim line As Integer = objSelection.CurrentLine
        objSelection.StartOfDocument()

        ' find all EasyCODE blocks
        While objSelection.FindText("^.*\/\* EasyCODE.*((\n.*\*\/)|(\n.*\/\*.*)|(\n\/\/.*))*", vsFindOptions.vsFindOptionsRegularExpression)
            DTE.ExecuteCommand("Edit.HideSelection")
        End While
        objSelection.StartOfDocument()
        objSelection.GotoLine(line)

        DTE.UndoContext.Close()
        DTE.SuppressUI = False
    End Sub

End Module

Create a new macro in the macro IDE (Tools->Macros->Macro IDE), paste the above code into it, then assign a keyboard shortcut to it (Tools->Options->Environment->Keyboard, search for it in the listbox). Hit the keyboard shortcut and all EasyCode comments will be gone.

Have fun!

Scornik answered 7/9, 2010 at 6:37 Comment(1)
what does one do with the macro? Any linksLusatian
I
0

You can't do it automatically. However, you can select a piece of code, and choose from the context menu Outlining/Hide Selection (Ctrl+M Ctrl+H). So select the ugly comments and do it this way.

Taken from here.

Ilonailonka answered 7/9, 2010 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.