annotate vim/vimfiles/bundle/ctrlp.vim/autoload/ctrlp/changes.vim @ 7:86e0ac713642

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