diff --git a/autoload/jedi.vim b/autoload/jedi.vim index c545886..9243418 100644 --- a/autoload/jedi.vim +++ b/autoload/jedi.vim @@ -34,7 +34,8 @@ let s:default_settings = { \ 'quickfix_window_height': 10, \ 'completions_enabled': 1, \ 'force_py_version': "'auto'", - \ 'smart_auto_mappings': 1 + \ 'smart_auto_mappings': 1, + \ 'use_tag_stack': 1 \ } for [s:key, s:val] in items(s:deprecations) diff --git a/doc/jedi-vim.txt b/doc/jedi-vim.txt index 998e929..1b72607 100644 --- a/doc/jedi-vim.txt +++ b/doc/jedi-vim.txt @@ -43,6 +43,7 @@ Contents *jedi-vim-contents* 6.11. use_splits_not_buffers |g:jedi#use_splits_not_buffers| 6.12. force_py_version |g:jedi#force_py_version| 6.13. smart_auto_mappings |g:jedi#smart_auto_mappings| + 6.14. use_tag_stack |g:jedi#use_tag_stack| 7. Testing |jedi-vim-testing| 8. Contributing |jedi-vim-contributing| 9. License |jedi-vim-license| @@ -506,6 +507,17 @@ This option can be disabled in the .vimrc: Options: 0 or 1 Default: 1 (enabled by default) +------------------------------------------------------------------------------ +6.14. `g:jedi#use_tag_stack` *g:jedi#use_tag_stack* + +Write results of |jedi#goto| to a temporary file and use the *:tjump* command +to enable full |tagstack| functionality. Use of the tag stack allows +returning to the usage of a function with CTRL-T after exploring the +definition with arbitrary changes to the |jumplist|. + +Options: 0 or 1 +Default: 1 (enabled by default) + ============================================================================== 7. Testing *jedi-vim-testing* diff --git a/jedi_vim.py b/jedi_vim.py index 7f24b9e..c92b7f1 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -7,6 +7,8 @@ import traceback # for exception output import re import os import sys +import string +import random from shlex import split as shsplit try: from itertools import zip_longest @@ -244,9 +246,22 @@ def goto(mode="goto", no_output=False): % d.desc_with_module) else: if d.module_path != vim.current.buffer.name: - result = new_buffer(d.module_path) + result = new_buffer(d.module_path, using_tagstack=True) 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: + tagname = d.name + while vim_eval('taglist("^%s$")' % tagname) != []: + tagname = d.name + ' ' + ''.join( + [random.choice(string.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) vim.current.window.cursor = d.line, d.column else: # multiple solutions @@ -567,7 +582,7 @@ def py_import_completions(): @catch_and_print_exceptions -def new_buffer(path, options=''): +def new_buffer(path, options='', using_tagstack=False): # options are what you can to edit the edit options if vim_eval('g:jedi#use_tabs_not_buffers') == '1': _tabnew(path, options) @@ -593,6 +608,8 @@ def new_buffer(path, options=''): return False else: vim_command('w') + if using_tagstack: + return True vim_command('edit %s %s' % (options, escape_file_path(path))) # sometimes syntax is being disabled and the filetype not set. if vim_eval('!exists("g:syntax_on")') == '1':