Use s:dyncwd more

This commit is contained in:
Kien N 2012-04-06 04:42:05 +07:00
parent 045b66a6ab
commit b1a688fc2f
2 changed files with 25 additions and 27 deletions

View File

@ -233,15 +233,15 @@ fu! ctrlp#reset()
endf endf
" * Files {{{1 " * Files {{{1
fu! ctrlp#files() fu! ctrlp#files()
let [cwd, cafile, g:ctrlp_allfiles] = [getcwd(), ctrlp#utils#cachefile(), []] let [cafile, g:ctrlp_allfiles] = [ctrlp#utils#cachefile(), []]
if g:ctrlp_newcache || !filereadable(cafile) || !s:caching if g:ctrlp_newcache || !filereadable(cafile) || !s:caching
let lscmd = s:lsCmd() let lscmd = s:lsCmd()
" Get the list of files " Get the list of files
if empty(lscmd) if empty(lscmd)
cal s:GlobPath(cwd, 0) cal s:GlobPath(s:dyncwd, 0)
el el
sil! cal ctrlp#progress('Indexing...') sil! cal ctrlp#progress('Indexing...')
try | cal s:UserCmd(cwd, lscmd) try | cal s:UserCmd(lscmd)
cat | retu [] | endt cat | retu [] | endt
en en
" Remove base directory " Remove base directory
@ -268,8 +268,8 @@ fu! s:GlobPath(dirs, depth)
en en
endf endf
fu! s:UserCmd(path, lscmd) fu! s:UserCmd(lscmd)
let path = a:path let path = s:dyncwd
if exists('+ssl') && &ssl if exists('+ssl') && &ssl
let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')] let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')]
en en
@ -290,7 +290,7 @@ fu! s:lsCmd()
retu cmd retu cmd
elsei type(cmd) == 3 && len(cmd) >= 2 && cmd[:1] != ['', ''] elsei type(cmd) == 3 && len(cmd) >= 2 && cmd[:1] != ['', '']
" Find a repo root " Find a repo root
cal s:findroot(getcwd(), cmd[0], 0, 1) cal s:findroot(s:dyncwd, cmd[0], 0, 1)
if !exists('s:vcsroot') if !exists('s:vcsroot')
" Try the secondary_command " Try the secondary_command
retu len(cmd) == 3 ? cmd[2] : '' retu len(cmd) == 3 ? cmd[2] : ''
@ -300,7 +300,7 @@ fu! s:lsCmd()
retu cmd[1] retu cmd[1]
elsei type(cmd) == 4 && has_key(cmd, 'types') elsei type(cmd) == 4 && has_key(cmd, 'types')
for key in sort(keys(cmd['types']), 's:compval') for key in sort(keys(cmd['types']), 's:compval')
cal s:findroot(getcwd(), cmd['types'][key][0], 0, 1) cal s:findroot(s:dyncwd, cmd['types'][key][0], 0, 1)
if exists('s:vcsroot') | brea | en if exists('s:vcsroot') | brea | en
endfo endfo
if !exists('s:vcsroot') if !exists('s:vcsroot')
@ -786,7 +786,7 @@ endf
fu! s:SpecInputs(str) fu! s:SpecInputs(str)
let spi = !s:itemtype || s:getextvar('specinput') > 0 let spi = !s:itemtype || s:getextvar('specinput') > 0
if a:str == '..' && spi if a:str == '..' && spi
cal s:parentdir(getcwd()) cal s:parentdir(s:dyncwd)
cal ctrlp#setlines() cal ctrlp#setlines()
cal s:PrtClear() cal s:PrtClear()
retu 1 retu 1
@ -842,7 +842,7 @@ fu! s:CreateNewFile(...)
en en
if !exists('optyp') | retu | en if !exists('optyp') | retu | en
let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()] let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()]
if !stridx(filpath, getcwd()) | cal s:insertcache(str) | en if !stridx(filpath, s:dyncwd) | cal s:insertcache(str) | en
cal s:PrtExit() cal s:PrtExit()
let cmd = md == 'r' ? ctrlp#normcmd('e') : let cmd = md == 'r' ? ctrlp#normcmd('e') :
\ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' : \ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' :
@ -954,15 +954,14 @@ fu! s:compmre(...)
if !exists('s:mrbs') if !exists('s:mrbs')
let s:mrbs = ctrlp#mrufiles#bufs() let s:mrbs = ctrlp#mrufiles#bufs()
en en
let cwd = getcwd() let cwd = s:dyncwd
retu index(s:mrbs, cwd.s:lash().a:1) - index(s:mrbs, cwd.s:lash().a:2) retu index(s:mrbs, cwd.s:lash().a:1) - index(s:mrbs, cwd.s:lash().a:2)
endf endf
fu! s:comparent(s1, s2) fu! s:comparent(s1, s2)
" By same parent dir " By same parent dir
let cwd = getcwd() if match(s:crfpath, escape(s:dyncwd, '.^$*\')) >= 0
if match(s:crfpath, escape(cwd, '.^$*\')) >= 0 let [as1, as2] = [s:dyncwd.s:lash().a:s1, s:dyncwd.s:lash().a:s2]
let [as1, as2] = [cwd.s:lash().a:s1, cwd.s:lash().a:s2]
let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)] let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)]
if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en
if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en
@ -1059,7 +1058,7 @@ fu! ctrlp#statusline()
let byfname = '%#CtrlPMode1# '.byfname.' %*' let byfname = '%#CtrlPMode1# '.byfname.' %*'
let regex = s:regexp ? '%#CtrlPMode2# regex %*' : '' let regex = s:regexp ? '%#CtrlPMode2# regex %*' : ''
let slider = ' <'.prv.'>={'.item.'}=<'.nxt.'>' let slider = ' <'.prv.'>={'.item.'}=<'.nxt.'>'
let dir = ' %=%<%#CtrlPMode2# '.getcwd().' %*' let dir = ' %=%<%#CtrlPMode2# '.s:dyncwd.' %*'
let &l:stl = focus.byfname.regex.slider.marked.dir let &l:stl = focus.byfname.regex.slider.marked.dir
en en
endf endf
@ -1072,7 +1071,7 @@ endf
fu! ctrlp#progress(enum) fu! ctrlp#progress(enum)
if has('macunix') || has('mac') | sl 1m | en if has('macunix') || has('mac') | sl 1m | en
let &l:stl = s:status != {} ? call(s:status['prog'], [a:enum]) let &l:stl = s:status != {} ? call(s:status['prog'], [a:enum])
\ : '%#CtrlPStats# '.a:enum.' %* %=%<%#CtrlPMode2# '.getcwd().' %*' \ : '%#CtrlPStats# '.a:enum.' %* %=%<%#CtrlPMode2# '.s:dyncwd.' %*'
redraws redraws
endf endf
" Paths {{{2 " Paths {{{2
@ -1083,7 +1082,7 @@ endf
fu! s:dircompl(be, sd) fu! s:dircompl(be, sd)
if a:sd == '' | retu [] | en if a:sd == '' | retu [] | en
let [be, sd] = a:be == '' ? [getcwd(), a:sd] : [a:be, a:be.s:lash(a:be).a:sd] let [be, sd] = a:be == '' ? [s:dyncwd, a:sd] : [a:be, a:be.s:lash(a:be).a:sd]
let dirs = ctrlp#rmbasedir(split(globpath(be, a:sd.'*/'), "\n")) let dirs = ctrlp#rmbasedir(split(globpath(be, a:sd.'*/'), "\n"))
cal filter(dirs, '!match(v:val, escape(sd, ''~$.\''))' cal filter(dirs, '!match(v:val, escape(sd, ''~$.\''))'
\ . ' && match(v:val, ''\v(^|[\/])\.{1,2}[\/]$'') < 0') \ . ' && match(v:val, ''\v(^|[\/])\.{1,2}[\/]$'') < 0')
@ -1110,7 +1109,7 @@ fu! s:headntail(str)
endf endf
fu! s:lash(...) fu! s:lash(...)
retu match(a:0 ? a:1 : getcwd(), '[\/]$') < 0 ? s:lash : '' retu match(a:0 ? a:1 : s:dyncwd, '[\/]$') < 0 ? s:lash : ''
endf endf
fu! s:ispathitem() fu! s:ispathitem()
@ -1119,7 +1118,7 @@ fu! s:ispathitem()
endf endf
fu! ctrlp#dirnfile(entries) fu! ctrlp#dirnfile(entries)
let [items, cwd] = [[[], []], getcwd().s:lash()] let [items, cwd] = [[[], []], s:dyncwd.s:lash()]
for each in a:entries for each in a:entries
let etype = getftype(each) let etype = getftype(each)
if s:igntype >= 0 && s:usrign(each, etype) | con | en if s:igntype >= 0 && s:usrign(each, etype) | con | en
@ -1156,9 +1155,8 @@ fu! s:samerootsyml(each, isfile, cwd)
endf endf
fu! ctrlp#rmbasedir(items) fu! ctrlp#rmbasedir(items)
let cwd = getcwd() if a:items != [] && !stridx(a:items[0], s:dyncwd)
if a:items != [] && !stridx(a:items[0], cwd) let idx = strlen(s:dyncwd) + ( match(s:dyncwd, '[\/]$') < 0 )
let idx = strlen(cwd) + ( match(cwd, '[\/]$') < 0 )
retu map(a:items, 'strpart(v:val, idx)') retu map(a:items, 'strpart(v:val, idx)')
en en
retu a:items retu a:items

