comparison vendor/vim-packs/ctrlp.vim/autoload/ctrlp/line.vim @ 707:4576f1471f53

[update-vendor, vim] add ctrlp
author nanaya <me@nanaya.net>
date Sun, 18 Dec 2022 22:27:56 +0900
parents
children
comparison
equal deleted inserted replaced
706:4b30df382167 707:4576f1471f53
1 " =============================================================================
2 " File: autoload/ctrlp/line.vim
3 " Description: Line extension
4 " Author: Kien Nguyen <github.com/kien>
5 " =============================================================================
6
7 " Init {{{1
8 if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
9 fini
10 en
11 let g:loaded_ctrlp_line = 1
12
13 cal add(g:ctrlp_ext_vars, {
14 \ 'init': 'ctrlp#line#init(s:crbufnr)',
15 \ 'accept': 'ctrlp#line#accept',
16 \ 'act_farg' : 'dict',
17 \ 'lname': 'lines',
18 \ 'sname': 'lns',
19 \ 'type': 'tabe',
20 \ })
21
22 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
23 " Utilities {{{1
24 fu! s:syntax()
25 if !ctrlp#nosy()
26 cal ctrlp#hicheck('CtrlPBufName', 'Directory')
27 cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
28 sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$'
29 sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
30 en
31 endf
32 " Public {{{1
33 fu! ctrlp#line#init(bufnr)
34 let [lines, bufnr] = [[], exists('s:bufnr') ? s:bufnr : a:bufnr]
35 let bufs = exists('s:lnmode') && !empty(s:lnmode) ? ctrlp#buffers('id') : [bufnr]
36 for bufnr in bufs
37 let [lfb, bufn] = [getbufline(bufnr, 1, '$'), bufname(bufnr)]
38 if lfb == [] && bufn != ''
39 let lfb = ctrlp#utils#readfile(fnamemodify(bufn, ':p'))
40 en
41 cal map(lfb, 'tr(v:val, '' '', '' '')')
42 let [linenr, len_lfb] = [1, len(lfb)]
43 let buft = bufn == '' ? '[No Name]' : fnamemodify(bufn, ':t')
44 wh linenr <= len_lfb
45 let lfb[linenr - 1] .= ' |'.buft.'|'.bufnr.':'.linenr.'|'
46 let linenr += 1
47 endw
48 cal extend(lines, filter(lfb, 'v:val !~ ''^\s*\t|[^|]\+|\d\+:\d\+|$'''))
49 endfo
50 cal s:syntax()
51 retu lines
52 endf
53
54 fu! ctrlp#line#accept(dict)
55 let mode = a:dict['action']
56 let str = a:dict['line']
57 let input = a:dict['input']
58 let info = matchlist(str, '\t|[^|]\+|\(\d\+\):\(\d\+\)|$')
59 let bufnr = str2nr(get(info, 1))
60 if bufnr
61 cal ctrlp#acceptfile(mode, bufnr, get(info, 2))
62 if !empty(input)
63 let @/ = input
64 call search(input, 'c')
65 call histadd("search", input)
66 en
67 en
68 endf
69
70 fu! ctrlp#line#cmd(mode, ...)
71 let s:lnmode = a:mode
72 if a:0 && !empty(a:1)
73 let s:lnmode = 0
74 let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1
75 let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$')
76 en
77 retu s:id
78 endf
79 "}}}
80
81 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2