I cut and paste Objective-C examples off Safari into Xcode but the formatting gets messed up. I know I can do multiple find and replace for { and \r, but is there a one button fix somewhere? Xcode option / plugin. TextEdit plugin etc?
Answer: I created an AppleScript in TextWrangler
tell application "TextWrangler"
activate
replace "- (" using "\\r- (" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
select text 1 of find window
replace ";" using ";\\r" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
replace "{" using "{\\r" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
select find window
replace "//" using "\\r//" searching in text 1 of text document "untitled text" options {search mode:literal, starting at top:true, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
end tell
Control + I
will do some degree of formatting on whatever text you have selected.
Re-indenting in Xcode 4 should solve most formatting issues you might have. However, if you're still not happy with the result, you'll have to go third-party.
I used to change my code formatting quite regularly. I'd go to update some old code, only to find that it was written using deprecated, now unfamiliar, formats.
I've been using Uncrustify to adapt old files to new formats. It's got quite a few options, but is still lacking. However, it should suffice for most cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With