Created
February 22, 2015 00:57
-
-
Save WaltRitscher/f533f207407e56a95b42 to your computer and use it in GitHub Desktop.
Visual Studio 2010 Macros (Line Modifers)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Option Strict Off | |
Option Explicit On | |
Imports System | |
Imports EnvDTE | |
Imports EnvDTE80 | |
Imports EnvDTE90 | |
Imports EnvDTE90a | |
Imports EnvDTE100 | |
Imports System.Diagnostics | |
Public Module LineModifers | |
Public Sub RemoveAdjacentBlankLines() | |
' remove any blank line that is followed by another blank line | |
' therefore, reduces two blank lines to one, | |
' will not remove single blank lines | |
Dim selection As EnvDTE.TextSelection | |
Dim editPoint As EnvDTE.EditPoint | |
DTE.ActiveDocument.Selection.SelectAll() | |
selection = ActiveDocument.Selection | |
editPoint = selection.TopPoint.CreateEditPoint | |
ReplaceWhiteSpaceLines() | |
TrimWhitespaceAtEndOfLine() | |
Do While editPoint.Line < selection.BottomPoint.Line | |
If editPoint.LineLength = 0 Then | |
editPoint.LineDown() | |
If editPoint.LineLength = 0 Then | |
' adjacent blank line | |
editPoint.Delete(-1) | |
editPoint.LineUp() | |
End If | |
End If | |
editPoint.LineDown() | |
Loop | |
End Sub | |
Sub RemoveAllBlankLines() | |
Dim selection As EnvDTE.TextSelection | |
Dim editPoint As EnvDTE.EditPoint | |
DTE.ActiveDocument.Selection.SelectAll() | |
selection = ActiveDocument.Selection | |
editPoint = selection.TopPoint.CreateEditPoint | |
ReplaceWhiteSpaceLines() | |
TrimWhitespaceAtEndOfLine() | |
Do While editPoint.Line < selection.BottomPoint.Line | |
If editPoint.LineLength = 0 Then | |
editPoint.Delete(-1) | |
' editPoint.SetBookmark() | |
End If | |
editPoint.LineDown() | |
Loop | |
End Sub | |
Public Sub ReplaceWhiteSpaceLines() | |
DTE.Find.FindWhat = "^:b#\n" | |
DTE.Find.ReplaceWith = "\n" | |
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument | |
DTE.Find.MatchCase = False | |
DTE.Find.MatchWholeWord = False | |
DTE.Find.MatchInHiddenText = True | |
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr | |
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone | |
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll | |
DTE.Find.Execute() | |
End Sub | |
Public Sub TrimWhitespaceAtEndOfLine() | |
DTE.Find.FindWhat = "{[^ \t]+}{[ \t]#$}" | |
DTE.Find.ReplaceWith = "\1" | |
DTE.Find.Target = vsFindTarget.vsFindTargetCurrentDocument | |
DTE.Find.MatchCase = False | |
DTE.Find.MatchWholeWord = False | |
DTE.Find.MatchInHiddenText = True | |
DTE.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr | |
DTE.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone | |
DTE.Find.Action = vsFindAction.vsFindActionReplaceAll | |
DTE.Find.Execute() | |
'{[^ \t]+}{[ \t]#$} | |
'\1 | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment