From 7468d6ec1263373789c5a469a2b9e7617eb6dfce Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Sun, 17 Dec 2017 21:14:50 +0800 Subject: [PATCH] Auto set project name --- autoload/SpaceVim/autocmds.vim | 2 ++ autoload/SpaceVim/plugins/projectmanager.vim | 13 ++++++++++++- config/main.vim | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/autoload/SpaceVim/autocmds.vim b/autoload/SpaceVim/autocmds.vim index 5280ec28c..ece117d17 100644 --- a/autoload/SpaceVim/autocmds.vim +++ b/autoload/SpaceVim/autocmds.vim @@ -79,6 +79,8 @@ function! SpaceVim#autocmds#init() abort autocmd BufWritePost *.vim call s:generate_doc() autocmd ColorScheme gruvbox call s:fix_gruvbox() autocmd VimEnter * call SpaceVim#autocmds#VimEnter() + autocmd User RooterChDir call SpaceVim#plugins#projectmanager#RootchandgeCallback() + autocmd BufEnter * let b:_spacevim_project_name = get(g:, '_spacevim_project_name', '') augroup END endfunction diff --git a/autoload/SpaceVim/plugins/projectmanager.vim b/autoload/SpaceVim/plugins/projectmanager.vim index ac57e95e2..bf22bdc84 100644 --- a/autoload/SpaceVim/plugins/projectmanager.vim +++ b/autoload/SpaceVim/plugins/projectmanager.vim @@ -28,10 +28,21 @@ function! SpaceVim#plugins#projectmanager#list() abort endfunction -function! SpaceVim#plugins#projectmanager#current_() +function! SpaceVim#plugins#projectmanager#current_name() abort return get(b:, '_spacevim_project_name', '') endfunction +function! SpaceVim#plugins#projectmanager#RootchandgeCallback() abort + + 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 +endfunction + function! SpaceVim#plugins#projectmanager#current_root() abort try Rooter diff --git a/config/main.vim b/config/main.vim index 32acd58bd..9e4e4b670 100644 --- a/config/main.vim +++ b/config/main.vim @@ -31,6 +31,7 @@ function! s:parser_argv() abort endif endfunction let s:status = s:parser_argv() +call SpaceVim#plugins#projectmanager#RootchandgeCallback() if s:status[0] let g:_spacevim_enter_dir = s:status[1] augroup SPwelcome