views:

148

answers:

2

I'm looking for a tool (macro, extension) for Visual Studio 2008 that would reformat the source code (C/C++) when you save the file.

+3  A: 

AStyle was my first hit on Google. Looks reasonable. You can tie that to a keyboard event under 'External Tools' in Visual Studio. (I suspect writing/recording a small macro that formats and saves the file is easy, as is rebinding that to Ctrl-S)

See also http://stackoverflow.com/questions/841075/best-c-code-formatter-beautifier, which also recommends AStyle.

Marcus Lindblom
Sorry but AStyle has a big issue handling Unicode source files - it does garbage them.
Sorin Sbarnea
Marcus Lindblom
+1  A: 

Wasn't it so that you can define a "macro" in Visual Studio yourself? If so, you could try making one to do something like Ctrl+A -> Ctrl+K Ctrl+F -> Ctrl+S meaning select all, reformat, save and then bind it to your Ctrl+S. I'm not sure, but I think it wouldn't be too complicated.

Dmitry