Can I get Xcode's automatic indentation to indent continuation lines?
I want:
BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues
BOOL someOtherLongVariableName =
someEvenLongerValue;
[someLongVariableName
performSomeAction:someLongArgument]
I currently get:
BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues
BOOL someOtherLongVariableName =
someEvenLongerValue;
[someLongVariableName
performSomeAction:someLongArgument]
To be clear:
I ended up integrating uncrustify to partially get what I wanted. (Case 3 is still off, though.)
To get Xcode to indent the code automatically, I've created an "Aggregate" target with a "Run Script" phase:
find . -name '*.[mh]' -print0 \
| xargs -0 git diff-index HEAD -- | grep -v "D\t" | cut -c100- \
| xargs uncrustify -l OC --replace --no-backup -c uncrustify.cfg
This runs uncrustify on all files that are marked as changed in git. I've added my app target as a dependency to the format target, so it only formats if compilation succeeds. (Important, since uncrustify would be confused by broken syntax.) Finally, I've added the format target to my scheme, so every build starts a format. Xcode usually reloads the formatted file on its own.
The relevant setting my uncrustify.cfg is indent_continue = 4
.
Undo information is lost when Xcode reloads the formatted file. I could run the script from a git pre-commit hook, but I prefer quicker results.
Another downside is that Objective-C support in uncrustify isn't perfect, but there seems to be no alternative. (Maybe clang-format someday?)
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