diff options
author | Daniel Jasper <djasper@google.com> | 2014-05-22 11:37:05 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-05-22 11:37:05 +0000 |
commit | fc95a27fee8883d9dd403fdb46524fb95fb31f58 (patch) | |
tree | dbefa0836303d218a3cfc2853dc0bfe8fc03e6b4 /tools | |
parent | 25c29908626548cee8a40bd153bde2b4f98490d3 (diff) | |
download | clang-fc95a27fee8883d9dd403fdb46524fb95fb31f58.tar.gz clang-fc95a27fee8883d9dd403fdb46524fb95fb31f58.tar.bz2 clang-fc95a27fee8883d9dd403fdb46524fb95fb31f58.tar.xz |
clang-format: Fix vim-integration for empty files.
Discovered by Ahmed Charles in http://reviews.llvm.org/D3018.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209417 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/clang-format/clang-format.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py index 46af0682aa..16a1879108 100644 --- a/tools/clang-format/clang-format.py +++ b/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'): |