我想找出哪个clang格式样式选项负责插入(或删除)Objective-C中返回类型和方法名称之间的空格.我无法在clang格式样式指南中找到此选项.
例:
- (id) init;
Run Code Online (Sandbox Code Playgroud)
与
- (id)init;
Run Code Online (Sandbox Code Playgroud) 我.clang-format在我的主目录中并设置indentwidth 4如下.
BasedOnStyle: LLVM
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
UseTab: Never
Run Code Online (Sandbox Code Playgroud)
但当我clang-format -style='~/.clang-format' a.cpp用来格式化我的代码时,缩进宽度变为2.喜欢:
// See this indent width 2. The original file has width 4,
// but clang-format changes it to width 2.
int main(int argc, char const *argv[]) {
A a;
a.bar();
Run Code Online (Sandbox Code Playgroud)
clang-format --version的输出是
LLVM (http://llvm.org/):
LLVM version 3.4.2
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: core-avx-i
Run Code Online (Sandbox Code Playgroud)
如何让clang格式格式化我的代码(.h,.c,..),缩进宽度为4?
我正在使用clang-format和一个相当小的配置文件,我对这些选项并不是很熟悉.为了这个问题,请考虑这段未格式化的代码:
int msgResult = ShowMBox(R_MESSAGE, msgText, MB_OK_ENABLE | MB_CANCEL_ENABLE, MB_STYLE_ERROR);
Run Code Online (Sandbox Code Playgroud)
当我在这个片段上运行clang-format时,我明白了
int msgResult
= ShowMBox(R_MESSAGE, msgText, MB_OK_ENABLE | MB_CANCEL_ENABLE, MB_STYLE_ERROR);
Run Code Online (Sandbox Code Playgroud)
但我更喜欢
int msgResult = ShowMBox(R_MESSAGE, msgText, MB_OK_ENABLE | MB_CANCEL_ENABLE,
MB_STYLE_ERROR);
Run Code Online (Sandbox Code Playgroud)
有没有办法强制执行不破坏=,或者至少不愿意破坏?
我正在_clang-format使用BBUncrustifyPluginfor Xcode 运行文件.
在Xcode中,每当我创建换行符时,它都会保留缩进空格.(空格显示为•)像这样:
if(YES) {
••••NSInteger myNum = 2;
••••
••••myNum = 4;
}
Run Code Online (Sandbox Code Playgroud)
当我运行我的_clang-format文件时,它会从我的代码中删除空格,所以它现在看起来像这样:
if(YES) {
••••NSInteger myNum = 2;
••••myNum = 4;
}
Run Code Online (Sandbox Code Playgroud)
这并不是什么大不了的事,但它确实会导致每个换行符删除空格的烦人提交更改.更不用说如果我回去编辑文件,我希望那些空间已经存在.
我似乎找不到_clang-format可以帮助我解决这个问题的密钥.有帮助吗?
这是我当前的_clang-format文件
BasedOnStyle: Chromium,
AlignTrailingComments: true,
BreakBeforeBraces: Linux,
ColumnLimit: 140,
IndentWidth: 4,
KeepEmptyLinesAtTheStartOfBlocks: false,
ObjCBlockIndentWidth: 4,
ObjCSpaceAfterProperty: true,
ObjCSpaceBeforeProtocolList: true,
PointerBindsToType: false,
SpacesBeforeTrailingComments: 1,
TabWidth: 8,
MaxEmptyLinesToKeep: 2,
UseTab: Never,
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有一些代码,其中的数据或参数表按如下所示的列对齐(人为的简单示例;实际代码具有更大的表):
// Name Size Starting val
// ======= ======= ============
S s = {
{ "Dubs", abc, 123 },
{ "X", n, m },
{ "YZ", ij / q, kl }
};
// Name Size Starting val
// ======= ======= ============
w = Create( "Dubs", abc, 123 );
x = Create( "X", n, m );
yz = Create( "YZ", ij / q, kl );
Run Code Online (Sandbox Code Playgroud)
clang-format杀死表格式:
// Name Size Starting val
// ======= ======= ============
S s = {
{ "Dubs", …Run Code Online (Sandbox Code Playgroud) 在我们的项目中,有时我们在一行上初始化数组,有时我们将它们初始化为块。那是
strings::UniChar const s[] = {'H', 'e', 'l', 'l', 'o'};
与
string :: UniChar const s [] =
{
'H',
'e',
'l',
'l',
'o'
};
我希望clang-format能够区分这两种类型,而不是将第二种转换为第一种,也不要在开括号后对齐元素。那不是这样的:
string :: UniChar const s [] = {'H',
'e',
'l',
'l',
'o'};
有没有一种方法可以使用配置文件来实现?
我知道可以将变量定义和影响对齐clang-format,使用AlignConsecutiveAssignments和AlignConsecutiveDeclarations得到类似的东西
int a_value;
unsigned int another_value;
float a_last_value;
a_value = 2;
another_value = 3;
a_last_value = 42.0f;
// Or both at the same time
int a_value = 2;
unsigned int another_value = 3;
float a_last_value = 42.0f;
Run Code Online (Sandbox Code Playgroud)
现在,有没有办法用单行函数/方法做一个类似的东西(AllowShortFunctionsOnASingleLine例如使用单行)?我的意思是得到类似的东西
void SetPositions(const vec3_array& p) { m_Data.Positions = p; }
void SetUVs(const vec2_array& u) { m_Data.UVs = u; }
void SetNormals(const vec3_array& n) { m_Data.Normals = n; }
void SetIndices(const UIntArray& i) { m_Data.Indices = …Run Code Online (Sandbox Code Playgroud) 我想配置clang格式,而不必将我的.clang-format文件复制到每个新的工作区中。
在我settings.json目前
"C_Cpp.clang_format_style": "{BasedOnStyle: Google, IndentWidth: 4, IndentCaseLabels: false, TabWidth: 4, UseTab: ForIndentation, ColumnLimit: 0}",
"C_Cpp.clang_format_fallbackStyle": "Google"
Run Code Online (Sandbox Code Playgroud)
描述了C_Cpp.clang_format_style说
编码样式,当前支持:Visual Studio,LLVM,Google,Chromium,Mozilla,WebKit。使用“文件”从当前目录或父目录中的.clang格式文件加载样式。使用“ {键:值,...}”设置特定的参数,例如:“ {BasedOnStyle:LLVM,IndentWidth:8}”
这让我认为我的方法行得通,但事实并非如此。当我使用自动格式时,它始终使用Google fallbackStyle。
这是不可能的还是我在这里做错了什么?
我写了一系列git提交,代码格式很糟糕.
在我将它们推送到github之前,我想git-clang-format在每次提交时运行,以便在我的历史记录中获得格式良好的代码.
有一些组合rebase和git-clang-format这将做到这一点?
在运行clang-format之前,请看以下示例:
struct ApplicationState app_state = {
.signal = {
.use_crash_handler = true,
.use_abort_handler = true,
},
.exit_code_on_error = {
.python = 0,
}
};
Run Code Online (Sandbox Code Playgroud)
运行后,clang-format适用如下:
struct ApplicationState app_state = {.signal =
{
.use_crash_handler = true,
.use_abort_handler = true,
},
.exit_code_on_error = {
.python = 0,
}};
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以在大括号后,struct成员之前添加换行符,因此更像第一个示例,而不像第二个示例?