14

I am using clang-format as the auto-formatting tool for my codebase. But some of its features are bugging me.

For instance, I don't want it to format my macro definitions, since most of the time, it's more clear to just formatting them manually. But I don't know how to disable it in clang-format.

Another minor issue is pointer alignment. Sometimes, it's clear to make it aligned left, sometimes it's right. So I'd rather do it by hand. But disable it from clang-format seems impossible?

Any help on these issues?

1
  • Have you had success with this? I've tried using BasedOnStyle: None, but then it ignores all other settings (which it shouldn't do, either, as far as I understand. Commented Aug 12, 2019 at 11:21

2 Answers 2

14

You can wrap your macros in

// clang-format off
#define ... \
   ...
// clang-format on

To escape manually editing of each file you can use the regex

search: ^([ \t]*#[ \t]*define[ \t]+.+?\\\r?\n(?:.*?\\\r?\n)*.*?\r?\n)

replace: // clang-format off\r\n$1// clang-format on\r\n

for instance, in Notepad++, Ctrl+Shift+F - "Find in Files - "Replace in Files".

To date (up to v11) there is no way to disable pointer alignment. You can either set the style, or derive the style (clang-format will analyze a file for the most common alignment of & and * and will use it).

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

Comments

1

Since clang-format 18, there is SkipMacroDefinitionBody. If set to true, clang-format will not format any macro definitions. Example on godbolt.

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.