Make line, undo, and changes official

This commit is contained in:
Kien N 2012-03-12 15:34:40 +07:00
parent 01910d3bb6
commit b8c16c71a7
5 changed files with 86 additions and 47 deletions

View File

@ -1,20 +1,9 @@
" =============================================================================
" File: autoload/ctrlp/changes.vim
" Description: Change list extension - Jump to a recent change in any buffer
" Description: Change list extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['changes']
" Create Some Commands:
" " Single buffer
" com! -n=? -com=buffer CtrlPChange
" \ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))
" " All listed buffers
" com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1))
"}}}
" Init {{{1
if exists('g:loaded_ctrlp_changes') && g:loaded_ctrlp_changes
fini
@ -54,6 +43,17 @@ fu! s:process(clines, ...)
endfo
retu reverse(filter(clines, 'count(clines, v:val) == 1'))
endf
fu! s:syntax()
if !hlexists('CtrlPBufName')
hi link CtrlPBufName Directory
en
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPBufName '\t|\d\+:\zs[^|]\+\ze|\d\+:\d\+|$'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
endf
" Public {{{1
fu! ctrlp#changes#init(original_bufnr, fname)
let fname = exists('s:bufname') ? s:bufname : a:fname
@ -72,10 +72,7 @@ fu! ctrlp#changes#init(original_bufnr, fname)
let g:ctrlp_nolimit = 1
if has('syntax') && exists('g:syntax_on')
cal ctrlp#syntax()
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
cal s:syntax()
en
retu lines
endf

View File

