2011-12-13 09:42:57 -05:00
|
|
|
" =============================================================================
|
|
|
|
" File: autoload/ctrlp/line.vim
|
2012-03-12 04:34:40 -04:00
|
|
|
" Description: Line extension
|
2011-12-13 09:42:57 -05:00
|
|
|
" Author: Kien Nguyen <github.com/kien>
|
|
|
|
" =============================================================================
|
|
|
|
|
|
|
|
" Init {{{1
|
|
|
|
if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
|
|
|
|
fini
|
|
|
|
en
|
|
|
|
let g:loaded_ctrlp_line = 1
|
|
|
|
|
2012-01-15 12:42:14 -05:00
|
|
|
let s:line_var = {
|
|
|
|
\ 'init': 'ctrlp#line#init()',
|
|
|
|
\ 'accept': 'ctrlp#line#accept',
|
|
|
|
\ 'lname': 'lines',
|
|
|
|
\ 'sname': 'lns',
|
|
|
|
\ 'type': 'tabe',
|
|
|
|
\ }
|
2011-12-13 09:42:57 -05:00
|
|
|
|
|
|
|
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
|
|
|
|
\ ? add(g:ctrlp_ext_vars, s:line_var) : [s:line_var]
|
|
|
|
|
|
|
|
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
2012-03-12 04:34:40 -04:00
|
|
|
" Utilities {{{1
|
|
|
|
fu! s:syntax()
|
|
|
|
if !hlexists('CtrlPBufName')
|
|
|
|
hi link CtrlPBufName Directory
|
|
|
|
en
|
|
|
|
if !hlexists('CtrlPTabExtra')
|
|
|
|
hi link CtrlPTabExtra Comment
|
|
|
|
en
|
|
|
|
sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$'
|
|
|
|
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
|
|
|
|
endf
|
2011-12-13 09:42:57 -05:00
|
|
|
" Public {{{1
|
|
|
|
fu! ctrlp#line#init()
|
2012-03-09 18:49:16 -05:00
|
|
|
let [bufs, lines] = [filter(ctrlp#buffers(), 'filereadable(v:val)'), []]
|
2011-12-13 09:42:57 -05:00
|
|
|
for each in bufs
|
2012-03-09 18:49:16 -05:00
|
|
|
let [fnamet, from_file] = [fnamemodify(each, ':t'), readfile(each)]
|
2011-12-13 09:42:57 -05:00
|
|
|
cal map(from_file, 'tr(v:val, '' '', '' '')')
|
2012-02-01 06:08:06 -05:00
|
|
|
let [id, len_ff, bufnr] = [1, len(from_file), bufnr('^'.each.'$')]
|
2011-12-13 09:42:57 -05:00
|
|
|
wh id <= len_ff
|
2012-03-09 18:49:16 -05:00
|
|
|
let from_file[id-1] .= ' |'.fnamet.'|'.bufnr.':'.id.'|'
|
2011-12-13 09:42:57 -05:00
|
|
|
let id += 1
|
|
|
|
endw
|
2012-03-09 18:49:16 -05:00
|
|
|
cal filter(from_file, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$''')
|
2011-12-13 09:42:57 -05:00
|
|
|
cal extend(lines, from_file)
|
|
|
|
endfo
|
2012-03-09 18:49:16 -05:00
|
|
|
if has('syntax') && exists('g:syntax_on')
|
2012-03-12 04:34:40 -04:00
|
|
|
cal s:syntax()
|
2012-02-05 04:13:52 -05:00
|
|
|
en
|
2011-12-13 09:42:57 -05:00
|
|
|
retu lines
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#line#accept(mode, str)
|
2012-03-09 18:49:16 -05:00
|
|
|
let info = matchlist(a:str, '\t|[^|]\+|\(\d\+\):\(\d\+\)|$')
|
|
|
|
let [bufnr, linenr] = [str2nr(get(info, 1)), get(info, 2)]
|
|
|
|
if bufnr > 0
|
2011-12-13 09:42:57 -05:00
|
|
|
cal ctrlp#acceptfile(a:mode, fnamemodify(bufname(bufnr), ':p'), linenr)
|
|
|
|
en
|
|
|
|
endf
|
|
|
|
|
|
|
|
fu! ctrlp#line#id()
|
|
|
|
retu s:id
|
|
|
|
endf
|
|
|
|
"}}}
|
|
|
|
|
|
|
|
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|