Skip to content

Commit

Permalink
fix issue #156
Browse files Browse the repository at this point in the history
tempfile.NamedTemporaryFile 缺少 encoding 时 出错
  • Loading branch information
Yggdroot committed May 13, 2018
1 parent ddfcfe0 commit e33e5ff
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
22 changes: 16 additions & 6 deletions autoload/leaderf/python/leaderf/bufTagExpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import vim
import re
import os
import sys
import os.path
import subprocess
import tempfile
Expand Down Expand Up @@ -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}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..]
# {tagname}<Tab>{tagfile}<Tab>{tagaddress};"<Tab>{kind}<Tab>{scope}
cmd = '{} -n -u --fields=Ks {} -f- "{}"'.format(self._ctags, extra_options, lfDecode(file_name))
Expand Down
22 changes: 16 additions & 6 deletions autoload/leaderf/python/leaderf/functionExpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import vim
import re
import os
import sys
import os.path
import subprocess
import tempfile
Expand Down Expand Up @@ -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}<Tab>{tagfile}<Tab>{tagaddress};"<Tab>{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))
Expand Down

0 comments on commit e33e5ff

Please sign in to comment.