Author: djasper Date: Thu May 22 06:37:05 2014 New Revision: 209417 URL: http://llvm.org/viewvc/llvm-project?rev=209417&view=rev Log: clang-format: Fix vim-integration for empty files.
Discovered by Ahmed Charles in http://reviews.llvm.org/D3018. 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=209417&r1=209416&r2=209417&view=diff ============================================================================== --- cfe/trunk/tools/clang-format/clang-format.py (original) +++ cfe/trunk/tools/clang-format/clang-format.py Thu May 22 06:37:05 2014 @@ -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'): _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
