]> oss.titaniummirror.com Git - vim-mkbuild.git/commitdiff
Include unite-xrefs source
authorR. Steve McKown <rsmckown@gmail.com>
Mon, 18 Jan 2016 00:11:41 +0000 (17:11 -0700)
committerR. Steve McKown <rsmckown@gmail.com>
Mon, 18 Jan 2016 00:11:43 +0000 (17:11 -0700)
As of this commit, unite-xrefs functionality is now incorporated into
vim-mkbuild.

autoload/unite/sources/xrefs.vim [new file with mode: 0644]

diff --git a/autoload/unite/sources/xrefs.vim b/autoload/unite/sources/xrefs.vim
new file mode 100644 (file)
index 0000000..87f9b53
--- /dev/null
@@ -0,0 +1,56 @@
+" unite source: tags file and/or cscope database selection for projects using
+" mkbuild
+
+let s:save_cpo = &cpo
+set cpo&vim
+
+let s:source = {
+  \ 'name': 'xrefs',
+  \ 'description': 'select cross references from a directory',
+  \ 'action_table': {
+  \   'setxrefs' : { 'is_selectable': 1 },
+  \ },
+  \ 'default_action': 'setxrefs'
+  \ }
+
+function! s:source.action_table.setxrefs.func(candidates)
+  call s:select(a:candidates[0].word)
+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
+
+function! s: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! unite#sources#xrefs#define()
+  return s:source
+endfunction
+
+let &cpo = s:save_cpo
+unlet s:save_cpo