clang-format leading whitespace

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

clang-format leading whitespace

Alex Denisov via cfe-dev
I am interested in contributing to clang-format, to add an option to preserve and correct leading indentation.

Right now if you write code such as:

{
....int x = 10;
....
....return x;
}

The line in the middle will be truncated and there is no option to control it.

Some code prefers to have indented leading whitespace, indented to the same level as the previous line.

Would such a contribution be accepted and is anyone willing to help me through the process where necessary?

Thanks
Samuel

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang-format leading whitespace

Alex Denisov via cfe-dev
On Sat, Nov 11, 2017 at 7:20 AM Samuel Williams via cfe-dev <[hidden email]> wrote:
I am interested in contributing to clang-format, to add an option to preserve and correct leading indentation.

Right now if you write code such as:

{
....int x = 10;
....
....return x;
}

The line in the middle will be truncated and there is no option to control it.

Some code prefers to have indented leading whitespace, indented to the same level as the previous line.

Would such a contribution be accepted and is anyone willing to help me through the process where necessary?

The current reasoning is that with an automated formatter the indented leading whitespace doesn't help any more.
 

Thanks
Samuel
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang-format leading whitespace

Alex Denisov via cfe-dev
Generally, see here:

I vaguely remember this question being brought up before and I think we decided against it.

On Mon, Nov 13, 2017 at 2:14 PM, Manuel Klimek via cfe-dev <[hidden email]> wrote:
On Sat, Nov 11, 2017 at 7:20 AM Samuel Williams via cfe-dev <[hidden email]> wrote:
I am interested in contributing to clang-format, to add an option to preserve and correct leading indentation.

Right now if you write code such as:

{
....int x = 10;
....
....return x;
}

The line in the middle will be truncated and there is no option to control it.

Some code prefers to have indented leading whitespace, indented to the same level as the previous line.

Would such a contribution be accepted and is anyone willing to help me through the process where necessary?

The current reasoning is that with an automated formatter the indented leading whitespace doesn't help any more.
 

Thanks
Samuel
_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang-format leading whitespace

Alex Denisov via cfe-dev
In reply to this post by Alex Denisov via cfe-dev
Thanks for your feedback, and I appreciate the link and the logic behind it.

Unfortunately, by stripping all trailing whitespace, clang-format has made a policy decision, but with no way to control it via the configuration. I understand it's not desirable for every option to be configurable, but this is something which significantly affects existing code. I propose that it would be good to have an option "TrailingWhitespace: Truncate|Preserve|Fix". Truncate would be existing behaviour. Preserve would not alter leading whitespace on blank lines or touch trailing whitespace. Fix would fix leading whitespace on blank lines, fix trailing whitespace on code, but avoid making any changes in comments except if it was reflowed. It could be more granular but that's where I'd start.

## Some objective problems:

- Existing code which is indented this way would require a lot of changes.
- Markdown (which is useful in comments) is sensitive to trailing whitespace.

It's possible to add a post process script to normalise leading whitespace but not trailing whitespace (e.g. in the case of markdown).

## Some subjective problems:

- It's my preference when I start editing on a line, the indentation is correct already.
- When moving cursor up and down it's my preference that it doesn't jump back and forward when crossing blank lines.

Some of these issues can be fixed by editor configuration/plugins, but it's still not 100% correct.

Thanks for your time.

Kind regards,
Samuel


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev