views:

2285

answers:

4

As a C# developer, I have become highly dependent on the automatic formatting in Visual Studio 2008. Specifically, I will use the CTRL-K,D keyboard shortcut to force things back into shape after my sloppy implementation.

I am now trying to learn Objective-C and am missing certain features in Xcode, but probably none are quite as painful as the formatting shortcut. My Google searches have yielded nothing built in, though it seems there are some hacks. Am I missing something or does this feature not exist natively in Xcode?

Thanks!

A: 

Unfortunately, Xcode doesn't have anything nearly as extensive as VS or Jalopy for Eclipse available. There are SOME disparate features, such as Edit > Format > Re-Indent as well as the auto-formatting used when you paste code into your source file. I am totally with you, though; there definitely should be something in there to help with formatting issues.

Marc W
Thank you, at least I know I am not missing something. Auto-identing does help dull the pain some what, but I will have to look into a third-party solution.
jslatts
+3  A: 

That's Control- I.

Or for low-tech, cut and then paste. It'll reformat on paste.

Ken
Thanks! That is helpful, especially since the menu doesn't actually show the keyboard shortcut.
jslatts
+1  A: 

There are some good links to Xcode scripting solutions in the answers to this SO question

nall
Thanks for the link. I did find this as well: http://blog.carbonfive.com/2009/08/iphone/code-formatting-in-xcodeIt covers basically the same technique as your link. I will give it a try and see how well it works.
jslatts
+3  A: 

My personal fav PrettyC wantabe is uncrustify: http://uncrustify.sourceforge.net/. It's got a few billion options however so I also suggest you download UniversalIndentGUI_macx, (also on sourceforge) a GUI someone wrote to help set the options the way you like them.

You can then add this custom user script to uncrustify the selected text:

#! /bin/sh
#
# uncrustify!
echo -n "%%%{PBXSelection}%%%"
/usr/local/bin/uncrustify -q -c /usr/local/share/uncrustify/geo_uncrustify.cfg -l oc+ <&0
echo -n "%%%{PBXSelection}%%%"
geowar