bgneal@7: " ============================================================================= bgneal@7: " File: autoload/ctrlp/changes.vim bgneal@7: " Description: Change list extension bgneal@7: " Author: Kien Nguyen bgneal@7: " ============================================================================= bgneal@7: bgneal@7: " Init {{{1 bgneal@7: if exists('g:loaded_ctrlp_changes') && g:loaded_ctrlp_changes bgneal@7: fini bgneal@7: en bgneal@7: let g:loaded_ctrlp_changes = 1 bgneal@7: bgneal@7: cal add(g:ctrlp_ext_vars, { bgneal@7: \ 'init': 'ctrlp#changes#init(s:bufnr, s:crbufnr)', bgneal@7: \ 'accept': 'ctrlp#changes#accept', bgneal@7: \ 'lname': 'changes', bgneal@7: \ 'sname': 'chs', bgneal@7: \ 'exit': 'ctrlp#changes#exit()', bgneal@7: \ 'type': 'tabe', bgneal@7: \ 'sort': 0, bgneal@7: \ 'nolim': 1, bgneal@7: \ }) bgneal@7: bgneal@7: let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) bgneal@7: " Utilities {{{1 bgneal@7: fu! s:changelist(bufnr) bgneal@7: sil! exe 'noa hid b' a:bufnr bgneal@7: redi => result bgneal@7: sil! changes bgneal@7: redi END bgneal@7: retu map(split(result, "\n")[1:], 'tr(v:val, " ", " ")') bgneal@7: endf bgneal@7: bgneal@7: fu! s:process(clines, ...) bgneal@7: let [clines, evas] = [[], []] bgneal@7: for each in a:clines bgneal@7: let parts = matchlist(each, '\v^.\s*\d+\s+(\d+)\s+(\d+)\s(.*)$') bgneal@7: if !empty(parts) bgneal@7: if parts[3] == '' | let parts[3] = ' ' | en bgneal@7: cal add(clines, parts[3].' |'.a:1.':'.a:2.'|'.parts[1].':'.parts[2].'|') bgneal@7: en bgneal@7: endfo bgneal@7: retu reverse(filter(clines, 'count(clines, v:val) == 1')) bgneal@7: endf bgneal@7: bgneal@7: fu! s:syntax() bgneal@7: if !ctrlp#nosy() bgneal@7: cal ctrlp#hicheck('CtrlPBufName', 'Directory') bgneal@7: cal ctrlp#hicheck('CtrlPTabExtra', 'Comment') bgneal@7: sy match CtrlPBufName '\t|\d\+:\zs[^|]\+\ze|\d\+:\d\+|$' bgneal@7: sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName bgneal@7: en bgneal@7: endf bgneal@7: " Public {{{1 bgneal@7: fu! ctrlp#changes#init(original_bufnr, bufnr) bgneal@7: let bufnr = exists('s:bufnr') ? s:bufnr : a:bufnr bgneal@7: let bufs = exists('s:clmode') && s:clmode ? ctrlp#buffers('id') : [bufnr] bgneal@7: cal filter(bufs, 'v:val > 0') bgneal@7: let [swb, &swb] = [&swb, ''] bgneal@7: let lines = [] bgneal@7: for each in bufs bgneal@7: let fnamet = fnamemodify(bufname(each), ':t') bgneal@7: cal extend(lines, s:process(s:changelist(each), each, fnamet)) bgneal@7: endfo bgneal@7: sil! exe 'noa hid b' a:original_bufnr bgneal@7: let &swb = swb bgneal@7: cal ctrlp#syntax() bgneal@7: cal s:syntax() bgneal@7: retu lines bgneal@7: endf bgneal@7: bgneal@7: fu! ctrlp#changes#accept(mode, str) bgneal@7: let info = matchlist(a:str, '\t|\(\d\+\):[^|]\+|\(\d\+\):\(\d\+\)|$') bgneal@7: if info == [] | retu | en bgneal@7: let bufnr = str2nr(get(info, 1)) bgneal@7: if bufnr bgneal@7: cal ctrlp#acceptfile(a:mode, fnamemodify(bufname(bufnr), ':p')) bgneal@7: cal cursor(get(info, 2), get(info, 3)) bgneal@7: sil! norm! zvzz bgneal@7: en bgneal@7: endf bgneal@7: bgneal@7: fu! ctrlp#changes#cmd(mode, ...) bgneal@7: let s:clmode = a:mode bgneal@7: if a:0 && !empty(a:1) bgneal@7: let s:bufnr = bufnr('^'.fnamemodify(a:1, ':p').'$') bgneal@7: en bgneal@7: retu s:id bgneal@7: endf bgneal@7: bgneal@7: fu! ctrlp#changes#exit() bgneal@7: unl! s:clmode s:bufnr bgneal@7: endf bgneal@7: "}}} bgneal@7: bgneal@7: " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2