properly support wildignore

This commit is contained in:
Kien N 2011-09-09 04:39:59 +07:00
parent 68236f6ec9
commit 1daeb3291d
3 changed files with 13 additions and 15 deletions

View File

@ -125,13 +125,14 @@ endfunc
" s:ListAllFiles(path) {{{
func! s:List(path)
let allfiles = split(globpath(a:path, '**'), '\n')
" note: wildignore is ignored when using **, so find all the directories
" first then glob with * for the files
let alldirs = split(globpath(a:path, '**'), '\n')
cal filter(alldirs, 'isdirectory(v:val)')
let dirs = join(alldirs, ',')
let allfiles = split(globpath(a:path, '*'), '\n')
let allfiles = extend(allfiles, split(globpath(dirs, '*'), '\n'))
cal filter(allfiles, '!isdirectory(v:val)')
" filter all entries matched wildignore's patterns (in addition to globpath's)
if exists('+wig') && !empty(&wig)
let ignores = map(split(&wig, ','), 's:wigfilter(v:val)')
cal filter(allfiles, 's:matchlists(v:val, string(ignores))')
endif
" remove base directory
let path = &ssl || !exists('+ssl') ? getcwd().'/' : substitute(getcwd(), '\', '\\\\', 'g').'\\'
cal map(allfiles, 'substitute(v:val, path, "", "g")')
@ -749,17 +750,12 @@ func! s:matchsubstr(item, pat)
endfunc
func! s:matchlists(item, lst)
for each in eval(a:lst)
for each in a:lst
if match(a:item, each) >= 0 | retu 0 | endif
endfor
retu 1
endfunc
func! s:wigfilter(val)
let val = substitute(a:val, '\\', '\\\\', 'g')
retu substitute(val, '*\+', '\.*', 'g')
endfunc
func! s:syntax()
syn match CtrlPNoEntries '^ == NO MATCHES ==$'
syn match CtrlPNoEntries '^ == DISABLED ==$'

View File

@ -206,6 +206,7 @@ Example: >
*:CtrlPCurWD*
:CtrlPCurWD
Find files in the current working directory.
Ignores |g:ctrlp_working_path_mode|.
*:CtrlPCurFile*
:CtrlPCurFile
@ -213,7 +214,7 @@ Example: >
*:CtrlPRoot*
:CtrlPRoot
Same as |:CtrlPCurFile| but from the projects root.
Same as |:CtrlPCurFile| but start from the projects root.
See also |g:ctrlp_working_path_mode|.
===============================================================================

View File

@ -19,8 +19,9 @@ com! CtrlPMRUFiles cal ctrlp#init(2)
com! ClearCtrlPCache cal ctrlp#clearcache()
com! ClearAllCtrlPCaches cal ctrlp#clearallcaches()
com! CtrlPRoot cal ctrlp#init(0, 2)
com! CtrlPCurDir cal ctrlp#init(0, 1)
com! CtrlPCurWD cal ctrlp#init(0, 0)
com! CtrlPCurFile cal ctrlp#init(0, 1)
com! CtrlPRoot cal ctrlp#init(0, 2)
exe 'nn <silent>' g:ctrlp_map ':<c-u>CtrlP<cr>'