ctrlp.vim/autoload/ctrlp/changes.vim

96 lines
2.5 KiB
VimL
Raw Normal View History

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