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