Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clang Format is removing all the indent spaces on my empty lines

I'm running _clang-format file using the BBUncrustifyPlugin for Xcode.

In Xcode, whenever I make a newline, it preserves the indentation spaces. (Spaces shown as •) Like so:

if(YES) { 
••••NSInteger myNum = 2;
••••
••••myNum = 4;
}

When I run my _clang-format file it removes the spaces from my code so now it looks like this:

if(YES) { 
••••NSInteger myNum = 2;

••••myNum = 4;
}

Not a huge deal, but it does make for annoying commit changes where every newline removes spaces. Not to mention if I go back to edit the file, I would prefer those spaces to already be there.

I can't seem to find a _clang-format key that can help me fix this. Any help?

Here's my current _clang-format file

BasedOnStyle: Chromium,
AlignTrailingComments: true,
BreakBeforeBraces: Linux,
ColumnLimit: 140,
IndentWidth: 4,
KeepEmptyLinesAtTheStartOfBlocks: false,
ObjCBlockIndentWidth: 4,
ObjCSpaceAfterProperty: true,
ObjCSpaceBeforeProtocolList: true,
PointerBindsToType: false,
SpacesBeforeTrailingComments: 1,
TabWidth: 8,
MaxEmptyLinesToKeep: 2,
UseTab: Never,

Thanks.

like image 438
teradyl Avatar asked Sep 16 '15 22:09

teradyl


1 Answers

What you're looking for is an option to disable the removal of trailing spaces. However, clang-format does not appear to have that option. You can, however, set an option in Xcode to automatically remove trailing whitespace. (It's in the Xcode preferences; unfortunately, I'm not on a Mac right now, so I can't get a screenshot for you.)

like image 99
mipadi Avatar answered Oct 06 '22 21:10

mipadi