Mat*_*ias 5 c++ formatting c-preprocessor clang-format
我的情况是这样的:
#ifdef NOISE
#ifdef NOISE_2D
DECLARE_NOISE2D();
#else // NOISE_3D
DECLARE_NOISE3D();
#endif
#else
DECLARE_NO_NOISE();
#endif
Run Code Online (Sandbox Code Playgroud)
有没有办法让 Clang-format 查看这段代码并将其格式化为这样:
#ifdef NOISE
#ifdef NOISE_2D
DECLARE_NOISE2D();
#else // NOISE_3D
DECLARE_NOISE3D();
#endif
#else
DECLARE_NO_NOISE();
#endif
Run Code Online (Sandbox Code Playgroud)
我能做的最好的事情就是 with IndentPPDirectives: BeforeHash,结果如下:
#ifdef NOISE
#ifdef NOISE_2D
DECLARE_NOISE2D();
#else // NOISE_3D
DECLARE_NOISE3D();
#endif
#else
DECLARE_NO_NOISE();
#endif
Run Code Online (Sandbox Code Playgroud)
我还尝试在宏块开始和结束时传递预处理器指令,但似乎它们没有被拾取(值得一试)。
看起来预处理器指令和 C++ 代码都有自己的缩进树,但它们似乎并不共享。无论如何,是否有 Clang-format 提供所需的输出,或者是否有任何其他自动格式化程序能够提供此功能?