Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Improve buffer switching #409

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 26 additions & 17 deletions jedi_vim.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ 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 = edit_buffer(d.module_path)
if not result:
return []
vim.current.window.cursor = d.line, d.column
Expand Down Expand Up @@ -543,8 +543,7 @@ def py_import():
if completion.in_builtin_module():
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)


@catch_and_print_exceptions
Expand All @@ -563,10 +562,24 @@ def py_import_completions():


@catch_and_print_exceptions
def new_buffer(path, options=''):
# options are what you can to edit the edit options
def edit_buffer(path):
"""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('update')
vim_command('edit %s' % escape_file_path(path))
fix_buffer_options()
return True


@catch_and_print_exceptions
def new_buffer(path):
"""Edit the given path in a new window."""
if vim_eval('g:jedi#use_tabs_not_buffers') == '1':
_tabnew(path, options)
_tabnew(path)
elif not vim_eval('g:jedi#use_splits_not_buffers') == '1':
user_split_option = vim_eval('g:jedi#use_splits_not_buffers')
split_options = {
Expand All @@ -583,19 +596,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)

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 All @@ -606,9 +618,6 @@ def _tabnew(path, options=''):
:param options: `:tabnew` options, read vim help.
"""
path = os.path.abspath(path)
if vim_eval('has("gui")') == '1':
vim_command('tab drop %s %s' % (options, escape_file_path(path)))
return

for tab_nr in range(int(vim_eval("tabpagenr('$')"))):
for buf_nr in vim_eval("tabpagebuflist(%i + 1)" % tab_nr):
Expand Down