keep cwd if reached max depth

This commit is contained in:
Kien N 2011-10-11 16:49:36 +07:00
parent a7dbff85d2
commit 976a1025e0
2 changed files with 23 additions and 13 deletions

View File

@ -3,7 +3,7 @@
" Description: Full path fuzzy file, buffer and MRU file finder for Vim. " Description: Full path fuzzy file, buffer and MRU file finder for Vim.
" Author: Kien Nguyen <github.com/kien> " Author: Kien Nguyen <github.com/kien>
" License: MIT " License: MIT
" Version: 1.5.2 " Version: 1.5.3
" ============================================================================= " =============================================================================
if v:version < '700' "{{{ if v:version < '700' "{{{
@ -115,16 +115,16 @@ func! s:UserCommand(path, lscmd)
if exists('+ssl') && &ssl if exists('+ssl') && &ssl
let ssl = &ssl let ssl = &ssl
let &ssl = 0 let &ssl = 0
let path = substitute(path, '/', '\', 'g') let path = tr(path, '/', '\')
endif endif
let path = exists('*shellescape') ? shellescape(path) : path let path = exists('*shellescape') ? shellescape(path) : path
let g:ctrlp_allfiles = split(system(printf(a:lscmd, path)), '\n') let g:ctrlp_allfiles = split(system(printf(a:lscmd, path)), '\n')
if exists('+ssl') && exists('ssl') if exists('+ssl') && exists('ssl')
let &ssl = ssl let &ssl = ssl
cal map(g:ctrlp_allfiles, 'substitute(v:val, "\\", "/", "g")') cal map(g:ctrlp_allfiles, 'tr(v:val, "\\", "/")')
endif endif
if exists('s:vcscmd') && s:vcscmd if exists('s:vcscmd') && s:vcscmd
cal map(g:ctrlp_allfiles, 'substitute(v:val, "/", "\\", "g")') cal map(g:ctrlp_allfiles, 'tr(v:val, "/", "\\")')
endif endif
endfunc endfunc
@ -189,6 +189,7 @@ func! s:SplitPattern(str,...) "{{{
" Remove the tail " Remove the tail
let str = substitute(str, ':\([^:]\|\\:\)*$', '', 'g') let str = substitute(str, ':\([^:]\|\\:\)*$', '', 'g')
endif endif
let s:savestr = str
if s:regexp || match(str, '[*|]') >= 0 if s:regexp || match(str, '[*|]') >= 0
\ || match(str, '\\\(zs\|ze\|<\|>\)') >= 0 \ || match(str, '\\\(zs\|ze\|<\|>\)') >= 0
let array = [str] let array = [str]
@ -285,7 +286,7 @@ func! s:BufOpen(...) "{{{
exe 'chd!' s:cwd exe 'chd!' s:cwd
unl s:cwd unl s:cwd
endif endif
unl! s:focus s:hisidx s:hstgot s:marked s:winnr s:init unl! s:focus s:hisidx s:hstgot s:marked s:winnr s:init s:savestr
" Record the input string " Record the input string
let prt = g:CtrlP_prompt let prt = g:CtrlP_prompt
cal s:recordhist(prt[0] . prt[1] . prt[2]) cal s:recordhist(prt[0] . prt[1] . prt[2])
@ -375,11 +376,18 @@ func! s:Renderer(lines, pat) "{{{
endfunc "}}} endfunc "}}}
func! s:UpdateMatches(pat) "{{{ func! s:UpdateMatches(pat) "{{{
" Delete the buffer's content let pat = a:pat
sil! %d _ " Get the previous string if existed
let pats = s:SplitPattern(a:pat) let oldstr = exists('s:savestr') ? s:savestr : ''
let pats = s:SplitPattern(pat)
" Get the new string sans tail
let notail = substitute(pat, ':\([^:]\|\\:\)*$', '', 'g')
" Stop if the string's unchanged
if notail == oldstr && !empty(notail) | retu | endif
let lines = s:GetMatchedItems(g:ctrlp_lines, pats, s:mxheight) let lines = s:GetMatchedItems(g:ctrlp_lines, pats, s:mxheight)
let pat = pats[-1] let pat = pats[-1]
" Delete the buffer's content
sil! %d _
cal s:Renderer(lines, pat) cal s:Renderer(lines, pat)
" Highlighting " Highlighting
if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0] && exists('*clearmatches') if type(s:mathi) == 3 && len(s:mathi) == 2 && s:mathi[0] && exists('*clearmatches')
@ -396,8 +404,8 @@ func! s:BuildPrompt(upd,...) "{{{
let estr = '"\' let estr = '"\'
let prt = deepcopy(g:CtrlP_prompt) let prt = deepcopy(g:CtrlP_prompt)
cal map(prt, 'escape(v:val, estr)') cal map(prt, 'escape(v:val, estr)')
let str = prt[0] . prt[1] . prt[2] let str = prt[0] . prt[1] . prt[2]
if ( s:matches || s:regexp || match(str, '[*|]') >= 0 ) && a:upd if a:upd && ( s:matches || s:regexp || match(str, '[*|]') >= 0 )
sil! cal s:UpdateMatches(str) sil! cal s:UpdateMatches(str)
endif endif
sil! cal s:statusline() sil! cal s:statusline()
@ -408,7 +416,7 @@ func! s:BuildPrompt(upd,...) "{{{
elseif exists('a:1') || ( exists('a:1') && !a:1 ) elseif exists('a:1') || ( exists('a:1') && !a:1 )
let hiactive = 'Comment' let hiactive = 'Comment'
let hicursor = 'Comment' let hicursor = 'Comment'
let base = substitute(base, '>', '-', 'g') let base = tr(base, '>', '-')
endif endif
let hibase = 'Comment' let hibase = 'Comment'
" Build it " Build it
@ -796,7 +804,9 @@ endfunc
" * SetWorkingPath {{{ " * SetWorkingPath {{{
func! s:FindRoot(curr, mark, depth, type) func! s:FindRoot(curr, mark, depth, type)
let depth = a:depth + 1 let depth = a:depth + 1
if !empty(globpath(a:curr, a:mark)) || depth > s:maxdepth let notfound = empty(globpath(a:curr, a:mark))
if !notfound || depth > s:maxdepth
if notfound | retu | endif
if a:type if a:type
let s:vcsroot = depth <= s:maxdepth ? a:curr : '' let s:vcsroot = depth <= s:maxdepth ? a:curr : ''
else else

View File

@ -1,4 +1,4 @@
*ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.2 *ctrlp.txt* Full path fuzzy file, buffer and MRU file finder. v1.5.3
*CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'* *CtrlP* *ControlP* *'ctrlp'* *'ctrl-p'*
=============================================================================== ===============================================================================
# # # #