From 50461a952fa39baab2176545017296c0cdc21b44 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Wed, 14 Jan 2015 14:30:51 +0100 Subject: [PATCH] [vim] make autotags look for tag/cscope in parent dir until HOME or / --- .vim/plugin/autotags.vim | 50 +++++++++++++++++++++++++++++-------- .vim/plugin/cscope_plus.vim | 3 +++ 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/.vim/plugin/autotags.vim b/.vim/plugin/autotags.vim index 070253e..6c88af0 100644 --- a/.vim/plugin/autotags.vim +++ b/.vim/plugin/autotags.vim @@ -217,7 +217,7 @@ fun! s:AutotagsInit() while l:dir != "/" if getftype(g:autotagsdir . '/' . s:PathHash(l:dir)) == "dir" let s:autotags_subdir = g:autotagsdir . '/' . s:PathHash(l:dir) - "echomsg "autotags subdir exist: " . s:autotags_subdir + echomsg "autotags subdir exist: " . s:autotags_subdir break endif " get parent directory @@ -239,20 +239,48 @@ fun! s:AutotagsIsC() endif endfun +fun! GetLocalCscopeDb(pathname) + if !isdirectory(a:pathname) || a:pathname == $HOME || a:pathname == '/' + return + endif + let s:cscopefile = a:pathname."/cscope.out" + if filereadable(s:cscopefile) +" echo "Add cscope db for ".a:pathname + execute "cscope add ".s:cscopefile." ".a:pathname + endif + unlet s:cscopefile + call GetLocalCscopeDb(fnamemodify(a:pathname, ":h")) +endfunction + +fun! GetLocalTags(pathname) + if !isdirectory(a:pathname) || a:pathname == $HOME || a:pathname == '/' + return + endif + let s:ctagsfile = a:pathname."/tags" + if filereadable(s:ctagsfile) +" echo "Add tags db for ".a:pathname + exe "set tags+=" . s:ctagsfile + endif + unlet s:ctagsfile + call GetLocalTags(fnamemodify(a:pathname, ":h")) +endfunction + fun! s:AutotagsSearchLoadTags() " search ctags in current tree - if filereadable(findfile("tags", ".;")) - let l:ctagsfile = findfile("tags", ".;") - exe "set tags+=" . l:ctagsfile - echomsg "found local ctags file: " . l:ctagsfile - endif + call GetLocalTags(expand("%:p:h")) +" if filereadable(findfile("tags", ".;")) +" let l:ctagsfile = findfile("tags", ".;") +" exe "set tags+=" . l:ctagsfile +" echomsg "found local ctags file: " . l:ctagsfile +" endif + call GetLocalCscopeDb(expand("%:p:h")) " search cscope db in current tree - if filereadable(findfile("cscope.out", ".;")) - let l:cscopedb = findfile("cscope.out", ".;") - exe "cs add " . l:cscopedb . " " . fnamemodify(l:cscopedb, ":p:h") - echomsg "found local cscopedb file: " . l:cscopedb - endif +" if filereadable(findfile("cscope.out", ".;")) +" let l:cscopedb = findfile("cscope.out", ".;") +" exe "cs add " . l:cscopedb . " " . fnamemodify(l:cscopedb, ":p:h") +" echomsg "found local cscopedb file: " . l:cscopedb +" endif endfun " remove stale tags for non-existing source directories diff --git a/.vim/plugin/cscope_plus.vim b/.vim/plugin/cscope_plus.vim index b182a9d..602a795 100644 --- a/.vim/plugin/cscope_plus.vim +++ b/.vim/plugin/cscope_plus.vim @@ -103,6 +103,9 @@ if has("cscope") endfunction command! GenerateCscopeDb :call GenerateCscopeDb() +" Let autotags find all cscodepeDb +" LoadLocalCscopeDb + "" if has("cscope") "" map :call GetCscopeDb(expand("%:p:h")) "" map :call GenerateCscopeDb()