Format nested namespaces in C ++ on one line using astil

In my company coding convention, we format the nested namespaces on a single line. For example:

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

      

I'm trying to apply this style using astil but couldn't find anything in the documentation http://astyle.sourceforge.net/astyle.html

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

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

      

Ultimately, each of the nested namespaces on a separate line is shown below:

namespace Foo {
namespace Bar {
...
}
}

      

+3


source to share


1 answer


Try changing the source code astyle

. Find method ASFormater::isOkToBreakBlock

and insert at the beginning:

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

      



Make sure it doesn't break all formatting.

PS Hopefully the team astyle

hears and makes the correct changes with the option.

+1


source







All Articles