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
|
|
|
|
2011-11-29 06:05:25 -05:00
|
|
|
let s:tag_var = ['ctrlp#tag#init(s:tagfiles)', 'ctrlp#tag#accept',
|
2011-11-28 19:12:58 -05:00
|
|
|
\ 'tags', 'tag']
|
2011-11-28 07:52:28 -05:00
|
|
|
|
|
|
|
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]
|
|
|
|
|
|
|
|
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:nodup(items)
|
2011-11-29 06:05:25 -05:00
|
|
|
let dict = {}
|
2011-11-30 10:13:37 -05:00
|
|
|
for each in a:items
|
|
|
|
cal extend(dict, { each : 0 })
|
|
|
|
endfo
|
2011-11-29 06:05:25 -05:00
|
|
|
retu keys(dict)
|
|
|
|
endf
|
2011-11-29 22:28:14 -05:00
|
|
|
|
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]\+$')
|
|
|
|
let [&l:tags, fname] = [s:ltags, expand(fname, 1)]
|
|
|
|
let tgs = taglist('^'.tg.'$')
|
2011-12-02 22:54:18 -05:00
|
|
|
if empty(tgs) | retu [1, 1] | en
|
2011-12-01 00:59:14 -05:00
|
|
|
let [fnd, ct, pos] = [0, 0, 0]
|
|
|
|
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-02 22:54:18 -05:00
|
|
|
" Public {{{1
|
2011-11-29 06:05:25 -05:00
|
|
|
fu! ctrlp#tag#init(tagfiles)
|
|
|
|
if empty(a:tagfiles) | retu [] | en
|
|
|
|
let tagfiles = sort(s:nodup(a:tagfiles))
|
2011-11-30 10:13:37 -05:00
|
|
|
let s:ltags = join(tagfiles, ',')
|
2011-12-01 00:59:14 -05:00
|
|
|
let g:ctrlp_alltags = []
|
|
|
|
for each in tagfiles
|
|
|
|
let alltags = ctrlp#utils#readfile(each)
|
|
|
|
cal extend(g:ctrlp_alltags, alltags)
|
|
|
|
endfo
|
2011-12-13 09:42:57 -05:00
|
|
|
sy match CtrlPTabExtra '\zs\t.*\ze$'
|
|
|
|
hi link CtrlPTabExtra Comment
|
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')
|
|
|
|
let [md, tg] = [a:mode, split(str, '^[^\t]\+\zs\t')[0]]
|
|
|
|
let fnd = s:findcount(str)
|
2011-12-13 09:42:57 -05:00
|
|
|
let cmds = {
|
|
|
|
\ 't': ['tabe', 'tab stj'],
|
|
|
|
\ 'h': ['new', 'stj'],
|
|
|
|
\ 'v': ['vne', 'vert stj'],
|
|
|
|
\ 'e': ['ene', 'tj'],
|
|
|
|
\ }
|
|
|
|
let cmd = fnd[0] == 1 ? cmds[md][0] : cmds[md][1]
|
2011-11-30 10:13:37 -05:00
|
|
|
let cmd = cmd =~ 'tj\|ene' && &modified ? 'hid '.cmd : cmd
|
2011-11-28 07:52:28 -05:00
|
|
|
try
|
2011-11-30 10:13:37 -05:00
|
|
|
if fnd[0] == 1
|
|
|
|
exe cmd
|
|
|
|
let &l:tags = s:ltags
|
|
|
|
exe fnd[1].'ta' tg
|
|
|
|
el
|
|
|
|
exe cmd.' '.tg
|
|
|
|
en
|
2011-11-28 07:52:28 -05:00
|
|
|
cat
|
|
|
|
cal ctrlp#msg("Tag not found.")
|
|
|
|
endt
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#tag#id()
|
|
|
|
retu s:id
|
|
|
|
endf
|
|
|
|
"}}}
|
|
|
|
|
2011-12-02 22:54:18 -05:00
|
|
|
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|