diff --git a/autoload/ctrlp.vim b/autoload/ctrlp.vim index f79da1a..7b85f02 100644 --- a/autoload/ctrlp.vim +++ b/autoload/ctrlp.vim @@ -44,7 +44,6 @@ fu! s:opts() exe 'let' va[0] '=' string(exists(ke) ? eval(ke) : va[1]) endfo if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en - let s:glob = s:dotfiles ? '.*\|*' : '*' let s:maxdepth = min([s:maxdepth, 100]) let s:igntype = empty(s:usrign) ? -1 : type(s:usrign) " Extensions @@ -66,11 +65,12 @@ fu! s:opts() \ 'AcceptSelection("h")': ['', '', ''], \ 'AcceptSelection("t")': ['', ''], \ 'AcceptSelection("v")': ['', ''], - \ 'ToggleFocus()': ['', ''], + \ 'ToggleFocus()': [''], \ 'ToggleRegex()': [''], \ 'ToggleByFname()': [''], \ 'ToggleType(1)': ['', ''], \ 'ToggleType(-1)': ['', ''], + \ 'PrtExpandDir()': ['', ''], \ 'PrtInsert("w")': [''], \ 'PrtInsert("s")': [''], \ 'PrtInsert("v")': [''], @@ -224,7 +224,10 @@ fu! s:Files() endf fu! s:GlobPath(dirs, depth) - let entries = split(globpath(a:dirs, s:glob), "\n") + let entries = split(globpath(a:dirs, '*'), "\n") + if s:dotfiles + let entries += split(globpath(a:dirs, '.*'), "\n") + en let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1] cal extend(g:ctrlp_allfiles, dnf[1]) if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth @@ -487,6 +490,26 @@ fu! s:PrtInsert(type) \ : a:type == '+' ? substitute(getreg('+'), '\n', '\\n', 'g') : s:prompt[0] cal s:BuildPrompt(1) endf + +fu! s:PrtExpandDir() + let prt = s:prompt + if prt[0] == '' | retu | en + let parts = split(prt[0], '[\/]\ze[^\/]\+[\/:]\?$') + if len(parts) == 1 + let seed = parts[0] + let begin = '' + elsei len(parts) > 1 + let seed = parts[1] + let begin = parts[0].s:lash + en + let dirs = s:dircompl(begin, seed) + if len(dirs) == 1 + let prt[0] = dirs[0] + elsei len(dirs) > 1 + let prt[0] .= s:findcommon(dirs, prt[0]) + en + cal s:BuildPrompt(1) +endf " Movement {{{2 fu! s:PrtCurLeft() if !empty(s:prompt[0]) @@ -960,6 +983,33 @@ fu! ctrlp#progress(enum) redr endf " Paths {{{2 +fu! s:dircompl(dir, seed) + if a:seed == '' | retu [] | en + let [dir, seed] = a:dir == '' + \ ? [getcwd().s:lash, a:seed] : [a:dir, a:dir.a:seed] + let dirs = ctrlp#rmbasedir(split(globpath(dir, '*/'), "\n")) + if s:dotfiles + let dirs += ctrlp#rmbasedir(split(globpath(dir, '.*/'), "\n")) + en + cal filter(dirs, '!match(v:val, escape(seed, ''''''~$.\'')) && ( !s:dotfiles' + \ . ' || ( s:dotfiles && match(v:val, ''[\/]\.\{,2}[\/:]$'') < 0) )') + retu dirs +endf + +fu! s:findcommon(items, seed) + let [items, id, cmn, ic] = [copy(a:items), strlen(a:seed), '', 0] + cal map(items, 'strpart(v:val, id)') + for char in split(items[0], '\zs') + for item in items[1:] + if item[ic] != char | let brk = 1 | brea | en + endfo + if exists('brk') | brea | en + let cmn .= char + let ic += 1 + endfo + retu cmn +endf + fu! s:ispathitem() let ext = s:itemtype - ( g:ctrlp_builtins + 1 ) retu s:itemtype < 3 diff --git a/autoload/ctrlp/dir.vim b/autoload/ctrlp/dir.vim index 76b2dfc..875f54e 100644 --- a/autoload/ctrlp/dir.vim +++ b/autoload/ctrlp/dir.vim @@ -14,7 +14,7 @@ let s:ars = [ \ 's:maxdepth', \ 's:maxfiles', \ 's:compare_lim', - \ 's:glob', + \ 's:dotfiles', \ ] let s:dir_var = { @@ -31,7 +31,10 @@ 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) " Utilities {{{1 fu! s:globdirs(dirs, depth) - let entries = split(globpath(a:dirs, s:glob), "\n") + let entries = split(globpath(a:dirs, '*'), "\n") + if s:dotfiles + let entries += split(globpath(a:dirs, '.*'), "\n") + en let [dirs, depth] = [ctrlp#dirnfile(entries)[0], a:depth + 1] cal extend(g:ctrlp_alldirs, dirs) if !empty(dirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles) diff --git a/doc/ctrlp.txt b/doc/ctrlp.txt index e99926b..e179a64 100644 --- a/doc/ctrlp.txt +++ b/doc/ctrlp.txt @@ -142,11 +142,12 @@ only need to keep the lines that you’ve changed the values (inside []): > \ 'AcceptSelection("h")': ['', '', ''], \ 'AcceptSelection("t")': ['', ''], \ 'AcceptSelection("v")': ['', ''], - \ 'ToggleFocus()': ['', ''], + \ 'ToggleFocus()': [''], \ 'ToggleRegex()': [''], \ 'ToggleByFname()': [''], \ 'ToggleType(1)': ['', ''], \ 'ToggleType(-1)': ['', ''], + \ 'PrtExpandDir()': ['', ''], \ 'PrtInsert("w")': [''], \ 'PrtInsert("s")': [''], \ 'PrtInsert("v")': [''], @@ -443,6 +444,10 @@ Once inside the prompt:~ Scroll to the 'previous' search mode in the sequence. + Auto-complete directory names under the current working directory inside + the prompt. + + Toggle the focus between the match window and the prompt. , @@ -738,6 +743,8 @@ CHANGELOG *ctrlp-changelog* Before 2012/01/15~ + + New mapping: Switch and . is now used for completion + of directory names under the current working directory. + New options: |g:ctrlp_arg_map| for , to accept an argument. |g:ctrlp_status_func| custom statusline. |g:ctrlp_mruf_relative| show only MRU files inside cwd. diff --git a/plugin/ctrlp.vim b/plugin/ctrlp.vim index 3a1754f..b0f416e 100644 --- a/plugin/ctrlp.vim +++ b/plugin/ctrlp.vim @@ -55,7 +55,7 @@ if index(s:ext, 'buffertag') >= 0 com! CtrlPBufTagAll cal ctrlp#init(ctrlp#buffertag#cmd(1)) en -if index(s:ext, 'rts') >= 0 +if index(s:ext, 'rtscript') >= 0 com! CtrlPRTS cal ctrlp#init(ctrlp#rtscript#id()) en