[clang-format] Another attempt at python 3 compatibility
The entries in vim.current.buffer appear to be decoded strings, which
means that python3 won't allow invoking 'decode' on them. Keep the old
behavior when running under python2, but skip the error-inducing decode
step with python3..
git-svn-id: svn://svn.chromium.org/llvm-project/cfe/trunk/tools/clang-format@289308 0b72dbe1-c17f-4bc7-b9db-2b4152be0356
diff --git a/clang-format.py b/clang-format.py
index aded301..ae8a6eb 100644
--- a/clang-format.py
+++ b/clang-format.py
@@ -29,6 +29,7 @@
import difflib
import json
+import platform
import subprocess
import sys
import vim
@@ -48,10 +49,15 @@
if vim.eval('exists("g:clang_format_fallback_style")') == "1":
fallback_style = vim.eval('g:clang_format_fallback_style')
+def get_buffer(encoding):
+ if platform.python_version_tuple()[0] == '3':
+ return vim.current.buffer
+ return [ line.decode(encoding) for line in vim.current.buffer ]
+
def main():
# Get the current text.
encoding = vim.eval("&encoding")
- buf = [ line.decode(encoding) for line in vim.current.buffer ]
+ buf = get_buffer(encoding)
text = '\n'.join(buf)
# Determine range to format.