views:

843

answers:

7

Are there any VS.NET plugins that will format a selection of code for printing or emailing and is also free?

+4  A: 

Have you checked the inbuilt formatting provided by VS? Select code and enter key chord Ctrl+K, Ctrl+F.

Or goto (menu)Edit->Advanced->FormatSelection or Edit->Advanced->FormatDocument

SDX2000
A: 

That doesn't do anything. The code looks fine in the editor. It's when you paste it somewhere else or try to print it that there are problems. Mainly because of the identing. The method signature might be all the way to the left but your method body floats off to the right.

4thSpace
Use spaces, not tabs.
leppie
I disagree. Use tabs, not spaces. Then you can adjust the size of the tab for each different environment.
Vilx-
+3  A: 

If you copy your code from Visual Studio and paste it into Word, the syntax highlighting will be kept.

Alternatively, you could take a look at the Copy Source As HTML add-in.

Arnout
I didn’t know about the copy/paste to Word. That’s awesome! +1 for you.
Jeffrey L Whitledge
+1  A: 

Is this just a matter of using spaces instead of tabs to do indent your code?

Mike Hall
A: 

Use some kind of tabs-to-spaces function, and make sure the print or email uses a monospaced (aka. typewriter or console) font.

I'm pretty sure VisualStudio had a (little well hidden) function to convert indenting from tabs to spaces and vice versa.

I'm normally using vim where you can use:

:set expandtab
:%retab

to replace tabs with spaces and:

:set noexpandtab
:%retab

to replace spaces to tabs.

Spaces is better for emailing etc. because noone can agree on the length (in spaces) of a tab.

Stein G. Strindhaug
A: 

try Artistic Style 1.22, http://astyle.sourceforge.net/

it's easy to use, has 3 or 4 predefined styles and is configurable.

paul
A: 

To turn tabs to spaces, select the code and use Editor -> Advanced -> Untabify Selected Lines.

configurator