Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line breaks between function definitions

Tags:

clang-format

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.

like image 278
PovilasB Avatar asked Nov 25 '14 08:11

PovilasB


People also ask

How many blank lines should be before and after method definitions inside a class method definitions inside a class are just another term for functions in a class?

Surround top-level function and class definitions with two blank lines. Method definitions inside a class are surrounded by a single blank line. Extra blank lines may be used (sparingly) to separate groups of related functions.

What is clang format?

Clang-Format is a widely-used C++ code formatter. As it provides an option to define code style options in YAML-formatted files — named . clang-format or _clang-format — these files often become a part of your project where you keep all code style rules.


2 Answers

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 are none. IMHO this is a huge missing feature.

like image 183
Keith F. Kelly Avatar answered Oct 06 '22 07:10

Keith F. Kelly


Your best bet is to set 'MaxEmptyLinesToKeep: 2' inside .clang-format file to let clang-format keep 2 lines intact.

like image 38
Nuray Altin Avatar answered Oct 06 '22 07:10

Nuray Altin