Skip to content

Commit

Permalink
Improve :
Browse files Browse the repository at this point in the history
* Improve s:sanstail() and ':' input
* Shorten s:samerootsyml(), s:ispathitem()
* Add g:ctrlp_log, an option to write all output to .ctrlp_cache/ctrlp.log
* Fix an error with ctrlp#utils#glob()
  • Loading branch information
kien committed Dec 23, 2011
1 parent 9e88a8c commit ea4c602
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 27 deletions.
49 changes: 23 additions & 26 deletions autoload/ctrlp.vim
Expand Up @@ -64,6 +64,9 @@ en
let [s:compare_lim, s:nocache_lim, s:mltipats_lim] = [3000, 4000, 2000]
" * Open & Close {{{1
fu! s:Open()
if exists('g:ctrlp_log') && g:ctrlp_log
sil! exe 'redi >>' ctrlp#utils#cachedir().s:lash.'ctrlp.log'
en
let [s:cwd, s:winres] = [getcwd(), winrestcmd()]
let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
let [s:crword, s:crline] = [expand('<cword>'), getline('.')]
Expand Down Expand Up @@ -99,6 +102,9 @@ fu! s:Close()
\ s:crfile s:crfpath s:crword s:crvisual s:tagfiles s:crline s:crcursor
\ g:ctrlp_nolimit s:crbufnr
cal ctrlp#recordhist()
if exists('g:ctrlp_log') && g:ctrlp_log
redi END
en
ec
endf
" * Clear caches {{{1
Expand Down Expand Up @@ -327,13 +333,15 @@ fu! s:Update(str)
let oldstr = exists('s:savestr') ? s:savestr : ''
let pats = s:SplitPattern(a:str)
" Get the new string sans tail
let notail = substitute(a:str, '\\\@<!:\([^:]\|\\:\)*$', '', '')
let notail = substitute(a:str, '\\\\', '\', 'g')
let notail = substitute(notail, '\\\@<!:\([^:]\|\\:\)*$', '', '')
let notail = substitute(notail, '\\\ze:', '', 'g')
" Stop if the string's unchanged
if notail == oldstr && !empty(notail) && !exists('s:force')
retu
en
let lines = exists('g:ctrlp_nolimit') && empty(notail) ? copy(g:ctrlp_lines)
\ : s:MatchedItems(g:ctrlp_lines, pats, s:mxheight)
\ : s:MatchedItems(g:ctrlp_lines, copy(pats), s:mxheight)
cal s:Render(lines, pats[-1])
endf

Expand Down Expand Up @@ -817,7 +825,7 @@ fu! s:OpenMulti()
let spt = len(s:opmul) > 1 ? cmds[matchstr(s:opmul, '\w$')] : 'vne'
let nr = matchstr(s:opmul, '^\d\+')
exe wnr.'winc w'
for [ke, va] in items(mkd)
for va in values(mkd)
let cmd = ic == 1 ? 'e' : spt
cal s:openfile(cmd, va)
if nr > 1 && nr < ic | clo! | el | let ic += 1 | en
Expand Down Expand Up @@ -926,14 +934,11 @@ endf
" Paths {{{2
fu! s:ispathitem()
let ext = s:itemtype - ( g:ctrlp_builtins + 1 )
if s:itemtype < 3 || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext][3] == 'dir' )
retu 1
en
retu 0
retu s:itemtype < 3 || ( s:itemtype > 2 && g:ctrlp_ext_vars[ext][3] == 'dir' )
endf

fu! ctrlp#dirnfile(entries)
let items = [[], []]
let [items, cwd] = [[[], []], getcwd().s:lash]
for each in a:entries
let etype = getftype(each)
if etype == 'dir'
Expand All @@ -945,7 +950,7 @@ fu! ctrlp#dirnfile(entries)
elsei etype == 'link'
if s:folsym
let isfile = !isdirectory(each)
if !s:samerootsyml(each, isfile)
if !s:samerootsyml(each, isfile, cwd)
cal add(items[isfile], each)
en
en
Expand All @@ -956,14 +961,10 @@ fu! ctrlp#dirnfile(entries)
retu items
endf

fu! s:samerootsyml(each, isfile)
let resl = resolve(a:each).( a:isfile ? '' : s:lash )
let resl = a:isfile ? fnamemodify(resl, ':p:h').s:lash : resl
let cwd = getcwd().s:lash
if stridx(resl, cwd) && ( stridx(cwd, resl) || a:isfile )
retu 0
en
retu 1
fu! s:samerootsyml(each, isfile, cwd)
let resolve = resolve(a:each)
let resolve = ( a:isfile ? fnamemodify(resolve, ':p:h') : resolve ).s:lash
retu !( stridx(resolve, a:cwd) && ( stridx(a:cwd, resolve) || a:isfile ) )
endf

fu! ctrlp#rmbasedir(items)
Expand Down Expand Up @@ -1050,7 +1051,7 @@ endf

fu! s:highlight(pat, grp)
cal clearmatches()
if !empty(a:pat) && a:pat != '..' && s:itemtype < 3
if !empty(a:pat) && s:itemtype < 3
let pat = substitute(a:pat, '\~', '\\~', 'g')
if !s:regexp | let pat = escape(pat, '.') | en
" Match only filename
Expand Down Expand Up @@ -1166,7 +1167,7 @@ endf
fu! s:setupblank()
setl noswf nobl nonu nowrap nolist nospell nocuc wfh
setl fdc=0 fdl=99 tw=0 bt=nofile bh=unload
if v:version >= 703
if v:version > 702
setl nornu noudf cc=0
en
endf
Expand Down Expand Up @@ -1195,17 +1196,13 @@ fu! s:tail()
endf

fu! s:sanstail(str)
" Restore the number of backslashes
let [str, pat] = [substitute(a:str, '\\\\', '\', 'g'), '\([^:]\|\\:\)*$']
unl! s:optail
if match(str, '\\\@<!:'.pat) >= 0
let s:optail = matchstr(str, ':\zs'.pat)
retu substitute(str, ':'.pat, '', '')
let s:optail = matchstr(str, '\\\@<!:\zs'.pat)
let str = substitute(str, '\\\@<!:'.pat, '', '')
en
if match(str, '\\\=:'.pat) >= 0
let str = substitute(str, '\\\=\ze:'.pat, '', '')
en
retu str
retu substitute(str, '\\\ze:', '', 'g')
endf
" Misc {{{2
fu! s:lastvisual()
Expand Down
2 changes: 1 addition & 1 deletion autoload/ctrlp/utils.vim
Expand Up @@ -61,7 +61,7 @@ fu! ctrlp#utils#writecache(lines, ...)
endf

fu! ctrlp#utils#glob(...)
retu call('glob', v:version > 701 ? a:000 : a:1)
retu call('glob', v:version > 701 ? a:000 : [a:1])
endf
"}}}

Expand Down

0 comments on commit ea4c602

Please sign in to comment.