1. kien
  2. ctrlp.vim

Commits

kien  committed e6a5492 Draft

Small tweaks for tag and buffertag [...]

Account for perma cache when use_caching is bigger than 1.
Allow manually adding MRU entries.
Disable the default <c-h> mapping for all non-GUI Vim.
Store cachefile's modified time.
Option to use the ignore options for g:ctrlp_user_command.

  • Participants
  • Parent commits 2fcf4cb
  • Branches default

Comments (0)

Files changed (5)

File autoload/ctrlp.vim

View file
 " ** Static variables {{{1
 fu! s:ignore() "{{{2
 	let igdirs = [
-		\ '\.git$',
-		\ '\.hg$',
-		\ '\.svn$',
-		\ '_darcs$',
-		\ '\.bzr$',
-		\ '\.cdv$',
-		\ '\~\.dep$',
-		\ '\~\.dot$',
-		\ '\~\.nib$',
-		\ '\~\.plst$',
-		\ '\.pc$',
-		\ '_MTN$',
-		\ '<blib$',
-		\ '<CVS$',
-		\ '<RCS$',
-		\ '<SCCS$',
-		\ '_sgbak$',
-		\ '<autom4te\.cache$',
-		\ '<cover_db$',
-		\ '_build$',
+		\ '\.git',
+		\ '\.hg',
+		\ '\.svn',
+		\ '_darcs',
+		\ '\.bzr',
+		\ '\.cdv',
+		\ '\~\.dep',
+		\ '\~\.dot',
+		\ '\~\.nib',
+		\ '\~\.plst',
+		\ '\.pc',
+		\ '_MTN',
+		\ '<blib',
+		\ '<CVS',
+		\ '<RCS',
+		\ '<SCCS',
+		\ '_sgbak',
+		\ '<autom4te\.cache',
+		\ '<cover_db',
+		\ '_build',
 		\ ]
 	let igfiles = [
 		\ '\~$',
 		\ '\.tar\.gz$',
 		\ ]
 	retu {
-		\ 'dir': '\v'.join(igdirs, '|'),
+		\ 'dir': '\v('.join(igdirs, '|').')($|[\/])',
 		\ 'file': '\v'.join(igfiles, '|'),
 		\ }
 endf "}}}2
 	\ 'PrtExit()':            ['<esc>', '<c-c>', '<c-g>'],
 	\ }]
 
-if !has('gui_running') && ( has('win32') || has('win64') )
+if !has('gui_running')
 	cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
 en
 
 
 let s:ficounts = {}
 
