diff --git a/jedi_vim.py b/jedi_vim.py index 5cb7a956..11c3dc43 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -228,7 +228,7 @@ def goto(is_definition=False, is_related_name=False, no_output=False): % d.desc_with_module) else: if d.module_path != vim.current.buffer.name: - result = new_buffer(d.module_path) + result = edit_buffer(d.module_path) if not result: return vim.current.window.cursor = d.line, d.column @@ -521,7 +521,7 @@ def py_import(): echo_highlight('%s is a builtin module.' % import_path) else: cmd_args = ' '.join([a.replace(' ', '\\ ') for a in args]) - new_buffer(completion.module_path, cmd_args) + edit_buffer(completion.module_path, cmd_args) @catch_and_print_exceptions @@ -539,8 +539,22 @@ def py_import_completions(): vim.command("return '%s'" % '\n'.join(comps)) +@catch_and_print_exceptions +def edit_buffer(path, options=''): + """Edit the given path in the current window.""" + if vim_eval("!&hidden && &modified") == '1': + if vim_eval("bufname('%')") is None: + echo_highlight('Cannot open a new buffer, use `:set hidden` or save your buffer') + return False + else: + vim_command('w') + vim_command('edit %s %s' % (options, escape_file_path(path))) + fix_buffer_options() + + @catch_and_print_exceptions def new_buffer(path, options=''): + """Edit the given path in a new window.""" # options are what you can to edit the edit options if vim_eval('g:jedi#use_tabs_not_buffers') == '1': _tabnew(path, options) @@ -560,19 +574,18 @@ def new_buffer(path, options=''): else: vim_command(split_options[user_split_option] + " %s" % path) else: - if vim_eval("!&hidden && &modified") == '1': - if vim_eval("bufname('%')") is None: - echo_highlight('Cannot open a new buffer, use `:set hidden` or save your buffer') - return False - else: - vim_command('w') - vim_command('edit %s %s' % (options, escape_file_path(path))) + edit_buffer(path, options) + + fix_buffer_options() + return True + + +def fix_buffer_options(): # sometimes syntax is being disabled and the filetype not set. if vim_eval('!exists("g:syntax_on")') == '1': vim_command('syntax enable') if vim_eval("&filetype != 'python'") == '1': vim_command('set filetype=python') - return True @catch_and_print_exceptions