View File

@ -38,25 +38,25 @@ fu! s:getnewmix(cwd, clim)
cal ctrlp#mrufiles#refresh('raw') cal ctrlp#mrufiles#refresh('raw')
let g:ctrlp_newcache = 1 let g:ctrlp_newcache = 1
en en
cal ctrlp#files() let g:ctrlp_lines = ctrlp#files()
cal ctrlp#progress('Mixing...') cal ctrlp#progress('Mixing...')
let mrufs = ctrlp#mrufiles#list('raw') let mrufs = ctrlp#mrufiles#list('raw')
if exists('+ssl') && &ssl if exists('+ssl') && &ssl
cal map(mrufs, 'tr(v:val, "\\", "/")') cal map(mrufs, 'tr(v:val, "\\", "/")')
en en
if len(mrufs) > len(g:ctrlp_allfiles) || v:version < 702 if len(mrufs) > len(g:ctrlp_lines) || v:version < 702
cal filter(mrufs, 'stridx(v:val, a:cwd)') cal filter(mrufs, 'stridx(v:val, a:cwd)')
el el
let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)') let cwd_mrufs = filter(copy(mrufs), '!stridx(v:val, a:cwd)')
let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs) let cwd_mrufs = ctrlp#rmbasedir(cwd_mrufs)
for each in cwd_mrufs for each in cwd_mrufs
let id = index(g:ctrlp_allfiles, each) let id = index(g:ctrlp_lines, each)
if id >= 0 | cal remove(g:ctrlp_allfiles, id) | en if id >= 0 | cal remove(g:ctrlp_lines, id) | en
endfo endfo
en en
cal map(mrufs, 'fnamemodify(v:val, ":.")') cal map(mrufs, 'fnamemodify(v:val, ":.")')
let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_allfiles) let g:ctrlp_lines = len(mrufs) > len(g:ctrlp_lines)
\ ? g:ctrlp_allfiles + mrufs : mrufs + g:ctrlp_allfiles \ ? g:ctrlp_lines + mrufs : mrufs + g:ctrlp_lines
if len(g:ctrlp_lines) <= a:clim if len(g:ctrlp_lines) <= a:clim
cal sort(g:ctrlp_lines, 'ctrlp#complen') cal sort(g:ctrlp_lines, 'ctrlp#complen')
en en