Understanding clang-format's IncludeIsMainRegex

Hello,

I try to understand the IncludeIsMainRegex setting of clang-format http://releases.llvm.org/3.9.0/tools/clang/docs/ClangFormatStyleOptions.html

My cpp file indention.cpp contains includes:

#include <string>

#include "../precice/src/action/Action.hpp"
#include "indention.hpp"
#include <boost/array.hpp>

Now I try to assess what affect IncludeIsMainRegex has:

1) IncludeIsMainRegex: '$' (default for style LLVM)

clang-format -style=file indention.cpp
shows no effect

neither do

2) IncludeIsMainRegex: ''
3) IncludeIsMainRegex: 'hpp$'
4) IncludeIsMainRegex: '\.hpp$
5) IncludeIsMainRegex: '.hpp$

According to the documentation I expected that 2 and 3 match the suffix and assign category 0 to the include, thus placing it at the top.

Where is my understanding wrong?

Thanks,
Florian

Hi Florian,

Note that clang-format only sorts #includes in the same block. If you delete the empty line between the two blocks, clang-format should do the right thing for you.

Cheers,
Eric

Hey,

Hi Florian,

Note that clang-format only sorts #includes in the same block. If you delete the empty line between the two blocks, clang-format should do the right
thing for you.

Thanks, that seem to work. Is that documented somewhere? Maybe it should be added.

Best,
Florian