summaryrefslogtreecommitdiffstats
path: root/clang/tools
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-07-21 10:45:33 +0000
committerDaniel Jasper <djasper@google.com>2013-07-21 10:45:33 +0000
commit68c03c82dfff45c7c497f43aa758b55e26cc4b64 (patch)
treec189190d902a51ac700cec1480593b7e41e90a1d /clang/tools
parent7aa9ebb5465726ae722e23aa706dda439dfd1882 (diff)
downloadbcm5719-llvm-68c03c82dfff45c7c497f43aa758b55e26cc4b64.tar.gz
bcm5719-llvm-68c03c82dfff45c7c497f43aa758b55e26cc4b64.zip
clang-format: Smarter replacement in the vim integration.
With this fix, only changed regions will be replaced in vim's buffer. Thereby, marks should mostly be left intact. Furthermore, this is a better fix for the performance problem in conjunction with 'foldmethod=syntax' (see r186660). llvm-svn: 186789
Diffstat (limited to 'clang/tools')
-rw-r--r--clang/tools/clang-format/clang-format.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py
index 866baf50f10..bf84ed0f5cf 100644
--- a/clang/tools/clang-format/clang-format.py
+++ b/clang/tools/clang-format/clang-format.py
@@ -17,6 +17,7 @@
# It operates on the current, potentially unsaved buffer and does not create
# or save any files. To revert a formatting, just undo.
+import difflib
import json
import subprocess
import sys
@@ -67,10 +68,8 @@ else:
lines = stdout.split('\n')
output = json.loads(lines[0])
lines = lines[1:]
- if '\n'.join(lines) != text:
- common_length = min(len(buf), len(lines))
- buf[:common_length] = lines[:common_length]
- for line in lines[len(buf):]:
- buf.append(line)
- del buf[len(lines):]
- vim.command('goto %d' % (output['Cursor'] + 1))
+ sequence = difflib.SequenceMatcher(None, vim.current.buffer, lines)
+ for op in sequence.get_opcodes():
+ if op[0] is not 'equal':
+ vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]]
+ vim.command('goto %d' % (output['Cursor'] + 1))
OpenPOWER on IntegriCloud