Index: tools/clang-format/clang-format.py =================================================================== --- tools/clang-format/clang-format.py +++ tools/clang-format/clang-format.py @@ -26,6 +26,7 @@ # It operates on the current, potentially unsaved buffer and does not create # or save any files. To revert a formatting, just undo. +from __future__ import print_function import difflib import json import subprocess @@ -61,7 +62,7 @@ # 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?' + print('Couldn\'t determine cursor position. Is your file empty?') return # Avoid flashing an ugly, ugly cmd prompt on Windows when invoking clang-format. @@ -81,15 +82,15 @@ command.extend(['-assume-filename', vim.current.buffer.name]) p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - stdin=subprocess.PIPE, startupinfo=startupinfo) + stdin=subprocess.PIPE, startupinfo=startupinfo, universal_newlines=True) stdout, stderr = p.communicate(input=text) # If successful, replace buffer contents. if stderr: - print stderr + print(stderr) if not stdout: - print ('No output from clang-format (crashed?).\n' + + print('No output from clang-format (crashed?).\n' + 'Please report to bugs.llvm.org.') else: lines = stdout.split('\n') @@ -100,7 +101,7 @@ if op[0] is not 'equal': vim.current.buffer[op[1]:op[2]] = lines[op[3]:op[4]] if output.get('IncompleteFormat'): - print 'clang-format: incomplete (syntax errors)' + print('clang-format: incomplete (syntax errors)') vim.command('goto %d' % (output['Cursor'] + 1)) main()