blackball
blackball

Reputation: 748

clang-format: disable formatting for macros?

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?

Upvotes: 13

Views: 6829

Answers (1)

Dmitry Sokolov
Dmitry Sokolov

Reputation: 3180

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).

Upvotes: 13

Related Questions