[vim] make autotags look for tag/cscope in parent dir until HOME or /

This commit is contained in:
Mathieu Maret 2015-01-14 14:30:51 +01:00 committed by Mathieu Maret
parent 71a9364222
commit 50461a952f
2 changed files with 42 additions and 11 deletions

View File

@ -217,7 +217,7 @@ fun! s:AutotagsInit()
while l:dir != "/" while l:dir != "/"
if getftype(g:autotagsdir . '/' . s:PathHash(l:dir)) == "dir" if getftype(g:autotagsdir . '/' . s:PathHash(l:dir)) == "dir"
let s:autotags_subdir = g:autotagsdir . '/' . s:PathHash(l: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 break
endif endif
" get parent directory " get parent directory
@ -239,20 +239,48 @@ fun! s:AutotagsIsC()
endif endif
endfun 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() fun! s:AutotagsSearchLoadTags()
" search ctags in current tree " search ctags in current tree
if filereadable(findfile("tags", ".;")) call GetLocalTags(expand("%:p:h"))
let l:ctagsfile = findfile("tags", ".;") " if filereadable(findfile("tags", ".;"))
exe "set tags+=" . l:ctagsfile " let l:ctagsfile = findfile("tags", ".;")
echomsg "found local ctags file: " . l:ctagsfile " exe "set tags+=" . l:ctagsfile
endif " echomsg "found local ctags file: " . l:ctagsfile
" endif
call GetLocalCscopeDb(expand("%:p:h"))
" search cscope db in current tree " search cscope db in current tree
if filereadable(findfile("cscope.out", ".;")) " if filereadable(findfile("cscope.out", ".;"))
let l:cscopedb = findfile("cscope.out", ".;") " let l:cscopedb = findfile("cscope.out", ".;")
exe "cs add " . l:cscopedb . " " . fnamemodify(l:cscopedb, ":p:h") " exe "cs add " . l:cscopedb . " " . fnamemodify(l:cscopedb, ":p:h")
echomsg "found local cscopedb file: " . l:cscopedb " echomsg "found local cscopedb file: " . l:cscopedb
endif " endif
endfun endfun
" remove stale tags for non-existing source directories " remove stale tags for non-existing source directories

View File

@ -103,6 +103,9 @@ if has("cscope")
endfunction endfunction
command! GenerateCscopeDb :call GenerateCscopeDb() command! GenerateCscopeDb :call GenerateCscopeDb()
" Let autotags find all cscodepeDb
" LoadLocalCscopeDb
"" if has("cscope") "" if has("cscope")
"" map <F9> :call GetCscopeDb(expand("%:p:h")) <CR><CR> "" map <F9> :call GetCscopeDb(expand("%:p:h")) <CR><CR>
"" map <S-F9> :call GenerateCscopeDb() <CR><CR> "" map <S-F9> :call GenerateCscopeDb() <CR><CR>