Astyle msvc: Difference between revisions
Jump to navigation
Jump to search
Created page with "Add a macro in Visual Studio with the following content. Change the fileName and shellCmd paths. <nowiki> Public Sub formatDocWithAStyle() Dim fileName As Strin..." |
(No difference)
|
Latest revision as of 19:27, 22 September 2013
Add a macro in Visual Studio with the following content. Change the fileName and shellCmd paths.
Public Sub formatDocWithAStyle()
Dim fileName As String
Dim textDocument As TextDocument
Dim startPoint As EnvDTE.EditPoint
Dim endPoint As EnvDTE.EditPoint
Dim text As String
Dim shellCmd As String
Dim procId As Integer
If DTE.ActiveDocument Is Nothing Then
Return
End If
fileName = "c:\temp\formattedCode"
shellCmd = """D:\Program Files\AStyle\bin\AStyle" & """" & " --style=allman --align-reference=name --align-pointer=type --indent-switches --unpad-paren " & """" & fileName & """"
textDocument = DTE.ActiveDocument.Object
startPoint = textDocument.StartPoint.CreateEditPoint
endPoint = textDocument.EndPoint.CreateEditPoint
text = startPoint.GetText(endPoint)
My.Computer.FileSystem.WriteAllText(fileName, text, False)
procId = Shell(shellCmd, AppWinStyle.Hide, True, 30000)
If procId = 0 Then
text = My.Computer.FileSystem.ReadAllText(fileName)
startPoint.ReplaceText(endPoint, text, vsEPReplaceTextOptions.vsEPReplaceTextTabsSpaces)
End If
End Sub