mirror of
https://github.com/davidhalter/jedi-vim.git
synced 2025-12-06 10:54:22 +08:00
Merge pull request #481 from blueyed/improve-taglist-hack
Improve use_tag_stack-hack: use context managers, short 'tags'
This commit is contained in:
20
jedi_vim.py
20
jedi_vim.py
@@ -8,9 +8,8 @@ import traceback # for exception output
|
||||
import re
|
||||
import os
|
||||
import sys
|
||||
import string
|
||||
import random
|
||||
from shlex import split as shsplit
|
||||
from tempfile import NamedTemporaryFile
|
||||
try:
|
||||
from itertools import zip_longest
|
||||
except ImportError:
|
||||
@@ -254,18 +253,17 @@ def goto(mode="goto", no_output=False):
|
||||
if not result:
|
||||
return []
|
||||
if d.module_path and vim_eval('g:jedi#use_tag_stack') == '1':
|
||||
with open(vim_eval('tempname()'), 'w') as f:
|
||||
with NamedTemporaryFile('w', prefix=vim_eval('tempname()')) as f:
|
||||
tagname = d.name
|
||||
while vim_eval('taglist("^%s$")' % tagname) != []:
|
||||
tagname = d.name + ' ' + ''.join(
|
||||
[random.choice(string.ascii_lowercase)
|
||||
for _ in range(4)])
|
||||
f.write('{0}\t{1}\t{2}'.format(tagname, d.module_path,
|
||||
'call cursor({0}, {1})'.format(d.line, d.column + 1)))
|
||||
f.seek(0)
|
||||
vim.command('set tags+=%s' % f.name)
|
||||
vim.command('tjump %s' % tagname)
|
||||
vim.command('set tags-=%s' % f.name)
|
||||
f.flush()
|
||||
old_tags = vim.eval('&tags')
|
||||
try:
|
||||
vim.command('set tags=%s' % f.name)
|
||||
vim.command('tjump %s' % tagname)
|
||||
finally:
|
||||
vim.command('set tags=%s' % old_tags)
|
||||
vim.current.window.cursor = d.line, d.column
|
||||
else:
|
||||
# multiple solutions
|
||||
|
||||
Reference in New Issue
Block a user