我可以获得 Xcode 的自动缩进来缩进连续行吗?
我想要:
BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues
BOOL someOtherLongVariableName =
someEvenLongerValue;
[someLongVariableName
performSomeAction:someLongArgument]
我目前得到:
BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues
BOOL someOtherLongVariableName =
someEvenLongerValue;
[someLongVariableName
performSomeAction:someLongArgument]
要清楚:
最佳答案
我最终整合了 uncrustify部分得到我想要的。 (不过,情况 3 仍处于关闭状态。)
Xcode 集成
为了让 Xcode 自动缩进代码,我创建了一个带有“运行脚本”阶段的“聚合”目标:
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
这会在 git 中标记为已更改的所有文件上运行 uncrustify。我已将我的应用程序目标添加为格式目标的依赖项,因此它仅在编译成功时进行格式化。 (很重要,因为 uncrustify 会被损坏的语法弄糊涂。)最后,我已经将格式目标添加到我的方案中,所以每个构建都开始一个格式。 Xcode 通常会自行重新加载格式化文件。
我的 uncrustify.cfg 的相关设置是
indent_continue = 4
.问题
当 Xcode 重新加载格式化文件时,撤消信息会丢失。我可以从 git pre-commit hook 运行脚本,但我更喜欢更快的结果。
另一个缺点是 uncrustify 中的 Objective-C 支持并不完美,但似乎别无选择。 (也许 clang-format 有一天?)
关于xcode - 在 Xcode 中缩进连续行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4177390/