-
Notifications
You must be signed in to change notification settings - Fork 123
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
Error when formatting empty file #58
Comments
This is the cause of the error. If I change it to this I fix the case for 2 blank lines, but 1 blank line still causes an error. \ && a:result !~# '^$' Elsewhere, if I add a trailing newline to the text on its way to the clang-format system call, I fix the case for 1 blank line (and fix the problem where blank lines were being erroneously deleted). Old: return s:system(clang_format, join(getline(1, '$'), "\n")) New: return s:system(clang_format, join(getline(1, '$'), "\n") . "\n") Everything seems to be working fine for me with these changes in place. |
I could reproduce and addressed this issue. Could you confirm the latest? |
Your changes fix the case for 2 or more empty lines, but do not fix the case for 1 empty line. For that case I get an error here. Also, with 2 or more empty lines the script is still incorrectly removing one EOL each time the script is run. You should add this change: Old: return s:system(clang_format, join(getline(1, '$'), "\n")) New: return s:system(clang_format, join(getline(1, '$'), "\n") . "\n") The |
I also recommend adding this test case. I think it will fail with your current code: it 'can format a buffer containing a single empty line'
call setline('.', [''])
ClangFormat
end |
I couldn't reproduce the issue. It works with a buffer containing two newlines only. What version clang-format are you using? My clang-format is 4.0.0. |
The issue is with a buffer containing exactly 1 newline. I agree it works now for a buffer with 2 newlines. For example, try opening a new file and immediately running ClangFormat. It will fail with an error. This is especially an issue when using ClangFormatAutoEnable since I cannot write an empty file to disk due to the error. |
I am getting an error when executing ClangFormat in Vim on an empty file.
I get this error when the target buffer has exactly one empty line, and when the buffer has exactly two empty lines. I do not get the error when the buffer has three or more empty lines, nor when the buffer has at least one non-empty line.
Here's an example file that causes the error:
foo.hpp
This file does not cause the error:
bar.hpp
Also, when I run ClangFormat on a file with multiple blank lines, each format will remove one of those lines. So 4 blank lines goes to 3 blank lines, 3 blank lines goes to 2 blank lines, 2 blank lines results in an error.
clang-format
on the target file from the shell works correctly, and preserves the correct number of blank lines.The text was updated successfully, but these errors were encountered: