1
0
mirror of https://github.com/gryf/.vim.git synced 2025-12-17 19:40:29 +01:00

Update of Mark, syntastic, taglisttoo and ctrlp plugins

This commit is contained in:
2012-03-26 19:05:47 +02:00
parent 1e1164cd0c
commit 1178b8be6d
21 changed files with 1335 additions and 778 deletions

View File

@@ -2,10 +2,10 @@
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer, mru and tag finder.
" Author: Kien Nguyen <github.com/kien>
" Version: 1.7.2
" Version: 1.7.4
" =============================================================================
" Static variables {{{1
" * Static variables {{{1
fu! s:opts()
" Options
let hst = exists('+hi') ? &hi : 20
@@ -21,6 +21,7 @@ fu! s:opts()
\ 'g:ctrlp_highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
\ 'g:ctrlp_jump_to_buffer': ['s:jmptobuf', 2],
\ 'g:ctrlp_lazy_update': ['s:lazy', 0],
\ 'g:ctrlp_match_func': ['s:matcher', {}],
\ 'g:ctrlp_match_window_bottom': ['s:mwbottom', 1],
\ 'g:ctrlp_match_window_reversed': ['s:mwreverse', 1],
\ 'g:ctrlp_max_depth': ['s:maxdepth', 40],
@@ -203,7 +204,7 @@ fu! s:Close()
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ g:ctrlp_nolimit
cal ctrlp#recordhist()
cal s:onexit()
cal s:extvar('exit')
cal s:log(0)
ec
endf
@@ -224,8 +225,10 @@ endf
fu! ctrlp#reset()
cal s:opts()
cal s:autocmds()
cal ctrlp#utils#opts()
cal ctrlp#mrufiles#opts()
cal s:extvar('opts')
endf
" * Files {{{1
fu! ctrlp#files()
@@ -307,25 +310,28 @@ fu! s:lsCmd()
retu cmd['types'][key][1]
en
endf
" Buffers {{{1
" - Buffers {{{1
fu! ctrlp#buffers()
retu map(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'),
\ 'fnamemodify(bufname(v:val), ":.")')
endf
" * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, mfunc, ipt)
let [newitems, crfile] = [[], exists('s:crfilerel') ? s:crfilerel : '']
for item in a:items
try | if !( a:ipt && item == crfile ) && call(a:mfunc, [item, a:pat]) >= 0
fu! s:MatchIt(items, pat, limit, mfunc, ipt, exc)
let [newitems, id, itlen] = [[], 0, len(a:items)]
wh id < itlen
let item = a:items[id]
let id += 1
try | if !( a:ipt && item == a:exc ) && call(a:mfunc, [item, a:pat]) >= 0
cal add(newitems, item)
en | cat | brea | endt
if a:limit > 0 && len(newitems) >= a:limit | brea | en
endfo
endw
let s:mdata = [s:dyncwd, s:itemtype, s:regexp, a:items[(id):]]
retu newitems
endf
fu! s:MatchedItems(items, pat, limit, ipt)
fu! s:MatchedItems(items, str, pat, limit, ipt)
let [type, mfunc] = [s:type(1), 'match']
if s:byfname && a:ipt
let mfunc = 's:matchfname'
@@ -333,11 +339,20 @@ fu! s:MatchedItems(items, pat, limit, ipt)
let types = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
if has_key(types, type) | let mfunc = types[type] | en
en
let newitems = s:MatchIt(a:items, a:pat, a:limit, mfunc, a:ipt)
let exc = exists('s:crfilerel') ? s:crfilerel : ''
let matfunc = 's:MatchIt'
let items = s:narrowable() ? s:matched + s:mdata[3] : a:items
let argms = [items, a:pat, a:limit, mfunc, a:ipt, exc]
if s:matcher != {} && has_key(s:matcher, 'match')
let [matfunc, argms[1], argms[3]] = s:matargs(mfunc, a:str)
let argms += [s:regexp]
en
let newitems = call(matfunc, argms)
let s:matches = len(newitems)
retu newitems
endf
fu! s:SplitPattern(str) "{{{1
fu! s:SplitPattern(str)
let str = a:str
if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo')
let str = s:migemo(str)
@@ -379,9 +394,8 @@ fu! s:Render(lines, pat, ipt)
if s:dohighlight() | cal clearmatches() | en
retu
en
" Sort if not MRU
if ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') )
\ || s:prompt != ['', '', '']
if ( ( s:itemtype != 2 && !exists('g:ctrlp_nolimit') )
\ || s:prompt != ['', '', ''] ) && s:matcher == {}
let s:compat = a:pat
cal sort(lines, 's:mixedsort')
unl s:compat
@@ -412,7 +426,7 @@ fu! s:Update(str)
if str == oldstr && !empty(str) && !exists('s:force') | retu | en
let [pat, ipt] = [s:SplitPattern(str), s:ispathitem()]
let lines = exists('g:ctrlp_nolimit') && empty(str) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pat, s:winh, ipt)
\ : s:MatchedItems(g:ctrlp_lines, str, pat, s:winh, ipt)
cal s:Render(lines, pat, ipt)
endf
@@ -459,8 +473,10 @@ endf
fu! s:PrtAdd(char)
unl! s:hstgot
let s:act_add = 1
let s:prompt[0] .= a:char
cal s:BuildPrompt(1)
unl s:act_add
endf
fu! s:PrtBS()
@@ -577,7 +593,7 @@ fu! s:PrtClearCache()
cal ctrlp#clr(s:statypes[s:itemtype][1])
en
if s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#list(-1, 1)
let g:ctrlp_lines = ctrlp#mrufiles#refresh()
el
cal ctrlp#setlines(s:itemtype)
en
@@ -588,13 +604,13 @@ endf
fu! s:PrtDeleteMRU()
if s:itemtype != 2 | retu | en
let [s:force, ags] = [1, [-1, 2]]
let [s:force, tbrem] = [1, []]
if exists('s:marked')
let ags = [-1, 2, values(s:marked)]
let tbrem = values(s:marked)
cal s:unmarksigns()
unl s:marked
en
let g:ctrlp_lines = call('ctrlp#mrufiles#list', ags)
let g:ctrlp_lines = ctrlp#mrufiles#remove(tbrem)
cal s:BuildPrompt(1)
unl s:force
endf
@@ -684,7 +700,7 @@ endf
fu! s:ToggleType(dir)
let ext = exists('g:ctrlp_ext_vars') ? len(g:ctrlp_ext_vars) : 0
let s:itemtype = s:walker(g:ctrlp_builtins + ext, s:itemtype, a:dir)
let s:itemtype = s:walker(2 + ext, s:itemtype, a:dir)
if s:byfname && !s:ispathitem() | let s:byfname = 0 | en
unl! g:ctrlp_nolimit
if has('syntax') && exists('g:syntax_on')
@@ -699,8 +715,10 @@ fu! s:PrtSwitcher()
cal s:BuildPrompt(1, s:Focus())
unl s:force
endf
fu! s:SetWD(...) "{{{1
let [pathmode, s:crfilerel] = [s:wpmode, fnamemodify(s:crfile, ':.')]
" - SetWD() {{{1
fu! s:SetWD(...)
let pathmode = s:wpmode
let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
if a:0 && strlen(a:1) | if type(a:1)
cal ctrlp#setdir(a:1) | retu
el
@@ -717,7 +735,7 @@ fu! s:SetWD(...) "{{{1
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
@@ -742,7 +760,7 @@ fu! ctrlp#acceptfile(mode, line, ...)
if j2l | cal ctrlp#j2l(j2l) | en
el
" Determine the command to use
let useb = bufnr > 0 && empty(tail)
let useb = bufnr > 0 && getbufvar(bufnr, '&bl') && empty(tail)
let cmd =
\ md == 't' || s:splitwin == 1 ? ( useb ? 'tab sb' : 'tabe' ) :
\ md == 'h' || s:splitwin == 2 ? ( useb ? 'sb' : 'new' ) :
@@ -794,10 +812,11 @@ fu! s:AcceptSelection(mode)
if empty(line) | retu | en
" Do something with it
let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile'
\ : g:ctrlp_ext_vars[s:itemtype - ( g:ctrlp_builtins + 1 )]['accept']
\ : g:ctrlp_ext_vars[s:itemtype - 3]['accept']
cal call(actfunc, [a:mode, line])
endf
fu! s:CreateNewFile(...) "{{{1
" - CreateNewFile() {{{1
fu! s:CreateNewFile(...)
let [md, str] = ['', join(s:prompt, '')]
if empty(str) | retu | en
if s:argmap && !a:0
@@ -830,8 +849,7 @@ fu! s:CreateNewFile(...) "{{{1
endf
" * OpenMulti() {{{1
fu! s:MarkToOpen()
if s:bufnr <= 0 || s:opmul == '0'
\ || ( s:itemtype > g:ctrlp_builtins && s:type() !~ 'rts' )
if s:bufnr <= 0 || s:opmul == '0' || ( s:itemtype > 2 && s:type() !~ 'rts' )
retu
en
let line = !empty(s:matched) ? s:matched[line('.') - 1] : ''
@@ -875,7 +893,8 @@ fu! s:OpenMulti()
" Move the cursor to a reusable window
let [tail, fnesc] = [s:tail(), exists('*fnameescape') && v:version > 701]
let [emptytail, nwpt] = [empty(tail), exists('g:ctrlp_open_multiple_files')]
let useb = bufnr('^'.mkd[0].'$') > 0 && emptytail
let bufnr = bufnr('^'.mkd[0].'$')
let useb = bufnr > 0 && getbufvar(bufnr, '&bl') && emptytail
let fst = call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
" Check if it's a replaceable buffer
let repabl = ( empty(bufname('%')) && empty(&l:ft) ) || s:nosplit()
@@ -886,7 +905,7 @@ fu! s:OpenMulti()
" Open the files
for va in mkd
let bufnr = bufnr('^'.va.'$')
let useb = bufnr > 0 && emptytail
let useb = bufnr > 0 && getbufvar(bufnr, '&bl') && emptytail
let snd = md != '' && has_key(cmds, md) ?
\ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' )
let cmd = ic == 1 && ( ucr == 'r' || repabl ) ? fst : snd
@@ -925,6 +944,15 @@ fu! s:comptime(s1, s2)
retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1
endf
fu! s:compmre(...)
" By last entered time (buffer only)
if !exists('s:mrbs')
let s:mrbs = ctrlp#mrufiles#bufs()
en
let cwd = getcwd()
retu index(s:mrbs, cwd.s:lash().a:1) - index(s:mrbs, cwd.s:lash().a:2)
endf
fu! s:comparent(s1, s2)
" By same parent dir
let cwd = getcwd()
@@ -968,8 +996,11 @@ fu! s:mixedsort(s1, s2)
if s:itemtype < 3 && s:height < 51
let [par, cfn] = [s:comparent(a:s1, a:s2), s:compfnlen(a:s1, a:s2)]
if s:height < 21
let ctm = s:comptime(a:s1, a:s2)
retu 12 * cml + 6 * par + 3 * cfn + 2 * ctm + cln
let [muls, ctm] = s:itemtype == 1
\ ? [[6, 3, 2, 12], s:compmre(a:s1, a:s2)]
\ : [[12, 6, 3, 2], s:comptime(a:s1, a:s2)]
unl! s:mrbs
retu muls[0] * cml + muls[1] * par + muls[2] * cfn + muls[3] * ctm + cln
en
retu 6 * cml + 3 * par + 2 * cfn + cln
en
@@ -1001,7 +1032,7 @@ fu! ctrlp#statusline()
let byfname = s:byfname ? 'file' : 'path'
let marked = s:opmul != '0' ?
\ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <->' : ''
if has_key(s:status, 'main')
if s:status != {} && has_key(s:status, 'main')
let args = [focus, byfname, s:regexp, prv, item, nxt, marked]
let &l:stl = call(s:status['main'], args)
el
@@ -1022,7 +1053,8 @@ endf
fu! ctrlp#progress(enum)
if has('macunix') || has('mac') | sl 1m | en
let &l:stl = has_key(s:status, 'prog') ? call(s:status['prog'], [a:enum])
let &l:stl = s:status != {} && has_key(s:status, 'prog')
\ ? call(s:status['prog'], [a:enum])
\ : '%#CtrlPStats# '.a:enum.' %* %=%<%#CtrlPMode2# '.getcwd().' %*'
redraws
endf
@@ -1065,9 +1097,8 @@ fu! s:lash(...)
endf
fu! s:ispathitem()
let ext = s:itemtype - ( g:ctrlp_builtins + 1 )
retu s:itemtype < 3
\ || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext]['type'] == 'path' )
retu s:itemtype < 3 ||
\ ( s:itemtype > 2 && g:ctrlp_ext_vars[s:itemtype - 3]['type'] == 'path' )
endf
fu! ctrlp#dirnfile(entries)
@@ -1156,7 +1187,7 @@ endf
fu! ctrlp#setdir(path, ...)
let cmd = a:0 ? a:1 : 'lc!'
sil! exe cmd ctrlp#fnesc(a:path)
let s:crfilerel = fnamemodify(s:crfile, ':.')
let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
endf
fu! ctrlp#setlcdir()
@@ -1180,6 +1211,7 @@ fu! ctrlp#syntax()
endf
fu! s:highlight(pat, grp, ipt)
if s:matcher != {} | retu | en
cal clearmatches()
if !empty(a:pat) && a:ipt
let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat
@@ -1342,6 +1374,22 @@ fu! s:argmaps(md, ...)
retu a:md
endf
" Misc {{{2
fu! s:narrowable()
retu exists('s:act_add') && exists('s:matched') && s:matched != []
\ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
\ && s:matcher == {}
endf
fu! s:matargs(mfunc, str)
let match_type = {
\ 'match': 'full-line',
\ 's:matchfname': 'filename-only',
\ 's:matchtabs': 'first-non-tab',
\ 's:matchtabe': 'until-last-tab',
\ }
retu [s:matcher['match'], a:str, match_type[a:mfunc]]
endf
fu! s:log(m)
if exists('g:ctrlp_log') && g:ctrlp_log | if a:m
let cadir = ctrlp#utils#cachedir()
@@ -1365,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()
@@ -1440,8 +1487,8 @@ fu! s:regexfilter(str)
retu str
endf
fu! s:walker(max, pos, dir)
retu a:dir > 0 ? a:pos < a:max ? a:pos + 1 : 0 : a:pos > 0 ? a:pos - 1 : a:max
fu! s:walker(m, p, d)
retu a:d > 0 ? a:p < a:m ? a:p + a:d : 0 : a:p > 0 ? a:p + a:d : a:m
endf
fu! s:matchfname(item, pat)
@@ -1478,18 +1525,30 @@ fu! s:insertcache(str)
endf
" Extensions {{{2
fu! s:type(...)
let ext = s:itemtype - ( g:ctrlp_builtins + 1 )
retu s:itemtype > 2 ? g:ctrlp_ext_vars[ext][a:0 ? 'type' : 'sname'] : s:itemtype
retu s:itemtype > 2
\ ? g:ctrlp_ext_vars[s:itemtype - 3][a:0 ? 'type' : 'sname'] : s:itemtype
endf
fu! s:tagfiles()
retu filter(map(tagfiles(), 'fnamemodify(v:val, ":p")'), 'filereadable(v:val)')
endf
fu! s:onexit()
fu! s:extvar(key)
if exists('g:ctrlp_ext_vars')
cal map(filter(copy(g:ctrlp_ext_vars),
\ 'has_key(v:val, "exit")'), 'eval(v:val["exit"])')
\ 'has_key(v:val, a:key)'), 'eval(v:val[a: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
@@ -1500,6 +1559,10 @@ endf
fu! ctrlp#prtclear()
cal s:PrtClear()
endf
fu! ctrlp#switchtype(id)
cal s:ToggleType(a:id - s:itemtype)
endf
"}}}1
" * Initialization {{{1
fu! ctrlp#setlines(type)
@@ -1507,7 +1570,7 @@ fu! ctrlp#setlines(type)
let types = [
\ 'ctrlp#files()',
\ 'ctrlp#buffers()',
\ 'ctrlp#mrufiles#list(-1)',
\ 'ctrlp#mrufiles#list()',
\ ]
if exists('g:ctrlp_ext_vars')
cal map(copy(g:ctrlp_ext_vars), 'add(types, v:val["init"])')
@@ -1527,16 +1590,27 @@ fu! ctrlp#init(type, ...)
cal ctrlp#setlines(a:type)
cal s:BuildPrompt(1)
endf
if has('autocmd') "{{{1
" - Autocmds {{{1
fu! s:autocmds()
if !has('autocmd') | retu | en
aug CtrlPAug
au!
au BufEnter ControlP cal s:checkbuf()
au BufLeave ControlP cal s:Close()
au VimLeavePre * cal s:leavepre()
if s:lazy
au CursorHold ControlP cal s:ForceUpdate()
en
aug END
en "}}}
if exists('#CtrlPLazy')
au! CtrlPLazy
en
if s:lazy
aug CtrlPLazy
au!
au CursorHold ControlP cal s:ForceUpdate()
aug END
en
endf
cal s:autocmds()
"}}}
" vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2

