Refactoring
This commit is contained in:
parent
a0495a994e
commit
cb3325970e
@ -326,10 +326,17 @@ def TryJumpLocationInOpenedTab( filename, line, column ):
|
|||||||
|
|
||||||
# Center the screen on the jumped-to location
|
# Center the screen on the jumped-to location
|
||||||
vim.command( 'normal! zz' )
|
vim.command( 'normal! zz' )
|
||||||
return
|
return True
|
||||||
else:
|
# 'filename' is not opened in any tab pages
|
||||||
# 'filename' is not opened in any tab pages
|
return False
|
||||||
raise ValueError
|
|
||||||
|
|
||||||
|
# Maps User jump command to vim jump command
|
||||||
|
def GetVimJumpCommand( user_command ):
|
||||||
|
vim_command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
|
||||||
|
if vim_command == 'edit' and not BufferIsUsable( vim.current.buffer ):
|
||||||
|
vim_command = 'split'
|
||||||
|
return vim_command
|
||||||
|
|
||||||
|
|
||||||
# Both |line| and |column| need to be 1-based
|
# Both |line| and |column| need to be 1-based
|
||||||
@ -347,28 +354,23 @@ def JumpToLocation( filename, line, column ):
|
|||||||
user_command = user_options_store.Value( 'goto_buffer_command' )
|
user_command = user_options_store.Value( 'goto_buffer_command' )
|
||||||
|
|
||||||
if user_command == 'new-or-existing-tab':
|
if user_command == 'new-or-existing-tab':
|
||||||
try:
|
if TryJumpLocationInOpenedTab( filename, line, column ):
|
||||||
TryJumpLocationInOpenedTab( filename, line, column )
|
|
||||||
return
|
return
|
||||||
except ValueError:
|
user_command = 'new-tab'
|
||||||
user_command = 'new-tab'
|
|
||||||
|
|
||||||
command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
|
vim_command = GetVimJumpCommand( user_command )
|
||||||
if command == 'edit' and not BufferIsUsable( vim.current.buffer ):
|
|
||||||
command = 'split'
|
|
||||||
try:
|
try:
|
||||||
vim.command( 'keepjumps {0} {1}'.format( command,
|
vim.command( 'keepjumps {0} {1}'.format( vim_command,
|
||||||
EscapedFilepath( filename ) ) )
|
EscapedFilepath( filename ) ) )
|
||||||
# When the file we are trying to jump to has a swap file
|
# When the file we are trying to jump to has a swap file
|
||||||
# Vim opens swap-exists-choices dialog and throws vim.error with E325 error,
|
# Vim opens swap-exists-choices dialog and throws vim.error with E325 error,
|
||||||
# or KeyboardInterrupt after user selects one of the options.
|
# or KeyboardInterrupt after user selects one of the options.
|
||||||
except vim.error as e:
|
except vim.error as e:
|
||||||
if 'E325' in str(e):
|
if 'E325' not in str( e ):
|
||||||
# Do nothing if the target file is still not opened (user chose (Q)uit)
|
|
||||||
if filename != GetCurrentBufferFilepath():
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
raise
|
raise
|
||||||
|
# Do nothing if the target file is still not opened (user chose (Q)uit)
|
||||||
|
if filename != GetCurrentBufferFilepath():
|
||||||
|
return
|
||||||
# Thrown when user chooses (A)bort in .swp message box
|
# Thrown when user chooses (A)bort in .swp message box
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user