【发布时间】:2020-03-06 23:45:24
【问题描述】:
相关帖子how to make clang-format add new line before opening brace of a function?的回答无济于事。
我在 Windows 上的 Eclipse CDT 中使用带有 Cppstyle 的 clang-format 9.0.0。 clang-format 像这样格式化以下 getter:
int returnNumber() { return 3; }
但我更喜欢这种格式
int returnNumber()
{
return 3;
}
我无法让 clang-format 做到这一点,无论是打破风格 BS_Allman 还是自定义风格。除了手动格式化还有其他解决方案吗?
我的示例源文件如下所示:
头文件.h
#pragma once
namespace Test
{
class MyClass
{
public:
int returnNumber() { return 3; }
};
} /* namespace Test */
而我的配置文件是这样的:
Language: Cpp
AlwaysBreakTemplateDeclarations: 'true'
BreakBeforeBraces: Allman
ColumnLimit: '80'
IndentWidth: '2'
NamespaceIndentation: None
Standard: Cpp11
TabWidth: '2'
UseTab: Always
PointerAlignment: Left
AlignAfterOpenBracket: DontAlign
BreakConstructorInitializers: AfterColon
MaxEmptyLinesToKeep: 2
【问题讨论】:
-
clang-format应该能够做到这一点。您可以使用相同的配置在源文件上手动运行它,看看会发生什么? -
当我从控制台使用
clang-format Header.h > Out.h运行它时,我得到了相同的(坏的)结果:getter 被压缩成一行。 -
你能用你正在使用的
clang-format.config文件更新问题吗?
标签: c++ code-formatting clang-format