我的主目录中有.clang-format
,并设置indentwidth 4如下。
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();
clang格式的输出——版本为
LLVM (http://llvm.org/):
LLVM version 3.4.2
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: core-avx-i
如何让clang格式格式化缩进宽度为4的代码(.h,.c,..)
http://clang.llvm.org/docs/ClangFormat.html
-style
选项不采用文件路径。它使用字符串file
来指示.clang格式文件的使用,并且在转换stdin时在正在处理的文件的父目录或工作目录及其父目录中查找该文件。
你也可以给它一个字符串,直接设置你想要的选项:
clang-format -style="{IndentWidth: 4,TabWidth: 4}"
您也可以使用-dump-config
选项来检查配置。
-style='~/.clang-format'
使用~
引用主目录通常依赖于shell globbing。在这样的争论中,shell不会为你做到这一点。因此,即使-style
确实走了一条路,也不会产生正确的路。