@ -1,16 +1,9 @@
" =============================================================================
" File: autoload/ctrlp/line.vim
" Description: Line extension - Find a line in any buffer
" Description: Line extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['line']
" Create A Command:
" com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
"}}}
" Init {{{1
if exists('g:loaded_ctrlp_line') && g:loaded_ctrlp_line
fini
@ -29,6 +22,17 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
\ ? add(g:ctrlp_ext_vars, s:line_var) : [s:line_var]
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:syntax()
if !hlexists('CtrlPBufName')
hi link CtrlPBufName Directory
en
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPBufName '\t|\zs[^|]\+\ze|\d\+:\d\+|$'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName
endf
" Public {{{1
fu! ctrlp#line#init()
let [bufs, lines] = [filter(ctrlp#buffers(), 'filereadable(v:val)'), []]
@ -44,10 +48,7 @@ fu! ctrlp#line#init()
cal extend(lines, from_file)
endfo
if has('syntax') && exists('g:syntax_on')
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTabExtra '\zs\t.*\ze$'
cal s:syntax()
en
retu lines
endf

View File

@ -1,16 +1,9 @@
" =============================================================================
" File: autoload/ctrlp/undo.vim
" Description: Undo extension - Browse undo history (requires Vim 7.3.005+)
" Description: Undo extension
" Author: Kien Nguyen <github.com/kien>
" =============================================================================
" User Configuration {{{1
" Enable:
" let g:ctrlp_extensions += ['undo']
" Create A Command:
" com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
"}}}
" Init {{{1
if ( exists('g:loaded_ctrlp_undo') && g:loaded_ctrlp_undo )
\ || !( v:version > 703 || ( v:version == 703 && has('patch005') ) )
@ -31,12 +24,14 @@ let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
" Utilities {{{1
fu! s:flatten(tree)
fu! s:flatten(tree, cur)
let flatdict = {}
for each in a:tree
cal extend(flatdict, { each['seq'] : each['time'] })
let saved = has_key(each, 'save') ? 'saved' : ''
let current = each['seq'] == a:cur ? 'current' : ''
cal extend(flatdict, { each['seq'] : [each['time'], saved, current] })
if has_key(each, 'alt')
cal extend(flatdict, s:flatten(each['alt']))
cal extend(flatdict, s:flatten(each['alt'], a:cur))
en
endfo
retu flatdict
@ -80,24 +75,35 @@ fu! s:humantime(nr)
endf
fu! s:syntax()
for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String'})
for [ke, va] in items({'T': 'Directory', 'Br': 'Comment', 'Nr': 'String',
\ 'Sv': 'Comment', 'Po': 'Title'})
if !hlexists('CtrlPUndo'.ke)
exe 'hi link CtrlPUndo'.ke va
en
endfo
sy match CtrlPUndoT '\d\+ \zs[^ ]\+\ze'
sy match CtrlPUndoBr '\[\|\]'
sy match CtrlPUndoNr '\[\d\+\]$' contains=CtrlPUndoBr
sy match CtrlPUndoNr '\[\d\+\]' contains=CtrlPUndoBr
sy match CtrlPUndoSv 'saved'
sy match CtrlPUndoPo 'current'
endf
fu! s:dict2list(dict)
let dict = map(a:dict, 's:humantime(v:val)')
retu map(keys(dict), 'eval(''[v:val, dict[v:val]]'')')
for ke in keys(a:dict)
let a:dict[ke][0] = s:humantime(a:dict[ke][0])
endfo
retu map(keys(a:dict), 'eval(''[v:val, a:dict[v:val]]'')')
endf
fu! s:compval(...)
retu a:2[0] - a:1[0]
endf
fu! s:format(...)
let saved = !empty(a:1[1][1]) ? ' '.a:1[1][1] : ''
let current = !empty(a:1[1][2]) ? ' '.a:1[1][2] : ''
retu a:1[1][0].' ['.a:1[0].']'.saved.current
endf
" Public {{{1
fu! ctrlp#undo#init(undo)
let entries = a:undo['entries']
@ -106,8 +112,8 @@ fu! ctrlp#undo#init(undo)
cal s:syntax()
en
let g:ctrlp_nolimit = 1
let entries = sort(s:dict2list(s:flatten(entries)), 's:compval')
retu map(entries, 'v:val[1]." [".v:val[0]."]"')
let entries = s:dict2list(s:flatten(entries, a:undo['seq_cur']))
retu map(sort(entries, 's:compval'), 's:format(v:val)')
endf
fu! ctrlp#undo#accept(mode, str)

View File

@ -699,8 +699,8 @@ Available extensions:~
- Name: 'buffertag'
- Commands: ':CtrlPBufTag [buffer-name]',
':CtrlPBufTagAll'.
- Search for a tag within the current buffer or all buffers and jump to the
definition. Requires |exuberant_ctags| or compatible programs.
- Search for a tag within the current buffer or all listed buffers and jump
to the definition. Requires |exuberant_ctags| or compatible programs.
*:CtrlPQuickfix*
* Quickfix mode:~
@ -726,6 +726,27 @@ Available extensions:~
- Command: ':CtrlPRTS'
- Search for files (vimscripts, docs, snippets...) in runtimepath.
*:CtrlPUndo*
* Undo mode:~
- Name: 'undo'
- Command: ':CtrlPUndo'
- Browse undo history (requires Vim 7.3.005+).
*:CtrlPLine*
* Line mode:~
- Name: 'line'
- Command: ':CtrlPLine'
- Search for a line in all listed buffer.
*:CtrlPChange*
*:CtrlPChangeAll*
* Change list mode:~
- Name: 'changes'
- Commands: ':CtrlPChange [buffer-name]',
':CtrlPChangeAll'.
- Search for and jump to a recent change in the current buffer or in all
listed buffers.
-------------------------------------------------------------------------------
Buffer Tag mode options:~

View File

@ -65,4 +65,18 @@ if index(s:ext, 'rtscript') >= 0
com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id())
en
if index(s:ext, 'undo') >= 0
com! CtrlPUndo cal ctrlp#init(ctrlp#undo#id())
en
if index(s:ext, 'line') >= 0
com! CtrlPLine cal ctrlp#init(ctrlp#line#id())
en
if index(s:ext, 'changes') >= 0
com! -n=? -com=buffer CtrlPChange
\ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))
com! CtrlPChangeAll cal ctrlp#init(ctrlp#changes#cmd(1))
en
unl s:ext