I want to introduce clang-formatter to our company, but there are some restrictions, like:
Some files in our company that are better read with a tab-width=2 while others are better read with tab-width=4.
This means that some files (due to the nature of their content) should have a different .clang-format configuration file. So, assumming that we end up with 2 or 3 configurations, suitable for each content, is there a way that I can force some files to be formatted by a particular .clang_format ?
for example,
or
we use C, C++, visual studio and vim
You have limited control over which .clang_format file is used, as the formatter will start searching for a file in the source file directory and will then consecutively search the parent directories. However, organizing your directory structure in a way that this works can be quite inconvenient.
You can however override specific options from the style with each call. From the clang-format docs:
Use
-style="{key: value, ...}"to set specific parameters, e.g.:-style="{BasedOnStyle: llvm, IndentWidth: 8}"
Unfortunately the Visual Studio plugin currently does not allow to change the options passed to clang-format on a per-file basis, so the latter approach won't work here.
To my knowledge there is no support for 'modeline' comments that would allow to set style options from within the source file yet, although I'd love to see that added in future versions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With