]> oss.titaniummirror.com Git - vim-mkbuild.git/blobdiff - autoload/unite/sources/mkbuild.vim
Improve plugin; consolidate unite sources
[vim-mkbuild.git] / autoload / unite / sources / mkbuild.vim
diff --git a/autoload/unite/sources/mkbuild.vim b/autoload/unite/sources/mkbuild.vim
new file mode 100644 (file)
index 0000000..0a293bd
--- /dev/null
@@ -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