Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to configure clang-format to keep nested namespace declarations on the same line?

In the codebase I'm working in, we always declare nested namespaces thusly:

namespace foo { namespace detail {

// stuff

} }  // foo::detail namespace

I haven't yet been able to find a way to configure clang-format not to break this out into multiple lines:

namespace foo {
namespace detail {

// stuff

}
}  // foo::detail namespace

I've played around with the BreakBeforeBraces configuration, and I've looked into the new BraceWrapping configuration in clang 3.8, both without success.

Is it possible to do this without annotating the code with // clang-format [on/off]?

like image 369
Ian Avatar asked Oct 02 '15 21:10

Ian


People also ask

How do you customize your clang-format?

clang-format supports two ways to provide custom style options: directly specify style configuration in the -style= command line option or use -style=file and put style configuration in the . clang-format or _clang-format file in the project directory.

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.

What is clang-format default style?

clang-format file uses YAML format: key1: value1 key2: value2 # A comment. ... The configuration file can consist of several sections each having different Language: parameter denoting the programming language this section of the configuration is targeted at.

Where do I put the clang-format?

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

It turns out that this is a feature that has been considered by the clang-format team, but has been rejected. For additional details, see https://llvm.org/bugs/show_bug.cgi?id=17928.

like image 176
Ian Avatar answered Oct 21 '22 13:10

Ian