Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option for using VCS's list command instead of Vim's globpath() #17

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions autoload/ctrlp.vim
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func! s:opts()
\ 'g:ctrlp_max_depth' : ['s:maxdepth', 40],
\ 'g:ctrlp_open_new_file' : ['s:newfop', 3],
\ 'g:ctrlp_open_multi' : ['s:opmul', 1],
\ 'g:ctrlp_use_vcs_ls' : ['s:usevcsls', 0],
\ }
for key in keys(opts)
let def = call('exists', [key]) ? string(eval(key)) : string(opts[key][1])
Expand All @@ -48,6 +49,8 @@ func! s:opts()
endif
if !exists('g:ctrlp_user_command')
let g:ctrlp_user_command = ''
else
let s:usevcsls = 0 " Disable use_vcs_ls
endif
if !exists('g:ctrlp_max_history')
let s:maxhst = exists('+hi') ? &hi : 20
Expand Down Expand Up @@ -115,6 +118,7 @@ func! s:ListAllFiles(path)
let cache_file = ctrlp#utils#cachefile()
if g:ctrlp_newcache || !filereadable(cache_file) || !s:caching
" Get the list of files
cal s:SetUserCommand()
if empty(g:ctrlp_user_command)
cal s:List(a:path, [], 0)
else
Expand All @@ -129,6 +133,10 @@ func! s:ListAllFiles(path)
let &ssl = ssl
cal map(g:ctrlp_allfiles, 'substitute(v:val, "\\", "/", "g")')
endif
" Remove directories (svn)
if g:ctrlp_user_command =~ '^svn'
cal filter(g:ctrlp_allfiles, 'v:val[-1:] != "/"')
endif
catch
retu []
endtry
Expand Down Expand Up @@ -793,6 +801,52 @@ func! s:PrtSwitcher()
endfunc
"}}}

" * UseVCSls {{{
func! s:FindRepoType(curr, markers, depth)
let depth = a:depth + 1

if a:depth == 0 && !empty(globpath(a:curr, '.svn/'))
retu '.svn/'
endif

for marker in a:markers
if !empty(globpath(a:curr, marker))
retu marker
endif
endfor

if depth > s:maxdepth
retu ''
endif

let parent = substitute(a:curr, '[\/]\zs[^\/]\+[\/]\?$', '', '')
if parent != a:curr | retu s:FindRepoType(parent, a:markers, depth) | endif
endfunc

func! s:SetUserCommand()
if !s:usevcsls
retu
endif

let markers = [
\ '.git/',
\ '.hg/',
\ ]

let type = s:FindRepoType(getcwd(), markers, 0)

if empty(type)
let g:ctrlp_user_command = ''
elseif type == '.git/' && executable('git')
let g:ctrlp_user_command = 'cd %s && git ls-files'
elseif type == '.hg/' && executable('hg')
let g:ctrlp_user_command = 'hg --cwd %s locate --fullpath -I .'
elseif type == '.svn/' && executable('svn')
let g:ctrlp_user_command = 'svn list -R %s'
endif
endfunc
"}}}

" * SetWorkingPath {{{
func! s:FindRoot(curr, mark, depth)
let depth = a:depth + 1
Expand Down