Add new-or-existing-tab as ycm_goto_buffer_command method
resolves #1398
This commit is contained in:
parent
a4a4f038d7
commit
3c63d22c59
@ -1579,7 +1579,8 @@ Default: `1`
|
|||||||
|
|
||||||
Defines where `GoTo*` commands result should be opened.
|
Defines where `GoTo*` commands result should be opened.
|
||||||
Can take one of the following values:
|
Can take one of the following values:
|
||||||
`[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab' ]`
|
`[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab',
|
||||||
|
'new-or-existing-tab' ]`
|
||||||
If this option is set to the `'same-buffer'` but current buffer can not
|
If this option is set to the `'same-buffer'` but current buffer can not
|
||||||
be switched (when buffer is modified and `nohidden` option is set),
|
be switched (when buffer is modified and `nohidden` option is set),
|
||||||
then result will be opened in horizontal split.
|
then result will be opened in horizontal split.
|
||||||
|
@ -301,6 +301,25 @@ def EscapedFilepath( filepath ):
|
|||||||
return filepath.replace( ' ' , r'\ ' )
|
return filepath.replace( ' ' , r'\ ' )
|
||||||
|
|
||||||
|
|
||||||
|
# Both |line| and |column| need to be 1-based
|
||||||
|
def TryJumpLocationInOpenedTab( filename, line, column ):
|
||||||
|
filepath = os.path.realpath( filename )
|
||||||
|
|
||||||
|
for tab in vim.tabpages:
|
||||||
|
for win in tab.windows:
|
||||||
|
if win.buffer.name == filepath:
|
||||||
|
vim.current.tabpage = tab
|
||||||
|
vim.current.window = win
|
||||||
|
vim.current.window.cursor = ( line, column - 1 )
|
||||||
|
|
||||||
|
# Center the screen on the jumped-to location
|
||||||
|
vim.command( 'normal! zz' )
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# 'filename' is not opened in any tab pages
|
||||||
|
raise ValueError
|
||||||
|
|
||||||
|
|
||||||
# Both |line| and |column| need to be 1-based
|
# Both |line| and |column| need to be 1-based
|
||||||
def JumpToLocation( filename, line, column ):
|
def JumpToLocation( filename, line, column ):
|
||||||
# Add an entry to the jumplist
|
# Add an entry to the jumplist
|
||||||
@ -314,6 +333,14 @@ def JumpToLocation( filename, line, column ):
|
|||||||
# Sadly this fails on random occasions and the undesired jump remains in the
|
# Sadly this fails on random occasions and the undesired jump remains in the
|
||||||
# jumplist.
|
# jumplist.
|
||||||
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':
|
||||||
|
try:
|
||||||
|
TryJumpLocationInOpenedTab( filename, line, column )
|
||||||
|
return
|
||||||
|
except ValueError:
|
||||||
|
user_command = 'new-tab'
|
||||||
|
|
||||||
command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
|
command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
|
||||||
if command == 'edit' and not BufferIsUsable( vim.current.buffer ):
|
if command == 'edit' and not BufferIsUsable( vim.current.buffer ):
|
||||||
command = 'split'
|
command = 'split'
|
||||||
|
Loading…
Reference in New Issue
Block a user