Skip to content

Conversation

@jreybert
Copy link
Contributor

This new feature fixes a behavior difference between vim-clang-format
and clang-format.

If the 'to be formatted' buffer ends with one or several empty lines,
vim-clang-format keeps one final empty line. clang-format does not let
any empty line.

If the 'to be formatted' buffer ends with a non empty line, both
vim-clang-format and clang-format produce the same result, a code
finishing with the non empty line.

This problem seems to have been a problem for other clang plugin, in
other editors, eg in VisualCode:
https://stackoverflow.com/questions/55374304/add-a-single-empty-line-as-the-last-line-in-the-code-clang-format

The culprit in vim-clang-format is the split() function: as the
formatted string ends with a newline, it generates a List with a last
empty item.

This new feature fixes a behavior difference between vim-clang-format and clang-format. If the 'to be formatted' buffer ends with one or several empty lines, vim-clang-format keeps one final empty line. clang-format does not let any empty line. If the 'to be formatted' buffer ends with a non empty line, both vim-clang-format and clang-format produce the same result, a code finishing with the non empty line. This problem seems to have been a problem for other clang plugin, in other editors, eg in VisualCode: https://stackoverflow.com/questions/55374304/add-a-single-empty-line-as-the-last-line-in-the-code-clang-format The culprit in vim-clang-format is the `split()` function: as the `formatted` string ends with a newline, it generates a List with a last empty item.
@rhysd
Copy link
Owner

rhysd commented Feb 3, 2022

Thank you for making this patch.

If the 'to be formatted' buffer ends with one or several empty lines,
vim-clang-format keeps one final empty line. clang-format does not let
any empty line.

It means, output of clang-format does not contain extra empty line at the end but vim-clang-format adds it, am I correct? It would be a bug of vim-clang-format. So fixing it rather than adding a new option would be better.

@jreybert
Copy link
Contributor Author

jreybert commented Feb 3, 2022

It means, output of clang-format does not contain extra empty line at the end but vim-clang-format adds it, am I correct? It would be a bug of vim-clang-format. So fixing it rather than adding a new option would be better.

You are correct. I made an option to not break existing behavior. But if you want to merge this fix without option, I totally agree too. Tell me what you prefer.

Anyway, if you're OK with this fix, I will take time to add one or few tests about empty lines.

@jreybert
Copy link
Contributor Author

jreybert commented Apr 4, 2022

Hi @rhysd , let me know what you want to do with this patch.

@jreybert
Copy link
Contributor Author

ping, any news?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants