[cfe-dev] [clang-format] Indentation of preprocessor directives

Curdeius Curdeius via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 30 07:49:08 PDT 2016


Hi all,

I've written a working draft for a new clang-format option
"PPDirectiveIndentation" (available at
https://github.com/mkurdej/clang/tree/indent-pp-directives).
Basically, it indents preprocessor directives. So, the code

#if 0
#define A
#endif

becomes

#if 0
#   define A
#endif

when PPDirectiveIndentation = All.

So far, there are only two options (None, All), but I foresee another
option Inner or something like that to mimic the behaviour of
NamespaceIndentation.
The number of spaces between '#' and the directive name is controlled by
IndentWidth option (to be consistent with indentation inside namespaces,
classes, blocks etc.), but it may be easily modified.

What's the interest in it? Among well known source code that indents
preprocessor directives, there are many Boost libraries (a quick search
shows e.g.
https://github.com/boostorg/asio/blob/develop/include/boost/asio/buffer.hpp
).
What are the chances that it gets merged?

I'll submit the code for revision to Phabricator this week when I find some
more time.

Best regards,
Marek
-- 
Marek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160830/634ca57e/attachment.html>


More information about the cfe-dev mailing list