Over the last years I’ve been contributing to several Open Source software projects, just to name the most recent:
All of the above projects follow their own style how to lay out the source code using indents. It seems like everybody has a different opinion you would have to cater for, for example:
Often times these conventions are implicit, you have to read the source code to see the actual style the authors follow. It is encouraged to apply these guidelines to your patches ensure they will be accepted.
I often switch between developing for projects, so before writing a single line of code I have to hit Visual Studio’s Tools | Options | Text Editor Options dialog and change the indent settings to match the project’s conventions.
This has become very tedious, additionally, I often forget to adjust the indent settings before writing code. (Perhaps I forget it because it’s so annoying.)
To scratch that itch I sat down and wrote some Visual Studio macros that apply the most commonly used settings:
Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports System.Diagnostics Public Module Fonts Sub TwoSpaces() Dim textEditor As Properties textEditor = DTE.Properties("TextEditor", "AllLanguages") textEditor.Item("IndentStyle").Value = vsIndentStyle.vsIndentStyleSmart textEditor.Item("TabSize").Value = 4 textEditor.Item("IndentSize").Value = 2 textEditor.Item("InsertTabs").Value = False End Sub Sub FourSpaces() Dim textEditor As Properties textEditor = DTE.Properties("TextEditor", "AllLanguages") textEditor.Item("IndentStyle").Value = vsIndentStyle.vsIndentStyleSmart textEditor.Item("TabSize").Value = 4 textEditor.Item("IndentSize").Value = 4 textEditor.Item("InsertTabs").Value = False End Sub Sub OneTab() Dim textEditor As Properties textEditor = DTE.Properties("TextEditor", "AllLanguages") textEditor.Item("IndentStyle").Value = vsIndentStyle.vsIndentStyleSmart textEditor.Item("TabSize").Value = 4 textEditor.Item("IndentSize").Value = 4 textEditor.Item("InsertTabs").Value = True End Sub Public Sub NormalFonts() SetFontSize(10) End Sub Public Sub LargeFonts() SetFontSize(14) End Sub Sub SetFontSize(ByVal size As Int32) Dim textEditor As Properties textEditor = DTE.Properties("FontsAndColors", "TextEditor") textEditor.Item("FontSize").Value = size End Sub End Module
These macros are associated with toolbar buttons:
The first two buttons are associated to the LargeFonts and NormalFonts macros that set the editor font size. I like to invoke these when doing presentations. No more fiddling with Tools | Options to ensure your audience is able to read the code on the wall.
LargeFonts
NormalFonts
The last three buttons should be self-explaining, they’re to quickly set tabbed, two-space and four-space indents, respectively.
a@href@title, blockquote@cite, em, strike, strong, sub, sup, u