设置IndentWidth不工作在铛格式
问题描述:
我在我的主目录.clang-format
并设置indentwidth 4如下。设置IndentWidth不工作在铛格式
BasedOnStyle: LLVM
Standard: Cpp11
IndentWidth: 4
TabWidth: 4
UseTab: Never
但是当我使用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();
铛格式--version的输出是
LLVM (http://llvm.org/):
LLVM version 3.4.2
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: core-avx-i
我怎样才能让我的代码(.h,.c,..)以缩进宽度4格式格式化?
答
http://clang.llvm.org/docs/ClangFormat.html
的-style
选项不使用文件路径。它使用字符串file
来指示.clang格式文件的使用,并且在转换stdin时,它会在要处理的文件的父目录或工作目录及其父目录中查找该文件。
你也可以把它直接设置你想要的选项字符串:
clang-format -style="{IndentWidth: 4,TabWidth: 4}"
您还可以使用-dump-config
选项来检查配置。
-style='~/.clang-format'
使用~
指你的主目录通常依赖于外壳通配。 shell不会为你这样做。所以即使-style
确实走上了一条路,这也不会产生正确的道路。
感谢您对-style = file的解释。我从来没有想过'file'意味着一个文字'文件'。 – 2014-11-04 17:09:44