Support multiple user commands

Support defining multiple user VCS commands with g:ctrlp_user_command
following this format:

let g:ctrlp_user_command = {
  \ 'types': {
    \ 1: [root_marker_1, listing_command_1],
    \ n: [root_marker_n, listing_command_n],
    \ },
  \ 'fallback': fallback_command
  \ }

Check the docs for a working example (:help ctrlp_user_command).

Refs #118
This commit is contained in:
Kien N 2012-01-30 08:54:06 +07:00
parent 2d90da985d
commit 6a9f1e3a46
3 changed files with 43 additions and 14 deletions

View File

@ -218,13 +218,13 @@ fu! s:Files()
" Remove base directory " Remove base directory
cal ctrlp#rmbasedir(g:ctrlp_allfiles) cal ctrlp#rmbasedir(g:ctrlp_allfiles)
let read_cache = 0 let read_cache = 0
if len(g:ctrlp_allfiles) <= s:compare_lim
cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
en
el el
let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile) let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
let read_cache = 1 let read_cache = 1
en en
if len(g:ctrlp_allfiles) <= s:compare_lim
cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
en
cal s:writecache(read_cache, cafile) cal s:writecache(read_cache, cafile)
retu g:ctrlp_allfiles retu g:ctrlp_allfiles
endf endf
@ -266,9 +266,20 @@ fu! s:lsCmd()
" Try the secondary_command " Try the secondary_command
retu len(cmd) == 3 ? cmd[2] : '' retu len(cmd) == 3 ? cmd[2] : ''
en en
unl! s:vcsroot unl s:vcsroot
let s:vcscmd = s:lash == '\' ? 1 : 0 let s:vcscmd = s:lash == '\' ? 1 : 0
retu cmd[1] retu cmd[1]
elsei type(cmd) == 4 && has_key(cmd, 'types')
for key in sort(keys(cmd['types']), 's:compval')
cal s:findroot(getcwd(), cmd['types'][key][0], 0, 1)
if exists('s:vcsroot') | brea | en
endfo
if !exists('s:vcsroot')
retu has_key(cmd, 'fallback') ? cmd['fallback'] : ''
en
unl s:vcsroot
let s:vcscmd = s:lash == '\' ? 1 : 0
retu cmd['types'][key][1]
en en
endf endf
fu! s:Buffers() "{{{1 fu! s:Buffers() "{{{1
@ -944,6 +955,10 @@ fu! s:mixedsort(s1, s2)
en en
retu 2 * cml + cln retu 2 * cml + cln
endf endf
fu! s:compval(...)
retu a:1 - a:2
endf
" Statusline {{{2 " Statusline {{{2
fu! ctrlp#statusline() fu! ctrlp#statusline()
if !exists('s:statypes') if !exists('s:statypes')
@ -1126,8 +1141,8 @@ fu! s:syntax()
sy match CtrlPNoEntries '^ == NO ENTRIES ==$' sy match CtrlPNoEntries '^ == NO ENTRIES ==$'
sy match CtrlPLinePre '^>' sy match CtrlPLinePre '^>'
hi link CtrlPNoEntries Error hi link CtrlPNoEntries Error
if exists('g:colors_name') if hlexists('Normal')
exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg' sil! exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg'
en en
endf endf

View File

@ -57,13 +57,13 @@ fu! ctrlp#dir#init(...)
cal s:globdirs(s:cwd, 0) cal s:globdirs(s:cwd, 0)
cal ctrlp#rmbasedir(g:ctrlp_alldirs) cal ctrlp#rmbasedir(g:ctrlp_alldirs)
let read_cache = 0 let read_cache = 0
if len(g:ctrlp_alldirs) <= s:compare_lim
cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
en
el el
let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile) let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
let read_cache = 1 let read_cache = 1
en en
if len(g:ctrlp_alldirs) <= s:compare_lim
cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
en
if !read_cache if !read_cache
cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile) cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile)
let g:ctrlp_newdir = 0 let g:ctrlp_newdir = 0

View File

@ -147,7 +147,7 @@ only need to keep the lines that youve changed the values (inside []): >
\ 'ToggleType(1)': ['<c-f>', '<c-up>'], \ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'], \ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>', '<c-i>'], \ 'PrtExpandDir()': ['<tab>', '<c-i>'],
\ 'PrtInsert("w")': ['<F2>'], \ 'PrtInsert("w")': ['<F2>', '<insert>'],
\ 'PrtInsert("s")': ['<F3>'], \ 'PrtInsert("s")': ['<F3>'],
\ 'PrtInsert("v")': ['<F4>'], \ 'PrtInsert("v")': ['<F4>'],
\ 'PrtInsert("+")': ['<F6>'], \ 'PrtInsert("+")': ['<F6>'],
@ -239,7 +239,7 @@ Examples: >
let g:ctrlp_custom_ignore = { let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$\|\.svn$', \ 'dir': '\.git$\|\.hg$\|\.svn$',
\ 'file': '\.exe$\|\.so$\|\.dll$', \ 'file': '\.exe$\|\.so$\|\.dll$',
\ 'link': 'some$\|bad$\|symbolic$\|links$', \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
\ } \ }
< <
@ -276,14 +276,28 @@ Examples: >
< <
Use a version control listing command when inside a repository, this is faster Use a version control listing command when inside a repository, this is faster
when scanning large projects: > when scanning large projects: >
let g:ctrlp_user_command = [repo_marker, vcs_ls_command, fallback_command] let g:ctrlp_user_command = [root_marker, listing_command, fallback_command]
let g:ctrlp_user_command = {
\ 'types': {
\ 1: [root_marker_1, listing_command_1],
\ n: [root_marker_n, listing_command_n],
\ },
\ 'fallback': fallback_command
\ }
< <
If the fallback_command is empty or not defined, |globpath()| will then be used
when searching outside a repo.
Examples: > Examples: >
let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files'] let g:ctrlp_user_command = ['.git/', 'cd %s && git ls-files']
let g:ctrlp_user_command = ['.hg/', 'hg --cwd %s locate -I .'] let g:ctrlp_user_command = ['.hg/', 'hg --cwd %s locate -I .']
let g:ctrlp_user_command = {
\ 'types': {
\ 1: ['.git/', 'cd %s && git ls-files'],
\ 2: ['.hg/', 'hg --cwd %s locate -I .'],
\ },
\ 'fallback': 'find %s -type f'
\ }
< <
If the fallback_command is empty or not defined, |globpath()| will then be used
when searching outside a repo.
*'g:ctrlp_max_history'* *'g:ctrlp_max_history'*
The maximum number of input strings you want |CtrlP| to remember. The default The maximum number of input strings you want |CtrlP| to remember. The default