From c94fe6fcee39ff862e64961dc0598ac209303c47 Mon Sep 17 00:00:00 2001 From: Jacob Niehus Date: Sat, 22 Aug 2015 15:50:37 -0700 Subject: [PATCH] Check if buffer can be hidden before tjump --- jedi_vim.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/jedi_vim.py b/jedi_vim.py index 6dfd93f..eb2d7d6 100644 --- a/jedi_vim.py +++ b/jedi_vim.py @@ -246,6 +246,8 @@ def goto(mode="goto", no_output=False): % d.desc_with_module) else: if vim_eval('g:jedi#use_tag_stack') == '1': + if not can_switch_buffers(): + return [] with open(vim_eval('tempname()'), 'w') as f: tagname = d.name while vim_eval('taglist("^%s$")' % tagname) != []: @@ -603,12 +605,8 @@ 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') + if not can_switch_buffers(): + return False 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': @@ -618,6 +616,17 @@ def new_buffer(path, options=''): return True +@catch_and_print_exceptions +def can_switch_buffers(): + 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') + return True + + @catch_and_print_exceptions def _tabnew(path, options=''): """