如何在Visual Studio 2010中自动折叠某些注释? [英] How to auto-collapse certain comments in Visual Studio 2010?

查看:938
本文介绍了如何在Visual Studio 2010中自动折叠某些注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个同事使用可憎的文本编辑器,常规地在代码上留下注释块。不用说,这让我很生气。注释块如下所示:

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 */

$ c> EasyCODE ,并且大多数跨越几行。幸运的是,VS2010可以折叠注释块,因此我不必始终看到它们。

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.

有自动化的方法吗?自动折叠所有这些可怕的 EasyCODE 块的方法将是神话! >

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

推荐答案

这里有一个宏,应该这样做。有一些简单的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

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

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.

玩得开心!

这篇关于如何在Visual Studio 2010中自动折叠某些注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