3

In my company's coding convention, we format nested namespaces on one line. For example:

namespace Foo { namespace Bar {
...
}} // Foo::Bar

I am trying to enforce this style using astyle but could not find anything in the documentation at http://astyle.sourceforge.net/astyle.html

When I run the following astyle command (ignore the irrelevant options)

astyle --style=allman --add-brackets --align-reference=name --align-pointer=name --attach-namespaces --pad-header --pad-oper --unpad-paren -n <filename>

I end up with each of the nested namespace on a separate line as shown below:

namespace Foo {
namespace Bar {
...
}
}
shibumi
  • 378
  • 2
  • 11
  • I was never happy with Astyle. I prefer clang format (https://clang.llvm.org/docs/ClangFormat.html) - there is even a Visual Studio add-in for clang format. Consider switching to clang format. – Vertexwahn Jul 24 '17 at 17:31
  • I mostly work in vim but don't mind moving to clang-format. Do you know the exact switch for the use case I mentioned? Thanks. – shibumi Jul 26 '17 at 11:20
  • Unfortunately not: https://bugs.llvm.org/show_bug.cgi?id=17928 – Vertexwahn Jul 26 '17 at 18:48

1 Answers1

2

Try to modify astyle source code. Find method ASFormater::isOkToBreakBlock and insert at the beginning:

if (isBraceType(braceType, NAMESPACE_TYPE))
    return false;

Make sure that it doesn't break the whole formatting.

P.S. Hope that astyle team will hear and will make correct changes with option.