views:

549

answers:

3

MonoDevelop 1.0 doesn't appear to have a code-formatter like Eclipse does for Java. Is there a preferred shell script (or MonoDevelop add-in?) that you've found to work well?

+6  A: 

At the moment, source code formatting in MonoDevelop is marked as a future enhancement: https://bugzilla.novell.com/show_bug.cgi?id=321946

In the meantime, you may want to check out Artistic Style for C# formatting: http://astyle.sourceforge.net/

I'm planning to see how this might be wired up as an external tool within MonoDevelop. If I get to that, I will edit my answer with the information. UPDATE: I don't have enough reputation to leave a comment, so I'll make one here: Nice job, Dustin, and patch for MonoDevelop too :-) I wonder how recent the version is that is included with Ubuntu... Either way, I'm glad you found something that works for you.

Brandon Payton
Awesome -- I just realized AStyle is available in Ubuntu as a package.
Dustin
I'm able to add "astyle" as an external tool in MonoDevelop, but it barfs when trying to use the variable substitutions. It appears MonoDevelop is not expanding the ${itemPath} like it is supposed to -- perhaps it is quoting it? I'm going to take a look at the source now to see.
Dustin
Well, I was able to patch MonoDevelop to properly use astyle as an external tool. I'll look for existing bug reports and submit a new bug if necessary along with the patch. Thanks for the idea!
Dustin
+2  A: 

Thanks, Brandon. I submitted a patch to MonoDevelop. The issue with MonoDevelop add-ins is that there is a mono compiler bug that doesn't handle anonymous delegates correctly. (bug report: https://bugzilla.novell.com/show_bug.cgi?id=394347)

The patch/workaround is to just cast the anonymous delegate to the proper delegate type. (bug report & patch: https://bugzilla.novell.com/show_bug.cgi?id=369538)

I'm running with the patched version now and am able to execute AStyle on the current edited document by simply creating a new External Tool setting with the following settings:

TITLE: A_Style (put in underscore to enable hotkeys) COMMAND: astyle ARGUMENTS: ${ItemPath}

Then, just execute it using Tools->AStyle (or ALT-T, S)

9/25/08 Edit -- I just put up a blog posting on how to patch MonoDevelop 1.0 and get it working with AStyle : http://dustinbreese.blogspot.com/2008/09/auto-formatting-code-in-monodevelop-10.html

Dustin
+1  A: 

It's a nice programming exercise to write your own formatter . I wrote one for C++ , and it was a nice challenge . You could learn a lot by writing it :)

Vhaerun