From: Alexander Kornienko Date: Mon, 24 Oct 2016 16:31:26 +0000 (+0000) Subject: Fix clang-format vim integration issue with non-ascii characters X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d818d497fdf2f361d5ea4160061440b6329d6ee4;p=clang Fix clang-format vim integration issue with non-ascii characters clang-format.py currently seems to treat vim.current.buf as ascii-encoded data, which leads to an UnicodeDecodeError when trying to format any text containing non-ascii characters: Traceback (most recent call last): File "", line 1, in File ".../tools/clang/tools/clang-format/clang-format.py", line 110, in main() File ".../tools/clang/tools/clang-format/clang-format.py", line 87, in main stdout, stderr = p.communicate(input=text.encode(encoding)) UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 3996: ordinal not in range(128) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@284988 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/tools/clang-format/clang-format.py b/tools/clang-format/clang-format.py index 37d970b477..6a5740679b 100644 --- a/tools/clang-format/clang-format.py +++ b/tools/clang-format/clang-format.py @@ -52,7 +52,7 @@ def main(): # Get the current text. encoding = vim.eval("&encoding") buf = vim.current.buffer - text = '\n'.join(buf) + text = unicode('\n'.join(buf), encoding) # Determine range to format. if vim.eval('exists("l:lines")') == '1':