Skip to content

clang-format: add option to preserve indentation-only whitespace lines #126543

Closed as duplicate of#18815
@seanm

Description

@seanm

Unless I'm missing it, clang-format has no option to keep whitespace-only lines that keep indentation level with the code.

The bullets represent spaces. I'm looking for a way to not have the indentation-only line 3 be changed:

if (true) { 
••••int myNum = 2;
••••
••••myNum = 4;
}

Always becomes:

if (true) { 
••••int myNum = 2;

••••myNum = 4;
}

Xcode has an option (default I think) to create/preserve such indentation, in Xcode > Settings > Text Editing > Editing:

While Editing:  ☑ Automatically trim trailing spaces  
                          ☑ Including whitespace-only lines

Xcode's "re-indent" command also adds such indentation, and so all my code has such indentation, hence I'd like clang-format to not touch it.

Having this option would make it easier for Xcode users to adopt clang-format in their workflow.

(I've seen others want the same, ex: https://stackoverflow.com/questions/32619716/clang-format-is-removing-all-the-indent-spaces-on-my-empty-lines)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions