[cfe-dev] clang-format leading whitespace
Manuel Klimek via cfe-dev
cfe-dev at lists.llvm.org
Fri Jan 26 03:21:33 PST 2018
On Fri, Jan 26, 2018 at 10:06 AM Samuel Williams via cfe-dev <
cfe-dev at lists.llvm.org> wrote:
> ## Some objective problems:
>>>
>>> - Existing code which is indented this way would require a lot of
>>> changes.
>>>
>>
>> That's true for any project starting to use clang-format. That's why we'd
>> suggest to use editor and version control system integrations and only
>> format the lines that are touched.
>>
>
> I'm not really sure the workflow you describe really makes sense.
>
> I'd prefer to apply it to the whole project in one shot and then keep it
> formatted that way using pre-commit hooks or something like that.
>
>
>>
>>
>>> - Markdown (which is useful in comments) is sensitive to trailing
>>> whitespace.
>>>
>>
>> I haven't seen a project using markdown in comments and relying on the
>> trailing whitespace. However, even if some do, I think it'd be better for
>> clang-format to recognize this and not remove spaces for those comments
>> specifically.
>>
>
> clang-format simply can't know that the comments contain markdown or not,
> so what you propose is impossible. One option would be to not reformat
> comments.
>
>
>>
>> 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.
>>>
>>
>> How often do you even start editing in a currently empty line? Don't you
>> normally start with some existing code and have to insert a line break?
>> clang-format wouldn't help there..
>>
>
> I start editing on empty lines all the time.
>
>
>>
>> (It's also a really easy habit to loose once you have gotten yourself to
>> rely on clang-format working in your editor).
>>
>>
>>> - When moving cursor up and down it's my preference that it doesn't jump
>>> back and forward when crossing blank lines.
>>>
>>
>> But the proposal wouldn't really change much here, unless you happen to
>> have the cursor right at the start of the line and it would all be indented
>> the exact same level. Isn't that a really rare case?
>>
>
> It's not a rare case at all if you have lots of empty 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
>>> cfe-dev at lists.llvm.org
>>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>>
>>>
>>
> I still think this is a good idea. and the fact that many top projects
> prefer this style is a good indication that it would be a useful addition,
> IMHO.
>
Do you have links to example projects? Do those projects have public style
guides?
>
> Kind regards,
> Samuel
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180126/f1b6a75b/attachment.html>
More information about the cfe-dev
mailing list