From dbefd008fe702a790c7904e77d58afbf170acb8a Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 24 Dec 2017 21:58:39 +0800 Subject: [PATCH] Add callback for projectmanager --- autoload/SpaceVim/layers/lang/c.vim | 10 ++++++++++ autoload/SpaceVim/plugins/projectmanager.vim | 17 +++++++++++++++-- autoload/SpaceVim/util.vim | 16 ++++++++++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/autoload/SpaceVim/layers/lang/c.vim b/autoload/SpaceVim/layers/lang/c.vim index 642f2ade2..42f95543d 100644 --- a/autoload/SpaceVim/layers/lang/c.vim +++ b/autoload/SpaceVim/layers/lang/c.vim @@ -51,7 +51,9 @@ function! SpaceVim#layers#lang#c#plugins() abort call add(plugins, ['tweekmonster/deoplete-clang2']) endif elseif g:spacevim_autocomplete_method ==# 'ycm' + " no need extra plugins elseif g:spacevim_autocomplete_method ==# 'completor' + " no need extra plugins elseif g:spacevim_autocomplete_method ==# 'asyncomplete' else call add(plugins, ['Rip-Rip/clang_complete']) @@ -63,6 +65,10 @@ endfunction function! SpaceVim#layers#lang#c#config() abort call SpaceVim#plugins#runner#reg_runner('c', ['gcc -o #TEMP# %s', '#TEMP#']) call SpaceVim#mapping#space#regesit_lang_mappings('c', funcref('s:language_specified_mappings')) + call SpaceVim#plugins#projectmanager#reg_callback(funcref('s:update_clang_flag')) + if filereadable('.clang') + call s:update_clang_flag() + endif endfunction function! SpaceVim#layers#lang#c#set_variable(var) abort @@ -84,3 +90,7 @@ function! s:language_specified_mappings() abort \ 'execute current file', 1) endfunction +function! s:update_clang_flag() abort + +endfunction + diff --git a/autoload/SpaceVim/plugins/projectmanager.vim b/autoload/SpaceVim/plugins/projectmanager.vim index a4b07952c..484a6e7d9 100644 --- a/autoload/SpaceVim/plugins/projectmanager.vim +++ b/autoload/SpaceVim/plugins/projectmanager.vim @@ -48,15 +48,28 @@ function! SpaceVim#plugins#projectmanager#current_name() abort return get(b:, '_spacevim_project_name', '') endfunction +" this func is called when vim-rooter change the dir, That means the project +" is changed, so will call call the registered function. function! SpaceVim#plugins#projectmanager#RootchandgeCallback() abort - - let project = { + let project = { \ 'path' : getcwd(), \ 'name' : fnamemodify(getcwd(), ':t') \ } call s:cache_project(project) let g:_spacevim_project_name = project.name let b:_spacevim_project_name = g:_spacevim_project_name + for callback in s:project_callback + call call(callback, []) + endfor +endfunction + +let s:project_callback = [] +function! SpaceVim#plugins#projectmanager#reg_callback(func) abort + if type(a:func) == 2 + call add(s:project_callback, a:func) + else + call SpaceVim#logger#warn('can not register the project callback: ' . string(a:func)) + endif endfunction function! SpaceVim#plugins#projectmanager#current_root() abort diff --git a/autoload/SpaceVim/util.vim b/autoload/SpaceVim/util.vim index 2fcdc8d21..6c1ed8ca7 100644 --- a/autoload/SpaceVim/util.vim +++ b/autoload/SpaceVim/util.vim @@ -6,6 +6,22 @@ function! SpaceVim#util#globpath(path, expr) abort endif endfunction +function! SpaceVim#util#findFileInParent(what, where) abort + let old_suffixesadd = &suffixesadd + let &suffixesadd = '' + let file = findfile(a:what, escape(a:where, ' ') . ';') + let &suffixesadd = old_suffixesadd + return file +endfunction + +function! SpaceVim#util#findDirInParent(what, where) abort + let old_suffixesadd = &suffixesadd + let &suffixesadd = '' + let dir = finddir(a:what, escape(a:where, ' ') . ';') + let &suffixesadd = old_suffixesadd + return dir +endfunction + function! SpaceVim#util#echoWarn(msg) abort echohl WarningMsg echo a:msg