clang-format

How can I clang-format my WHOLE git history?

只谈情不闲聊 提交于 2021-02-10 20:26:42
问题 I have now finished a small library of mine. When I started using it, I didn't know about clang-format. Now I would like to format the whole repository with it. I know that this breaks other peoples repositories as the commit hashes changes. However, as no one is using my library yet, this is fine with me. Thus, what do I have to do to run clang-format for every commit in my history? 回答1: Git comes with a git filter-branch command that is a tool that helps with this kind of task. Note that

How to format objective-c block with clang-format?

你离开我真会死。 提交于 2021-02-07 05:33:51
问题 I have the following code, for example: [cardRegistrationVC setCancelBlock:^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }]; When I apply clang-format on it, it turns into: [cardRegistrationVC setCancelBlock:^{ [weakSelf.navigationController popViewControllerAnimated:YES]; }]; As you can see, code inside the block appears on the same line. But I should be always on a new line. How to set up clang-format correct? My following settings file: BasedOnStyle: LLVM

Double newlines following function definitions

我是研究僧i 提交于 2021-01-29 03:06:52
问题 Is it possible to use clang-format to have double newlines between function definitions: void func1() { return; } void func2() { return; } 回答1: If you are asking whether the IDE can insert these lines automatically, I don't believe so. You can have any number of lines but only by manually entering them. 回答2: clang-format does not have an option controlling the number of newlines after the function definition. However, it does have an option, MaxEmptyLinesToKeep , which will keep it from

Double newlines following function definitions

五迷三道 提交于 2021-01-29 02:57:41
问题 Is it possible to use clang-format to have double newlines between function definitions: void func1() { return; } void func2() { return; } 回答1: If you are asking whether the IDE can insert these lines automatically, I don't believe so. You can have any number of lines but only by manually entering them. 回答2: clang-format does not have an option controlling the number of newlines after the function definition. However, it does have an option, MaxEmptyLinesToKeep , which will keep it from

clang-format main include sorting with folders prefix

淺唱寂寞╮ 提交于 2021-01-28 13:34:58
问题 I am trying to get clang-format to recognize the main include for foo.cpp in the following setup: project/my_lib ├── CMakeLists.txt ├── include │ └── project │ └── my_lib │ └── foo.hpp ├── src │ └── foo.cpp └── tests └── foo_test.cpp And foo.cpp has the following content: #include <project/another_lib/bar.hpp> #include <project/my_lib/foo.hpp> #include <vector> // ... The problem I think I have identified is the following: clang tries to identify the 'main' include based on the file name, in

clang-format main include sorting with folders prefix

一曲冷凌霜 提交于 2021-01-28 13:34:43
问题 I am trying to get clang-format to recognize the main include for foo.cpp in the following setup: project/my_lib ├── CMakeLists.txt ├── include │ └── project │ └── my_lib │ └── foo.hpp ├── src │ └── foo.cpp └── tests └── foo_test.cpp And foo.cpp has the following content: #include <project/another_lib/bar.hpp> #include <project/my_lib/foo.hpp> #include <vector> // ... The problem I think I have identified is the following: clang tries to identify the 'main' include based on the file name, in

clang-format: break function parameters

血红的双手。 提交于 2021-01-27 08:00:51
问题 I would like to use clang-format to product C functions like: void cfg_InitConfig ( cfg_Config_t* cfg, char* name ) { // TODO function } After reading the manual I don't think clang-format can do it. Is it possible? 回答1: I have studied lot of lot of documents according to your problem. Unfortunately there is no way to break your code like this void cfg_InitConfig ( cfg_Config_t* cfg, char* name ) but someone can be create patch for break that kind of alignment it could be possible. Creating

clang-format: break function parameters

隐身守侯 提交于 2021-01-27 07:58:49
问题 I would like to use clang-format to product C functions like: void cfg_InitConfig ( cfg_Config_t* cfg, char* name ) { // TODO function } After reading the manual I don't think clang-format can do it. Is it possible? 回答1: I have studied lot of lot of documents according to your problem. Unfortunately there is no way to break your code like this void cfg_InitConfig ( cfg_Config_t* cfg, char* name ) but someone can be create patch for break that kind of alignment it could be possible. Creating

How can I align function parameter names in clang-format?

青春壹個敷衍的年華 提交于 2021-01-19 05:04:24
问题 Is it possible to use clang-format to format struct members and function parameter names into columns? For example: struct { int alpha; //aligned to 'b' of "beta" unsigned int beta; MyObject *gamma; //aligned with 'g' not '*' }; void foobar (int alpha, //aligned to 'b' of "beta" unsigned int beta MyObject *gamma) //aligned with 'g' not '*' { } If it's not possible, could I extend clang-format somehow to achieve this? 回答1: Well, you can get close. For function declarations: You can set

Indenting preprocessor directives with clang-format

[亡魂溺海] 提交于 2020-11-30 17:36:38
问题 I am working on a c++ project where I am using a lot of #pragma omp . I use the wonderful clang-format for tidiness but it always deletes the indentation for all preprocessor directives. Is there a way to change that behavior? Or is there another formatting tool that is more recommendable? Or should I avoid using these tools at all? 回答1: You might want to just patch it yourself and make a pull request. It's not that hard, I made a similarly mundane pull request once. The clang-format code is