From ba6b40e48545955b4143d42b82f2487df05edd22 Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Sun, 3 Mar 2013 10:48:34 -0800 Subject: [PATCH] Refactoring the ClangAvailableForBuffer method --- python/completers/cpp/clang_completer.py | 9 +++------ python/vimsupport.py | 7 +++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/python/completers/cpp/clang_completer.py b/python/completers/cpp/clang_completer.py index 4fc93a1c..a934f339 100644 --- a/python/completers/cpp/clang_completer.py +++ b/python/completers/cpp/clang_completer.py @@ -246,9 +246,6 @@ def DiagnosticsToDiagStructure( diagnostics ): def ClangAvailableForBuffer( buffer_object ): - filetypes = vim.eval( 'getbufvar({0}, "&ft")'.format( buffer_object.number ) ) - supported_fts = [ft for ft in filetypes.split('.') if ft in CLANG_FILETYPES] - if supported_fts: - return True - else: - return False + filetypes = vimsupport.FiletypesForBuffer( buffer_object ) + return any( [ filetype in CLANG_FILETYPES for filetype in filetypes ] ) + diff --git a/python/vimsupport.py b/python/vimsupport.py index 75e15218..5a720c7b 100644 --- a/python/vimsupport.py +++ b/python/vimsupport.py @@ -104,6 +104,13 @@ def CurrentFiletypes(): return ft_string.split( '.' ) +def FiletypesForBuffer( buffer_object ): + # NOTE: Getting &ft for other buffers only works when the buffer has been + # visited by the user at least once, which is true for modified buffers + ft_string = vim.eval( 'getbufvar({0}, "&ft")'.format( buffer_object.number ) ) + return ft_string.split( '.' ) + + def GetVariableValue( variable ): return vim.eval( variable )