Supporting multiple filetypes set for current file

Vim allows setting the filetype string to something like "cpp.c", which means
that the file is both cpp and c (nonsense, but allowed). We need to support such
filetype strings.
This commit is contained in:
Strahinja Val Markovic 2013-01-31 16:19:56 -08:00
parent 1779cbbb55
commit c67658bbce
2 changed files with 19 additions and 5 deletions

View File

@ -67,8 +67,9 @@ def EscapeForVim( text ):
return text.replace( "'", "''" ) return text.replace( "'", "''" )
def CurrentFiletype(): def CurrentFiletypes():
return vim.eval( "&filetype" ) ft_string = vim.eval( "&filetype" )
return ft_string.split( '.' )
def GetVariableValue( variable ): def GetVariableValue( variable ):

View File

@ -51,7 +51,17 @@ class YouCompleteMe( object ):
def GetFiletypeCompleterForCurrentFile( self ): def GetFiletypeCompleterForCurrentFile( self ):
filetype = vimsupport.CurrentFiletype() filetypes = vimsupport.CurrentFiletypes()
for filetype in filetypes:
completer = self.GetFiletypeCompleterForFiletype( filetype )
if completer:
return completer
return None
def GetFiletypeCompleterForFiletype( self, filetype ):
try: try:
return self.filetype_completers[ filetype ] return self.filetype_completers[ filetype ]
except KeyError: except KeyError:
@ -92,8 +102,11 @@ class YouCompleteMe( object ):
def FiletypeCompletionEnabledForCurrentFile( self ): def FiletypeCompletionEnabledForCurrentFile( self ):
return ( vimsupport.CurrentFiletype() not in filetypes = vimsupport.CurrentFiletypes()
FILETYPE_SPECIFIC_COMPLETION_TO_DISABLE and filetype_disabled = all([ x in FILETYPE_SPECIFIC_COMPLETION_TO_DISABLE
for x in filetypes ])
return ( not filetype_disabled and
self.FiletypeCompletionAvailableForFile() ) self.FiletypeCompletionAvailableForFile() )