From 88c0758ecb26cafc1a243531059fabf26c790639 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Tue, 21 Jul 2015 14:53:13 -0600 Subject: [PATCH] Add new function mkbuild#SelectXref() --- doc/mkbuild.txt | 16 ++++++++++++++-- plugin/mkbuild.vim | 26 ++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/doc/mkbuild.txt b/doc/mkbuild.txt index 4f658ff..c29f711 100644 --- a/doc/mkbuild.txt +++ b/doc/mkbuild.txt @@ -8,8 +8,11 @@ This plugin is only available if 'compatible' is not set. INTRODUCTION *mkbuild* This plugin provides features for working with code using the mkbuild build -system. The only tool currently available is a method to select files from -the project using dmenu, which will also work without mkbuild. +system. + + +The first tool is a method to select files from the project using dmenu, which +will also work without mkbuild. Map mkbuild#DmenuOpen(cmd) to some key, such as: nnoremap e :call mkbuild#DmenuOpen('e') @@ -37,4 +40,13 @@ following priority order: 3. Perform a 'find . -type f' in the current directory. + +The second tool is a method to allow switching to a new tags and/or cscope +database. This is especially useful for mkbuild, which can build the same +code for multiple platforms, and each platform build directory contains its +own tags and cscope database files. + +Map mkbuild#SelectXref() to some key, such as: +nnoremap x :call mkbuild#SelectXref() + vim:tw=78:ts=8:ft=help:norl: diff --git a/plugin/mkbuild.vim b/plugin/mkbuild.vim index fd92caa..82c03a2 100644 --- a/plugin/mkbuild.vim +++ b/plugin/mkbuild.vim @@ -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 -- 2.39.2