@@ -11,13 +11,14 @@ fu! s:opts()
1111 let opts = {
1212 \ ' g:ctrlp_by_filename' : [' s:byfname' , 0 ],
1313 \ ' g:ctrlp_clear_cache_on_exit' : [' s:clrex' , 1 ],
14+ \ ' g:ctrlp_custom_ignore' : [' s:usrign' , ' ' ],
1415 \ ' g:ctrlp_dont_split' : [' s:nosplit' , ' ' ],
1516 \ ' g:ctrlp_dotfiles' : [' s:dotfiles' , 1 ],
1617 \ ' g:ctrlp_extensions' : [' s:extensions' , []],
1718 \ ' g:ctrlp_follow_symlinks' : [' s:folsym' , 0 ],
1819 \ ' g:ctrlp_highlight_match' : [' s:mathi' , [1 , ' Identifier' ]],
1920 \ ' g:ctrlp_lazy_update' : [' s:lazy' , 0 ],
20- \ ' g:ctrlp_jump_to_buffer' : [' s:jmptobuf' , 1 ],
21+ \ ' g:ctrlp_jump_to_buffer' : [' s:jmptobuf' , 2 ],
2122 \ ' g:ctrlp_match_window_bottom' : [' s:mwbottom' , 1 ],
2223 \ ' g:ctrlp_match_window_reversed' : [' s:mwreverse' , 1 ],
2324 \ ' g:ctrlp_max_depth' : [' s:maxdepth' , 40 ],
@@ -126,23 +127,67 @@ fu! ctrlp#reset()
126127 unl ! s: cline
127128endf
128129" * Files() {{{1
130+ fu ! s: Files ()
131+ let [cwd, cache_file] = [getcwd (), ctrlp#utils#cachefile ()]
132+ if g: ctrlp_newcache || ! filereadable (cache_file) || ! s: caching
133+ let lscmd = s: lsCmd ()
134+ " Get the list of files
135+ if empty (lscmd)
136+ cal s: GlobPath (cwd, [], 0 )
137+ el
138+ sil ! cal ctrlp#progress (' Indexing...' )
139+ try | cal s: UserCmd (cwd, lscmd) | cat | retu [] | endt
140+ en
141+ " Remove base directory
142+ cal ctrlp#rmbasedir (g: ctrlp_allfiles )
143+ let read_cache = 0
144+ el
145+ let g: ctrlp_allfiles = ctrlp#utils#readfile (cache_file)
146+ let read_cache = 1
147+ en
148+ if len (g: ctrlp_allfiles ) <= s: compare_lim
149+ cal sort (g: ctrlp_allfiles , ' ctrlp#complen' )
150+ en
151+ cal s: writecache (read_cache, cache_file)
152+ retu g: ctrlp_allfiles
153+ endf
154+
129155fu ! s: GlobPath (dirs, allfiles, depth)
130156 let entries = split (globpath (a: dirs , s: glob ), " \n " )
131- if ! s: folsym
132- let entries = filter (entries, ' getftype( v:val) != "link" ' )
157+ if s: usrign != ' '
158+ cal filter (entries, ' v:val !~ s:usrign ' )
133159 en
134- let g: ctrlp_allfiles = filter (copy (entries), ' !isdirectory(v:val)' )
135- let ftrfunc = s: dotfiles ? ' ctrlp#dirfilter(v:val)' : ' isdirectory(v:val)'
136- let alldirs = filter (entries, ftrfunc)
160+ let [dirs, g: ctrlp_allfiles ] = s: DirAndFile (copy (entries))
137161 cal extend (g: ctrlp_allfiles , a: allfiles , 0 )
138162 let depth = a: depth + 1
139- if ! empty (alldirs ) && ! s: maxfiles (len (g: ctrlp_allfiles )) && depth <= s: maxdepth
163+ if ! empty (dirs ) && ! s: maxf (len (g: ctrlp_allfiles )) && depth <= s: maxdepth
140164 sil ! cal ctrlp#progress (len (g: ctrlp_allfiles ))
141- cal s: GlobPath (join (alldirs , ' ,' ), g: ctrlp_allfiles , depth)
165+ cal s: GlobPath (join (dirs , ' ,' ), g: ctrlp_allfiles , depth)
142166 en
143167endf
144168
145- fu ! s: UserCommand (path , lscmd)
169+ fu ! s: DirAndFile (entries)
170+ let items = [[], []]
171+ for each in a: entries
172+ let etype = getftype (each)
173+ if etype == ' dir'
174+ if s: dotfiles | if match (each, ' [\/]\.\{,2}$' ) < 0
175+ cal add (items [0 ], each)
176+ en | el
177+ cal add (items [0 ], each)
178+ en
179+ el
180+ if s: folsym
181+ cal add (items [1 ], each)
182+ el | if etype != ' link'
183+ cal add (items [1 ], each)
184+ en | en
185+ en
186+ endfo
187+ retu items
188+ endf
189+
190+ fu ! s: UserCmd (path , lscmd)
146191 let path = a: path
147192 if exists (' +ssl' ) && &ssl
148193 let [ssl , &ssl , path ] = [&ssl , 0 , tr (path , ' /' , ' \' )]
@@ -158,29 +203,21 @@ fu! s:UserCommand(path, lscmd)
158203 en
159204endf
160205
161- fu ! s: Files ()
162- let [cwd, cache_file] = [getcwd (), ctrlp#utils#cachefile ()]
163- if g: ctrlp_newcache || ! filereadable (cache_file) || ! s: caching
164- let lscmd = s: lscommand ()
165- " Get the list of files
166- if empty (lscmd)
167- cal s: GlobPath (cwd, [], 0 )
168- el
169- sil ! cal ctrlp#progress (' Waiting...' )
170- try | cal s: UserCommand (cwd, lscmd) | cat | retu [] | endt
206+ fu ! s: lsCmd ()
207+ let cmd = s: usrcmd
208+ if type (cmd) == 1
209+ retu cmd
210+ elsei type (cmd) == 3 && len (cmd) >= 2 && ! empty (cmd[0 ]) && ! empty (cmd[1 ])
211+ let rmarker = cmd[0 ]
212+ " Find a repo root
213+ cal s: findroot (getcwd (), rmarker, 0 , 1 )
214+ if ! exists (' s:vcsroot' ) || ( exists (' s:vcsroot' ) && empty (s: vcsroot ) )
215+ " Try the secondary_command
216+ retu len (cmd) == 3 ? cmd[2 ] : ' '
171217 en
172- " Remove base directory
173- cal ctrlp#rmbasedir (g: ctrlp_allfiles )
174- let read_cache = 0
175- el
176- let g: ctrlp_allfiles = ctrlp#utils#readfile (cache_file)
177- let read_cache = 1
178- en
179- if len (g: ctrlp_allfiles ) <= s: compare_lim
180- cal sort (g: ctrlp_allfiles , ' ctrlp#complen' )
218+ let s: vcscmd = s: lash == ' \' ? 1 : 0
219+ retu cmd[1 ]
181220 en
182- cal s: writecache (read_cache, cache_file)
183- retu g: ctrlp_allfiles
184221endf
185222fu ! s: Buffers () " {{{1
186223 let allbufs = []
@@ -669,19 +706,19 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
669706 let filpath = s: itemtype ? matchstr : getcwd ().s: lash .matchstr
670707 cal s: PrtExit ()
671708 let bufnum = bufnr (filpath)
672- if s: jmptobuf && bufnum > 0 && ( md == ' e' || md == ' t ' )
709+ if s: jmptobuf && bufnum > 0 && md = ~ ' e\|t '
673710 let [jmpb, bufwinnr ] = [1 , bufwinnr (bufnum)]
674- let buftab = s: jmptobuf > 1 ? s: buftab (bufnum) : [0 , 0 ]
711+ let buftab = s: jmptobuf > 1 ? s: buftab (bufnum, md ) : [0 , 0 ]
675712 let j2l = a: 0 ? a: 1 : str2nr (matchstr (s: tail (), ' ^ +\zs\d\+$' ))
676713 en
677714 " Switch to existing buffer or open new one
678- if exists (' jmpb' ) && buftab[0 ]
679- exe ' tabn' buftab[1 ]
680- exe buftab[0 ].' winc w'
681- if j2l | cal s: j2l (j2l) | en
682- elsei exists (' jmpb' ) && bufwinnr > 0
715+ if exists (' jmpb' ) && bufwinnr > 0 && md != ' t'
683716 exe bufwinnr .' winc w'
684717 if j2l | cal s: j2l (j2l) | en
718+ elsei exists (' jmpb' ) && buftab[0 ]
719+ exe ' tabn' buftab[0 ]
720+ exe buftab[1 ].' winc w'
721+ if j2l | cal s: j2l (j2l) | en
685722 el
686723 " Determine the command to use
687724 let cmd = md == ' t' || s: splitwin == 1 ? ' tabe'
@@ -692,8 +729,31 @@ fu! ctrlp#acceptfile(mode, matchstr, ...)
692729 en
693730endf
694731
732+ fu ! s: SpecInputs ()
733+ let str = join (s: prompt , ' ' )
734+ let type = s: itemtype > 2 ?
735+ \ g: ctrlp_ext_vars [s: itemtype - ( g: ctrlp_builtins + 1 )][3 ] : s: itemtype
736+ if str == ' ..' && type = ~ ' 0\|dir'
737+ cal s: parentdir (getcwd ())
738+ cal s: SetLines (s: itemtype )
739+ cal s: PrtClear ()
740+ retu 1
741+ elsei ( str == ' /' || str == ' \' ) && type = ~ ' 0\|dir'
742+ cal s: SetWD (2 , 0 )
743+ cal s: SetLines (s: itemtype )
744+ cal s: PrtClear ()
745+ retu 1
746+ elsei str == ' ?'
747+ cal s: PrtExit ()
748+ let hlpwin = &columns > 159 ? ' | vert res 80' : ' '
749+ sil ! exe ' bo vert h ctrlp-mappings' hlpwin ' | norm! 0'
750+ retu 1
751+ en
752+ retu 0
753+ endf
754+
695755fu ! s: AcceptSelection (mode )
696- if a: mode == ' e' | if s: specinputs () | retu | en | en
756+ if a: mode == ' e' | if s: SpecInputs () | retu | en | en
697757 " Get the selected line
698758 let matchstr = matchstr (getline (' .' ), ' ^> \zs.\+\ze\t*$' )
699759 if empty (matchstr ) | retu | en
@@ -885,10 +945,6 @@ fu! ctrlp#progress(len)
885945 redr
886946endf
887947" Paths {{{2
888- fu ! ctrlp#dirfilter (val)
889- retu isdirectory (a: val ) && match (a: val , ' [\/]\.\{,2}$' ) < 0 ? 1 : 0
890- endf
891-
892948fu ! s: ispathitem ()
893949 let ext = s: itemtype - ( g: ctrlp_builtins + 1 )
894950 if s: itemtype < 3 || ( s: itemtype > 2 && g: ctrlp_ext_vars [ext][3 ] == ' dir' )
@@ -1051,14 +1107,14 @@ fu! s:vacantdict(dict)
10511107 retu filter (range (1 , max (keys (a: dict ))), ' !has_key(a:dict, v:val)' )
10521108endf
10531109" Buffers {{{2
1054- fu ! s: buftab (bufnum)
1055- for nr in range (1 , tabpagenr (' $' ))
1056- let buflist = tabpagebuflist (nr)
1057- if match ( buflist, a: bufnum ) >= 0
1058- let [buftabnr, tabwinnrs] = [nr, tabpagewinnr (nr, ' $ ' )]
1059- for ewin in range (1 , tabwinnrs )
1060- if buflist[ewin - 1 ] == a: bufnum
1061- retu [ewin, buftabnr ]
1110+ fu ! s: buftab (bufnum, md )
1111+ for tabnr in range (1 , tabpagenr (' $' ))
1112+ if tabpagenr () == tabnr && a: md == ' t ' | con | en
1113+ let buflist = tabpagebuflist (tabnr)
1114+ if index (buflist, a: bufnum ) >= 0
1115+ for winnr in range (1 , tabpagewinnr (tabnr, ' $ ' ) )
1116+ if buflist[winnr - 1 ] == a: bufnum
1117+ retu [tabnr, winnr ]
10621118 en
10631119 endfo
10641120 en
@@ -1136,29 +1192,6 @@ fu! s:sanstail(str)
11361192 retu str
11371193endf
11381194" Misc {{{2
1139- fu ! s: specinputs ()
1140- let str = join (s: prompt , ' ' )
1141- let type = s: itemtype > 2 ?
1142- \ g: ctrlp_ext_vars [s: itemtype - ( g: ctrlp_builtins + 1 )][3 ] : s: itemtype
1143- if str == ' ..' && type = ~ ' 0\|dir'
1144- cal s: parentdir (getcwd ())
1145- cal s: SetLines (s: itemtype )
1146- cal s: PrtClear ()
1147- retu 1
1148- elsei ( str == ' /' || str == ' \' ) && type = ~ ' 0\|dir'
1149- cal s: SetWD (2 , 0 )
1150- cal s: SetLines (s: itemtype )
1151- cal s: PrtClear ()
1152- retu 1
1153- elsei str == ' ?'
1154- cal s: PrtExit ()
1155- let hlpwin = &columns > 159 ? ' | vert res 80' : ' '
1156- sil ! exe ' bo vert h ctrlp-mappings' hlpwin ' | norm! 0'
1157- retu 1
1158- en
1159- retu 0
1160- endf
1161-
11621195fu ! s: lastvisual ()
11631196 let cview = winsaveview ()
11641197 let [ovreg, ovtype] = [getreg (' v' ), getregtype (' v' )]
@@ -1228,7 +1261,7 @@ fu! s:matchtab(item, pat)
12281261 retu match (split (a: item , ' \t\+[^\t]\+$' )[0 ], a: pat )
12291262endf
12301263
1231- fu ! s: maxfiles (len )
1264+ fu ! s: maxf (len )
12321265 retu s: maxfiles && a: len > s: maxfiles ? 1 : 0
12331266endf
12341267
@@ -1248,23 +1281,6 @@ fu! s:insertcache(str)
12481281 cal insert (data, str, pos)
12491282 cal s: writecache (0 , ctrlp#utils#cachefile ())
12501283endf
1251-
1252- fu ! s: lscommand ()
1253- let cmd = s: usrcmd
1254- if type (cmd) == 1
1255- retu cmd
1256- elsei type (cmd) == 3 && len (cmd) >= 2 && ! empty (cmd[0 ]) && ! empty (cmd[1 ])
1257- let rmarker = cmd[0 ]
1258- " Find a repo root
1259- cal s: findroot (getcwd (), rmarker, 0 , 1 )
1260- if ! exists (' s:vcsroot' ) || ( exists (' s:vcsroot' ) && empty (s: vcsroot ) )
1261- " Try the secondary_command
1262- retu len (cmd) == 3 ? cmd[2 ] : ' '
1263- en
1264- let s: vcscmd = s: lash == ' \' ? 1 : 0
1265- retu cmd[1 ]
1266- en
1267- endf
12681284" Extensions {{{2
12691285fu ! s: tagfiles ()
12701286 retu filter (map (tagfiles (), ' fnamemodify(v:val, ":p")' ), ' filereadable(v:val)' )
0 commit comments