diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index 96aa925..193e170 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -735,7 +735,7 @@ fu! s:SetWD(...) cal extend(markers, s:rmarkers, 0) en for marker in markers - cal s:findroot(getcwd(), marker, 0, 0) + cal s:findroot(s:dyncwd, marker, 0, 0) if exists('s:foundroot') | brea | en endfo unl! s:foundroot @@ -1413,9 +1413,8 @@ fu! s:getenv() let s:wpmode = exists('b:ctrlp_working_path_mode') \ ? b:ctrlp_working_path_mode : s:pathmode if exists('g:ctrlp_extensions') - if index(g:ctrlp_extensions, 'undo') >= 0 && exists('*undotree') - \ && ( v:version > 703 || ( v:version == 703 && has('patch005') ) ) - let s:undotree = undotree() + if index(g:ctrlp_extensions, 'undo') >= 0 + let s:undos = s:getundo() en if index(g:ctrlp_extensions, 'tag') >= 0 let s:tagfiles = s:tagfiles() @@ -1541,6 +1540,18 @@ fu! s:extvar(key) en endf +fu! s:getundo() + if exists('*undotree') + \ && ( v:version > 703 || ( v:version == 703 && has('patch005') ) ) + retu [1, undotree()] + el + redi => result + sil! undol + redi END + retu [0, split(result, "\n")[1:]] + en +endf + fu! ctrlp#exit() cal s:PrtExit() endf diff --git a/autoload/ctrlp/undo.vim b/autoload/ctrlp/undo.vim index 74d4673..889f663 100644 --- a/autoload/ctrlp/undo.vim +++ b/autoload/ctrlp/undo.vim @@ -6,16 +6,16 @@ " Init {{{1 if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo ) - \ || !( v:version > 703 || ( v:version == 703 && has('patch005') ) ) fini en let g:loaded_ctrlp_undo = 1 let s:undo_var = { - \ 'init': 'ctrlp#undo#init(s:undotree)', + \ 'init': 'ctrlp#undo#init(s:undos)', \ 'accept': 'ctrlp#undo#accept', \ 'lname': 'undo', \ 'sname': 'udo', + \ 'exit': 'ctrlp#undo#exit()', \ 'type': 'line', \ } @@ -23,6 +23,9 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars) \ ? add(g:ctrlp_ext_vars, s:undo_var) : [s:undo_var] let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars) + +let s:text = map(['second', 'seconds', 'minutes', 'hours', 'days', 'weeks', + \ 'months', 'years'], '" ".v:val." ago"') " Utilities {{{1 fu! s:flatten(tree, cur) let flatdict = {} @@ -37,24 +40,14 @@ fu! s:flatten(tree, cur) retu flatdict endf -fu! s:humantime(nr) - let elapsed = localtime() - a:nr - let mins = elapsed / 60 - let hrs = elapsed / 3600 - let days = elapsed / 86400 - let wks = elapsed / 604800 - let mons = elapsed / 2592000 - let yrs = elapsed / 31536000 - let text = [ - \ ' second ago', - \ ' seconds ago', - \ ' minutes ago', - \ ' hours ago', - \ ' days ago', - \ ' weeks ago', - \ ' months ago', - \ ' years ago', - \ ] +fu! s:elapsed(nr) + let [text, time] = [s:text, localtime() - a:nr] + let mins = time / 60 + let hrs = time / 3600 + let days = time / 86400 + let wks = time / 604800 + let mons = time / 2592000 + let yrs = time / 31536000 if yrs > 1 retu yrs.text[7] elsei mons > 1 @@ -67,10 +60,10 @@ fu! s:humantime(nr) retu hrs.text[3] elsei mins > 1 retu mins.text[2] - elsei elapsed == 1 - retu elapsed.text[0] - elsei elapsed < 120 - retu elapsed.text[1] + elsei time == 1 + retu time.text[0] + elsei time < 120 + retu time.text[1] en endf @@ -81,7 +74,7 @@ fu! s:syntax() exe 'hi link CtrlPUndo'.ke va en endfo - sy match CtrlPUndoT '\d\+ \zs[^ ]\+\ze' + sy match CtrlPUndoT '\v\d+ \zs[^ ]+\ze|\d+:\d+:\d+' sy match CtrlPUndoBr '\[\|\]' sy match CtrlPUndoNr '\[\d\+\]' contains=CtrlPUndoBr sy match CtrlPUndoSv 'saved' @@ -90,7 +83,7 @@ endf fu! s:dict2list(dict) for ke in keys(a:dict) - let a:dict[ke][0] = s:humantime(a:dict[ke][0]) + let a:dict[ke][0] = s:elapsed(a:dict[ke][0]) endfo retu map(keys(a:dict), 'eval(''[v:val, a:dict[v:val]]'')') endf @@ -104,16 +97,29 @@ fu! s:format(...) let current = !empty(a:1[1][2]) ? ' '.a:1[1][2] : '' retu a:1[1][0].' ['.a:1[0].']'.saved.current endf + +fu! s:formatul(...) + let parts = matchlist(a:1, + \ '\v^\s+(\d+)\s+\d+\s+([^ ]+\s?[^ ]+|\d+\s\w+\s\w+)(\s*\d*)$') + retu parts[2].' ['.parts[1].']'.( parts[3] != '' ? ' saved' : '' ) +endf " Public {{{1 fu! ctrlp#undo#init(undo) - let entries = a:undo['entries'] + let entries = a:undo[0] ? a:undo[1]['entries'] : a:undo[1] if empty(entries) | retu [] | en if has('syntax') && exists('g:syntax_on') cal s:syntax() en let g:ctrlp_nolimit = 1 - let entries = s:dict2list(s:flatten(entries, a:undo['seq_cur'])) - retu map(sort(entries, 's:compval'), 's:format(v:val)') + if !exists('s:lines') + if a:undo[0] + let entries = s:dict2list(s:flatten(entries, a:undo[1]['seq_cur'])) + let s:lines = map(sort(entries, 's:compval'), 's:format(v:val)') + el + let s:lines = map(reverse(entries), 's:formatul(v:val)') + en + en + retu s:lines endf fu! ctrlp#undo#accept(mode, str) @@ -126,6 +132,10 @@ endf fu! ctrlp#undo#id() retu s:id endf + +fu! ctrlp#undo#exit() + unl! s:lines +endf "}}} " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2 diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index ac1282c..444d658 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -729,7 +729,7 @@ Available extensions:~ * Undo mode:~ - Name: 'undo' - Command: ':CtrlPUndo' - - Browse undo history (requires Vim 7.3.005+). + - Browse undo history. *:CtrlPLine* * Line mode:~