Commits

kien committed a0afe12 Draft

Ignore the vertical bar [...]

Use the global caching option for extensions
Respect smartcase

  • Participants
  • Parent commits 5fd37ed

Comments (0)

Files changed (5)

File autoload/ctrlp.vim

 " Global options
 let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
 	\ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
-	\ 'gcr': 'a:blinkon0', 'ic': 1, 'scs': 1, 'lmap': '', 'mousef': 0,
-	\ 'imd': 1 }
+	\ 'gcr': 'a:blinkon0', 'ic': 1, 'lmap': '', 'mousef': 0, 'imd': 1 }
 
 " Keymaps
 let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
 
 let s:lash = ctrlp#utils#lash()
 
-" Limiters
-let [s:compare_lim, s:nocache_lim] = [3000, 4000]
+let s:compare_lim = 3000
+
+let s:ficounts = {}
 
 " Regexp
 let s:fpats = {
 " * Files {{{1
 fu! ctrlp#files()
 	let cafile = ctrlp#utils#cachefile()
-	if g:ctrlp_newcache || !filereadable(cafile) || !s:caching
+	if g:ctrlp_newcache || !filereadable(cafile) || s:nocache()
 		let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
 		" Get the list of files
 		if empty(lscmd)
 			let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
 		en
 	en
+	cal extend(s:ficounts, { s:dyncwd : len(g:ctrlp_allfiles) })
 	retu g:ctrlp_allfiles
 endf
 
 " * MatchedItems() {{{1
 fu! s:MatchIt(items, pat, limit, exc)
 	let [lines, id] = [[], 0]
-	let pat = s:byfname ? split(a:pat, '^[^;]\+\zs;', 1) : a:pat
+	let pat = s:byfname ?
+		\ map(split(a:pat, '^[^;]\+\zs;', 1), 's:martcs.v:val') : s:martcs.a:pat
 	for item in a:items
 		let id += 1
 		try | if !( s:ispath && item == a:exc ) && call(s:mfunc, [item, pat]) >= 0
 	let s:matched = copy(lines)
 	" Sorting
 	if !s:nosort()
-		let s:compat = pat
+		let s:compat = s:martcs.pat
 		cal sort(lines, 's:mixedsort')
 		unl s:compat
 	en
 	let str = s:sanstail(a:str)
 	" Stop if the string's unchanged
 	if str == oldstr && !empty(str) && !exists('s:force') | retu | en
+	let s:martcs = &scs && str =~ '\u' ? '\C' : ''
 	let pat = s:matcher == {} ? s:SplitPattern(str) : str
 	let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines)
 		\ : s:MatchedItems(g:ctrlp_lines, pat, s:winh)
 			let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g')
 			let pat = substitute(pat, '\$\@<!$', '\\ze[^\\/]*$', 'g')
 		en
-		cal matchadd(a:grp, '\c'.pat)
+		cal matchadd(a:grp, ( s:martcs == '' ? '\c' : '\C' ).pat)
 		cal matchadd('CtrlPLinePre', '^>')
 	en
 endf
 endf
 " Cache {{{2
 fu! s:writecache(cache_file)
-	let fwrite = len(g:ctrlp_allfiles) > s:nocache_lim
-	if ( g:ctrlp_newcache || !filereadable(a:cache_file) ) && s:caching || fwrite
-		if fwrite | let s:caching = 1 | en
+	if ( g:ctrlp_newcache || !filereadable(a:cache_file) ) && !s:nocache()
 		cal ctrlp#utils#writecache(g:ctrlp_allfiles)
 		let g:ctrlp_newcache = 0
 	en
 endf
 
+fu! s:nocache()
+	retu !s:caching || ( s:caching > 1 && get(s:ficounts, s:dyncwd) < s:caching )
+endf
+
 fu! s:insertcache(str)
 	let [data, g:ctrlp_newcache, str] = [g:ctrlp_allfiles, 1, a:str]
 	if strlen(str) <= strlen(data[0])

File autoload/ctrlp/dir.vim

 en
 let [g:loaded_ctrlp_dir, g:ctrlp_newdir] = [1, 0]
 
-let s:ars = [
-	\ 's:maxdepth',
-	\ 's:maxfiles',
-	\ 's:compare_lim',
-	\ 's:glob',
-	\ ]
+let s:ars = ['s:maxdepth', 's:maxfiles', 's:compare_lim', 's:glob', 's:caching']
 
 cal add(g:ctrlp_ext_vars, {
 	\ 'init': 'ctrlp#dir#init('.join(s:ars, ', ').')',
 	\ })
 
 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
