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() function! s:AddIdentifierIfNeeded()
py vim.command( "let should_add_identifier = '" + py vim.command( "let should_add_identifier = '" +
\ str( ycm.ShouldAddIdentifier() ) + "'" ) \ str( int( ycm.ShouldAddIdentifier() ) ) + "'" )
if should_add_identifier != 1 if should_add_identifier != 1
return return
endif endif

View File

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