55" Version: 1.6.3
66" =============================================================================
77
8- " Static variables {{{
8+ " Static variables {{{1
99fu ! s: opts ()
1010 let hst = exists (' +hi' ) ? &hi : 20
1111 let opts = {
6262
6363" Limiters
6464let [s: compare_lim , s: nocache_lim , s: mltipats_lim ] = [3000 , 4000 , 2000 ]
65- " }}}
66- " * Open & Close {{{
65+ " * Open & Close {{{1
6766fu ! s: Open ()
6867 let [s: cwd , s: winres ] = [getcwd (), winrestcmd ()]
6968 let [s: crfile , s: crfpath ] = [expand (' %:p' , 1 ), expand (' %:p:h' , 1 )]
@@ -102,8 +101,7 @@ fu! s:Close()
102101 cal ctrlp#recordhist ()
103102 ec
104103endf
105- " }}}
106- " * Clear caches {{{
104+ " * Clear caches {{{1
107105fu ! ctrlp#clr (... )
108106 exe ' let g:ctrlp_new' .( exists (' a:1' ) ? a: 1 : ' cache' ).' = 1'
109107endf
@@ -113,8 +111,8 @@ fu! ctrlp#clra(...)
113111 \ confirm (" Delete all cache files?" , " &OK\n &Cancel" ) != 1 | retu | en
114112 let cache_dir = ctrlp#utils#cachedir ()
115113 if isdirectory (cache_dir)
116- let cache_files = split (s: glbpath (cache_dir, ' *.txt ' , 1 ), " \n " )
117- cal filter (cache_files, ' !isdirectory(v:val)' )
114+ let cache_files = split (s: glbpath (cache_dir, ' ** ' , 1 ), " \n " )
115+ cal filter (cache_files, ' !isdirectory(v:val) && v:val !~ '' \<cache\.txt$ '' ' )
118116 sil ! cal map (cache_files, ' delete(v:val)' )
119117 en
120118 cal ctrlp#clr ()
@@ -128,8 +126,7 @@ fu! ctrlp#reset()
128126 cal ctrlp#mrufiles#opts ()
129127 unl ! s: cline
130128endf
131- " }}}
132- " * Files() {{{
129+ " * Files() {{{1
133130fu ! s: GlobPath (dirs, allfiles, depth)
134131 let entries = split (globpath (a: dirs , s: glob ), " \n " )
135132 if ! s: folsym
@@ -186,8 +183,7 @@ fu! s:Files()
186183 cal s: writecache (read_cache, cache_file)
187184 retu g: ctrlp_allfiles
188185endf
189- " }}}
190- fu ! s: Buffers () " {{{
186+ fu ! s: Buffers () " {{{1
191187 let allbufs = []
192188 for each in range (1 , bufnr (' $' ))
193189 if getbufvar (each, ' &bl' ) && each != bufnr (' #' )
@@ -198,8 +194,8 @@ fu! s:Buffers() "{{{
198194 en
199195 endfo
200196 retu allbufs
201- endf " }}}
202- " * MatchedItems() {{{
197+ endf
198+ " * MatchedItems() {{{1
203199fu ! s: MatchIt (items , pat, limit, ispathitem)
204200 let [items , pat, limit, newitems] = [a: items , a: pat , a: limit , []]
205201 let mfunc = s: byfname && a: ispathitem ? ' s:matchfname'
@@ -234,8 +230,7 @@ fu! s:MatchedItems(items, pats, limit)
234230 let s: matches = len (newitems)
235231 retu newitems
236232endf
237- " }}}
238- fu ! s: SplitPattern (str, ... ) " {{{
233+ fu ! s: SplitPattern (str, ... ) " {{{1
239234 let str = s: sanstail (a: str )
240235 if s: migemo && s: regexp && len (str) > 0 && executable (' cmigemo' )
241236 let dict = s: glbpath (&rtp , printf (" dict/%s/migemo-dict" , &encoding ), 1 )
@@ -275,8 +270,8 @@ fu! s:SplitPattern(str, ...) "{{{
275270 endfo
276271 en
277272 retu newpats
278- endf " }}}
279- " * BuildPrompt() {{{
273+ endf
274+ " * BuildPrompt() {{{1
280275fu ! s: Render (lines , pat)
281276 let lines = a: lines
282277 " Setup the match window
@@ -360,9 +355,8 @@ fu! s:BuildPrompt(upd, ...)
360355 exe ' echoh' hibase ' | echon "_" | echoh None'
361356 en
362357endf
363- " }}}
364- " ** Prt Actions {{{
365- " Editing {{{
358+ " ** Prt Actions {{{1
359+ " Editing {{{2
366360fu ! s: PrtClear ()
367361 unl ! s: hstgot
368362 let [s: prompt , s: matches ] = [[' ' , ' ' , ' ' ], 1 ]
@@ -410,8 +404,7 @@ fu! s:PrtInsert(type)
410404 \ : a: type == ' +' ? substitute (getreg (' +' ), ' \n' , ' \\n' , ' g' ) : s: prompt [0 ]
411405 cal s: BuildPrompt (1 )
412406endf
413- " }}}
414- " Movement {{{
407+ " Movement {{{2
415408fu ! s: PrtCurLeft ()
416409 if ! empty (s: prompt [0 ])
417410 let prt = s: prompt
@@ -472,8 +465,7 @@ fu! s:PrtSelectJump(char, ...)
472465 if line (' $' ) > winheight (0 ) | cal s: BuildPrompt (0 , s: Focus ()) | en
473466 en
474467endf
475- " }}}
476- " Misc {{{
468+ " Misc {{{2
477469fu ! s: PrtClearCache ()
478470 if s: itemtype == 1 | retu | en
479471 if s: itemtype == 0
@@ -518,9 +510,8 @@ fu! s:PrtHistory(...)
518510 cal s: BuildPrompt (1 )
519511 unl s: force
520512endf
521- " }}}
522- " }}}
523- " * MapKeys() {{{
513+ " }}}1
514+ " * MapKeys() {{{1
524515fu ! s: MapKeys (... )
525516 " Normal keys
526517 let pfunc = exists (' a:1' ) && ! a: 1 ? ' PrtSelectJump' : ' PrtAdd'
@@ -604,8 +595,7 @@ fu! s:MapSpecs(...)
604595 endfo | endfo
605596 en
606597endf
607- " }}}
608- " * Toggling {{{
598+ " * Toggling {{{1
609599fu ! s: Focus ()
610600 retu ! exists (' s:focus' ) ? 1 : s: focus
611601endf
@@ -650,8 +640,7 @@ fu! s:PrtSwitcher()
650640 cal s: BuildPrompt (1 , s: Focus ())
651641 unl s: force
652642endf
653- " }}}
654- fu ! s: SetWD (... ) " {{{
643+ fu ! s: SetWD (... ) " {{{1
655644 let pathmode = s: pathmode
656645 if exists (' a:1' ) && len (a: 1 ) == 1 && ! type (a: 1 )
657646 let pathmode = a: 1
@@ -673,8 +662,8 @@ fu! s:SetWD(...) "{{{
673662 if exists (' s:foundroot' ) | brea | en
674663 endfo
675664 unl ! s: foundroot
676- endf " }}}
677- " * AcceptSelection() {{{
665+ endf
666+ " * AcceptSelection() {{{1
678667fu ! ctrlp#acceptfile (mode , matchstr )
679668 let [md, matchstr ] = [a: mode , a: matchstr ]
680669 " Get the full path
@@ -711,8 +700,7 @@ fu! s:AcceptSelection(mode)
711700 \ : g: ctrlp_ext_vars [s: itemtype - ( g: ctrlp_builtins + 1 )][1 ]
712701 cal call (actfunc, [a: mode , matchstr ])
713702endf
714- " }}}
715- fu ! s: CreateNewFile () " {{{
703+ fu ! s: CreateNewFile () " {{{1
716704 let str = join (s: prompt , ' ' )
717705 if empty (str) | retu | en
718706 let str = s: sanstail (str)
@@ -732,8 +720,8 @@ fu! s:CreateNewFile() "{{{
732720 \ : s: newfop == 3 ? ' vne' : ctrlp#normcmd (' e' )
733721 cal s: openfile (cmd, filpath)
734722 en
735- endf " }}}
736- " * OpenMulti() {{{
723+ endf
724+ " * OpenMulti() {{{1
737725fu ! s: MarkToOpen ()
738726 if s: bufnr <= 0 || ! s: opmul || s: itemtype > g: ctrlp_builtins | retu | en
739727 let matchstr = matchstr (getline (' .' ), ' ^> \zs.\+\ze\t*$' )
@@ -794,9 +782,8 @@ fu! s:OpenMulti()
794782 if nr > 1 && nr < ic | clo ! | el | let ic += 1 | en
795783 endfo
796784endf
797- " }}}
798- " ** Helper functions {{{
799- " Sorting {{{
785+ " ** Helper functions {{{1
786+ " Sorting {{{2
800787fu ! ctrlp#complen (s1, s2)
801788 " By length
802789 let [len1, len2] = [strlen (a: s1 ), strlen (a: s2 )]
@@ -856,8 +843,7 @@ fu! s:mixedsort(s1, s2)
856843 en
857844 retu 2 * cml + cln
858845endf
859- " }}}
860- " Statusline {{{
846+ " Statusline {{{2
861847fu ! ctrlp#statusline (... )
862848 if ! exists (' s:statypes' )
863849 let s: statypes = [
@@ -896,8 +882,7 @@ fu! ctrlp#progress(len)
896882 let &l: stl = ' %#Function# ' .a: len .' %* %=%<%#LineNr# ' .getcwd ().' %*'
897883 redr
898884endf
899- " }}}
900- " Paths {{{
885+ " Paths {{{2
901886fu ! ctrlp#dirfilter (val)
902887 retu isdirectory (a: val ) && match (a: val , ' [\/]\.\{,2}$' ) < 0 ? 1 : 0
903888endf
@@ -969,7 +954,7 @@ fu! s:findroot(curr, mark, depth, type)
969954endf
970955
971956fu ! s: glbpath (... )
972- retu call (' globpath' , v: version > 701 ? [ a: 1 , a: 2 , a: 3 ] : [ a: 1 , a: 2 ])
957+ retu call (' globpath' , v: version > 701 ? a: 000 : a: 000 [: 1 ])
973958endf
974959
975960fu ! ctrlp#fnesc (path )
@@ -984,8 +969,7 @@ fu! ctrlp#setdir(path, ...)
984969 cal ctrlp#msg (" Can't change working dir. Directory not exists." )
985970 endt
986971endf
987- " }}}
988- " Highlighting {{{
972+ " Highlighting {{{2
989973fu ! s: syntax ()
990974 sy match CtrlPNoEntries ' ^ == NO ENTRIES ==$'
991975 sy match CtrlPLineMarker ' ^>'
@@ -1012,8 +996,7 @@ fu! s:dohighlight()
1012996 retu type (s: mathi ) == 3 && len (s: mathi ) == 2 && s: mathi [0 ]
1013997 \ && exists (' *clearmatches' )
1014998endf
1015- " }}}
1016- " Prompt history {{{
999+ " Prompt history {{{2
10171000fu ! s: gethistloc ()
10181001 let cache_dir = ctrlp#utils#cachedir ().s: lash .' hist'
10191002 retu [cache_dir, cache_dir.s: lash .' cache.txt' ]
@@ -1031,8 +1014,7 @@ fu! ctrlp#recordhist()
10311014 cal extend (hst, [str], 1 )
10321015 if len (hst) > s: maxhst | cal remove (hst, s: maxhst , -1 ) | en
10331016endf
1034- " }}}
1035- " Signs {{{
1017+ " Signs {{{2
10361018fu ! s: unmarksigns ()
10371019 if ! s: dosigns () | retu | en
10381020 for key in keys (s: marked )
@@ -1055,8 +1037,7 @@ endf
10551037fu ! s: dosigns ()
10561038 retu exists (' s:marked' ) && s: bufnr > 0 && s: opmul && has (' signs' )
10571039endf
1058- " }}}
1059- " Dictionaries {{{
1040+ " Dictionaries {{{2
10601041fu ! s: dictindex (dict , expr )
10611042 for key in keys (a: dict )
10621043 if a: dict [key ] == a: expr | retu key | en
@@ -1067,8 +1048,7 @@ endf
10671048fu ! s: vacantdict (dict )
10681049 retu filter (range (1 , max (keys (a: dict ))), ' !has_key(a:dict, v:val)' )
10691050endf
1070- " }}}
1071- " Buffers {{{
1051+ " Buffers {{{2
10721052fu ! s: buftab (bufnum)
10731053 for nr in range (1 , tabpagenr (' $' ))
10741054 let buflist = tabpagebuflist (nr)
@@ -1121,7 +1101,10 @@ fu! s:setupblank()
11211101endf
11221102
11231103fu ! s: leavepre ()
1124- if s: clrex | cal ctrlp#clra (1 ) | en
1104+ if s: clrex && ( ! has (' clientserver' ) ||
1105+ \ ( has (' clientserver' ) && len (split (serverlist (), " \n " )) == 1 ) )
1106+ cal ctrlp#clra (1 )
1107+ en
11251108 cal ctrlp#utils#writecache (s: hstry , s: gethistloc ()[0 ], s: gethistloc ()[1 ])
11261109endf
11271110
@@ -1131,8 +1114,7 @@ fu! s:checkbuf()
11311114 exe s: bufnr .' bw!'
11321115 en
11331116endf
1134- " }}}
1135- " Arguments {{{
1117+ " Arguments {{{2
11361118fu ! s: tail ()
11371119 if exists (' s:optail' ) && ! empty (' s:optail' )
11381120 let tailpref = match (s: optail , ' ^\s*+' ) < 0 ? ' +' : ' '
@@ -1151,8 +1133,7 @@ fu! s:sanstail(str)
11511133 en
11521134 retu str
11531135endf
1154- " }}}
1155- " Misc {{{
1136+ " Misc {{{2
11561137fu ! s: specinputs ()
11571138 let str = join (s: prompt , ' ' )
11581139 let type = s: itemtype > 2 ?
@@ -1177,10 +1158,13 @@ fu! s:specinputs()
11771158endf
11781159
11791160fu ! s: lastvisual ()
1180- let [cview, oreg, oreg_type] = [winsaveview (), getreg (' v' ), getregtype (' v' )]
1161+ let cview = winsaveview ()
1162+ let [ovreg, ovtype] = [getreg (' v' ), getregtype (' v' )]
1163+ let [oureg, outype] = [getreg (' "' ), getregtype (' "' )]
11811164 sil ! norm! gv" vy
11821165 let selected = substitute (getreg (' v' ), ' \n' , ' \\n' , ' g' )
1183- cal setreg (' v' , oreg, oreg_type)
1166+ cal setreg (' v' , ovreg, ovtype)
1167+ cal setreg (' "' , oureg, outype)
11841168 cal winrestview (cview)
11851169 retu selected
11861170endf
@@ -1274,8 +1258,7 @@ fu! s:lscommand()
12741258 retu cmd[1 ]
12751259 en
12761260endf
1277- " }}}
1278- " Extensions {{{
1261+ " Extensions {{{2
12791262fu ! s: tagfiles ()
12801263 retu filter (map (tagfiles (), ' fnamemodify(v:val, ":p")' ), ' filereadable(v:val)' )
12811264endf
@@ -1291,9 +1274,8 @@ endf
12911274fu ! ctrlp#setlines (type )
12921275 cal s: SetLines (a: type )
12931276endf
1294- " }}}
1295- " }}}
1296- " * Initialization {{{
1277+ " }}}1
1278+ " * Initialization {{{1
12971279fu ! s: SetLines (type )
12981280 let s: itemtype = a: type
12991281 let types = [
@@ -1315,10 +1297,11 @@ fu! ctrlp#init(type, ...)
13151297 cal s: MapKeys ()
13161298 cal s: SetLines (a: type )
13171299 cal s: BuildPrompt (1 )
1318- if has (' syntax' ) && exists (' g:syntax_on' ) | cal s: syntax () | en
1300+ if has (' syntax' ) && exists (' g:syntax_on' )
1301+ cal s: syntax ()
1302+ en
13191303endf
1320- " }}}
1321- if has (' autocmd' ) " {{{
1304+ if has (' autocmd' ) " {{{1
13221305 aug CtrlPAug
13231306 au !
13241307 au BufEnter ControlP cal s: checkbuf ()
@@ -1330,4 +1313,4 @@ if has('autocmd') "{{{
13301313 aug END
13311314en " }}}
13321315
1333- " vim:fen :fdl = 0 :fdc = 1 :ts = 2 :sw = 2 :sts = 2
1316+ " vim:fen :fdm = marker: fmr = {{{,}}}: fdl = 0 :fdc = 1 :ts = 2 :sw = 2 :sts = 2
0 commit comments