1
0
Fork 0
mirror of synced 2024-11-26 10:45:35 -05:00
ultimate-vim/sources_non_forked/ctrlp.vim/autoload/ctrlp/line.vim

82 lines
2.3 KiB
VimL
Raw Normal View History

2012-08-16 23:41:25 -04:00
" =============================================================================
" File: autoload/ctrlp/line.vim
" Description: Line extension
" 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
cal add(g:ctrlp_ext_vars, {
2013-07-17 19:06:05 -04:00
\ 'init': 'ctrlp#line#init(s:crbufnr)',
2012-08-16 23:41:25 -04:00
\ 'accept': 'ctrlp#line#accept',
2017-07-06 08:57:35 -04:00
\ 'act_farg' : 'dict',
2012-08-16 23:41:25 -04:00
\ 'lname': 'lines',
\ 'sname': 'lns',
\ 'type': 'tabe',
\ })
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:syntax()
if !ctrlp#nosy()
cal ctrlp#hicheck('CtrlPBufName', 'Directory')
cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
en
endf
" Public {{{1
2013-07-17 19:06:05 -04:00
fu! ctrlp#line#init(bufnr)
let [lines, bufnr] = [[], exists('s:bufnr') ? s:bufnr : a:bufnr]
2017-05-02 08:42:08 -04:00
let bufs = exists('s:lnmode') && !empty(s:lnmode) ? ctrlp#buffers('id') : [bufnr]
2012-08-16 23:41:25 -04:00
for bufnr in bufs
let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)]
if lfb == [] && bufn != ''
let lfb = ctrlp#utils#readfile(fnamemodify(bufn, ':p'))
en
2012-08-16 23:41:25 -04:00
cal map(lfb, 'tr(v:val, '' '', '' '')')
let [linenr, len_lfb] = [1, len(lfb)]
let buft = bufn == '' ? '[No Name]' : fnamemodify(bufn, ':t')
2012-08-16 23:41:25 -04:00
wh linenr <= len_lfb
let lfb[linenr - 1] .= ' |'.buft.'|'.bufnr.':'.linenr.'|'
let linenr += 1
endw
cal extend(lines, filter(lfb, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$'''))
endfo
cal s:syntax()
retu lines
endf
2017-07-06 08:57:35 -04:00
fu! ctrlp#line#accept(dict)
let mode = a:dict['action']
let str = a:dict['line']
let input = a:dict['input']
let info = matchlist(str, '\t|[^|]\+|\(\d\+\):\(\d\+\)|$')
2012-08-16 23:41:25 -04:00
let bufnr = str2nr(get(info, 1))
if bufnr
2017-07-06 08:57:35 -04:00
cal ctrlp#acceptfile(mode, bufnr, get(info, 2))
2018-02-04 06:35:08 -05:00
if !empty(input)
let @/ = input
call search(input, 'c')
call histadd("search", input)
en
2012-08-16 23:41:25 -04:00
en
endf
2013-07-17 19:06:05 -04:00
fu! ctrlp#line#cmd(mode, ...)
let s:lnmode = a:mode
if a:0 && !empty(a:1)
let s:lnmode = 0
let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1
let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$')
en
2012-08-16 23:41:25 -04:00
retu s:id
endf
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2