首页 > 解决方案 > 获取 clang 格式以将多行函数调用的右括号放在单独的行上?

问题描述

我一直在使用 clang 格式来帮助保持我的代码干净。对于多行函数调用,有没有办法让 clang 将克隆括号放在它自己的行上?

例子:

它现在在做什么:

increment_and_call_on_match(
    clique_colors,
    0,
    max_clique_color,
    [&](int clique_color) { 
        comms.emplace_back(context.split_by_color(clique_color)); 
    },
    [&](int) { context.split_by_color(); });

我想要的是:

increment_and_call_on_match(
    clique_colors,
    0,
    max_clique_color,
    [&](int clique_color) { 
        comms.emplace_back(context.split_by_color(clique_color)); 
    },
    [&](int) { context.split_by_color(); }
); //Closing paren on new line

标签: c++clang-format

解决方案


在已批准的代码审查https://reviews.llvm.org/D109557中添加了一个新选项AlignAfterOpenBracket: BlockIndent2022-01-17,该选项位于LLVM 14.0.0-rc1或更高版本中。

(我也想要这个,因为我们有数千行使用这种风格的代码,支持这种风格的 clang 格式会让我在 Visual Studio 中采用 clang 格式 - https://developercommunity.visualstudio.com/content/problem/ 232465/clang-format-messes-with-close-parentheses-in-fu.html )


推荐阅读