我正在使用Linux内核.clang格式作为参考,但是这部分让我感到困扰。
如何获取clang格式来格式化此代码
const struct my_struct hello = {.id = 0,
.modsmin = 10,
.modsmax = 20,
.strengthmin = 0,
.strengthmax = 100,
.color = COLOR_FOREGROUND };
对此
const struct my_struct hello = {
.id = 0,
.modsmin = 10,
.modsmax = 20,
.strengthmin = 0,
.strengthmax = 100,
.color = COLOR_FOREGROUND
};
查看文档,似乎没有任何clang-format
样式选项可以满足您的需求。
但是,您可以使用“最后一个逗号”的把戏。在最后一个指定的初始值设定项之后,最后一个结束括号之前放置一个逗号。我相信这仍然是有效的C代码。然后clang-format
将每个初始化程序放在单独的行上,这会将缩进移回您要查找的内容。所以输出看起来像这样:
const struct my_struct hello = {
.id = 0,
.modsmin = 10,
.modsmax = 20,
.strengthmin = 0,
.strengthmax = 100,
.color = COLOR_FOREGROUND,
};
据我所知,这种行为在任何地方都没有记录,因此我想将来可以更改。但是这种行为已经存在了很多年,并且版本很多,clang-format
因此我认为依靠它是合理的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句