X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=autoload%2Funite%2Fsources%2Fmkbuild.vim;fp=autoload%2Funite%2Fsources%2Fmkbuild.vim;h=0a293bdf0a59c8d0783764e514a81c2d8ec2a26f;hb=6e251a420b39df1ab77ce60af69905891632d113;hp=0000000000000000000000000000000000000000;hpb=b927f34f30485d6448f10abf196d7e32c503aff5;p=vim-mkbuild.git diff --git a/autoload/unite/sources/mkbuild.vim b/autoload/unite/sources/mkbuild.vim new file mode 100644 index 0000000..0a293bd --- /dev/null +++ b/autoload/unite/sources/mkbuild.vim @@ -0,0 +1,96 @@ +" unite mkbuild sources + +let s:save_cpo = &cpo +set cpo&vim + +let s:xref_source = { + \ 'name': 'mkbuild/xref', + \ 'description': 'select cross references built from an mkbuild build', + \ 'action_table': { + \ 'setxrefs' : { 'is_selectable': 1 }, + \ }, + \ 'default_action': 'setxrefs' + \ } + +function! s:xref_source.action_table.setxrefs.func(candidates) + call s:select(a:candidates[0].word) +endfunction + +function! s:xref_source.gather_candidates(args, context) + let cmd = 'find . -maxdepth 4 -type f -name tags -o -name cscope.out | ' . + \ 'while read f; do echo $(dirname $f); done | sort -u | sed -e "s|\./||"' + let xrefdirs = split(s:chompsys(cmd), '\n') + + return map(xrefdirs, '{ "word": v:val }') +endfunction + +function! s:select(dirname) + if empty(a:dirname) + return + endif + let file = a:dirname . "/tags" + let &tags='' + if filereadable(file) + let &tags = file + endif + if has('cscope') + let file = a:dirname . "/cscope.out" + execute 'cscope kill -1' + if filereadable(file) + execute 'cscope add ' . file + endif + endif +endfunction + +" Return the results of a command without the ending newline +function! s:chompsys(cmd) + return substitute(system(a:cmd), '\n$', '', '') +endfunction + + +let s:xfile_source = { + \ 'name': 'mkbuild/file_xref', + \ 'description': 'select files used in an mkbuild build', + \ 'action_table': { + \ 'open' : { 'is_selectable': 1 }, + \ }, + \ 'default_action': 'open' + \ } + +function! s:xfile_source.action_table.open.func(candidates) + for c in a:candidates + execute 'e ' . c.word + endfor +endfunction + +function! s:xfile_source.gather_candidates(args, context) + return map(mkbuild#buildFiles(), '{ "word": v:val }') +endfunction + + +let s:file_source = { + \ 'name': 'mkbuild/file', + \ 'description': 'select files in an mkbuild project', + \ 'action_table': { + \ 'open' : { 'is_selectable': 1 }, + \ }, + \ 'default_action': 'open' + \ } + +function! s:file_source.action_table.open.func(candidates) + for c in a:candidates + execute 'e ' . c.word + endfor +endfunction + +function! s:file_source.gather_candidates(args, context) + return map(mkbuild#allFiles(), '{ "word": v:val }') +endfunction + + +function! unite#sources#mkbuild#define() + return [s:xref_source, s:xfile_source, s:file_source] +endfunction + +let &cpo = s:save_cpo +unlet s:save_cpo