[PATCH] Fix error condition in vim integration when cursor is invalid.
Ahmed Charles
acharles at outlook.com
Sat Mar 8 22:00:44 PST 2014
Hi djasper,
This can happen, for example, if the file is empty.
http://llvm-reviews.chandlerc.com/D3018
Files:
tools/clang-format/clang-format.py
Index: tools/clang-format/clang-format.py
===================================================================
--- tools/clang-format/clang-format.py
+++ tools/clang-format/clang-format.py
@@ -38,7 +38,10 @@
text = '\n'.join(buf)
# Determine range to format.
- cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
+ cursor = int(vim.eval('line2byte(line("."))')) # line2byte is 1 based.
+ if cursor == -1: # -1 is an error, e.g. empty file
+ return
+ cursor = (cursor - 1) + vim.current.window.cursor[1] # col is 0 based.
lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
# Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3018.1.patch
Type: text/x-patch
Size: 707 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140308/c36c2b5e/attachment.bin>
More information about the cfe-commits
mailing list