Pass s:tagfiles to tag.vim

* Pass s:tagfiles and path of the current buffer to tag.vim
  to properly expand '.' in the 'tags' option. Continue #27.
This commit is contained in:
Kien N 2011-11-29 07:12:58 +07:00
parent a4b8d4cd38
commit d6504d2eb5
2 changed files with 12 additions and 9 deletions

View File

@ -67,6 +67,7 @@ fu! s:Open()
let [s:cwd, s:winres] = [getcwd(), winrestcmd()] let [s:cwd, s:winres] = [getcwd(), winrestcmd()]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)] let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crvisual] = [expand('<cword>'), s:lastvisual()] let [s:crword, s:crvisual] = [expand('<cword>'), s:lastvisual()]
let s:tagfiles = s:tagfiles()
sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP' sil! exe s:mwbottom ? 'bo' : 'to' '1new ControlP'
let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1 let s:currwin = s:mwbottom ? winnr('#') : winnr('#') + 1
let [s:bufnr, s:prompt] = [bufnr('%'), ['', '', '']] let [s:bufnr, s:prompt] = [bufnr('%'), ['', '', '']]
@ -94,7 +95,7 @@ fu! s:Close()
let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []] let [g:ctrlp_lines, g:ctrlp_allfiles] = [[], []]
exe s:winres exe s:winres
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ s:crfile s:crfpath s:crword s:crvisual g:ctrlp_nolimit \ s:crfile s:crfpath s:crword s:crvisual s:tagfiles g:ctrlp_nolimit
cal s:recordhist(join(s:prompt, '')) cal s:recordhist(join(s:prompt, ''))
ec ec
endf endf
@ -1243,6 +1244,11 @@ fu! s:lscommand()
en en
endf endf
"}}} "}}}
" Extensions {{{
fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
endf
"}}}
"}}} "}}}
" * Initialization {{{ " * Initialization {{{
fu! s:SetLines(type) fu! s:SetLines(type)

View File

@ -10,20 +10,17 @@ if exists('g:loaded_ctrlp_tag') && g:loaded_ctrlp_tag
en en
let [g:loaded_ctrlp_tag, g:ctrlp_newtag] = [1, 0] let [g:loaded_ctrlp_tag, g:ctrlp_newtag] = [1, 0]
let s:tag_var = ['ctrlp#tag#init()', 'ctrlp#tag#accept', 'tags', 'tag'] let s:tag_var = ['ctrlp#tag#init(s:tagfiles, s:crfpath)', 'ctrlp#tag#accept',
\ 'tags', 'tag']
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:tag_var) : [s:tag_var] \ ? add(g:ctrlp_ext_vars, s:tag_var) : [s:tag_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, '':p'')'), 'filereadable(v:val)')
endf
"}}} "}}}
" Public {{{ " Public {{{
fu! ctrlp#tag#init() fu! ctrlp#tag#init(tagfiles, crfpath)
let &l:tags = join(sort(s:tagfiles()), ',') let &l:tags = join(sort(a:tagfiles), ',')
if empty(&l:tags) | retu [] | en if empty(&l:tags) | retu [] | en
if exists('s:ltags') && s:ltags == &l:tags if exists('s:ltags') && s:ltags == &l:tags
let newtags = 0 let newtags = 0
@ -31,7 +28,7 @@ fu! ctrlp#tag#init()
let s:ltags = &l:tags let s:ltags = &l:tags
let newtags = 1 let newtags = 1
en en
let s:cwd = getcwd() let s:cwd = a:crfpath
if ( newtags && !exists('g:ctrlp_alltags['''.s:ltags.''']') ) if ( newtags && !exists('g:ctrlp_alltags['''.s:ltags.''']') )
\ || g:ctrlp_newtag \ || g:ctrlp_newtag
let tags = taglist('^.*$') let tags = taglist('^.*$')