View File

@@ -20,6 +20,7 @@ let s:buftag_var = {
\ 'sname': 'bft',
\ 'exit': 'ctrlp#buffertag#exit()',
\ 'type': 'tabs',
\ 'opts': 'ctrlp#buffertag#opts()',
\ }
let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
@@ -27,7 +28,7 @@ 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)
fu! s:opts()
fu! ctrlp#buffertag#opts()
let opts = {
\ 'g:ctrlp_buftag_systemenc': ['s:enc', &enc],
\ 'g:ctrlp_buftag_ctags_bin': ['s:bin', ''],
@@ -37,7 +38,7 @@ fu! s:opts()
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo
endf
cal s:opts()
cal ctrlp#buffertag#opts()
fu! s:bins()
let bins = [
@@ -196,6 +197,21 @@ fu! s:parseline(line)
let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]
retu vals[1].' '.vals[4].'|'.bufnr.':'.bufname.'|'.vals[6].'| '.vals[3]
endf
fu! s:syntax()
if !hlexists('CtrlPTagKind')
hi link CtrlPTagKind Title
en
if !hlexists('CtrlPBufName')
hi link CtrlPBufName Directory
en
if !hlexists('CtrlPTabExtra')
hi link CtrlPTabExtra Comment
en
sy match CtrlPTagKind '\zs[^\t|]\+\ze|\d\+:[^|]\+|\d\+|'
sy match CtrlPBufName '|\d\+:\zs[^|]\+\ze|\d\+|'
sy match CtrlPTabExtra '\zs\t.*\ze$' contains=CtrlPBufName,CtrlPTagKind
endf
" Public {{{1
fu! ctrlp#buffertag#init(fname)
let bufs = exists('s:btmode') && s:btmode
@@ -203,14 +219,12 @@ fu! ctrlp#buffertag#init(fname)
\ : [exists('s:bufname') ? s:bufname : a:fname]
let lines = []
for each in bufs
let tftype = get(split(getbufvar(each, '&ft'), '\.'), 0, '')
cal extend(lines, s:process(each, tftype))
let bname = fnamemodify(each, ':p')
let tftype = get(split(getbufvar(bname, '&ft'), '\.'), 0, '')
cal extend(lines, s:process(bname, tftype))
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,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
@@ -62,7 +62,8 @@ fu! ctrlp#changes#init(original_bufnr, fname)
let [swb, &swb] = [&swb, '']
let lines = []
for each in bufs
let [bufnr, fnamet] = [bufnr('^'.each.'$'), fnamemodify(each, ':t')]
let [bname, fnamet] = [fnamemodify(each, ':p'), fnamemodify(each, ':t')]
let bufnr = bufnr('^'.bname.'$')
if bufnr > 0
cal extend(lines, s:process(s:changelist(bufnr), bufnr, fnamet))
en
@@ -72,10 +73,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,13 +22,25 @@ 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)'), []]
for each in bufs
let [fnamet, from_file] = [fnamemodify(each, ':t'), readfile(each)]
let bname = fnamemodify(each, ':p')
cal map(from_file, 'tr(v:val, '' '', '' '')')
let [id, len_ff, bufnr] = [1, len(from_file), bufnr('^'.each.'$')]
let [id, len_ff, bufnr] = [1, len(from_file), bufnr('^'.bname.'$')]
wh id <= len_ff
let from_file[id-1] .= ' |'.fnamet.'|'.bufnr.':'.id.'|'
let id += 1
@@ -44,10 +49,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

