1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-02-03 07:50:05 +08:00

Fix project switch function (#2718)

Add fzf menu support
This commit is contained in:
Wang Shidong 2019-04-02 22:57:20 +08:00 committed by GitHub
parent c50ea97e08
commit e2cb874ed1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 1 deletions

View File

@ -425,3 +425,39 @@ function! s:helptags(...) abort
\ 'down': '40%'
\ }))
endfunction
" fzf menu command
function! SpaceVim#layers#fzf#complete_menu(ArgLead, CmdLine, CursorPos) abort
return join(keys(g:unite_source_menu_menus), "\n")
endfunction
command! -nargs=* -complete=custom,SpaceVim#layers#fzf#complete_menu FzfMenu call <SID>menu(<q-args>)
function! s:menu_action(e) abort
let action = get(s:menu_action, a:e, '')
exe action
endfunction
function! s:menu(name) abort
let s:source = 'menu'
let s:menu_name = a:name
let s:menu_action = {}
function! s:menu_content() abort
let menu = get(g:unite_source_menu_menus, s:menu_name, {})
if has_key(menu, 'command_candidates')
let rt = []
for item in menu.command_candidates
call add(rt, item[0])
call extend(s:menu_action, {item[0] : item[1]}, 'force')
endfor
return rt
else
return []
endif
endfunction
call fzf#run(fzf#wrap('menu', {
\ 'source': reverse(<sid>menu_content()),
\ 'sink': function('s:menu_action'),
\ 'options': '+m',
\ 'down': '40%'
\ }))
endfunction

View File

@ -36,8 +36,19 @@ let g:unite_source_menu_menus.Projects = {'description':
let g:unite_source_menu_menus.Projects.command_candidates =
\ get(g:unite_source_menu_menus.Projects,'command_candidates', [])
" this function will use fuzzy find layer, now only denite and unite are
" supported.
function! SpaceVim#plugins#projectmanager#list() abort
Unite menu:Projects
if SpaceVim#layers#isLoaded('unite')
Unite menu:Projects
elseif SpaceVim#layers#isLoaded('denite')
Denite menu:Projects
elseif SpaceVim#layers#isLoaded('fzf')
FzfMenu Projects
else
call SpaceVim#logger#warn('fuzzy find layer is needed to find project!')
endif
endfunction
function! SpaceVim#plugins#projectmanager#open(project) abort