2011-12-21 06:58:08 -05:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/buffertag.vim
|
|
|
|
" Description: Buffer Tag extension
|
|
|
|
" Maintainer: Kien Nguyen <github.com/kien>
|
2012-01-06 01:22:55 -05:00
|
|
|
" Credits: Much of the code was taken from tagbar.vim by Jan Larres, plus
|
|
|
|
" a few lines from taglist.vim by Yegappan Lakshmanan and from
|
|
|
|
" buffertag.vim by Takeshi Nishida.
|
2011-12-21 06:58:08 -05:00
|
|
|
" =============================================================================
|
|
|
|
|
|
|
|
" Init {{{1
|
|
|
|
if exists('g:loaded_ctrlp_buftag') && g:loaded_ctrlp_buftag
|
|
|
|
fini
|
|
|
|
en
|
|
|
|
let g:loaded_ctrlp_buftag = 1
|
|
|
|
|
2012-04-07 07:55:23 -04:00
|
|
|
cal add(g:ctrlp_ext_vars, {
|
2012-01-15 12:42:14 -05:00
|
|
|
\ 'init': 'ctrlp#buffertag#init(s:crfile)',
|
|
|
|
\ 'accept': 'ctrlp#buffertag#accept',
|
|
|
|
\ 'lname': 'buffer tags',
|
|
|
|
\ 'sname': 'bft',
|
|
|
|
\ 'exit': 'ctrlp#buffertag#exit()',
|
|
|
|
\ 'type': 'tabs',
|
2012-03-16 12:30:49 -04:00
|
|
|
\ 'opts': 'ctrlp#buffertag#opts()',
|
2012-04-07 07:55:23 -04:00
|
|
|
\ })
|
2011-12-21 06:58:08 -05:00
|
|
|
|
|
|
|
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
|
|
|
|
2012-04-21 21:42:05 -04:00
|
|
|
let [s:pref, s:opts] = ['g:ctrlp_buftag_', {
|
|
|
|
\ 'systemenc': ['s:enc', &enc],
|
|
|
|
\ 'ctags_bin': ['s:bin', ''],
|
|
|
|
\ 'types': ['s:usr_types', {}],
|
|
|
|
\ }]
|
|
|
|
|
2012-04-21 15:08:18 -04:00
|
|
|
let s:bins = [
|
|
|
|
\ 'ctags-exuberant',
|
|
|
|
\ 'exuberant-ctags',
|
|
|
|
\ 'exctags',
|
|
|
|
\ '/usr/local/bin/ctags',
|
|
|
|
\ '/opt/local/bin/ctags',
|
|
|
|
\ 'ctags',
|
|
|
|
\ 'ctags.exe',
|
|
|
|
\ 'tags',
|
|
|
|
\ ]
|
2011-12-21 06:58:08 -05:00
|
|
|
|
|
|
|
let s:types = {
|
2011-12-22 03:30:59 -05:00
|
|
|
\ 'asm' : '%sasm%sasm%sdlmt',
|
|
|
|
\ 'aspperl': '%sasp%sasp%sfsv',
|
|
|
|
\ 'aspvbs' : '%sasp%sasp%sfsv',
|
|
|
|
\ 'awk' : '%sawk%sawk%sf',
|
|
|
|
\ 'beta' : '%sbeta%sbeta%sfsv',
|
|
|
|
\ 'c' : '%sc%sc%sdgsutvf',
|
|
|
|
\ 'cpp' : '%sc++%sc++%snvdtcgsuf',
|
|
|
|
\ 'cs' : '%sc#%sc#%sdtncEgsipm',
|
|
|
|
\ 'cobol' : '%scobol%scobol%sdfgpPs',
|
|
|
|
\ 'eiffel' : '%seiffel%seiffel%scf',
|
|
|
|
\ 'erlang' : '%serlang%serlang%sdrmf',
|
|
|
|
\ 'expect' : '%stcl%stcl%scfp',
|
|
|
|
\ 'fortran': '%sfortran%sfortran%spbceiklmntvfs',
|
|
|
|
\ 'html' : '%shtml%shtml%saf',
|
|
|
|
\ 'java' : '%sjava%sjava%spcifm',
|
|
|
|
\ 'javascript': '%sjavascript%sjavascript%sf',
|
|
|
|
\ 'lisp' : '%slisp%slisp%sf',
|
|
|
|
\ 'lua' : '%slua%slua%sf',
|
|
|
|
\ 'make' : '%smake%smake%sm',
|
|
|
|
\ 'pascal' : '%spascal%spascal%sfp',
|
|
|
|
\ 'perl' : '%sperl%sperl%sclps',
|
|
|
|
\ 'php' : '%sphp%sphp%scdvf',
|
|
|
|
\ 'python' : '%spython%spython%scmf',
|
|
|
|
\ 'rexx' : '%srexx%srexx%ss',
|
|
|
|
\ 'ruby' : '%sruby%sruby%scfFm',
|
|
|
|
\ 'scheme' : '%sscheme%sscheme%ssf',
|
|
|
|
\ 'sh' : '%ssh%ssh%sf',
|
|
|
|
\ 'csh' : '%ssh%ssh%sf',
|
|
|
|
\ 'zsh' : '%ssh%ssh%sf',
|
|
|
|
\ 'slang' : '%sslang%sslang%snf',
|
|
|
|
\ 'sml' : '%ssml%ssml%secsrtvf',
|
|
|
|
\ 'sql' : '%ssql%ssql%scFPrstTvfp',
|
|
|
|
\ 'tcl' : '%stcl%stcl%scfmp',
|
|
|
|
\ 'vera' : '%svera%svera%scdefgmpPtTvx',
|
|
|
|
\ 'verilog': '%sverilog%sverilog%smcPertwpvf',
|
|
|
|
\ 'vim' : '%svim%svim%savf',
|
|
|
|
\ 'yacc' : '%syacc%syacc%sl',
|
2011-12-21 06:58:08 -05:00
|
|
|
\ }
|
|
|
|
|
2011-12-22 03:30:59 -05:00
|
|
|
cal map(s:types, 'printf(v:val, "--language-force=", " --", "-types=")')
|
|
|
|
|
2011-12-21 06:58:08 -05:00
|
|
|
if executable('jsctags')
|
|
|
|
cal extend(s:types, { 'javascript': { 'args': '-f -', 'bin': 'jsctags' } })
|
|
|
|
en
|
|
|
|
|
2012-04-21 15:08:18 -04:00
|
|
|
fu! ctrlp#buffertag#opts()
|
2012-04-21 21:42:05 -04:00
|
|
|
for [ke, va] in items(s:opts)
|
|
|
|
let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1]
|
2012-04-21 15:08:18 -04:00
|
|
|
endfo
|
|
|
|
" Ctags bin
|
|
|
|
if empty(s:bin)
|
|
|
|
for bin in s:bins | if executable(bin)
|
|
|
|
let s:bin = bin
|
|
|
|
brea
|
|
|
|
en | endfo
|
|
|
|
el
|
|
|
|
let s:bin = expand(s:bin, 1)
|
|
|
|
en
|
|
|
|
" Types
|
2011-12-21 06:58:08 -05:00
|
|
|
cal extend(s:types, s:usr_types)
|
2012-04-21 15:08:18 -04:00
|
|
|
endf
|
2011-12-21 06:58:08 -05:00
|
|
|
" Utilities {{{1
|
|
|
|
fu! s:validfile(fname, ftype)
|
|
|
|
if ( !empty(a:fname) || !empty(a:ftype) ) && filereadable(a:fname)
|
|
|
|
\ && index(keys(s:types), a:ftype) >= 0 | retu 1 | en
|
|
|
|
retu 0
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:exectags(cmd)
|
|
|
|
if exists('+ssl')
|
|
|
|
let [ssl, &ssl] = [&ssl, 0]
|
|
|
|
en
|
|
|
|
if &sh =~ 'cmd\.exe'
|
|
|
|
let [sxq, &sxq, shcf, &shcf] = [&sxq, '"', &shcf, '/s /c']
|
|
|
|
en
|
|
|
|
let output = system(a:cmd)
|
|
|
|
if &sh =~ 'cmd\.exe'
|
|
|
|
let [&sxq, &shcf] = [sxq, shcf]
|
|
|
|
en
|
|
|
|
if exists('+ssl')
|
|
|
|
let &ssl = ssl
|
|
|
|
en
|
|
|
|
retu output
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:exectagsonfile(fname, ftype)
|
2011-12-22 03:30:59 -05:00
|
|
|
let [ags, ft] = ['-f - --sort=no --excmd=pattern --fields=nKs ', a:ftype]
|
|
|
|
if type(s:types[ft]) == 1
|
|
|
|
let ags .= s:types[ft]
|
2011-12-21 06:58:08 -05:00
|
|
|
let bin = s:bin
|
2011-12-22 03:30:59 -05:00
|
|
|
elsei type(s:types[ft]) == 4
|
|
|
|
let ags = s:types[ft]['args']
|
|
|
|
let bin = expand(s:types[ft]['bin'], 1)
|
2011-12-21 06:58:08 -05:00
|
|
|
en
|
|
|
|
if empty(bin) | retu '' | en
|
2011-12-22 03:30:59 -05:00
|
|
|
let cmd = s:esctagscmd(bin, ags, a:fname)
|
2011-12-21 06:58:08 -05:00
|
|
|
if empty(cmd) | retu '' | en
|
|
|
|
let output = s:exectags(cmd)
|
|
|
|
if v:shell_error || output =~ 'Warning: cannot open' | retu '' | en
|
|
|
|
retu output
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:esctagscmd(bin, args, ...)
|
|
|
|
if exists('+ssl')
|
|
|
|
let [ssl, &ssl] = [&ssl, 0]
|
|
|
|
en
|
2012-09-13 19:18:11 -04:00
|
|
|
let fname = a:0 ? shellescape(a:1) : ''
|
2011-12-21 06:58:08 -05:00
|
|
|
let cmd = shellescape(a:bin).' '.a:args.' '.fname
|
2012-09-13 19:18:11 -04:00
|
|
|
if &sh =~ 'cmd\.exe'
|
|
|
|
let cmd = substitute(cmd, '[&()@^<>|]', '^\0', 'g')
|
|
|
|
en
|
2011-12-21 06:58:08 -05:00
|
|
|
if exists('+ssl')
|
|
|
|
let &ssl = ssl
|
|
|
|
en
|
|
|
|
if has('iconv')
|
2012-12-20 20:48:12 -05:00
|
|
|
let last = s:enc != &enc ? s:enc : !empty( $LANG ) ? $LANG : &enc
|
2011-12-22 03:30:59 -05:00
|
|
|
let cmd = iconv(cmd, &enc, last)
|
2011-12-21 06:58:08 -05:00
|
|
|
en
|
|
|
|
retu cmd
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:process(fname, ftype)
|
|
|
|
if !s:validfile(a:fname, a:ftype) | retu [] | endif
|
|
|
|
let ftime = getftime(a:fname)
|
|
|
|
if has_key(g:ctrlp_buftags, a:fname)
|
|
|
|
\ && g:ctrlp_buftags[a:fname]['time'] >= ftime
|
2012-01-06 01:22:55 -05:00
|
|
|
let lines = g:ctrlp_buftags[a:fname]['lines']
|
2011-12-21 06:58:08 -05:00
|
|
|
el
|
|
|
|
let data = s:exectagsonfile(a:fname, a:ftype)
|
2012-01-06 01:22:55 -05:00
|
|
|
let [raw, lines] = [split(data, '\n\+'), []]
|
2012-08-17 22:50:13 -04:00
|
|
|
for line in raw
|
|
|
|
if line !~# '^!_TAG_' && len(split(line, ';"')) == 2
|
|
|
|
let parsed_line = s:parseline(line)
|
|
|
|
if parsed_line != ''
|
|
|
|
cal add(lines, parsed_line)
|
|
|
|
en
|
2012-01-21 23:48:44 -05:00
|
|
|
en
|
2012-08-17 22:50:13 -04:00
|
|
|
endfo
|
2012-01-06 01:22:55 -05:00
|
|
|
let cache = { a:fname : { 'time': ftime, 'lines': lines } }
|
2011-12-21 06:58:08 -05:00
|
|
|
cal extend(g:ctrlp_buftags, cache)
|
|
|
|
en
|
|
|
|
retu lines
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! s:parseline(line)
|
2012-09-06 08:44:37 -04:00
|
|
|
let vals = matchlist(a:line,
|
|
|
|
\ '\v^([^\t]+)\t(.+)\t[?/]\^?(.{-1,})\$?[?/]\;\"\t(.+)\tline(no)?\:(\d+)')
|
2012-04-16 00:40:21 -04:00
|
|
|
if vals == [] | retu '' | en
|
2012-02-01 06:08:06 -05:00
|
|
|
let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]
|
2012-01-06 01:22:55 -05:00
|
|
|
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
|
2011-12-21 06:58:08 -05:00
|
|
|
endf
|
2012-03-13 05:20:56 -04:00
|
|
|
|
|
|
|
fu! s:syntax()
|
2012-04-07 07:55:23 -04:00
|
|
|
if !ctrlp#nosy()
|
|
|
|
cal ctrlp#hicheck('CtrlPTagKind', 'Title')
|
|
|
|
cal ctrlp#hicheck('CtrlPBufName', 'Directory')
|
|
|
|
cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
|
|
|
|
sy match CtrlPTagKind '\zs[^\t|]\+\ze|\d\+:[^|]\+|\d\+|'
|
|
|
|
sy match CtrlPBufName '|\d\+:\zs[^|]\+\ze|\d\+|'
|
|
|
|
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName,CtrlPTagKind
|
|
|
|
en
|
2012-03-13 05:20:56 -04:00
|
|
|
endf
|
2012-09-15 01:03:53 -04:00
|
|
|
|
|
|
|
fu! s:chknearby(pat)
|
|
|
|
if match(getline('.'), a:pat) < 0
|
|
|
|
let [int, forw, maxl] = [1, 1, line('$')]
|
|
|
|
wh !search(a:pat, 'W'.( forw ? '' : 'b' ))
|
|
|
|
if !forw
|
|
|
|
if int > maxl | brea | en
|
|
|
|
let int += int
|
|
|
|
en
|
|
|
|
let forw = !forw
|
|
|
|
endw
|
|
|
|
en
|
|
|
|
endf
|
2011-12-21 06:58:08 -05:00
|
|
|
" Public {{{1
|
2012-01-06 01:22:55 -05:00
|
|
|
fu! ctrlp#buffertag#init(fname)
|
2012-03-09 18:49:16 -05:00
|
|
|
let bufs = exists('s:btmode') && s:btmode
|
|
|
|
\ ? filter(ctrlp#buffers(), 'filereadable(v:val)')
|
|
|
|
\ : [exists('s:bufname') ? s:bufname : a:fname]
|
2012-01-06 01:22:55 -05:00
|
|
|
let lines = []
|
|
|
|
for each in bufs
|
2012-03-14 22:52:10 -04:00
|
|
|
let bname = fnamemodify(each, ':p')
|
2012-08-14 06:58:43 -04:00
|
|
|
let tftype = get(split(getbufvar('^'.bname.'$', '&ft'), '\.'), 0, '')
|
2012-03-14 22:52:10 -04:00
|
|
|
cal extend(lines, s:process(bname, tftype))
|
2012-01-06 01:22:55 -05:00
|
|
|
endfo
|
2012-04-06 22:01:06 -04:00
|
|
|
cal s:syntax()
|
2012-01-06 01:22:55 -05:00
|
|
|
retu lines
|
2011-12-21 06:58:08 -05:00
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#buffertag#accept(mode, str)
|
2012-09-06 08:44:37 -04:00
|
|
|
let vals = matchlist(a:str,
|
|
|
|
\ '\v^[^\t]+\t+[^\t|]+\|(\d+)\:[^\t|]+\|(\d+)\|\s(.+)$')
|
2012-07-12 04:10:52 -04:00
|
|
|
let bufnr = str2nr(get(vals, 1))
|
|
|
|
if bufnr
|
2013-03-26 00:10:15 -04:00
|
|
|
cal ctrlp#acceptfile(a:mode, bufnr)
|
2012-09-06 08:44:37 -04:00
|
|
|
exe 'norm!' str2nr(get(vals, 2, line('.'))).'G'
|
2012-09-15 01:03:53 -04:00
|
|
|
cal s:chknearby('\V\C'.get(vals, 3, ''))
|
2012-09-06 08:44:37 -04:00
|
|
|
sil! norm! zvzz
|
2012-07-12 04:10:52 -04:00
|
|
|
en
|
2011-12-21 06:58:08 -05:00
|
|
|
endf
|
|
|
|
|
2012-01-06 01:22:55 -05:00
|
|
|
fu! ctrlp#buffertag#cmd(mode, ...)
|
|
|
|
let s:btmode = a:mode
|
|
|
|
if a:0 && !empty(a:1)
|
|
|
|
let s:bufname = fnamemodify(a:1, ':p')
|
|
|
|
en
|
2011-12-21 06:58:08 -05:00
|
|
|
retu s:id
|
|
|
|
endf
|
2012-01-06 01:22:55 -05:00
|
|
|
|
|
|
|
fu! ctrlp#buffertag#exit()
|
|
|
|
unl! s:btmode s:bufname
|
|
|
|
endf
|
2011-12-21 06:58:08 -05:00
|
|
|
"}}}
|
|
|
|
|
|
|
|
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|