Skip to content

Commit

Permalink
beautify the code as @go2chenhua suggested in issue #156
Browse files Browse the repository at this point in the history
  • Loading branch information
Yggdroot committed May 13, 2018
1 parent e33e5ff commit fb57fd1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 26 deletions.
20 changes: 7 additions & 13 deletions autoload/leaderf/python/leaderf/bufTagExpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,14 @@ def _getTagResult(self, buffer):
self._executor.append(executor)
if buffer.options["modified"] == True:
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
tmp_file = partial(tempfile.NamedTemporaryFile, encoding=lfEval("&encoding"))
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
tmp_file = tempfile.NamedTemporaryFile

with tmp_file(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
20 changes: 7 additions & 13 deletions autoload/leaderf/python/leaderf/functionExpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,14 @@ def _getFunctionResult(self, buffer):
self._executor.append(executor)
if buffer.options["modified"] == True:
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
tmp_file = partial(tempfile.NamedTemporaryFile, encoding=lfEval("&encoding"))
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
tmp_file = tempfile.NamedTemporaryFile

with tmp_file(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 fb57fd1

Please sign in to comment.