forked from VimPlug/jedi-vim
Fix rename behaviour with empty cword; honor b:changedtick
Ref: https://github.com/davidhalter/jedi-vim/issues/416
This commit is contained in:
39
jedi_vim.py
39
jedi_vim.py
@@ -197,7 +197,7 @@ def completions():
|
|||||||
|
|
||||||
@_check_jedi_availability(show_error=True)
|
@_check_jedi_availability(show_error=True)
|
||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def goto(mode = "goto", no_output=False):
|
def goto(mode="goto", no_output=False):
|
||||||
"""
|
"""
|
||||||
:param str mode: "related_name", "definition", "assignment", "auto"
|
:param str mode: "related_name", "definition", "assignment", "auto"
|
||||||
:return: list of definitions/assignments
|
:return: list of definitions/assignments
|
||||||
@@ -433,30 +433,39 @@ def cmdline_call_signatures(signatures):
|
|||||||
@catch_and_print_exceptions
|
@catch_and_print_exceptions
|
||||||
def rename():
|
def rename():
|
||||||
if not int(vim.eval('a:0')):
|
if not int(vim.eval('a:0')):
|
||||||
_rename_cursor = vim.current.window.cursor
|
|
||||||
|
|
||||||
vim_command('normal A ') # otherwise startinsert doesn't work well
|
|
||||||
vim.current.window.cursor = _rename_cursor
|
|
||||||
|
|
||||||
vim_command('augroup jedi_rename')
|
vim_command('augroup jedi_rename')
|
||||||
vim_command('autocmd InsertLeave <buffer> call jedi#rename(1)')
|
vim_command('autocmd InsertLeave <buffer> call jedi#rename(1)')
|
||||||
vim_command('augroup END')
|
vim_command('augroup END')
|
||||||
|
|
||||||
vim_command("let s:jedi_replace_orig = expand('<cword>')")
|
vim_command("let s:jedi_replace_orig = expand('<cword>')")
|
||||||
vim_command('normal! diw')
|
vim_command('normal! diw')
|
||||||
vim_command(':startinsert')
|
vim_command("let s:jedi_changedtick = b:changedtick")
|
||||||
|
vim_command('startinsert')
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# reset autocommand
|
# Remove autocommand.
|
||||||
vim_command('autocmd! jedi_rename InsertLeave')
|
vim_command('autocmd! jedi_rename InsertLeave')
|
||||||
|
|
||||||
replace = vim_eval("expand('<cword>')")
|
# Get replacement, if there is something on the cursor.
|
||||||
vim_command('normal! u') # undo new word
|
# This won't be the case when the user ends insert mode right away,
|
||||||
|
# and `<cword>` would pick up the nearest word instead.
|
||||||
|
if vim_eval('getline(".")[getpos(".")[2]-1]') != ' ':
|
||||||
|
replace = vim_eval("expand('<cword>')")
|
||||||
|
else:
|
||||||
|
replace = None
|
||||||
|
|
||||||
cursor = vim.current.window.cursor
|
cursor = vim.current.window.cursor
|
||||||
vim_command('normal! u') # undo the space at the end
|
|
||||||
|
# Undo new word, but only if something was changed, which is not the
|
||||||
|
# case when ending insert mode right away.
|
||||||
|
if vim_eval('b:changedtick != s:jedi_changedtick') == '1':
|
||||||
|
vim_command('normal! u') # Undo new word.
|
||||||
|
vim_command('normal! u') # Undo diw.
|
||||||
|
|
||||||
vim.current.window.cursor = cursor
|
vim.current.window.cursor = cursor
|
||||||
|
|
||||||
return do_rename(replace)
|
if replace:
|
||||||
|
return do_rename(replace)
|
||||||
|
|
||||||
def rename_visual():
|
def rename_visual():
|
||||||
replace = vim.eval('input("Rename to: ")')
|
replace = vim.eval('input("Rename to: ")')
|
||||||
@@ -465,8 +474,8 @@ def rename_visual():
|
|||||||
|
|
||||||
|
|
||||||
def do_rename(replace, orig = None):
|
def do_rename(replace, orig = None):
|
||||||
if replace is None:
|
if not len(replace):
|
||||||
echo_highlight('No rename possible, if no name is given.')
|
echo_highlight('No rename possible without name.')
|
||||||
return
|
return
|
||||||
|
|
||||||
if orig is None:
|
if orig is None:
|
||||||
|
|||||||
Reference in New Issue
Block a user