r186789 - clang-format: Smarter replacement in the vim integration.
Daniel Jasper
djasper at google.com
Sun Jul 21 03:45:33 PDT 2013
Author: djasper
Date: Sun Jul 21 05:45:33 2013
New Revision: 186789
URL: http://llvm.org/viewvc/llvm-project?rev=186789&view=rev
Log:
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).
Modified:
cfe/trunk/tools/clang-format/clang-format.py
Modified: cfe/trunk/tools/clang-format/clang-format.py
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-format/clang-format.py?rev=186789&r1=186788&r2=186789&view=diff
==============================================================================
--- cfe/trunk/tools/clang-format/clang-format.py (original)
+++ cfe/trunk/tools/clang-format/clang-format.py Sun Jul 21 05:45:33 2013
@@ -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))
More information about the cfe-commits
mailing list