summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/tools/clang-format/clang-format.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py
index 976c222df05..596270cb55d 100644
--- a/clang/tools/clang-format/clang-format.py
+++ b/clang/tools/clang-format/clang-format.py
@@ -70,7 +70,8 @@ def main():
# Get the current text.
encoding = vim.eval("&encoding")
buf = get_buffer(encoding)
- text = '\n'.join(buf)
+ # Join the buffer into a single string with a terminating newline
+ text = '\n'.join(buf) + '\n'
# Determine range to format.
if vim.eval('exists("l:lines")') == '1':
@@ -129,7 +130,10 @@ def main():
else:
lines = stdout.decode(encoding).split('\n')
output = json.loads(lines[0])
- lines = lines[1:]
+ # Strip off the trailing newline (added above).
+ # This maintains trailing empty lines present in the buffer if
+ # the -lines specification requests them to remain unchanged.
+ lines = lines[1:-1]
sequence = difflib.SequenceMatcher(None, buf, lines)
for op in reversed(sequence.get_opcodes()):
if op[0] is not 'equal':
OpenPOWER on IntegriCloud