707
|
1 " =============================================================================
|
|
2 " File: autoload/ctrlp/changes.vim
|
|
3 " Description: Change list extension
|
|
4 " Author: Kien Nguyen <github.com/kien>
|
|
5 " =============================================================================
|
|
6
|
|
7 " Init {{{1
|
|
8 if exists('g:loaded_ctrlp_changes') && g:loaded_ctrlp_changes
|
|
9 fini
|
|
10 en
|
|
11 let g:loaded_ctrlp_changes = 1
|
|
12
|
|
13 cal add(g:ctrlp_ext_vars, {
|
|
14 \ 'init': 'ctrlp#changes#init(s:bufnr, s:crbufnr)',
|
|
15 \ 'accept': 'ctrlp#changes#accept',
|
|
16 \ 'lname': 'changes',
|
|
17 \ 'sname': 'chs',
|
|
18 \ 'exit': 'ctrlp#changes#exit()',
|
|
19 \ 'type': 'tabe',
|
|
20 \ 'sort': 0,
|
|
21 \ 'nolim': 1,
|
|
22 \ })
|
|
23
|
|
24 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
|
|
25 " Utilities {{{1
|
|
26 fu! s:changelist(bufnr)
|
|
27 sil! exe 'noa hid b' a:bufnr
|
|
28 redi => result
|
|
29 sil! changes
|
|
30 redi END
|
|
31 retu map(split(result, "\n")[1:], 'tr(v:val, " ", " ")')
|
|
32 endf
|
|
33
|
|
34 fu! s:process(clines, ...)
|
|
35 let [clines, evas] = [[], []]
|
|
36 for each in a:clines
|
|
37 let parts = matchlist(each, '\v^.\s*\d+\s+(\d+)\s+(\d+)\s(.*)$')
|
|
38 if !empty(parts)
|
|
39 if parts[3] == '' | let parts[3] = ' ' | en
|
|
40 cal add(clines, parts[3].' |'.a:1.':'.a:2.'|'.parts[1].':'.parts[2].'|')
|
|
41 en
|
|
42 endfo
|
|
43 retu reverse(filter(clines, 'count(clines, v:val) == 1'))
|
|
44 endf
|
|
45
|
|
46 fu! s:syntax()
|
|
47 if !ctrlp#nosy()
|
|
48 cal ctrlp#hicheck('CtrlPBufName', 'Directory')
|
|
49 cal ctrlp#hicheck('CtrlPTabExtra', 'Comment')
|
|
50 sy match CtrlPBufName '\t|\d\+:\zs[^|]\+\ze|\d\+:\d\+|$'
|
|
51 sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
|
|
52 en
|
|
53 endf
|
|
54 " Public {{{1
|
|
55 fu! ctrlp#changes#init(original_bufnr, bufnr)
|
|
56 let bufnr = exists('s:bufnr') ? s:bufnr : a:bufnr
|
|
57 let bufs = exists('s:clmode') && s:clmode ? ctrlp#buffers('id') : [bufnr]
|
|
58 cal filter(bufs, 'v:val > 0')
|
|
59 let [swb, &swb] = [&swb, '']
|
|
60 let lines = []
|
|
61 for each in bufs
|
|
62 let bname = bufname(each)
|
|
63 let fnamet = fnamemodify(bname == '' ? '[No Name]' : bname, ':t')
|
|
64 cal extend(lines, s:process(s:changelist(each), each, fnamet))
|
|
65 endfo
|
|
66 sil! exe 'noa hid b' a:original_bufnr
|
|
67 let &swb = swb
|
|
68 cal ctrlp#syntax()
|
|
69 cal s:syntax()
|
|
70 retu lines
|
|
71 endf
|
|
72
|
|
73 fu! ctrlp#changes#accept(mode, str)
|
|
74 let info = matchlist(a:str, '\t|\(\d\+\):[^|]\+|\(\d\+\):\(\d\+\)|$')
|
|
75 let bufnr = str2nr(get(info, 1))
|
|
76 if bufnr
|
|
77 cal ctrlp#acceptfile(a:mode, bufnr)
|
|
78 cal cursor(get(info, 2), get(info, 3))
|
|
79 sil! norm! zvzz
|
|
80 en
|
|
81 endf
|
|
82
|
|
83 fu! ctrlp#changes#cmd(mode, ...)
|
|
84 let s:clmode = a:mode
|
|
85 if a:0 && !empty(a:1)
|
|
86 let s:clmode = 0
|
|
87 let bname = a:1 =~# '^%$\|^#\d*$' ? expand(a:1) : a:1
|
|
88 let s:bufnr = bufnr('^'.fnamemodify(bname, ':p').'$')
|
|
89 en
|
|
90 retu s:id
|
|
91 endf
|
|
92
|
|
93 fu! ctrlp#changes#exit()
|
|
94 unl! s:clmode s:bufnr
|
|
95 endf
|
|
96 "}}}
|
|
97
|
|
98 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|