Add option to trim last empty line#120
Conversation
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.
|
Thank you for making this patch.
It means, output of |
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. |
|
Hi @rhysd , let me know what you want to do with this patch. |
|
ping, any news? |
|
I just ran into this (ci breaking builds of my submitted code because of an extra empty line after using the plugin). Any chance in upstreaming one of the suggested changes either from here or #127? |
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 theformattedstring ends with a newline, it generates a List with a lastempty item.