clang-format

Using clang-format with C++/CLI “for each”

試著忘記壹切 提交于 2020-01-05 05:45:06
问题 I currently try to format C++/CLI code using clang-format (version 9.0.0). I cannot figure how to handle for each statements. Before: for each (auto i in I) { } After (say, CTRL-K/CTRL-D in Visual Studio): for each (auto i in I) { } I read here this: ...you might want to change ForEachMacros to add "for each" I tried this: ForEachMacros: - for each - foreach - Q_FOREACH - BOOST_FOREACH then this: ForEachMacros: - 'for each' and this: - "for each" and even this: - "for\s+each" Nothing works.

exclude directory clang format

跟風遠走 提交于 2020-01-04 02:53:08
问题 Is there any official directive in .clang-format file to exclude directory for applying? Projects sometimes use git submodule , but it is not useful to run clang-format over all directory and then use git checkout to undo changes in submodule folder. I have found some related links: Mozilla Source Github Repo But they don't seem official. 回答1: So far, I don't know of any option of clang-format to exclude files or directories. But what I do, is to create the list of files I want to process in

How could I indent C++ pragma using clang-format?

↘锁芯ラ 提交于 2020-01-02 01:09:17
问题 I am using vim-autoformat , which uses clang-format as external formatter. It seems that clang-format won't indent the C++ #pragma . For example: #include <omp.h> #include <cstdio> int main() { #pragma omp parallel for for (int i = 0; i < 10; ++i) { puts("demo"); } return 0; } I would like to have it formatted into : #include <omp.h> #include <cstdio> int main() { #pragma omp parallel for for (int i = 0; i < 10; ++i) { puts("demo"); } return 0; } I checked clangformat, but didn't find which

how to make clang-format add new line before opening brace of a function?

戏子无情 提交于 2019-12-30 07:57:15
问题 I'm interested in putting an opening brace for functions (but not if statements and other contexts). For example void foo() { ... } Flamewars aside, is there a good rationale for not doing this? Although I use same-line open-brackets for if/else and smaller blocks, I think in this case visual organization of larger units of code (functions/methods/classes/structs) can trump perfect consistency. Moreover, how do I get clang-format to follow this style? 回答1: As the documentation says, invoke

clang-format regex syntax reference

天涯浪子 提交于 2019-12-23 12:06:43
问题 I want clang-format to not modify comment lines I use to separate functions from each other. I think commentPragmas is the right option for that, but I can't find info on the clang-format regex format. I tried commentPragmas: '^/\*-.*' to capture my separator lines that look like this /*------------------------------------------------------------------*/ But the above regex did not work... Where can I look up the syntax for regexes for clang-format? 回答1: TL/DR: The flavor is POSIX ERE As far

Clang-format line breaks

心不动则不痛 提交于 2019-12-17 15:42:20
问题 I'm looking for a clang-format setting to prevent the tool from removing line breaks. For example, I have my ColumnLimit set to 120, and here's what happens when I reformat some sample code. Before: #include <vector> #include <string> std::vector<std::string> get_vec() { return std::vector<std::string> { "this is a test", "some of the lines are longer", "than other, but I would like", "to keep them on separate lines" }; } int main() { auto vec = get_vec(); } After: #include <vector> #include

Line breaks between function definitions

南楼画角 提交于 2019-12-12 10:29:33
问题 Is there any way to to automatically insert spaces between function definitions. E.g. my initial sources are: void func1() { // func1 body. } void func2() { // func2 body. } I would like it to be reformatted to: void func1() { // func1 body. } void func2() { // func2 body. } And if there are more line breaks, fixed number of them should be kept. 回答1: As far as I can tell, there's currently no way to force clang-format to insert blank lines between consecutive functions where there currently

Disallow Clang-Format From Messing With Comments

折月煮酒 提交于 2019-12-11 11:13:58
问题 I'm having trouble getting my clang-format to quite cooperate with multi-line comments. I have tried: CodePragmas: '^[^ ]' But this still results in the following. Before formatting: class Test { /* ======= * Public Functions * ======== */ public: }; After formatting: class Test { /* ======= * Public Functions * ======== */ public: }; Any help would be greatly appreciated. Thanks. 回答1: I have a slightly different comment format, but same situation. If you know the format of your block

Clang format splits if statement body into multiple lines

青春壹個敷衍的年華 提交于 2019-12-10 19:03:35
问题 I have the following .cpp file: //////////////////////////////////////////////////////////////////////////////// void call_long_function_name(bool) {} void sf(bool) {} int main() { bool test = true; if (test) { call_function_name(test); } if (test) { sf(test); } return 0; } (the slashes delimit 80 characters). Using the following configuration file, clang-format suggests: //////////////////////////////////////////////////////////////////////////////// void call_long_function_name(bool) {}

Can you set clang-format's line length?

偶尔善良 提交于 2019-12-10 01:48:14
问题 clang-format is breaking up my lines at 80 columns. Is there a way to make stop breaking lines? The documentation at http://clang.llvm.org/docs/ClangFormatStyleOptions.html doesn't seem to address this. 回答1: The config option responsible for it is called ColumnLimit . ColumnLimit: 99 回答2: Find ColumnLimit (under "Configurable Format Style Options" heading) on that page and you'll find the following statement: ColumnLimit (unsigned) The column limit. A column limit of 0 means that there is no