+
+let s:dircounts = {}
 " Utilities {{{1
 fu! s:globdirs(dirs, depth)
 	let entries = split(globpath(a:dirs, s:glob), "\n")
 fu! s:max(len, max)
 	retu a:max && a:len > a:max ? 1 : 0
 endf
+
+fu! s:nocache()
+	retu !s:caching || ( s:caching > 1 && get(s:dircounts, s:cwd) < s:caching )
+endf
 " Public {{{1
 fu! ctrlp#dir#init(...)
 	let s:cwd = getcwd()
 	endfo
 	let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'dir'
 	let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile('dir')
-	if g:ctrlp_newdir || !filereadable(cafile)
+	if g:ctrlp_newdir || s:nocache() || !filereadable(cafile)
 		let [s:initcwd, g:ctrlp_alldirs] = [s:cwd, []]
 		cal s:globdirs(s:cwd, 0)
 		cal ctrlp#rmbasedir(g:ctrlp_alldirs)
 			let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
 		en
 	en
+	cal extend(s:dircounts, { s:cwd : len(g:ctrlp_alldirs) })
 	retu g:ctrlp_alldirs
 endf
 

File autoload/ctrlp/rtscript.vim

 let [g:loaded_ctrlp_rtscript, g:ctrlp_newrts] = [1, 0]
 
 cal add(g:ctrlp_ext_vars, {
-	\ 'init': 'ctrlp#rtscript#init()',
+	\ 'init': 'ctrlp#rtscript#init(s:caching)',
 	\ 'accept': 'ctrlp#acceptfile',
 	\ 'lname': 'runtime scripts',
 	\ 'sname': 'rts',
 	\ })
 
 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
+
+let s:filecounts = {}
+" Utilities {{{1
+fu! s:nocache()
+	retu !s:caching || ( s:caching > 1 && get(s:filecounts, s:cwd) < s:caching )
+endf
 " Public {{{1
-fu! ctrlp#rtscript#init()
-	if g:ctrlp_newrts
+fu! ctrlp#rtscript#init(caching)
+	let [s:caching, s:cwd] = [a:caching, getcwd()]
+	if g:ctrlp_newrts || s:nocache()
 		\ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[0] == &rtp )
 		sil! cal ctrlp#progress('Indexing...')
 		let entries = split(globpath(&rtp, '**/*.*'), "\n")
 	el
 		let [entries, results] = g:ctrlp_rtscache[2:3]
 	en
-	let cwd = getcwd()
-	if g:ctrlp_newrts
-		\ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, cwd] )
+	if g:ctrlp_newrts || s:nocache()
+		\ || !( exists('g:ctrlp_rtscache') && g:ctrlp_rtscache[:1] == [&rtp, s:cwd] )
 		if !exists('echoed') | sil! cal ctrlp#progress('Processing...') | en
 		let results = map(copy(entries), 'fnamemodify(v:val, '':.'')')
 	en
-	let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, cwd, entries, results], 0]
+	let [g:ctrlp_rtscache, g:ctrlp_newrts] = [[&rtp, s:cwd, entries, results], 0]
+	cal extend(s:filecounts, { s:cwd : len(results) })
 	retu results
 endf
 

File doc/ctrlp.txt

 <
 
                                                         *'g:ctrlp_use_caching'*
-Set this to 0 to disable per-session caching. When disabled, caching will still
-be enabled for directories that have more than 4000 files: >
+Enable/Disable per-session caching: >
   let g:ctrlp_use_caching = 1
 <
+  0 - Disable caching.
+  1 - Enable caching.
+  n - When bigger than 1, disable caching and use the number as the limit to
+      enable caching again.
 Note: you can quickly purge the cache by pressing <F5> while inside CtrlP.
 
                                                 *'g:ctrlp_clear_cache_on_exit'*
     \ }
 <
 Examples: >
-  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 = ['.git', 'cd %s && git ls-files']
+  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 .'],
+      \ 1: ['.git', 'cd %s && git ls-files'],
+      \ 2: ['.hg', 'hg --cwd %s locate -I .'],
       \ },
     \ 'fallback': 'find %s -type f'
     \ }

File plugin/ctrlp.vim

 
 com! -n=? -com=dir CtrlP cal ctrlp#init(0, <q-args>)
 
