如何在 Visual Studio 2010 中自动折叠某些注释?

发布于 2024-09-18 11:53:51 字数 325 浏览 13 评论 0原文

我的一位同事使用 abomination 文本编辑器,它通常会在代码中留下注释块。不用说,这让我很生气。注释块看起来像这样:

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

即它们都以 EasyCODE 开头,并且大多数跨越几行。值得庆幸的是,VS2010 可以折叠注释块,因此我不必一直看到它们。

有没有办法让它自动化?一种自动折叠所有那些可怕的 EasyCODE 块的方法将是天赐之物!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琉璃梦幻 2024-09-25 11:53:52

这是一个应该可以做到这一点的宏。有一些更奇怪的 EasyCode 注释它没有捕获,但它基本上可以解决问题。

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

在宏IDE中创建一个新宏(工具->宏->宏IDE),将上面的代码粘贴到其中,然后为其分配键盘快捷键(工具->选项->环境->键盘,在列表框中搜索它)。按键盘快捷键,所有 EasyCode 注释都会消失。

玩得开心!

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!

油焖大侠 2024-09-25 11:53:52

你不能自动完成它。但是,您可以选择一段代码,然后从上下文菜单“大纲/隐藏选择”(Ctrl+M Ctrl+H) 中进行选择。所以选择丑陋的评论并这样做。

摘自此处

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文