[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 != "/"
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

View File

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