" unite mkbuild sources let s:save_cpo = &cpo set cpo&vim let s:xref_source = { \ 'name': 'mkbuild/xref', \ 'description': 'select from cross references built by mkbuild', \ '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 source 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 from all 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