1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-03-11 08:55:43 +08:00
SpaceVim/autoload/SpaceVim/plugins/projectmanager.vim
2017-12-27 09:00:03 +08:00

103 lines
2.9 KiB
VimL

"=============================================================================
" projectmanager.vim --- project manager for SpaceVim
" Copyright (c) 2016-2017 Shidong Wang & Contributors
" Author: Shidong Wang < wsdjeg at 163.com >
" URL: https://spacevim.org
" License: MIT license
"=============================================================================
" project item:
" {
" "path" : "path/to/root",
" "name" : "name of the project, by default it is name of root directory",
" "type" : "git maven or svn",
" }
"
let s:project_paths = {}
function! s:cache_project(prj) abort
if !has_key(s:project_paths, a:prj.path)
let s:project_paths[a:prj.path] = a:prj
let desc = '[' . a:prj.name . '] ' . a:prj.path
let cmd = "call SpaceVim#plugins#projectmanager#open('" . a:prj.path . "')"
call add(g:unite_source_menu_menus.Projects.command_candidates, [desc,cmd])
endif
endfunction
let g:unite_source_menu_menus =
\ get(g:,'unite_source_menu_menus',{})
let g:unite_source_menu_menus.Projects = {'description':
\ 'Custom mapped keyboard shortcuts [SPC] p p'}
let g:unite_source_menu_menus.Projects.command_candidates =
\ get(g:unite_source_menu_menus.Projects,'command_candidates', [])
function! SpaceVim#plugins#projectmanager#list() abort
Unite menu:Projects
endfunction
function! SpaceVim#plugins#projectmanager#open(project) abort
let path = s:project_paths[a:project]['path']
tabnew
exe 'lcd ' . path
Startify | VimFiler
endfunction
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 = {
\ '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
try
Rooter
catch
endtry
return getcwd()
endfunction
let s:BUFFER = SpaceVim#api#import('vim#buffer')
function! SpaceVim#plugins#projectmanager#kill_project() abort
let name = get(b:, '_spacevim_project_name', '')
if name != ''
call s:BUFFER.filter_do(
\ {
\ 'expr' : [
\ 'buflisted(v:val)',
\ 'getbufvar(v:val, "_spacevim_project_name") == "' . name . '"',
\ ],
\ 'do' : 'bd %d'
\ }
\ )
endif
endfunction