diff --git a/clang/tools/clang-format/clang-format.py b/clang/tools/clang-format/clang-format.py --- a/clang/tools/clang-format/clang-format.py +++ b/clang/tools/clang-format/clang-format.py @@ -45,6 +45,7 @@ import subprocess import sys import vim +import os.path # set g:clang_format_path to the path to clang-format if it is not on the path # Change this to the full path if clang-format is not on the path. @@ -76,7 +77,7 @@ # Determine range to format. if vim.eval('exists("l:lines")') == '1': lines = ['-lines', vim.eval('l:lines')] - elif vim.eval('exists("l:formatdiff")') == '1': + elif vim.eval('exists("l:formatdiff")') == '1' and os.path.exists(vim.current.buffer.name): with open(vim.current.buffer.name, 'r') as f: ondisk = f.read().splitlines(); sequence = difflib.SequenceMatcher(None, ondisk, vim.current.buffer)