Small refactoring of the ShouldAddIdentifier func

This commit is contained in:
Strahinja Val Markovic 2012-05-12 20:42:45 -07:00
parent 6696d79518
commit 02a1f8780c
2 changed files with 6 additions and 10 deletions

View File

@ -96,7 +96,7 @@ endfunction
function! s:AddIdentifierIfNeeded()
py vim.command( "let should_add_identifier = '" +
\ str( ycm.ShouldAddIdentifier() ) + "'" )
\ str( int( ycm.ShouldAddIdentifier() ) ) + "'" )
if should_add_identifier != 1
return
endif

View File

@ -174,26 +174,22 @@ def ShouldAddIdentifier():
current_column = CurrentColumn()
previous_char_index = current_column - 1
if previous_char_index < 0:
return 1
return True
line = vim.current.line
try:
previous_char = line[ previous_char_index ]
except IndexError:
return 0
return False
if IsIdentifierChar( previous_char ):
return 0
return False
if ( not IsIdentifierChar( previous_char ) and
previous_char_index > 0 and
IsIdentifierChar( line[ previous_char_index - 1 ] ) ):
return 1
return True
else:
if line[ : current_column ].strip():
return 0
else:
return 1
return line[ : current_column ].isspace()
def SanitizeQuery( query ):