Combined same_buffer and buffer_command options.

This commit is contained in:
davits 2014-03-04 14:47:43 +04:00
parent 8c6857bf91
commit 40dc235136
3 changed files with 16 additions and 27 deletions

View File

@ -1336,22 +1336,14 @@ 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 ### The `g:ycm_goto_buffer_command` option
Defines command for the new buffer creation where GoTo command result will be opened. Defines where `GoTo*` commands result should be opened.
Value should be one of the following vim commands `[ 'sp[lit]', 'vs[plit]', 'tabe[dit]' ]` Can take one of the following values: `[ 'same-buffer', 'horizontal-split', 'vertical-split', 'new-tab' ]`
If this option is set to `'same-buffer'` but current buffer is modified then result will be opened in horizontal split.
Default: `split` Default: `'same-buffer'`
let g:ycm_goto_buffer_command = 'split' let g:ycm_goto_buffer_command = 'same-buffer'
FAQ FAQ
--- ---

View File

@ -144,15 +144,8 @@ 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 = let g:ycm_goto_buffer_command =
\ get( g:, 'ycm_goto_buffer_command', 'split' ) \ get( g:, 'ycm_goto_buffer_command', 'same-buffer' )
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.

View File

@ -23,6 +23,11 @@ import json
from ycm.utils import ToUtf8IfNeeded from ycm.utils import ToUtf8IfNeeded
from ycm import user_options_store from ycm import user_options_store
BUFFER_COMMAND_MAP = { 'same-buffer' : 'edit',
'horizontal-split' : 'split',
'vertical-split' : 'vsplit',
'new-tab' : 'tabedit' }
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."""
# See the comment in CurrentColumn about the calculation for the line and # See the comment in CurrentColumn about the calculation for the line and
@ -245,12 +250,11 @@ 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.
if ( user_options_store.Value( 'goto_same_buffer' ) and user_command = user_options_store.Value( 'goto_buffer_command' )
not BufferModified( vim.current.buffer ) ): command = BUFFER_COMMAND_MAP.get( user_command, 'edit' )
vim.command( 'keepjumps edit {0}'.format( filename ) ) if command == 'edit' and BufferModified( vim.current.buffer ):
else: command = 'split'
vim.command( 'keepjumps {0} {1}'.format( user_options_store.Value( 'goto_buffer_command' ), vim.command( 'keepjumps {0} {1}'.format( command, filename ) )
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