@@ -203,11 +203,11 @@ let s:hlgrps = {
203203 \ }
204204
205205" lname, sname of the basic(non-extension) modes
206- let s: coretypes = [
206+ let s: coretypes = filter ( [
207207 \ [' files' , ' fil' ],
208208 \ [' buffers' , ' buf' ],
209209 \ [' mru files' , ' mru' ],
210- \ ]
210+ \ ], ' index(g:ctrlp_types, v:val[1])!=-1 ' )
211211
212212" Get the options {{{2
213213fu ! s: opts (... )
@@ -439,9 +439,9 @@ fu! s:UserCmd(lscmd)
439439 en
440440 if has (' patch-7.4-597' ) && ! (has (' win32' ) || has (' win64' ))
441441 let g: ctrlp_allfiles = systemlist (printf (lscmd, path ))
442- else
442+ el
443443 let g: ctrlp_allfiles = split (system (printf (lscmd, path )), " \n " )
444- end
444+ en
445445 if exists (' +ssl' ) && exists (' ssl' )
446446 let &ssl = ssl
447447 cal map (g: ctrlp_allfiles , ' tr(v:val, "\\", "/")' )
@@ -719,7 +719,7 @@ fu! s:PrtBS()
719719 if empty (s: prompt [0 ]) && s: brfprt != 0
720720 cal s: PrtExit ()
721721 retu
722- endif
722+ en
723723 unl ! s: hstgot
724724 let [s: prompt [0 ], s: matches ] = [substitute (s: prompt [0 ], ' .$' , ' ' , ' ' ), 1 ]
725725 cal s: BuildPrompt (1 )
@@ -877,12 +877,13 @@ fu! s:PrtFocusMap(char)
877877endf
878878
879879fu ! s: PrtClearCache ()
880- if s: itemtype == 0
880+ let ct = s: curtype ()
881+ if ct == ' fil'
881882 cal ctrlp#clr ()
882- elsei s: itemtype > 2
883+ elsei s: itemtype >= len ( s: coretypes )
883884 cal ctrlp#clr (s: statypes [s: itemtype ][1 ])
884885 en
885- if s: itemtype == 2
886+ if ct == ' mru '
886887 let g: ctrlp_lines = ctrlp#mrufiles#refresh ()
887888 el
888889 cal ctrlp#setlines ()
@@ -893,17 +894,18 @@ fu! s:PrtClearCache()
893894endf
894895
895896fu ! s: PrtDeleteEnt ()
896- if s: itemtype == 2
897+ let ct = s: curtype ()
898+ if ct == ' mru'
897899 cal s: PrtDeleteMRU ()
898- elsei s: itemtype == 1
900+ elsei ct == ' buf '
899901 cal s: delbuf ()
900902 elsei type (s: getextvar (' wipe' )) == 1
901903 cal s: delent (s: getextvar (' wipe' ))
902904 en
903905endf
904906
905907fu ! s: PrtDeleteMRU ()
906- if s: itemtype == 2
908+ if s: curtype () == ' mru '
907909 cal s: delent (' ctrlp#mrufiles#remove' )
908910 en
909911endf
@@ -1011,7 +1013,7 @@ fu! s:ToggleByFname()
10111013endf
10121014
10131015fu ! s: ToggleType (dir )
1014- let max = len (g: ctrlp_ext_vars ) + 2
1016+ let max = len (g: ctrlp_ext_vars ) + len ( s: coretypes ) - 1
10151017 let next = s: walker (max , s: itemtype , a: dir )
10161018 cal ctrlp#setlines (next )
10171019 cal ctrlp#syntax ()
@@ -1151,7 +1153,7 @@ fu! s:AcceptSelection(action)
11511153 if subm | if s: SpecInputs (str) | retu | en | en
11521154 " Get the selected line
11531155 let line = ctrlp#getcline ()
1154- if ! subm && ! s: itemtype && line == ' ' && line (' .' ) > s: offset
1156+ if ! subm && s: curtype () != ' fil ' && line == ' ' && line (' .' ) > s: offset
11551157 \ && str !~ ' \v^(\.\.([\/]\.\.)*[\/]?[.\/]*|/|\\|\?|\@.+)$'
11561158 cal s: CreateNewFile (md) | retu
11571159 en
@@ -1161,7 +1163,7 @@ fu! s:AcceptSelection(action)
11611163 let actfunc = s: openfunc [s: ctype ]
11621164 let type = has_key (s: openfunc , ' arg_type' ) ? s: openfunc [' arg_type' ] : ' list'
11631165 el
1164- if s: itemtype < 3
1166+ if s: itemtype < len ( s: coretypes )
11651167 let [actfunc, type ] = [' ctrlp#acceptfile' , ' dict' ]
11661168 el
11671169 let [actfunc, exttype] = [s: getextvar (' accept' ), s: getextvar (' act_farg' )]
@@ -1206,15 +1208,16 @@ fu! s:CreateNewFile(...)
12061208endf
12071209" * OpenMulti() {{{1
12081210fu ! s: MarkToOpen ()
1211+ let ct = s: curtype ()
12091212 if s: bufnr <= 0 || s: opmul == ' 0'
1210- \ || ( s: itemtype > 2 && s: getextvar (' opmul' ) != 1 )
1213+ \ || ( s: itemtype >= len ( s: coretypes ) && s: getextvar (' opmul' ) != 1 )
12111214 retu
12121215 en
12131216 let line = ctrlp#getcline ()
12141217
12151218 " Do not allow to mark modified or current buffer
12161219 let bufnr = s: bufnrfilpath (line )[0 ]
1217- if (s: itemtype == 1 && s: delbufcond (bufnr ))
1220+ if (ct == ' buf ' && s: delbufcond (bufnr ))
12181221 retu
12191222 en
12201223
@@ -1247,7 +1250,7 @@ endf
12471250fu ! s: OpenMulti (... )
12481251 let has_marked = exists (' s:marked' )
12491252 if ( ! has_marked && a: 0 ) || s: opmul == ' 0' || ! s: ispath
1250- \ || ( s: itemtype > 2 && s: getextvar (' opmul' ) != 1 )
1253+ \ || ( s: itemtype >= len ( s: coretypes ) && s: getextvar (' opmul' ) != 1 )
12511254 retu -1
12521255 en
12531256 " Get the options
@@ -1442,7 +1445,8 @@ fu! s:shortest(lens)
14421445endf
14431446
14441447fu ! s: mixedsort (... )
1445- if s: itemtype == 1
1448+ let ct = s: curtype ()
1449+ if ct == ' buf'
14461450 let pat = ' [\/]\?\[\d\+\*No Name\]$'
14471451 if a: 1 = ~# pat && a: 2 = ~# pat | retu 0
14481452 elsei a: 1 = ~# pat | retu 1
@@ -1453,10 +1457,10 @@ fu! s:mixedsort(...)
14531457 let ms = []
14541458 if s: res_count < 21
14551459 let ms += [s: compfnlen (a: 1 , a: 2 )]
1456- if s: itemtype !~ ' ^[12] $' | let ms += [s: comptime (a: 1 , a: 2 )] | en
1460+ if ct !~ ' ^\(buf\|mru\) $' | let ms += [s: comptime (a: 1 , a: 2 )] | en
14571461 if ! s: itemtype | let ms += [s: comparent (a: 1 , a: 2 )] | en
14581462 en
1459- if s: itemtype = ~ ' ^[12] $'
1463+ if ct = ~ ' ^\(buf\|mru\) $'
14601464 let ms += [s: compmref (a: 1 , a: 2 )]
14611465 let cln = cml ? cln : 0
14621466 en
@@ -1540,7 +1544,8 @@ endf
15401544" Line formatting {{{3
15411545fu ! s: formatline (str)
15421546 let str = a: str
1543- if s: itemtype == 1
1547+ let ct = s: curtype ()
1548+ if ct == ' buf'
15441549 let bufnr = s: bufnrfilpath (str)[0 ]
15451550 let parts = s: bufparts (bufnr )
15461551 let str = printf (' %' .s: bufnr_width .' s' , bufnr )
@@ -1560,7 +1565,7 @@ fu! s:formatline(str)
15601565 en
15611566 en
15621567 en
1563- let cond = s: itemtype != 1 && s: ispath && ( s: winw - 4 ) < s: strwidth (str)
1568+ let cond = ct != ' buf ' && s: ispath && ( s: winw - 4 ) < s: strwidth (str)
15641569 retu s: lineprefix .( cond ? s: pathshorten (str) : str )
15651570endf
15661571
@@ -1615,7 +1620,7 @@ fu! s:lash(...)
16151620endf
16161621
16171622fu ! s: ispathitem ()
1618- retu s: itemtype < 3 || ( s: itemtype > 2 && s: getextvar (' type' ) == ' path' )
1623+ retu s: itemtype < len ( s: coretypes ) || s: getextvar (' type' ) == ' path'
16191624endf
16201625
16211626fu ! ctrlp#igncwd (cwd)
@@ -1649,20 +1654,20 @@ fu! ctrlp#dirnfile(entries)
16491654endf
16501655
16511656fu ! s: usrign (item, type )
1652- if s: igntype == 1 | retu a: item = ~ s: usrign | end
1657+ if s: igntype == 1 | retu a: item = ~ s: usrign | en
16531658 if s: igntype == 2
16541659 if call (s: usrign , [a: item , a: type ])
16551660 retu 1
1656- end
1661+ en
16571662 elsei s: igntype == 4
16581663 if has_key (s: usrign , a: type ) && s: usrign [a: type ] != ' '
16591664 \ && a: item = ~ s: usrign [a: type ]
16601665 retu 1
16611666 elsei has_key (s: usrign , ' func' ) && s: usrign [' func' ] != ' '
16621667 \ && call (s: usrign [' func' ], [a: item , a: type ])
16631668 retu 1
1664- end
1665- end
1669+ en
1670+ en
16661671 retu 0
16671672endf
16681673
@@ -1772,7 +1777,7 @@ fu! ctrlp#syntax()
17721777 exe " sy match CtrlPLinePre '^" .escape (get (g: , ' ctrlp_line_prefix' , ' >' ),' ^$.*~\' )." '"
17731778 en
17741779
1775- if s: itemtype == 1 && s: has_conceal
1780+ if s: curtype () == ' buf ' && s: has_conceal
17761781 sy region CtrlPBufferNr matchgroup =CtrlPLinePre start =' ^>\s\+ ' end =' \s '
17771782 sy region CtrlPBufferInd concealends matchgroup =Ignore start =' <bi>' end =' </bi>'
17781783 sy region CtrlPBufferRegion concealends matchgroup =Ignore start =' <bn>' end =' </bn>'
@@ -1810,7 +1815,7 @@ fu! s:highlight(pat, grp)
18101815 if s: byfname ()
18111816 " Make sure there are no slashes in our match
18121817 let beginning = beginning.' \([^\/]*$\)\@='
1813- end
1818+ en
18141819
18151820 for i in range (len (chars))
18161821 " Surround our current target letter with \zs and \ze so it only
@@ -1822,14 +1827,14 @@ fu! s:highlight(pat, grp)
18221827 if i == 0
18231828 let charcopy[i ] = ' \zs' .charcopy[i ].' \ze'
18241829 let middle = join (charcopy, ' .\{-}' )
1825- else
1830+ el
18261831 let before = join (charcopy[0 :i - 1 ], ' .\{-}' )
18271832 let after = join (charcopy[i + 1 :-1 ], ' .\{-}' )
18281833 let c = charcopy[i ]
18291834 " for abc, match either ab.\{-}c or a.*b.\{-}c in that order
18301835 let cpat = ' \(\zs' .c .' \|' .' .*\zs' .c .' \)\ze.*'
18311836 let middle = before.cpat.after
1832- endif
1837+ en
18331838
18341839 " Now we matchadd for each letter, the basic form being:
18351840 " ^.*\zsx\ze.*$, but with our pattern we built above for the letter,
@@ -2140,12 +2145,13 @@ fu! s:modevar()
21402145endf
21412146
21422147fu ! s: nosort ()
2143- retu s: matcher != {} || s: nolim == 1 || ( s: itemtype == 2 && s: mrudef )
2144- \ || ( s: itemtype = ~ ' \v^(1|2)$' && s: prompt == [' ' , ' ' , ' ' ] ) || ! s: dosort
2148+ let ct = s: curtype ()
2149+ retu s: matcher != {} || s: nolim == 1 || ( ct == ' mru' && s: mrudef )
2150+ \ || ( ct = ~ ' ^\(buf\|mru\)$' && s: prompt == [' ' , ' ' , ' ' ] ) || ! s: dosort
21452151endf
21462152
21472153fu ! s: byfname ()
2148- retu s: itemtype != 1 && s: ispath && s: byfname
2154+ retu s: curtype () != ' buf ' && s: ispath && s: byfname
21492155endf
21502156
21512157fu ! s: narrowable ()
@@ -2374,13 +2380,17 @@ fu! s:buildpat(lst)
23742380 retu pat
23752381endf
23762382
2383+ fu ! s: curtype ()
2384+ return s: CurTypeName ()[1 ]
2385+ endf
2386+
23772387fu ! s: mfunc ()
23782388 let mfunc = ' match'
23792389 if s: byfname ()
23802390 let mfunc = ' s:matchfname'
2381- elsei s: itemtype == 1
2391+ elsei s: curtype () == ' buf '
23822392 let mfunc = ' s:matchbuf'
2383- elsei s: itemtype > 2
2393+ elsei s: itemtype >= len ( s: coretypes )
23842394 let matchtypes = { ' tabs' : ' s:matchtabs' , ' tabe' : ' s:matchtabe' }
23852395 if has_key (matchtypes, s: matchtype )
23862396 let mfunc = matchtypes[s: matchtype ]
@@ -2439,7 +2449,7 @@ fu! s:insertcache(str)
24392449endf
24402450" Extensions {{{2
24412451fu ! s: mtype ()
2442- retu s: itemtype > 2 ? s: getextvar (' type' ) : ' path'
2452+ retu s: itemtype >= len ( s: coretypes ) ? s: getextvar (' type' ) : ' path'
24432453endf
24442454
24452455fu ! s: execextvar (key )
@@ -2450,8 +2460,8 @@ fu! s:execextvar(key)
24502460endf
24512461
24522462fu ! s: getextvar (key )
2453- if s: itemtype > 2
2454- let vars = g: ctrlp_ext_vars [s: itemtype - 3 ]
2463+ if s: itemtype >= len ( s: coretypes ) && len ( g: ctrlp_ext_vars ) > 0
2464+ let vars = g: ctrlp_ext_vars [s: itemtype - len ( s: coretypes ) ]
24552465 retu has_key (vars, a: key ) ? vars[a: key ] : -1
24562466 en
24572467 retu get (g: , ' ctrlp_' . s: matchtype . ' _' . a: key , -1 )
@@ -2505,7 +2515,8 @@ endf
25052515fu ! ctrlp#setlines (... )
25062516 if a: 0 | let s: itemtype = a: 1 | en
25072517 cal s: modevar ()
2508- let types = [' ctrlp#files()' , ' ctrlp#buffers()' , ' ctrlp#mrufiles#list()' ]
2518+ let inits = {' fil' : ' ctrlp#files()' , ' buf' : ' ctrlp#buffers()' , ' mru' : ' ctrlp#mrufiles#list()' }
2519+ let types = map (copy (g: ctrlp_types ), ' inits[v:val]' )
25092520 if ! empty (g: ctrlp_ext_vars )
25102521 cal map (copy (g: ctrlp_ext_vars ), ' add(types, v:val["init"])' )
25112522 en
@@ -2514,19 +2525,19 @@ endf
25142525
25152526" Returns [lname, sname]
25162527fu ! s: CurTypeName ()
2517- if s: itemtype < 3
2518- return s: coretypes[ s: itemtype ]
2519- else
2528+ if s: itemtype < len ( s: coretypes )
2529+ return filter ( copy ( s: coretypes), ' v:val[1]==g:ctrlp_types[ s:itemtype] ' )[ 0 ][ 1 ]
2530+ el
25202531 return [s: getextvar (" lname" ), s: getextvar (' sname' )]
2521- endif
2532+ en
25222533endfu
25232534
25242535fu ! s: ExitIfSingleCandidate ()
25252536 if len (s: Update (s: prompt [0 ])) == 1
25262537 call s: AcceptSelection (' e' )
25272538 call ctrlp#exit ()
25282539 return 1
2529- endif
2540+ en
25302541 return 0
25312542endfu
25322543
@@ -2539,14 +2550,23 @@ fu! ctrlp#init(type, ...)
25392550 cal s: SetWD (a: 0 ? a: 1 : {})
25402551 cal s: MapNorms ()
25412552 cal s: MapSpecs ()
2542- cal ctrlp#setlines (s: settype (a: type ))
2553+ if type (a: type ) == 0
2554+ let type = a: type
2555+ el
2556+ let type = index (g: ctrlp_types , a: type )
2557+ if type == -1
2558+ call ctrlp#exit ()
2559+ retu
2560+ en
2561+ en
2562+ cal ctrlp#setlines (s: settype (type ))
25432563 cal ctrlp#syntax ()
25442564 cal s: SetDefTxt ()
25452565 let curName = s: CurTypeName ()
25462566 let shouldExitSingle = index (s: opensingle , curName[0 ])>= 0 || index (s: opensingle , curName[1 ])>= 0
25472567 if shouldExitSingle && s: ExitIfSingleCandidate ()
25482568 return 0
2549- endif
2569+ en
25502570 cal s: BuildPrompt (1 )
25512571 if s: keyloop | cal s: KeyLoop () | en
25522572 return 1
0 commit comments