From e33e5ffb2f5eba3679cc50fec54203b7732f7aef Mon Sep 17 00:00:00 2001 From: Yggdroot Date: Sun, 13 May 2018 11:02:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=20issue=20#156=20tempfile.NamedTemporaryFil?= =?UTF-8?q?e=20=E7=BC=BA=E5=B0=91=20encoding=20=E6=97=B6=20=E5=87=BA?= =?UTF-8?q?=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- autoload/leaderf/python/leaderf/bufTagExpl.py | 22 ++++++++++++++----- .../leaderf/python/leaderf/functionExpl.py | 22 ++++++++++++++----- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/autoload/leaderf/python/leaderf/bufTagExpl.py b/autoload/leaderf/python/leaderf/bufTagExpl.py index 3f77d7dc..72751f0a 100644 --- a/autoload/leaderf/python/leaderf/bufTagExpl.py +++ b/autoload/leaderf/python/leaderf/bufTagExpl.py @@ -4,6 +4,7 @@ import vim import re import os +import sys import os.path import subprocess import tempfile @@ -103,12 +104,21 @@ def _getTagResult(self, buffer): executor = AsyncExecutor() self._executor.append(executor) if buffer.options["modified"] == True: - with tempfile.NamedTemporaryFile(mode='w+', - suffix='_'+os.path.basename(buffer.name), - delete=False) as f: - for line in buffer[:]: - f.write(line + '\n') - file_name = f.name + if sys.version_info >= (3, 0): + with tempfile.NamedTemporaryFile(mode='w+', + encoding=lfEval("&encoding"), + suffix='_'+os.path.basename(buffer.name), + delete=False) as f: + for line in buffer[:]: + f.write(line + '\n') + file_name = f.name + else: + with tempfile.NamedTemporaryFile(mode='w+', + suffix='_'+os.path.basename(buffer.name), + delete=False) as f: + for line in buffer[:]: + f.write(line + '\n') + file_name = f.name # {tagname}{tagfile}{tagaddress}[;"{tagfield}..] # {tagname}{tagfile}{tagaddress};"{kind}{scope} cmd = '{} -n -u --fields=Ks {} -f- "{}"'.format(self._ctags, extra_options, lfDecode(file_name)) diff --git a/autoload/leaderf/python/leaderf/functionExpl.py b/autoload/leaderf/python/leaderf/functionExpl.py index f35ed31f..561ea5ad 100644 --- a/autoload/leaderf/python/leaderf/functionExpl.py +++ b/autoload/leaderf/python/leaderf/functionExpl.py @@ -4,6 +4,7 @@ import vim import re import os +import sys import os.path import subprocess import tempfile @@ -119,12 +120,21 @@ def _getFunctionResult(self, buffer): executor = AsyncExecutor() self._executor.append(executor) if buffer.options["modified"] == True: - with tempfile.NamedTemporaryFile(mode='w+', - suffix='_'+os.path.basename(buffer.name), - delete=False) as f: - for line in buffer[:]: - f.write(line + '\n') - file_name = f.name + if sys.version_info >= (3, 0): + with tempfile.NamedTemporaryFile(mode='w+', + encoding=lfEval("&encoding"), + suffix='_'+os.path.basename(buffer.name), + delete=False) as f: + for line in buffer[:]: + f.write(line + '\n') + file_name = f.name + else: + with tempfile.NamedTemporaryFile(mode='w+', + suffix='_'+os.path.basename(buffer.name), + delete=False) as f: + for line in buffer[:]: + f.write(line + '\n') + file_name = f.name # {tagname}{tagfile}{tagaddress};"{kind} cmd = '{} -n -u --fields=k {} -f- "{}"'.format(self._ctags, extra_options, lfDecode(file_name)) result = executor.execute(cmd, cleanup=partial(os.remove, file_name))