Added options to choose whether GoTo commands result should be opened in the new buffer and in which one.

This commit is contained in:
davits 2014-02-23 17:50:51 +04:00
parent 3da402fdf9
commit 0102d23bfe
3 changed files with 37 additions and 4 deletions

View File

@ -1336,6 +1336,23 @@ Default: `1`
let g:ycm_use_ultisnips_completer = 1 let g:ycm_use_ultisnips_completer = 1
### The `g:ycm_goto_same_buffer` option
Indicates whether GoTo command result should be opened in the current buffer.
However if current buffer has unsaved modifications then this option will be ignored and result will be opened in the new buffer created with `g:ycm_goto_buffer_command` command.
Default: `1`
let g:ycm_goto_same_buffer = 1
### The `g:ycm_goto_buffer_command` option
Defines command for the new buffer creation where GoTo command result will be opened.
Value should be one of the following vim commands `[ 'sp[lit]', 'vs[plit]', 'tabe[dit]' ]`
Default: `split`
let g:ycm_goto_buffer_command = 'split'
FAQ FAQ
--- ---

View File

@ -144,6 +144,16 @@ let g:ycm_warning_symbol =
\ get( g:, 'ycm_warning_symbol', \ get( g:, 'ycm_warning_symbol',
\ get( g:, 'syntastic_warning_symbol', '>>' ) ) \ get( g:, 'syntastic_warning_symbol', '>>' ) )
let g:ycm_goto_same_buffer =
\ get( g:, 'ycm_goto_same_buffer', 1 )
let g:ycm_goto_buffer_command =
\ get( g:, 'ycm_goto_buffer_command', 'split' )
if index( [ 'sp', 'split', 'vs', 'vsplit', 'tabe', 'tabedit' ], g:ycm_goto_buffer_command ) < 0
let g:ycm_goto_buffer_command = 'split'
endif
" On-demand loading. Let's use the autoload folder and not slow down vim's " On-demand loading. Let's use the autoload folder and not slow down vim's
" startup procedure. " startup procedure.
augroup youcompletemeStart augroup youcompletemeStart

View File

@ -21,6 +21,7 @@ import vim
import os import os
import json import json
from ycm.utils import ToUtf8IfNeeded from ycm.utils import ToUtf8IfNeeded
from ycm import user_options_store
def CurrentLineAndColumn(): def CurrentLineAndColumn():
"""Returns the 0-based current line and 0-based current column.""" """Returns the 0-based current line and 0-based current column."""
@ -65,10 +66,10 @@ def GetBufferOption( buffer_object, option ):
return GetVariableValue( to_eval ) return GetVariableValue( to_eval )
def GetUnsavedAndCurrentBufferData(): def BufferModified( buffer_object ):
def BufferModified( buffer_object ): return bool( int( GetBufferOption( buffer_object, 'mod' ) ) )
return bool( int( GetBufferOption( buffer_object, 'mod' ) ) )
def GetUnsavedAndCurrentBufferData():
buffers_data = {} buffers_data = {}
for buffer_object in vim.buffers: for buffer_object in vim.buffers:
if not ( BufferModified( buffer_object ) or if not ( BufferModified( buffer_object ) or
@ -244,7 +245,12 @@ def JumpToLocation( filename, line, column ):
# location, not to the start of the newly opened file. # location, not to the start of the newly opened file.
# 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.
vim.command( 'keepjumps edit {0}'.format( filename ) ) if ( user_options_store.Value( 'goto_same_buffer' ) and
not BufferModified( vim.current.buffer ) ):
vim.command( 'keepjumps edit {0}'.format( filename ) )
else:
vim.command( 'keepjumps {0} {1}'.format( user_options_store.Value( 'goto_buffer_command'),
filename ) )
vim.current.window.cursor = ( line, column - 1 ) vim.current.window.cursor = ( line, column - 1 )
# Center the screen on the jumped-to location # Center the screen on the jumped-to location