在Xcode中缩进连续行

在Xcode中缩进连续行,xcode,indentation,Xcode,Indentation,我可以用Xcode的自动缩进来缩进连续行吗 我想: BOOL someLongVariableName = someLongValue | someOtherLongValue | moreLongValues BOOL someOtherLongVariableName = someEvenLongerValue; [someLongVariableName performSomeAction:someLongArgument] 我目前得到: BOOL s

我可以用Xcode的自动缩进来缩进连续行吗

我想:

BOOL someLongVariableName = someLongValue
    | someOtherLongValue
    | moreLongValues

BOOL someOtherLongVariableName =
    someEvenLongerValue;

[someLongVariableName
    performSomeAction:someLongArgument]
我目前得到:

BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues

BOOL someOtherLongVariableName =
someEvenLongerValue;

[someLongVariableName
 performSomeAction:someLongArgument]
要明确的是:

  • 我使用的是显式换行,而不是自动换行
  • 我希望在编辑时和按return键后立即获得正确的缩进,而不是在运行外部程序(如uncrustify)后

或尝试xcode首选项文本编辑缩进: 检查语法感知缩进,检查“Return”的自动缩进。

我最终集成了部分内容。(不过,案例3仍处于关闭状态。)

Xcode集成 为了让Xcode自动缩进代码,我创建了一个带有“运行脚本”阶段的“聚合”目标:

这将在git中标记为已更改的所有文件上运行uncrustify。我已将我的应用程序目标添加为格式目标的依赖项,因此只有在编译成功时,它才会格式化。(很重要,因为uncrustify会被错误的语法弄糊涂。)最后,我将格式目标添加到我的方案中,因此每个构建都会启动一种格式。Xcode通常会自行重新加载格式化文件

相关设置my uncrustify.cfg为
indent\u continue=4

问题 当Xcode重新加载格式化文件时,撤消信息将丢失。我可以从git预提交钩子运行脚本,但我更喜欢更快的结果


另一个缺点是uncrustify中的Objective-C支持并不完美,但似乎别无选择。(也许有一天?)

第一个:考虑在语句中使用()。其余部分:考虑重命名:)- 1忽略了问题的前提(这是关于修改压痕深度)。事实上,这甚至是默认设置。可以同时使用这两种设置。例如,先运行
clangformat
,然后在顶部运行
uncrustify
,或者反过来运行。我发现clang格式比uncrustify更好地处理一些ObjC事情,例如数组文本中的空格和
@property
之后的空格(也许uncrustify也能处理)。是的,自从写了答案之后,
clang格式已经成熟了很多。我可能现在只使用它(如果我没有转到Swift…
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