0

The following Objective-C code in XCode (which compiles)

NSString *someString = @"Lorem ipsum dolor.\nEget nisl nec risus";

after running Uncrustify becomes

NSString *someString = @"Lorem ipsum dolor.
Eget nisl nec risus";

which doesn't compile. Is there any way to avoid it changing line breaks embedded in an NString? I have been searching and reading the forums, as well as the cryptic Uncrustify config file and have been unable to find an answer.

By the way, I am using version 0.60 of Uncrustify.

Nate Cook
  • 8,395
  • 5
  • 46
  • 37
  • You should file a bug on the Uncrustify Sourceforge project page. – rmaddy Jun 07 '13 at 22:52
  • Done. Here's the link in case anyone wants to vote it up: https://sourceforge.net/p/uncrustify/bugs/554/ I'm leaving this question open in case anyone finds a workaround. – Nate Cook Jun 07 '13 at 23:30

2 Answers2

1

Figured it out!

The problem is not with the config. It's with the AppleScript that is ran. On my system the AppleScript is at ~/Library/Services/Uncrustify_opened_Xcode_sources.workflow.

Basically reworked it a bit to be functional for the latest version of Uncrustify by modifying the generated document.wflow within the Uncrustify_opened_Xcode_sources.workflow application. Runs great for me, but might need adjustments. I only changed lines 99-105. I deleted the blockers.

https://github.com/heliumroe/Xcode-formatter/compare/octo-online:master...patch-1?quick_pull=1 for more details!

if (suffix = "m" or suffix = "h") then

tell application "Xcode" to (do shell script "'/usr/local/bin/uncrustify' -c " & "'" & uncrustifyConfigFilePath & "' -l OC --no-backup '" & currentDocumentPath & "'")

end if

end repeat
display dialog "DONE"
end tell
Michael Petrotta
  • 59,888
  • 27
  • 145
  • 179
rardoz
  • 112
  • 10
  • I just tried this and verified that it works. This is an excellent change because now the scroll position of the xcode window doesn't jump, i.e. it stays approximately where you are on the page. Nice work Robert! – Nate Cook Aug 23 '13 at 22:02
  • Dumb question: What do you mean by "blockers"? – Nate Cook Aug 23 '13 at 22:10
0

Turns out it's a bug with Xcode-formatter, which does its magic in AppleScript. What we need is a wildcard or a regex in AppleScript to escape the \n linefeeds embedded in strings.

More info here:

https://github.com/octo-online/Xcode-formatter/issues/7

EDIT:

I found a workaround.

NSInteger newLineAsciiCode = 10;
NSString *newLineCharacter = [NSString stringWithFormat:@"%c", newLineAsciiCode];
NSString *someString = [NSString stringWithFormat:@"Lorem ipsum dolor.%@Eget nisl nec risus", newLineCharacter];
Nate Cook
  • 8,395
  • 5
  • 46
  • 37