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 {
...
}
}
3
  • I was never happy with Astyle. I prefer clang format (clang.llvm.org/docs/ClangFormat.html) - there is even a Visual Studio add-in for clang format. Consider switching to clang format. Commented Jul 24, 2017 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. Commented Jul 26, 2017 at 11:20
  • Unfortunately not: bugs.llvm.org/show_bug.cgi?id=17928 Commented Jul 26, 2017 at 18:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.