Solving Indentation Pains for Visual Studio 2010

So, I've been working on a lot of things lately that would not be very interesting at this point to share with you all. However I've now ran across something that might actually be useful for others.

Anyone that has ever worked in Mozilla code knows that because of various reasons indentation depth and type are not very consistent across the tree. Some code is 4 spaces indent, other code is 2 spaces indent, and Cairo for example is 4 spaces indent with an 8 space tab-width. Now luckily, most of our files actually have a modeline describing the supposed indentation settings for that file. However Visual Studio has no default way of using this information (or at least, I haven't found it).

After having made another mistake in indentation causing me significant pain by having to go back and delete spaces all over the places I decided to write a little Add-in for Visual Studio that reads the emacs modeline and sets the editor settings accordingly. I added a little easy installer so other people can hopefully use it to make their lives easier as well. Note that after installing 'Tools->Add-in Manager' can easily be used to (temporarily) disable it. Although you can of course also uninstall it. There's a couple of caveats I'd like to share:

  • It only reads modelines in the first line of the file. And its parsing isn't 100% correct (it works fine for all cases I found in the mozilla tree).
  • If it does not find a modeline in a file it sets your editor to a default: No tabs, 2 space indent, 2 space tab-width.
  • A lot of files in the Mozilla tree specify tab-width 20. Although this is fine since they don't use tabs, if you're like me and have multiple files open in Visual Studio at a time, setting the tab-width to 20 will make those files appear a little funky if they do contain tabs.
  • The installer only works with Visual Studio 2010 and only installs the Add-in for the current user (it does not require elevation)
  • When uninstalling the installer removes the Documents\Visual Studio 2010\Addins folder if it contains no other add-ins. This shouldn't actually matter.

Getting Visual Studio to output an installer the way I wanted it (no elevation prompt, etc.) turned out to be pretty painful! So I'm sure the installer isn't very good, but it gets the job done.

You can find the installer here, hopefully it will help you as it helps me! If you have any suggestions let me know.


# Justin Dolske on 2012-03-28 at 22:32

Seems really useful – file a bug to get it added to MozillaBuild? (

# [Member]   on 2012-03-29 at 02:04

@Justin: Hrm, great idea in theory, I’m a little worried how people who do a lot of non-mozilla stuff will respond to a mysterious influence meddling with their editor settings :). I could change some of the behavior to be more friendly to that I guess.

Form is loading...

February 2017
Mon Tue Wed Thu Fri Sat Sun
 << <   > >>
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28          
Certain events have made me realise it's probably a good idea to have a 'blog' to share ideas and get feedback...


  XML Feeds

free blog tool