llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang-format] feature request: add a DSL, to control clang-format from source.

Open Febbe opened this issue 3 years ago • 2 comments

Instead of completely disabling Clang-Format it might be useful, to disable specific options, or change a style temporarily. It would also allow for better, fine-grained formattings.

Imagine the case, where you have 2 main headers for one source file:

Then currently, only the first is detected as main include. It would be useful to have something like

// clang-format pragma: main_include

Which changes the following:

#include "a.h"

#include "b.h"
#include "a_test.h"

automatically into this:

#include "a.h"
#include "a_test.h" // clang-format pragma: main_include

#include "b.h"

Or the opposite:

#include "no/main/include/a.h"

#include "a.h"
#include "b.h"

with // clang-format pragma: no_main_include into this:

#include "a.h"

#include "b.h"
#include "no/main/include/a.h" // clang-format pragma: no_main_include

In the best case, all possible options are covered somehow.

Febbe avatar Feb 15 '23 15:02 Febbe

@llvm/issue-subscribers-clang-format

llvmbot avatar Feb 15 '23 15:02 llvmbot

Interesting issue. I also would like to see this feature request implemented.

earnol avatar Jun 09 '26 14:06 earnol