xcode - 在 Xcode 中缩进连续行

标签 xcode indentation

我可以获得 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 自动缩进代码,我创建了一个带有“运行脚本”阶段的“聚合”目标:

    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/

    相关文章:

    ios - 导航栏背景图片的 iOS 规范/指南是什么?

    iphone - Xcode malloc 错误

    c++ - Visual Studio Express 中访问说明符后的缩进问题

    Vim:垂直线表示一行代码缩进了多少?

    objective-c - 如何处理带空格的文件名?

    xcode - 在 "Framework Search Paths"中搜索私有(private)框架

    ios - 在 UITableViewCell 中添加 UICollectionView 时出错

    vb.net - Visual Studio : Override "Smart" indenting only for a few specific lines

    vim - 如何在 Vim 中缩进光标上方的多行?

    select - Vaadin - com.vaadin.ui.Select - 缩进