-com! CtrlPBuffer   cal ctrlp#init(1)
-com! CtrlPMRUFiles cal ctrlp#init(2)
+com! -bar CtrlPBuffer   cal ctrlp#init(1)
+com! -bar CtrlPMRUFiles cal ctrlp#init(2)
+com! -bar CtrlPLastMode cal ctrlp#init(-1)
 
-com! CtrlPLastMode cal ctrlp#init(-1)
+com! -bar CtrlPClearCache     cal ctrlp#clr()
+com! -bar CtrlPClearAllCaches cal ctrlp#clra()
+com! -bar CtrlPReload         cal ctrlp#reset()
 
-com! CtrlPClearCache     cal ctrlp#clr()
-com! CtrlPClearAllCaches cal ctrlp#clra()
-com! CtrlPReload         cal ctrlp#reset()
+com! -bar ClearCtrlPCache     cal ctrlp#clr()
+com! -bar ClearAllCtrlPCaches cal ctrlp#clra()
+com! -bar ResetCtrlP          cal ctrlp#reset()
 
-com! ClearCtrlPCache     cal ctrlp#clr()
-com! ClearAllCtrlPCaches cal ctrlp#clra()
-com! ResetCtrlP          cal ctrlp#reset()
-
-com! CtrlPCurWD   cal ctrlp#init(0, 0)
-com! CtrlPCurFile cal ctrlp#init(0, 1)
-com! CtrlPRoot    cal ctrlp#init(0, 2)
+com! -bar CtrlPCurWD   cal ctrlp#init(0, 0)
+com! -bar CtrlPCurFile cal ctrlp#init(0, 1)
+com! -bar CtrlPRoot    cal ctrlp#init(0, 2)
 
 if g:ctrlp_map != '' && !hasmapto(':<c-u>'.g:ctrlp_cmd.'<cr>', 'n')
 	exe 'nn <silent>' g:ctrlp_map ':<c-u>'.g:ctrlp_cmd.'<cr>'
 
 cal ctrlp#mrufiles#init()
 
-com! CtrlPTag         cal ctrlp#init(ctrlp#tag#id())
-com! CtrlPQuickfix    cal ctrlp#init(ctrlp#quickfix#id())
+com! -bar CtrlPTag         cal ctrlp#init(ctrlp#tag#id())
+com! -bar CtrlPQuickfix    cal ctrlp#init(ctrlp#quickfix#id())
 com! -n=? -com=dir CtrlPDir
 	\ cal ctrlp#init(ctrlp#dir#id(), <q-args>)
 com! -n=? -com=buffer CtrlPBufTag
 	\ cal ctrlp#init(ctrlp#buffertag#cmd(0, <q-args>))
-com! CtrlPBufTagAll   cal ctrlp#init(ctrlp#buffertag#cmd(1))
-com! CtrlPRTS         cal ctrlp#init(ctrlp#rtscript#id())
-com! CtrlPUndo        cal ctrlp#init(ctrlp#undo#id())
-com! CtrlPLine        cal ctrlp#init(ctrlp#line#id())
+com! -bar CtrlPBufTagAll   cal ctrlp#init(ctrlp#buffertag#cmd(1))
+com! -bar CtrlPRTS         cal ctrlp#init(ctrlp#rtscript#id())
+com! -bar CtrlPUndo        cal ctrlp#init(ctrlp#undo#id())
+com! -bar CtrlPLine        cal ctrlp#init(ctrlp#line#id())
 com! -n=? -com=buffer CtrlPChange
 	\ cal ctrlp#init(ctrlp#changes#cmd(0, <q-args>))
-com! CtrlPChangeAll   cal ctrlp#init(ctrlp#changes#cmd(1))
-com! CtrlPMixed       cal ctrlp#init(ctrlp#mixed#id())
-com! CtrlPBookmarkDir cal ctrlp#init(ctrlp#bookmarkdir#id())
+com! -bar CtrlPChangeAll   cal ctrlp#init(ctrlp#changes#cmd(1))
+com! -bar CtrlPMixed       cal ctrlp#init(ctrlp#mixed#id())
+com! -bar CtrlPBookmarkDir cal ctrlp#init(ctrlp#bookmarkdir#id())
 com! -n=? -com=dir CtrlPBookmarkDirAdd
 	\ cal ctrlp#call('ctrlp#bookmarkdir#add', <q-args>)