Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get clang format to put closing parenthesis of multiline function calls on separate lines?

I've been using clang format to help keep my code clean. For multiline function calls, is there any way to get clang to put the cloning parenthesis on it's own line?

Example:

What it's doing now:

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(); });

What I want:

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
like image 606
Alecto Irene Perez Avatar asked Jun 04 '18 21:06

Alecto Irene Perez


People also ask

Can clang-format break code?

Short answer: YES. The clang-format tool has a -sort-includes option. Changing the order of #include directives can definitely change the behavior of existing code, and may break existing code.

How do I run a clang-format from the command line?

You can install clang-format and git-clang-format via npm install -g clang-format . To automatically format a file according to Electron C++ code style, run clang-format -i path/to/electron/file.cc . It should work on macOS/Linux/Windows.

What is clang formatting?

 Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named . clang-format or _clang-format — these files often become a part of your project where you keep all code style rules.

Where do you put clang?

clang-format file, we need to place it in the project folder or in any parent folder of the file you want to format. clang-format.exe searches for the config file automatically starting with the folder where the file you want to format is located, all the way to the topmost directory.


1 Answers

A new option AlignAfterOpenBracket: BlockIndent was added 2022-01-17 in the approved code review https://reviews.llvm.org/D109557, which is in LLVM 14.0.0-rc1 or later.

(I too want this, as we have thousands of lines of code which use this style, and clang-format supporting this would get me to adopt clang format in Visual Studio - https://developercommunity.visualstudio.com/content/problem/232465/clang-format-messes-with-closing-parentheses-in-fu.html)

like image 78
Dwayne Robinson Avatar answered Sep 21 '22 10:09

Dwayne Robinson