summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-05-22 11:37:05 +0000
committerDaniel Jasper <djasper@google.com>2014-05-22 11:37:05 +0000
commit62f73ec1ef6d23baa36a08b86f19ffade56216b7 (patch)
tree3568be72c924e260b812f7a95ff5caa4cd88bf94
parent94ffc5bc124971af964b4a7523a0d95ba4abede7 (diff)
downloadbcm5719-llvm-62f73ec1ef6d23baa36a08b86f19ffade56216b7.tar.gz
bcm5719-llvm-62f73ec1ef6d23baa36a08b86f19ffade56216b7.zip
clang-format: Fix vim-integration for empty files.
Discovered by Ahmed Charles in http://reviews.llvm.org/D3018. llvm-svn: 209417
-rw-r--r--clang/tools/clang-format/clang-format.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py
index 46af0682aa7..16a18791083 100644
--- a/clang/tools/clang-format/clang-format.py
+++ b/clang/tools/clang-format/clang-format.py
@@ -38,9 +38,14 @@ def main():
text = '\n'.join(buf)
# Determine range to format.
- cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
lines = '%s:%s' % (vim.current.range.start + 1, vim.current.range.end + 1)
+ # Determine the cursor position.
+ cursor = int(vim.eval('line2byte(line("."))+col(".")')) - 2
+ if cursor < 0:
+ print 'Couldn\'t determine cursor position. Is your file empty?'
+ return
+
# Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format.
startupinfo = None
if sys.platform.startswith('win32'):
OpenPOWER on IntegriCloud