Skip to content

Commit

Permalink
goto: use existing window
Browse files Browse the repository at this point in the history
This add `jedi_vim.edit_buffer`, factored out of `new_buffer`, and
`goto` uses it.

Ref: davidhalter#408
  • Loading branch information
blueyed committed May 4, 2015
1 parent 991eabb commit 3d1f4cb
Showing 1 changed file with 23 additions and 10 deletions.
33 changes: 23 additions & 10 deletions jedi_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 3d1f4cb

Please sign in to comment.