Ian
Ian

Reputation: 872

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]?

Upvotes: 10

Views: 2402

Answers (2)

Eddie Velasquez
Eddie Velasquez

Reputation: 573

clang-format 6.0 has the "CompactNamespaces: true" option that does exactly what you're asking for. See http://clang.llvm.org/docs/ClangFormatStyleOptions.html

Upvotes: 4

Ian
Ian

Reputation: 872

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.

Upvotes: 5

Related Questions