[PATCH] D70864: update trailing newline treatment in clang-format.py

Paul Seyfert via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 29 10:59:20 PST 2019


pseyfert updated this revision to Diff 231568.
pseyfert added a comment.

added comments


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D70864/new/

https://reviews.llvm.org/D70864

Files:
  clang/tools/clang-format/clang-format.py


Index: clang/tools/clang-format/clang-format.py
===================================================================
--- clang/tools/clang-format/clang-format.py
+++ clang/tools/clang-format/clang-format.py
@@ -70,7 +70,8 @@
   # 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 @@
   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':


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70864.231568.patch
Type: text/x-patch
Size: 1010 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191129/0d266999/attachment.bin>


More information about the llvm-commits mailing list