@@ -17,76 +17,108 @@ fu! ctrlp#mrufiles#opts()
for [ke, va] in items(opts)
exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1])
endfo
let s:csen = s:csen ? '#' : '?'
let [s:csen, s:mrbs] = [s:csen ? '#' : '?', []]
if exists('s:locked')
cal ctrlp#mrufiles#init()
en
endf
cal ctrlp#mrufiles#opts()
fu! ctrlp#mrufiles#list(bufnr, ...) "{{{1
if s:locked | retu | en
let bufnr = a:bufnr + 0
if bufnr > 0
let fn = fnamemodify(bufname(bufnr), ':p')
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
retu
en
en
" Utilities {{{1
fu! s:excl(fn)
retu !empty(s:ex) && a:fn =~# s:ex
endf
fu! s:readcache()
if !exists('s:cadir') || !exists('s:cafile')
let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt'
en
if a:0 && a:1 == 2
let mrufs = []
if a:0 == 2
let mrufs = ctrlp#utils#readfile(s:cafile)
cal filter(mrufs, 'index(a:2, v:val) < 0')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
retu ctrlp#utils#readfile(s:cafile)
endf
fu! s:reformat(mrufs)
if s:re
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal filter(a:mrufs, '!stridx(v:val, cwd)')
en
" Get the list
let mrufs = ctrlp#utils#readfile(s:cafile)
" Remove non-existent files
if a:0 && a:1 == 1
cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
if exists('+ssl')
cal map(mrufs, 'tr(v:val, ''/'', ''\'')')
cal filter(mrufs, 'count(mrufs, v:val) == 1')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu map(a:mrufs, 'fnamemodify(v:val, '':.'')')
endf
fu! s:record(bufnr, ...)
if s:locked | retu | en
let bufnr = a:bufnr + 0
if bufnr <= 0 | retu | en
let fn = fnamemodify(bufname(bufnr), ':p')
let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
cal filter(s:mrbs, 'v:val !='.s:csen.' fn')
cal insert(s:mrbs, fn)
if empty(fn) || !empty(&bt) || ( !empty(s:in) && fn !~# s:in )
\ || ( !empty(s:ex) && fn =~# s:ex ) || !filereadable(fn)
\ || ( a:0 && a:1 == 1 )
retu
en
" Return the list with the active buffer removed
if bufnr == -1
if s:re
let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
cal filter(mrufs, '!stridx(v:val, cwd)')
en
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
en
" Remove old entry
let mrufs = s:readcache()
cal filter(mrufs, 'v:val !='.s:csen.' fn')
" Insert new one
cal insert(mrufs, fn)
" Remove oldest entry or entries
if len(mrufs) > s:max | cal remove(mrufs, s:max, -1) | en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
endf "}}}
fu! s:excl(fn) "{{{
retu !empty(s:ex) && a:fn =~# s:ex
endf "}}}
fu! ctrlp#mrufiles#init() "{{{1
endf
" Public {{{1
fu! ctrlp#mrufiles#refresh()
let mrufs = s:readcache()
cal filter(mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
if exists('+ssl')
cal map(mrufs, 'tr(v:val, ''/'', ''\'')')
cal filter(mrufs, 'count(mrufs, v:val) == 1')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu s:reformat(mrufs)
endf
fu! ctrlp#mrufiles#remove(files)
let mrufs = []
if a:files != []
let mrufs = s:readcache()
cal filter(mrufs, 'index(a:files, v:val) < 0')
en
cal ctrlp#utils#writecache(mrufs, s:cadir, s:cafile)
retu map(mrufs, 'fnamemodify(v:val, '':.'')')
endf
fu! ctrlp#mrufiles#list(...)
if a:0 | cal s:record(a:1) | retu | en
retu s:reformat(s:readcache())
endf
fu! ctrlp#mrufiles#bufs()
retu s:mrbs
endf
fu! ctrlp#mrufiles#init()
if !has('autocmd') | retu | en
let s:locked = 0
aug CtrlPMRUF
au!
au BufReadPost,BufNewFile,BufWritePost *
\ cal ctrlp#mrufiles#list(expand('<abuf>', 1))
if s:mre
au BufEnter,BufUnload *
\ cal ctrlp#mrufiles#list(expand('<abuf>', 1))
en
au BufReadPost,BufNewFile,BufWritePost * cal s:record(expand('<abuf>', 1))
au QuickFixCmdPre *vimgrep* let s:locked = 1
au QuickFixCmdPost *vimgrep* let s:locked = 0
aug END
aug CtrlPMREB
au!
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1), 1)
aug END
if exists('#CtrlPMREF')
au! CtrlPMREF
en
if s:mre
aug CtrlPMREF
au!
au BufEnter,BufUnload * cal s:record(expand('<abuf>', 1))
aug END
if exists('#CtrlPMREB')
au! CtrlPMREB
en
en
endf
"}}}

View File

@@ -1,28 +1,21 @@
" =============================================================================
" 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') ) )
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',
\ }
@@ -30,36 +23,31 @@ 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)
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
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
@@ -72,42 +60,66 @@ 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
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 CtrlPUndoT '\v\d+ \zs[^ ]+\ze|\d+:\d+:\d+'
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:elapsed(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
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 = sort(s:dict2list(s:flatten(entries)), 's:compval')
retu map(entries, 'v:val[1]." [".v:val[0]."]"')
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)
@@ -120,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