加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

缩进Xcode中的连续行

发布时间:2020-12-14 19:02:23 所属栏目:百科 来源:网络整理
导读:我可以使用 Xcode的自动缩进来缩进延续线吗? 我想要: BOOL someLongVariableName = someLongValue | someOtherLongValue | moreLongValuesBOOL someOtherLongVariableName = someEvenLongerValue;[someLongVariableName performSomeAction:someLongArgumen
我可以使用 Xcode的自动缩进来缩进延续线吗?

我想要:

BOOL someLongVariableName = someLongValue
    | someOtherLongValue
    | moreLongValues

BOOL someOtherLongVariableName =
    someEvenLongerValue;

[someLongVariableName
    performSomeAction:someLongArgument]

我目前得到:

BOOL someLongVariableName = someLongValue
| someOtherLongValue
| moreLongValues

BOOL someOtherLongVariableName =
someEvenLongerValue;

[someLongVariableName
 performSomeAction:someLongArgument]

要明确:

>我使用显式换行而不是自动换行.
>我希望在编辑时和按下返回后立即进行正确的缩进,而不是在运行外部程序(如uncrustify)之后.

解决方法

我最终整合了 uncrustify以部分获得我想要的东西. (但案例3仍未关闭.)

Xcode集成

为了让Xcode自动缩进代码,我创建了一个带有“Run Script”阶段的“Aggregate”目标:

find . -name '*.[mh]' -print0 
    | xargs -0 git diff-index HEAD -- | grep -v "Dt" | cut -c100- 
    | xargs uncrustify -l OC --replace --no-backup -c uncrustify.cfg

这对在git中标记为已更改的所有文件运行不明确.我已将我的应用目标添加为格式目标的依赖项,因此只有在编译成功时才会格式化. (重要的是,因为unrustify会因语法错误而混淆.)最后,我已经将格式目标添加到我的方案中,因此每个构建都会启动一种格式. Xcode通常会自行重新加载格式化文件.

我的uncrustify.cfg的相关设置是indent_continue = 4.

问题

当Xcode重新加载格式化文件时,撤消信息会丢失.我可以从git pre-commit钩子运行脚本,但我更喜欢更快的结果.

另一个缺点是Objectiverus C在uncrustify中的支持并不完美,但似乎没有其他选择. (有一天可能是clang-format?)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读