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?

jjnguy
  • 136,852
  • 53
  • 295
  • 323
DustinB
  • 11,037
  • 5
  • 46
  • 54

3 Answers3

7

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
  • 418
  • 3
  • 10
  • Awesome -- I just realized AStyle is available in Ubuntu as a package. – DustinB Sep 17 '08 at 18:07
  • 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. – DustinB Sep 17 '08 at 18:51
  • 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! – DustinB Sep 17 '08 at 20:18
3

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 currently edited document by simply creating a new External Tool setting with the following settings:

TITLE: A_Style (put in an 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

NIMISHAN
  • 1,265
  • 4
  • 20
  • 29
DustinB
  • 11,037
  • 5
  • 46
  • 54
1

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
  • 12,806
  • 16
  • 39
  • 38