]> oss.titaniummirror.com Git - vim-mkbuild.git/blobdiff - plugin/mkbuild.vim
Add new function mkbuild#SelectXref()
[vim-mkbuild.git] / plugin / mkbuild.vim
index fd92caa28683d51da22f310305e029dd17fee78f..82c03a2d9bf1c8271679c1a48b0d8fd494bb5470 100644 (file)
@@ -138,3 +138,29 @@ function! mkbuild#DmenuOpen(cmd)
     execute a:cmd . " " . fname
   endif
 endfunction
+
+" Look recursively from the current directory for directories containing a
+" tags files and/or a cscope database.  Allow the user to select one of these
+" directories.  Both its tag file and its associated cscope database, as
+" present, are made active for cross referencing.
+function! mkbuild#SelectXrefs()
+  let cmd = 'find . -type f -name tags -o -name cscope.out | ' .
+    \ 'while read f; do echo $(dirname $f); done | sort -u | sed -e "s|\./||"'
+  let curr = s:chompsys('dirname "' . &tags . '"')
+  let dname = s:chompsys(cmd . ' | dmenu -i -l 20 -p "xref (' . curr . ')"')
+  if empty(dname)
+    return
+  endif
+  let file = dname . "/tags"
+  let &tags=''
+  if filereadable(file)
+    let &tags = file
+  endif
+  if has('cscope')
+    let file = dname . "/cscope.out"
+    exe 'cscope kill -1'
+    if filereadable(file)
+      exe 'cscope add ' . file
+    endif
+  endif
+endfunction