[clang-format] sort includes and group per category

To fix bug 28203 and improve the includes sorting, I would like to add an includes grouping feature.

A ‘GroupIncludes (bool)’ format option could be added to group the includes per category.
The includes could be grouped with a empty line between every group.

Example priorities: system includes 3, boost 2, other 1
before:
#include

#include <boost/make_shared.hpp>
#include “Device.h”

after:

#include “Device.h”

#include <boost/make_shared.hpp>

#include

What do you think of the proposal?

Regards,

Wim

As a clang-format user, I'd love to see this kind of sort. This is the
general way many people structure their includes, so that they don't
introduce any hidden dependencies. One thing I'd propose is putting the
respective header of a given file on the top (or introduce a feature for
it).
For example, for file `foo.c`:

#include "foo.h"

/* Other "" includes */

/* Other <> includes which are inside the build tree, for example MOC
headers */

/* less common libs, i.e. home-made ones */

/* boost, Qt, whatever else headers */

/* standard library headers */

As a clang-format user, I'd love to see this kind of sort. This is the
general way many people structure their includes, so that they don't
introduce any hidden dependencies. One thing I'd propose is putting the
respective header of a given file on the top (or introduce a feature for
it).
For example, for file `foo.c`:

#include "foo.h"

/* Other "" includes */

/* Other <> includes which are inside the build tree, for example MOC
headers */

/* less common libs, i.e. home-made ones */

/* boost, Qt, whatever else headers */

/* standard library headers */

Hi.

I feel like mentioning that IncludeCategories parameter already exists,
and already allows to sort the includes according to the config-specified
rules. See Clang-Format Style Options — Clang 16.0.0git documentation

The one thing it does *not* allow to do, is to separate the include groups
with empty line.

And i **believe** (i can be wrong) clang-format only sorts the includes
within one block. So if you have two groups of #include's, separated
by empty line, only the includes withing each block will be sorted.

So this empty line #include block separation handling enhancements
is the only thing missing, and is the subject of that issue.

Roman.