+let s:ccex = s:pref.'clear_cache_on_exit'
+
 " Regexp
 let s:fpats = {
 	\ '^\(\\|\)\|\(\\|\)$': '\\|',
 " * Files {{{1
 fu! ctrlp#files()
 	let cafile = ctrlp#utils#cachefile()
-	if g:ctrlp_newcache || !filereadable(cafile) || s:nocache()
+	if g:ctrlp_newcache || !filereadable(cafile) || s:nocache(cafile)
 		let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
 		" Get the list of files
 		if empty(lscmd)
 			cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
 		en
 		cal s:writecache(cafile)
+		let catime = getftime(cafile)
 	el
+		let catime = getftime(cafile)
 		if !( exists('s:initcwd') && s:initcwd == s:dyncwd )
+			\ || get(s:ficounts, s:dyncwd, [0, catime])[1] != catime
 			let s:initcwd = s:dyncwd
 			let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
 		en
 	en
-	cal extend(s:ficounts, { s:dyncwd : len(g:ctrlp_allfiles) })
+	cal extend(s:ficounts, { s:dyncwd : [len(g:ctrlp_allfiles), catime] })
 	retu g:ctrlp_allfiles
 endf
 
 	if exists('s:vcscmd') && s:vcscmd
 		cal map(g:ctrlp_allfiles, 'tr(v:val, "/", "\\")')
 	en
+	if type(s:usrcmd) == 4 && has_key(s:usrcmd, 'ignore') && s:usrcmd['ignore']
+		if !empty(s:usrign)
+			let g:ctrlp_allfiles = ctrlp#dirnfile(g:ctrlp_allfiles)[1]
+		en
+		if &wig != ''
+			cal filter(g:ctrlp_allfiles, 'glob(v:val) != ""')
+		en
+	en
 endf
 
 fu! s:lsCmd()
 		en
 		let s:vcscmd = s:lash == '\' ? 1 : 0
 		retu cmd[1]
-	elsei type(cmd) == 4 && has_key(cmd, 'types')
-		let [markrs, cmdtypes] = [[], values(cmd['types'])]
-		for pair in cmdtypes
-			cal add(markrs, pair[0])
-		endfo
-		let fndroot = s:findroot(s:dyncwd, markrs, 0, 1)
+	elsei type(cmd) == 4 && ( has_key(cmd, 'types') || has_key(cmd, 'fallback') )
+		let fndroot = []
+		if has_key(cmd, 'types') && cmd['types'] != {}
+			let [markrs, cmdtypes] = [[], values(cmd['types'])]
+			for pair in cmdtypes
+				cal add(markrs, pair[0])
+			endfo
+			let fndroot = s:findroot(s:dyncwd, markrs, 0, 1)
+		en
 		if fndroot == []
 			retu has_key(cmd, 'fallback') ? cmd['fallback'] : ''
 		en
 
 fu! s:leavepre()
 	if exists('s:bufnr') && s:bufnr == bufnr('%') | bw! | en
-	if !( exists('g:ctrlp_clear_cache_on_exit') && !g:ctrlp_clear_cache_on_exit )
+	if !( exists(s:ccex) && !{s:ccex} )
 		\ && !( has('clientserver') && len(split(serverlist(), "\n")) > 1 )
 		cal ctrlp#clra()
 	en
 	retu matchmodes[s:mfunc]
 endf
 " Cache {{{2
-fu! s:writecache(cache_file)
-	if ( g:ctrlp_newcache || !filereadable(a:cache_file) ) && !s:nocache()
+fu! s:writecache(cafile)
+	if ( g:ctrlp_newcache || !filereadable(a:cafile) ) && !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 )
+fu! s:nocache(...)
+	if !s:caching
+		retu 1
+	elsei s:caching > 1
+		if !( exists(s:ccex) && !{s:ccex} ) || has_key(s:ficounts, s:dyncwd)
+			retu get(s:ficounts, s:dyncwd, [0, 0])[0] < s:caching
+		elsei a:0 && filereadable(a:1)
+			retu len(ctrlp#utils#readfile(a:1)) < s:caching
+		en
+		retu 1
+	en
+	retu 0
 endf
 
 fu! s:insertcache(str)

File autoload/ctrlp/buffertag.vim

View file
 	el
 		let data = s:exectagsonfile(a:fname, a:ftype)
 		let [raw, lines] = [split(data, '\n\+'), []]
-		for line in raw | if len(split(line, ';"')) == 2
-			let parsed_line = s:parseline(line)
-			if parsed_line != ''
-				cal add(lines, parsed_line)
+		for line in raw
+			if line !~# '^!_TAG_' && len(split(line, ';"')) == 2
+				let parsed_line = s:parseline(line)
+				if parsed_line != ''
+					cal add(lines, parsed_line)
+				en
 			en
-		en | endfo
+		endfo
 		let cache = { a:fname : { 'time': ftime, 'lines': lines } }
 		cal extend(g:ctrlp_buftags, cache)
 	en
 endf
 
 fu! s:parseline(line)
-	let eval = '\v^([^\t]+)\t(.+)\t\/\^(.+)\$\/\;\"\t(.+)\tline(no)?\:(\d+)'
+	let eval = '\v^([^\t]+)\t(.+)\t[?/]\^?(.{-1,})\$?[?/]\;\"\t(.+)\tline(no)?\:(\d+)'
 	let vals = matchlist(a:line, eval)
 	if vals == [] | retu '' | en
 	let [bufnr, bufname] = [bufnr('^'.vals[2].'$'), fnamemodify(vals[2], ':p:t')]
 	let lines = []
 	for each in bufs
 		let bname = fnamemodify(each, ':p')
-		let tftype = get(split(getbufvar(bname, '&ft'), '\.'), 0, '')
+		let tftype = get(split(getbufvar('^'.bname.'$', '&ft'), '\.'), 0, '')
 		cal extend(lines, s:process(bname, tftype))
 	endfo
 	cal s:syntax()

File autoload/ctrlp/mrufiles.vim

View file
 fu! s:record(bufnr)
 	if s:locked | retu | en
 	let bufnr = a:bufnr + 0
-	if bufnr <= 0 | retu | en
 	let bufname = bufname(bufnr)
-	if empty(bufname) | retu | en
-	let fn = fnamemodify(bufname, ':p')
+	if bufnr > 0 && !empty(bufname)
+		cal filter(s:mrbs, 'v:val != bufnr')
+		cal insert(s:mrbs, bufnr)
+		cal s:addtomrufs(bufname)
+	en
+endf
+
+fu! s:addtomrufs(fname)
+	let fn = fnamemodify(a:fname, ':p')
 	let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
-	cal filter(s:mrbs, 'v:val != bufnr')
-	cal insert(s:mrbs, bufnr)
 	if ( !empty({s:in}) && fn !~# {s:in} ) || ( !empty({s:ex}) && fn =~# {s:ex} )
-		\ || !empty(&bt) || !filereadable(fn) | retu
+		\ || !empty(getbufvar('^'.fn.'$', '&bt')) || !filereadable(fn) | retu
 	en
 	cal filter(s:mrufs, 'v:val !='.( {s:cseno} ? '#' : '?' ).' fn')
 	cal insert(s:mrufs, fn)
 	retu s:reformat(copy(s:mrufs))
 endf
 
+fu! ctrlp#mrufiles#add(fn)
+	if !empty(a:fn)
+		cal s:addtomrufs(a:fn)
+	en
+endf
+
 fu! ctrlp#mrufiles#list(...)
 	retu a:0 ? a:1 == 'raw' ? s:mergelists() : 0 : s:reformat(s:mergelists())
 endf

File autoload/ctrlp/tag.vim

View file
 	let nr = 0
 	wh 0 < 1
 		if a:tags == [] | brea | en
-		if a:tags[nr] =~ '^!' && a:tags[nr] !~ '^!_TAG_'
+		if a:tags[nr] =~ '^!' && a:tags[nr] !~# '^!_TAG_'
 			let nr += 1
 			con
 		en
-		if a:tags[nr] =~ '^!_TAG_' && len(a:tags) > nr
+		if a:tags[nr] =~# '^!_TAG_' && len(a:tags) > nr
 			cal remove(a:tags, nr)
 		el
 			brea

File doc/ctrlp.txt

View file
   c - the directory of the current file.
   r - the nearest ancestor that contains one of these directories or files:
       .git .hg .svn .bzr _darcs
-  {empty-string} - don't manage working directory.
+  0 or [empty-string] - don't manage working directory.
 
 Note #1: you can use b:ctrlp_working_path_mode (a |b:var|) to set this option
 on a per buffer basis.
 results.
 Examples: >
   " Excluding version control directories
-  set wildignore+=*/.git/*,*/.hg/*,*/.svn/*  " Linux/MacOSX
-  set wildignore+=.git\*,.hg\*,.svn\*        " Windows
+  set wildignore+=*/.git/*,*/.hg/*,*/.svn/*        " Linux/MacOSX
+  set wildignore+=*\\.git\\*,*\\.hg\\*,*\\.svn\\*  " Windows ('noshellslash')
 <
 Note #1: the `*/` in front of each directory glob is required.
 
   let g:ctrlp_custom_ignore = ''
 <
 Examples: >
-  let g:ctrlp_custom_ignore = '\.git$\|\.hg$\|\.svn$'
+  let g:ctrlp_custom_ignore = '\v(\.git|\.hg|\.svn)($|[\/])'
   let g:ctrlp_custom_ignore = {
-    \ 'dir':  '\.git$\|\.hg$\|\.svn$',
+    \ 'dir':  '\v(\.git|\.hg|\.svn)($|[\/])',
     \ 'file': '\.exe$\|\.so$\|\.dll$',
     \ 'link': 'SOME_BAD_SYMBOLIC_LINKS',
     \ }
+  let g:ctrlp_custom_ignore = {
+    \ 'file': '\v(\.cpp|\.h|\.hh|\.cxx)@<!$'
+    \ }
 <
-Note: ignoring only applies when |globpath()| is used to scan for files.
+Note #1: by default, |wildignore| and |g:ctrlp_custom_ignore| only apply when
+|globpath()| is used to scan for files, thus these options do not apply when a
+command defined with |g:ctrlp_user_command| is being used.
+
+Note #2: when changing the option's variable type, remember to |:unlet| it
+first or restart Vim to avoid the "E706: Variable type mismatch" error.
 
                                                           *'g:ctrlp_max_files'*
 The maximum number of files to scan, set to 0 for no limit: >
       \ 1: [root_marker_1, listing_command_1],
       \ n: [root_marker_n, listing_command_n],
       \ },
-    \ 'fallback': fallback_command
+    \ 'fallback': fallback_command,
+    \ 'ignore': 0 or 1
     \ }
 <
 Examples: >
       \ 1: ['.git', 'cd %s && git ls-files'],
       \ 2: ['.hg', 'hg --cwd %s locate -I .'],
       \ },
-    \ 'fallback': 'find %s -type f'
+    \ 'fallback': 'find %s -type f',
+    \ 'ignore': 0
     \ }
 <
-If the fallback_command is empty or not defined, |globpath()| will then be used
-when searching outside a repo.
+Note #1: if the fallback_command is empty or not defined, |globpath()| will
+then be used when searching outside a repo.
+
+Note #2: unless the |Dictionary| format is used and 'ignore' is defined and set
+to 1, the |wildignore| and |g:ctrlp_custom_ignore| options do not apply when
+these custom commands are being used. When not defined, 'ignore' is set to 0 by
+default to retain the performance advantage of using external commands.
+
+Note #3: when changing the option's variable type, remember to |:unlet| it
+first or restart Vim to avoid the "E706: Variable type mismatch" error.
 
                                                         *'g:ctrlp_max_history'*
 The maximum number of input strings you want CtrlP to remember. The default
     \ 'PrtExit()':            ['<esc>', '<c-c>', '<c-g>'],
     \ }
 <
-Note: In some terminals, it's not possible to remap <c-h> without also changing
-<bs> (|keycodes|). So if pressing <bs> moves the cursor to the left instead of
-deleting a char for you, add this to your |.vimrc| to disable the plugin's
+Note: if pressing <bs> moves the cursor one character to the left instead of
+deleting a character for you, add this to your |.vimrc| to disable the plugin's
 default <c-h> mapping: >
   let g:ctrlp_prompt_mappings = { 'PrtCurLeft()': ['<left>', '<c-^>'] }
 <
 ===============================================================================
 CHANGELOG                                                     *ctrlp-changelog*
 
+    + New key for |g:ctrlp_user_command| when it's a Dictionary: 'ignore'.
     + New options: |g:ctrlp_open_func|.
                    |g:ctrlp_tabpage_position|.