2011-11-28 07:52:28 -05:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/tag.vim
|
|
|
|
" Description: Tag file extension
|
|
|
|
" Author: Kien Nguyen <github.com/kien>
|
|
|
|
" =============================================================================
|
|
|
|
|
2011-12-02 22:54:18 -05:00
|
|
|
" Init {{{1
|
2011-11-28 07:52:28 -05:00
|
|
|
if exists('g:loaded_ctrlp_tag') && g:loaded_ctrlp_tag
|
|
|
|
fini
|
|
|
|
en
|
2011-12-01 00:59:14 -05:00
|
|
|
let g:loaded_ctrlp_tag = 1
|
2011-11-28 07:52:28 -05:00
|
|
|
|
2012-04-07 07:55:23 -04:00
|
|
|
cal add(g:ctrlp_ext_vars, {
|
2012-03-28 21:53:00 -04:00
|
|
|
\ 'init': 'ctrlp#tag#init()',
|
2012-01-15 12:42:14 -05:00
|
|
|
\ 'accept': 'ctrlp#tag#accept',
|
|
|
|
\ 'lname': 'tags',
|
|
|
|
\ 'sname': 'tag',
|
2012-03-28 21:53:00 -04:00
|
|
|
\ 'enter': 'ctrlp#tag#enter()',
|
2012-01-15 12:42:14 -05:00
|
|
|
\ 'type': 'tabs',
|
2012-04-07 07:55:23 -04:00
|
|
|
\ })
|
2011-11-28 07:52:28 -05:00
|
|
|
|
|
|
|
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
2011-12-02 22:54:18 -05:00
|
|
|
" Utilities {{{1
|
2011-11-30 10:13:37 -05:00
|
|
|
fu! s:findcount(str)
|
2011-12-01 00:59:14 -05:00
|
|
|
let [tg, fname] = split(a:str, '\t\+\ze[^\t]\+$')
|
2012-07-13 07:06:32 -04:00
|
|
|
let tgs = taglist('^'.tg.'$')
|
|
|
|
if len(tgs) < 2
|
|
|
|
retu [1, 1]
|
|
|
|
en
|
|
|
|
let bname = fnamemodify(bufname('%'), ':p')
|
|
|
|
let fname = expand(fnamemodify(simplify(fname), ':s?^[.\/]\+??:p:.'), 1)
|
|
|
|
let [fnd, ct, pos, idx] = [0, 0, 0, 0]
|
|
|
|
wh idx < len(tgs)
|
|
|
|
if bname == fnamemodify(tgs[idx]["filename"], ':p')
|
|
|
|
cal insert(tgs, remove(tgs, idx))
|
|
|
|
brea
|
|
|
|
en
|
|
|
|
let idx += 1
|
|
|
|
endw
|
2011-12-01 00:59:14 -05:00
|
|
|
for each in tgs
|
|
|
|
let ct += 1
|
|
|
|
let fulname = fnamemodify(each["filename"], ':p')
|
|
|
|
if stridx(fulname, fname) >= 0
|
|
|
|
\ && strlen(fname) + stridx(fulname, fname) == strlen(fulname)
|
|
|
|
let fnd += 1
|
|
|
|
let pos = ct
|
2011-11-30 10:13:37 -05:00
|
|
|
en
|
|
|
|
if fnd > 1 | brea | en
|
|
|
|
endfo
|
2011-12-01 00:59:14 -05:00
|
|
|
retu [fnd, pos]
|
2011-11-30 04:42:19 -05:00
|
|
|
endf
|
2011-12-14 05:46:21 -05:00
|
|
|
|
|
|
|
fu! s:filter(tags)
|
2012-05-01 15:59:37 -04:00
|
|
|
let nr = 0
|
2011-12-14 05:46:21 -05:00
|
|
|
wh 0 < 1
|
2012-05-01 15:59:37 -04:00
|
|
|
if a:tags == [] | brea | en
|
2012-08-17 22:50:13 -04:00
|
|
|
if a:tags[nr] =~ '^!' && a:tags[nr] !~# '^!_TAG_'
|
2011-12-14 05:46:21 -05:00
|
|
|
let nr += 1
|
|
|
|
con
|
|
|
|
en
|
2012-08-17 22:50:13 -04:00
|
|
|
if a:tags[nr] =~# '^!_TAG_' && len(a:tags) > nr
|
2012-05-01 15:59:37 -04:00
|
|
|
cal remove(a:tags, nr)
|
2011-12-14 05:46:21 -05:00
|
|
|
el
|
|
|
|
brea
|
|
|
|
en
|
|
|
|
endw
|
2012-05-01 15:59:37 -04:00
|
|
|
retu a:tags
|
2011-12-14 05:46:21 -05:00
|
|
|
endf
|
2012-04-06 22:01:06 -04:00
|
|
|
|
|
|
|
fu! s:syntax()
|
|
|
|
if !ctrlp#nosy()
|
|
|
|
cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
|
|
|
|
sy match CtrlPTabExtra '\zs\t.*\ze$'
|
|
|
|
en
|
|
|
|
endf
|
2011-12-02 22:54:18 -05:00
|
|
|
" Public {{{1
|
2012-03-28 21:53:00 -04:00
|
|
|
fu! ctrlp#tag#init()
|
|
|
|
if empty(s:tagfiles) | retu [] | en
|
2012-02-20 02:58:03 -05:00
|
|
|
let g:ctrlp_alltags = []
|
2012-03-28 21:53:00 -04:00
|
|
|
let tagfiles = sort(filter(s:tagfiles, 'count(s:tagfiles, v:val) == 1'))
|
2011-12-01 00:59:14 -05:00
|
|
|
for each in tagfiles
|
2011-12-14 05:46:21 -05:00
|
|
|
let alltags = s:filter(ctrlp#utils#readfile(each))
|
2011-12-01 00:59:14 -05:00
|
|
|
cal extend(g:ctrlp_alltags, alltags)
|
|
|
|
endfo
|
2012-04-06 22:01:06 -04:00
|
|
|
cal s:syntax()
|
2011-12-01 00:59:14 -05:00
|
|
|
retu g:ctrlp_alltags
|
2011-11-28 07:52:28 -05:00
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#tag#accept(mode, str)
|
|
|
|
cal ctrlp#exit()
|
2011-12-01 00:59:14 -05:00
|
|
|
let str = matchstr(a:str, '^[^\t]\+\t\+[^\t]\+\ze\t')
|
2012-02-20 02:58:03 -05:00
|
|
|
let [tg, fnd] = [split(str, '^[^\t]\+\zs\t')[0], s:findcount(str)]
|
2011-12-13 09:42:57 -05:00
|
|
|
let cmds = {
|
2012-01-17 11:13:39 -05:00
|
|
|
\ 't': ['tab sp', 'tab stj'],
|
|
|
|
\ 'h': ['sp', 'stj'],
|
|
|
|
\ 'v': ['vs', 'vert stj'],
|
|
|
|
\ 'e': ['', 'tj'],
|
2011-12-13 09:42:57 -05:00
|
|
|
\ }
|
2012-02-20 02:58:03 -05:00
|
|
|
let cmd = fnd[0] == 1 ? cmds[a:mode][0] : cmds[a:mode][1]
|
2012-08-30 22:28:09 -04:00
|
|
|
let cmd = a:mode == 'e' && ctrlp#modfilecond() && !&aw
|
|
|
|
\ ? ( cmd == 'tj' ? 'stj' : 'sp' ) : cmd
|
2012-07-13 07:06:32 -04:00
|
|
|
let cmd = a:mode == 't' ? ctrlp#tabcount().cmd : cmd
|
2012-02-01 15:18:04 -05:00
|
|
|
if fnd[0] == 1
|
|
|
|
if cmd != ''
|
2012-02-12 06:50:15 -05:00
|
|
|
exe cmd
|
2011-11-30 10:13:37 -05:00
|
|
|
en
|
2012-02-09 08:58:11 -05:00
|
|
|
exe fnd[1].'ta' tg
|
2012-02-01 15:18:04 -05:00
|
|
|
el
|
2012-02-12 06:50:15 -05:00
|
|
|
exe cmd tg
|
2012-02-01 15:18:04 -05:00
|
|
|
en
|
2012-03-03 10:31:50 -05:00
|
|
|
cal ctrlp#setlcdir()
|
2011-11-28 07:52:28 -05:00
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#tag#id()
|
|
|
|
retu s:id
|
|
|
|
endf
|
2012-03-28 21:53:00 -04:00
|
|
|
|
|
|
|
fu! ctrlp#tag#enter()
|
2012-03-31 01:11:36 -04:00
|
|
|
let tfs = tagfiles()
|
|
|
|
let s:tagfiles = tfs != [] ? filter(map(tfs, 'fnamemodify(v:val, ":p")'),
|
|
|
|
\ 'filereadable(v:val)') : []
|
2012-03-28 21:53:00 -04:00
|
|
|
endf
|
2011-11-28 07:52:28 -05:00
|
|
|
"}}}
|
|
|
|
|
2011-12-02 22:54:18 -05:00
|
|
|
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|