Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vim adds extra newlines when option 'InsertNewlineAtEOF' is set in clang-format #127

Open
loebl opened this issue Nov 29, 2024 · 1 comment

Comments

@loebl
Copy link

loebl commented Nov 29, 2024

  • OS: Ubuntu 22.04
  • vim version: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Sep 25 2024 05:30:01) (package vim-gtk3, version: 2:8.2.3995-1ubuntu2.21)
  • Included patches: 1-16, 647, 17-579, 1969, 580-647, 678, 648-1848, 4975, 5016, 5023, 5072, 2068, 1849-1854, 1857, 1855-1857, 1331, 1858, 1858-1859, 1873, 1860-1969, 1992, 1970-1992, 2010, 1993-2068, 2106, 2069-2106, 2108, 2107-2109, 2109
    -3995, 4563, 4646, 4774, 4895, 4899, 4901, 4919, 213, 1840, 1846-1847, 2110-2112, 2121
  • clang-format: v16.0.6

Observation

When using the the option 'InsertNewlineAtEOF: true' clang-format returns a string that will have a newline followed by a space, compared to no newline at then end when it is switched off. This newline will cause an empty line at the end of the file, which is unwanted.

Proposed fix

I am not well versed in Vimscript, so my current approach is to trim all outputs returned in the system function:

@@ -39,6 +39,9 @@ function! s:system(str, ...) abort
                     \ vimproc#system(command, input, a:2) : system(command, input)
     endif
 
+    " if clang-format option InsertNewlineAtEOF is set, there is a newline + space at the end
+    " of the output, which we don't want as this leads to additional newlines in vim
+    let output = trim(output, " \n", 2)
     return output
 endfunction

An alternative would be to only trim the output in the format_ranges function, as system is used in other places as well.

@loebl
Copy link
Author

loebl commented Nov 29, 2024

argh, just saw that this is the same issue that #120 tries to address. Though my proposed patch tries to solve it at a different position in the plugin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant