utils 0.0.57 → 0.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1772 @@
1
+ " =============================================================================
2
+ " File: autoload/ctrlp.vim
3
+ " Description: Fuzzy file, buffer, mru and tag finder.
4
+ " Author: Kien Nguyen <github.com/kien>
5
+ " Version: 1.7.6
6
+ " =============================================================================
7
+
8
+ " ** Static variables {{{1
9
+ fu! s:ignore() "{{{2
10
+ let igdirs = [
11
+ \ '\.git$',
12
+ \ '\.hg$',
13
+ \ '\.svn$',
14
+ \ '_darcs$',
15
+ \ '\.bzr$',
16
+ \ '\.cdv$',
17
+ \ '\~\.dep$',
18
+ \ '\~\.dot$',
19
+ \ '\~\.nib$',
20
+ \ '\~\.plst$',
21
+ \ '\.pc$',
22
+ \ '_MTN$',
23
+ \ '<blib$',
24
+ \ '<CVS$',
25
+ \ '<RCS$',
26
+ \ '<SCCS$',
27
+ \ '_sgbak$',
28
+ \ '<autom4te\.cache$',
29
+ \ '<cover_db$',
30
+ \ '_build$',
31
+ \ ]
32
+ let igfiles = [
33
+ \ '[.]bak$',
34
+ \ '\~$',
35
+ \ '#.+#$',
36
+ \ '[._].*\.swp$',
37
+ \ 'core\.\d+$',
38
+ \ ]
39
+ retu {
40
+ \ 'dir': '\v'.join(igdirs, '|'),
41
+ \ 'file': '\v'.join(igfiles, '|'),
42
+ \ }
43
+ endf "}}}2
44
+ " Options
45
+ let [s:pref, s:opts, s:new_opts] = ['g:ctrlp_', {
46
+ \ 'arg_map': ['s:argmap', 0],
47
+ \ 'buffer_func': ['s:buffunc', {}],
48
+ \ 'by_filename': ['s:byfname', 0],
49
+ \ 'clear_cache_on_exit': ['s:clrex', 1],
50
+ \ 'custom_ignore': ['s:usrign', s:ignore()],
51
+ \ 'default_input': ['s:deftxt', 0],
52
+ \ 'dont_split': ['s:nosplit', 'netrw'],
53
+ \ 'dotfiles': ['s:dotfiles', 1],
54
+ \ 'extensions': ['s:extensions', []],
55
+ \ 'follow_symlinks': ['s:folsym', 0],
56
+ \ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
57
+ \ 'jump_to_buffer': ['s:jmptobuf', 2],
58
+ \ 'lazy_update': ['s:lazy', 0],
59
+ \ 'match_func': ['s:matcher', {}],
60
+ \ 'match_window_bottom': ['s:mwbottom', 1],
61
+ \ 'match_window_reversed': ['s:mwreverse', 1],
62
+ \ 'max_depth': ['s:maxdepth', 40],
63
+ \ 'max_files': ['s:maxfiles', 10000],
64
+ \ 'max_height': ['s:mxheight', 10],
65
+ \ 'max_history': ['s:maxhst', exists('+hi') ? &hi : 20],
66
+ \ 'mruf_default_order': ['s:mrudef', 0],
67
+ \ 'open_multi': ['s:opmul', '1v'],
68
+ \ 'open_new_file': ['s:newfop', 'v'],
69
+ \ 'prompt_mappings': ['s:urprtmaps', 0],
70
+ \ 'regexp_search': ['s:regexp', 0],
71
+ \ 'root_markers': ['s:rmarkers', []],
72
+ \ 'split_window': ['s:splitwin', 0],
73
+ \ 'status_func': ['s:status', {}],
74
+ \ 'use_caching': ['s:caching', 1],
75
+ \ 'use_migemo': ['s:migemo', 0],
76
+ \ 'user_command': ['s:usrcmd', ''],
77
+ \ 'working_path_mode': ['s:pathmode', 2],
78
+ \ }, {
79
+ \ 'open_multiple_files': 's:opmul',
80
+ \ 'regexp': 's:regexp',
81
+ \ 'reuse_window': 's:nosplit',
82
+ \ 'switch_buffer': 's:jmptobuf',
83
+ \ }]
84
+
85
+ " Global options
86
+ let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
87
+ \ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'mouse': 'n',
88
+ \ 'gcr': 'a:blinkon0', 'ic': 1, 'scs': 1, 'lmap': '', 'mousef': 0,
89
+ \ 'imd': 1 }
90
+
91
+ " Keymaps
92
+ let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
93
+ \ 'PrtBS()': ['<bs>', '<c-]>'],
94
+ \ 'PrtDelete()': ['<del>'],
95
+ \ 'PrtDeleteWord()': ['<c-w>'],
96
+ \ 'PrtClear()': ['<c-u>'],
97
+ \ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
98
+ \ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
99
+ \ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
100
+ \ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
101
+ \ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
102
+ \ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
103
+ \ 'PrtHistory(-1)': ['<c-n>'],
104
+ \ 'PrtHistory(1)': ['<c-p>'],
105
+ \ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
106
+ \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
107
+ \ 'AcceptSelection("t")': ['<c-t>'],
108
+ \ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
109
+ \ 'ToggleFocus()': ['<s-tab>'],
110
+ \ 'ToggleRegex()': ['<c-r>'],
111
+ \ 'ToggleByFname()': ['<c-d>'],
112
+ \ 'ToggleType(1)': ['<c-f>', '<c-up>'],
113
+ \ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
114
+ \ 'PrtExpandDir()': ['<tab>'],
115
+ \ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>'],
116
+ \ 'PrtInsert()': ['<c-\>'],
117
+ \ 'PrtCurStart()': ['<c-a>'],
118
+ \ 'PrtCurEnd()': ['<c-e>'],
119
+ \ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
120
+ \ 'PrtCurRight()': ['<c-l>', '<right>'],
121
+ \ 'PrtClearCache()': ['<F5>'],
122
+ \ 'PrtDeleteEnt()': ['<F7>'],
123
+ \ 'CreateNewFile()': ['<c-y>'],
124
+ \ 'MarkToOpen()': ['<c-z>'],
125
+ \ 'OpenMulti()': ['<c-o>'],
126
+ \ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
127
+ \ }]
128
+
129
+ if !has('gui_running') && ( has('win32') || has('win64') )
130
+ cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
131
+ en
132
+
133
+ let s:lash = ctrlp#utils#lash()
134
+
135
+ " Limiters
136
+ let [s:compare_lim, s:nocache_lim] = [3000, 4000]
137
+
138
+ " Regexp
139
+ let s:fpats = {
140
+ \ '^\(\\|\)\|\(\\|\)$': '\\|',
141
+ \ '^\\\(zs\|ze\|<\|>\)': '^\\\(zs\|ze\|<\|>\)',
142
+ \ '^\S\*$': '\*',
143
+ \ '^\S\\?$': '\\?',
144
+ \ }
145
+
146
+ " Specials
147
+ let s:prtunmaps = [
148
+ \ 'PrtBS()',
149
+ \ 'PrtDelete()',
150
+ \ 'PrtDeleteWord()',
151
+ \ 'PrtClear()',
152
+ \ 'PrtCurStart()',
153
+ \ 'PrtCurEnd()',
154
+ \ 'PrtCurLeft()',
155
+ \ 'PrtCurRight()',
156
+ \ 'PrtHistory(-1)',
157
+ \ 'PrtHistory(1)',
158
+ \ 'PrtInsert("c")',
159
+ \ 'PrtInsert()',
160
+ \ ]
161
+
162
+ " Keypad
163
+ let s:kprange = {
164
+ \ 'Plus': '+',
165
+ \ 'Minus': '-',
166
+ \ 'Divide': '/',
167
+ \ 'Multiply': '*',
168
+ \ 'Point': '.',
169
+ \ }
170
+
171
+ " Highlight groups
172
+ let s:hlgrps = {
173
+ \ 'NoEntries': 'Error',
174
+ \ 'Mode1': 'Character',
175
+ \ 'Mode2': 'LineNr',
176
+ \ 'Stats': 'Function',
177
+ \ 'Match': 'Identifier',
178
+ \ 'PrtBase': 'Comment',
179
+ \ 'PrtText': 'Normal',
180
+ \ 'PrtCursor': 'Constant',
181
+ \ }
182
+
183
+ fu! s:opts() "{{{2
184
+ " Options
185
+ unl! s:usrign s:usrcmd s:urprtmaps
186
+ for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each)
187
+ let {each} = s:{each}
188
+ en | endfo
189
+ for [ke, va] in items(s:opts)
190
+ let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1]
191
+ endfo
192
+ unl va
193
+ for [ke, va] in items(s:new_opts)
194
+ let {va} = {exists(s:pref.ke) ? s:pref.ke : va}
195
+ endfo
196
+ for each in ['byfname', 'regexp'] | if exists(each)
197
+ let s:{each} = {each}
198
+ en | endfo
199
+ if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
200
+ let s:maxdepth = min([s:maxdepth, 100])
201
+ let s:mxheight = max([s:mxheight, 1])
202
+ let s:glob = s:dotfiles ? '.*\|*' : '*'
203
+ let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
204
+ if s:lazy
205
+ cal extend(s:glbs, { 'ut': ( s:lazy > 1 ? s:lazy : 250 ) })
206
+ en
207
+ " Extensions
208
+ if !( exists('extensions') && extensions == s:extensions )
209
+ for each in s:extensions
210
+ exe 'ru autoload/ctrlp/'.each.'.vim'
211
+ endfo
212
+ en
213
+ " Keymaps
214
+ if type(s:urprtmaps) == 4
215
+ cal extend(s:prtmaps, s:urprtmaps)
216
+ en
217
+ endf
218
+ "}}}1
219
+ " * Open & Close {{{1
220
+ fu! s:Open()
221
+ cal s:log(1)
222
+ cal s:getenv()
223
+ cal s:execextvar('enter')
224
+ sil! exe 'noa keepa' ( s:mwbottom ? 'bo' : 'to' ) '1new ControlP'
225
+ cal s:buffunc(1)
226
+ let [s:bufnr, s:prompt, s:winw] = [bufnr('%'), ['', '', ''], winwidth(0)]
227
+ abc <buffer>
228
+ if !exists('s:hstry')
229
+ let hst = filereadable(s:gethistloc()[1]) ? s:gethistdata() : ['']
230
+ let s:hstry = empty(hst) || !s:maxhst ? [''] : hst
231
+ en
232
+ for [ke, va] in items(s:glbs) | if exists('+'.ke)
233
+ sil! exe 'let s:glb_'.ke.' = &'.ke.' | let &'.ke.' = '.string(va)
234
+ en | endfo
235
+ if s:opmul != '0' && has('signs')
236
+ sign define ctrlpmark text=+> texthl=Search
237
+ en
238
+ cal s:setupblank()
239
+ endf
240
+
241
+ fu! s:Close()
242
+ cal s:buffunc(0)
243
+ try | noa bun!
244
+ cat | noa clo! | endt
245
+ cal s:unmarksigns()
246
+ for key in keys(s:glbs) | if exists('+'.key)
247
+ sil! exe 'let &'.key.' = s:glb_'.key
248
+ en | endfo
249
+ if exists('s:glb_acd') | let &acd = s:glb_acd | en
250
+ let g:ctrlp_lines = []
251
+ if s:winres[1] >= &lines && s:winres[2] == winnr('$')
252
+ exe s:winres[0]
253
+ en
254
+ unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
255
+ \ s:mrbs
256
+ cal ctrlp#recordhist()
257
+ cal s:execextvar('exit')
258
+ cal s:log(0)
259
+ ec
260
+ endf
261
+ " * Clear caches {{{1
262
+ fu! ctrlp#clr(...)
263
+ let g:ctrlp_new{ a:0 ? a:1 : 'cache' } = 1
264
+ endf
265
+
266
+ fu! ctrlp#clra()
267
+ let cache_dir = ctrlp#utils#cachedir()
268
+ if isdirectory(cache_dir)
269
+ let cache_files = split(s:glbpath(cache_dir, '**', 1), "\n")
270
+ let eval = '!isdirectory(v:val) && fnamemodify(v:val, ":t") !~'
271
+ \ . ' ''\v^<cache>[.a-z]+$|\.log$'''
272
+ sil! cal map(filter(cache_files, eval), 'delete(v:val)')
273
+ en
274
+ cal ctrlp#clr()
275
+ endf
276
+
277
+ fu! ctrlp#reset()
278
+ cal s:opts()
279
+ cal s:autocmds()
280
+ cal ctrlp#utils#opts()
281
+ cal s:execextvar('opts')
282
+ endf
283
+ " * Files {{{1
284
+ fu! ctrlp#files()
285
+ let cafile = ctrlp#utils#cachefile()
286
+ if g:ctrlp_newcache || !filereadable(cafile) || !s:caching
287
+ let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
288
+ " Get the list of files
289
+ if empty(lscmd)
290
+ cal s:GlobPath(s:dyncwd, 0)
291
+ el
292
+ sil! cal ctrlp#progress('Indexing...')
293
+ try | cal s:UserCmd(lscmd)
294
+ cat | retu [] | endt
295
+ en
296
+ " Remove base directory
297
+ cal ctrlp#rmbasedir(g:ctrlp_allfiles)
298
+ if len(g:ctrlp_allfiles) <= s:compare_lim
299
+ cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
300
+ en
301
+ cal s:writecache(cafile)
302
+ el
303
+ if !( exists('s:initcwd') && s:initcwd == s:dyncwd )
304
+ let s:initcwd = s:dyncwd
305
+ let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
306
+ en
307
+ en
308
+ retu g:ctrlp_allfiles
309
+ endf
310
+
311
+ fu! s:GlobPath(dirs, depth)
312
+ let entries = split(globpath(a:dirs, s:glob), "\n")
313
+ let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1]
314
+ cal extend(g:ctrlp_allfiles, dnf[1])
315
+ if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
316
+ sil! cal ctrlp#progress(len(g:ctrlp_allfiles), 1)
317
+ cal s:GlobPath(join(dnf[0], ','), depth)
318
+ en
319
+ endf
320
+
321
+ fu! s:UserCmd(lscmd)
322
+ let path = s:dyncwd
323
+ if exists('+ssl') && &ssl
324
+ let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')]
325
+ en
326
+ let path = exists('*shellescape') ? shellescape(path) : path
327
+ let g:ctrlp_allfiles = split(system(printf(a:lscmd, path)), "\n")
328
+ if exists('+ssl') && exists('ssl')
329
+ let &ssl = ssl
330
+ cal map(g:ctrlp_allfiles, 'tr(v:val, "\\", "/")')
331
+ en
332
+ if exists('s:vcscmd') && s:vcscmd
333
+ cal map(g:ctrlp_allfiles, 'tr(v:val, "/", "\\")')
334
+ en
335
+ endf
336
+
337
+ fu! s:lsCmd()
338
+ let cmd = s:usrcmd
339
+ if type(cmd) == 1
340
+ retu cmd
341
+ elsei type(cmd) == 3 && len(cmd) >= 2 && cmd[:1] != ['', '']
342
+ " Find a repo root
343
+ cal s:findroot(s:dyncwd, cmd[0], 0, 1)
344
+ if !exists('s:vcsroot')
345
+ " Try the secondary_command
346
+ retu len(cmd) == 3 ? cmd[2] : ''
347
+ en
348
+ unl s:vcsroot
349
+ let s:vcscmd = s:lash == '\' ? 1 : 0
350
+ retu cmd[1]
351
+ elsei type(cmd) == 4 && has_key(cmd, 'types')
352
+ for key in sort(keys(cmd['types']), 's:compval')
353
+ cal s:findroot(s:dyncwd, cmd['types'][key][0], 0, 1)
354
+ if exists('s:vcsroot') | brea | en
355
+ endfo
356
+ if !exists('s:vcsroot')
357
+ retu has_key(cmd, 'fallback') ? cmd['fallback'] : ''
358
+ en
359
+ unl s:vcsroot
360
+ let s:vcscmd = s:lash == '\' ? 1 : 0
361
+ retu cmd['types'][key][1]
362
+ en
363
+ endf
364
+ " - Buffers {{{1
365
+ fu! ctrlp#buffers(...)
366
+ let ids = sort(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
367
+ \ .' && getbufvar(v:val, "&bl") && strlen(bufname(v:val))'), 's:compmreb')
368
+ retu a:0 && a:1 == 'id' ? ids : map(ids, 'fnamemodify(bufname(v:val), ":.")')
369
+ endf
370
+ " * MatchedItems() {{{1
371
+ fu! s:MatchIt(items, pat, limit, exc)
372
+ let [lines, id] = [[], 0]
373
+ for item in a:items
374
+ let id += 1
375
+ try | if !( s:ispath && item == a:exc ) && call(s:mfunc, [item, a:pat]) >= 0
376
+ cal add(lines, item)
377
+ en | cat | brea | endt
378
+ if a:limit > 0 && len(lines) >= a:limit | brea | en
379
+ endfo
380
+ let s:mdata = [s:dyncwd, s:itemtype, s:regexp, s:sublist(a:items, id, -1)]
381
+ retu lines
382
+ endf
383
+
384
+ fu! s:MatchedItems(items, pat, limit)
385
+ let exc = exists('s:crfilerel') ? s:crfilerel : ''
386
+ let items = s:narrowable() ? s:matched + s:mdata[3] : a:items
387
+ if s:matcher != {}
388
+ let argms = [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp]
389
+ let lines = call(s:matcher['match'], argms)
390
+ el
391
+ let lines = s:MatchIt(items, a:pat, a:limit, exc)
392
+ en
393
+ let s:matches = len(lines)
394
+ retu lines
395
+ endf
396
+
397
+ fu! s:SplitPattern(str)
398
+ let str = a:str
399
+ if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo')
400
+ let str = s:migemo(str)
401
+ en
402
+ let s:savestr = str
403
+ if s:regexp
404
+ let pat = s:regexfilter(str)
405
+ el
406
+ let lst = split(str, '\zs')
407
+ if exists('+ssl') && !&ssl
408
+ cal map(lst, 'escape(v:val, ''\'')')
409
+ en
410
+ for each in ['^', '$', '.']
411
+ cal map(lst, 'escape(v:val, each)')
412
+ endfo
413
+ en
414
+ if exists('lst')
415
+ let pat = ''
416
+ if !empty(lst)
417
+ let pat = lst[0]
418
+ for item in range(1, len(lst) - 1)
419
+ let pat .= '[^'.lst[item - 1].']\{-}'.lst[item]
420
+ endfo
421
+ en
422
+ en
423
+ retu escape(pat, '~')
424
+ endf
425
+ " * BuildPrompt() {{{1
426
+ fu! s:Render(lines, pat)
427
+ let [&ma, lines, s:height] = [1, a:lines, min([len(a:lines), s:winh])]
428
+ " Setup the match window
429
+ sil! exe '%d _ | res' s:height
430
+ " Print the new items
431
+ if empty(lines)
432
+ let [s:matched, s:lines] = [[], []]
433
+ cal setline(1, ' == NO ENTRIES ==')
434
+ setl noma nocul
435
+ cal s:unmarksigns()
436
+ if s:dohighlight() | cal clearmatches() | en
437
+ retu
438
+ en
439
+ let s:matched = copy(lines)
440
+ " Sorting
441
+ if !s:nosort()
442
+ let s:compat = a:pat
443
+ cal sort(lines, 's:mixedsort')
444
+ unl s:compat
445
+ en
446
+ if s:mwreverse | cal reverse(lines) | en
447
+ let s:lines = copy(lines)
448
+ cal map(lines, 's:formatline(v:val)')
449
+ cal setline(1, lines)
450
+ setl noma cul
451
+ exe 'keepj norm!' ( s:mwreverse ? 'G' : 'gg' ).'1|'
452
+ cal s:unmarksigns()
453
+ cal s:remarksigns()
454
+ if exists('s:cline') && s:nolim != 1
455
+ cal cursor(s:cline, 1)
456
+ en
457
+ " Highlighting
458
+ if s:dohighlight()
459
+ cal s:highlight(a:pat, s:mathi[1])
460
+ en
461
+ endf
462
+
463
+ fu! s:Update(str)
464
+ " Get the previous string if existed
465
+ let oldstr = exists('s:savestr') ? s:savestr : ''
466
+ " Get the new string sans tail
467
+ let str = s:sanstail(a:str)
468
+ " Stop if the string's unchanged
469
+ if str == oldstr && !empty(str) && !exists('s:force') | retu | en
470
+ let pat = s:matcher == {} ? s:SplitPattern(str) : str
471
+ let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines)
472
+ \ : s:MatchedItems(g:ctrlp_lines, pat, s:winh)
473
+ cal s:Render(lines, pat)
474
+ endf
475
+
476
+ fu! s:ForceUpdate()
477
+ let [estr, prt] = ['"\', copy(s:prompt)]
478
+ cal map(prt, 'escape(v:val, estr)')
479
+ sil! cal s:Update(join(prt, ''))
480
+ endf
481
+
482
+ fu! s:BuildPrompt(upd, ...)
483
+ let base = ( s:regexp ? 'r' : '>' ).( s:byfname ? 'd' : '>' ).'> '
484
+ let [estr, prt] = ['"\', copy(s:prompt)]
485
+ cal map(prt, 'escape(v:val, estr)')
486
+ let str = join(prt, '')
487
+ let lazy = empty(str) || exists('s:force') || !has('autocmd') ? 0 : s:lazy
488
+ if a:upd && !lazy && ( s:matches || s:regexp
489
+ \ || match(str, '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)') >= 0 )
490
+ sil! cal s:Update(str)
491
+ en
492
+ sil! cal ctrlp#statusline()
493
+ " Toggling
494
+ let [hiactive, hicursor, base] = a:0 && !a:1
495
+ \ ? ['CtrlPPrtBase', 'CtrlPPrtBase', tr(base, '>', '-')]
496
+ \ : ['CtrlPPrtText', 'CtrlPPrtCursor', base]
497
+ let hibase = 'CtrlPPrtBase'
498
+ " Build it
499
+ redr
500
+ exe 'echoh' hibase '| echon "'.base.'"
501
+ \ | echoh' hiactive '| echon "'.prt[0].'"
502
+ \ | echoh' hicursor '| echon "'.prt[1].'"
503
+ \ | echoh' hiactive '| echon "'.prt[2].'" | echoh None'
504
+ " Append the cursor at the end
505
+ if empty(prt[1]) && !( a:0 && !a:1 )
506
+ exe 'echoh' hibase '| echon "_" | echoh None'
507
+ en
508
+ endf
509
+ " - SetDefTxt() {{{1
510
+ fu! s:SetDefTxt()
511
+ if s:deftxt == '0' || !s:ispath | retu | en
512
+ let txt = s:deftxt
513
+ if !type(txt)
514
+ let txt = txt && !stridx(s:crfpath, s:dyncwd)
515
+ \ ? ctrlp#rmbasedir([s:crfpath])[0] : ''
516
+ let txt = txt != '' ? txt.s:lash(s:crfpath) : ''
517
+ el
518
+ let txt = expand(txt, 1)
519
+ en
520
+ let s:prompt[0] = txt
521
+ endf
522
+ " ** Prt Actions {{{1
523
+ " Editing {{{2
524
+ fu! s:PrtClear()
525
+ unl! s:hstgot
526
+ let [s:prompt, s:matches] = [['', '', ''], 1]
527
+ cal s:BuildPrompt(1)
528
+ endf
529
+
530
+ fu! s:PrtAdd(char)
531
+ unl! s:hstgot
532
+ let s:act_add = 1
533
+ let s:prompt[0] .= a:char
534
+ cal s:BuildPrompt(1)
535
+ unl s:act_add
536
+ endf
537
+
538
+ fu! s:PrtBS()
539
+ unl! s:hstgot
540
+ let [s:prompt[0], s:matches] = [substitute(s:prompt[0], '.$', '', ''), 1]
541
+ cal s:BuildPrompt(1)
542
+ endf
543
+
544
+ fu! s:PrtDelete()
545
+ unl! s:hstgot
546
+ let [prt, s:matches] = [s:prompt, 1]
547
+ let prt[1] = matchstr(prt[2], '^.')
548
+ let prt[2] = substitute(prt[2], '^.', '', '')
549
+ cal s:BuildPrompt(1)
550
+ endf
551
+
552
+ fu! s:PrtDeleteWord()
553
+ unl! s:hstgot
554
+ let [str, s:matches] = [s:prompt[0], 1]
555
+ let str = match(str, '\W\w\+$') >= 0 ? matchstr(str, '^.\+\W\ze\w\+$')
556
+ \ : match(str, '\w\W\+$') >= 0 ? matchstr(str, '^.\+\w\ze\W\+$')
557
+ \ : match(str, '\s\+$') >= 0 ? matchstr(str, '^.*[^ \t]\+\ze\s\+$')
558
+ \ : match(str, ' ') <= 0 ? '' : str
559
+ let s:prompt[0] = str
560
+ cal s:BuildPrompt(1)
561
+ endf
562
+
563
+ fu! s:PrtInsert(...)
564
+ let type = !a:0 ? '' : a:1
565
+ if !a:0
566
+ let type = s:insertstr()
567
+ if type == 'cancel' | retu | en
568
+ en
569
+ unl! s:hstgot
570
+ let s:act_add = 1
571
+ let s:prompt[0] .= type == 'w' ? s:crword
572
+ \ : type == 's' ? getreg('/')
573
+ \ : type == 'v' ? s:crvisual
574
+ \ : type == 'c' ? substitute(getreg('+'), '\n', '\\n', 'g')
575
+ \ : type == 'f' ? s:crgfile : s:prompt[0]
576
+ cal s:BuildPrompt(1)
577
+ unl s:act_add
578
+ endf
579
+
580
+ fu! s:PrtExpandDir()
581
+ let prt = s:prompt
582
+ if prt[0] == '' | retu | en
583
+ unl! s:hstgot
584
+ let s:act_add = 1
585
+ let [base, seed] = s:headntail(prt[0])
586
+ let dirs = s:dircompl(base, seed)
587
+ if len(dirs) == 1
588
+ let prt[0] = dirs[0]
589
+ elsei len(dirs) > 1
590
+ let prt[0] .= s:findcommon(dirs, prt[0])
591
+ en
592
+ cal s:BuildPrompt(1)
593
+ unl s:act_add
594
+ endf
595
+ " Movement {{{2
596
+ fu! s:PrtCurLeft()
597
+ let prt = s:prompt
598
+ if !empty(prt[0])
599
+ let s:prompt = [substitute(prt[0], '.$', '', ''), matchstr(prt[0], '.$'),
600
+ \ prt[1] . prt[2]]
601
+ en
602
+ cal s:BuildPrompt(0)
603
+ endf
604
+
605
+ fu! s:PrtCurRight()
606
+ let prt = s:prompt
607
+ let s:prompt = [prt[0] . prt[1], matchstr(prt[2], '^.'),
608
+ \ substitute(prt[2], '^.', '', '')]
609
+ cal s:BuildPrompt(0)
610
+ endf
611
+
612
+ fu! s:PrtCurStart()
613
+ let str = join(s:prompt, '')
614
+ let s:prompt = ['', matchstr(str, '^.'), substitute(str, '^.', '', '')]
615
+ cal s:BuildPrompt(0)
616
+ endf
617
+
618
+ fu! s:PrtCurEnd()
619
+ let s:prompt = [join(s:prompt, ''), '', '']
620
+ cal s:BuildPrompt(0)
621
+ endf
622
+
623
+ fu! s:PrtSelectMove(dir)
624
+ let wht = winheight(0)
625
+ let dirs = {'t': 'gg','b': 'G','j': 'j','k': 'k','u': wht.'k','d': wht.'j'}
626
+ exe 'keepj norm!' dirs[a:dir]
627
+ if s:nolim != 1 | let s:cline = line('.') | en
628
+ if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
629
+ endf
630
+
631
+ fu! s:PrtSelectJump(char, ...)
632
+ let lines = copy(s:lines)
633
+ if a:0
634
+ cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
635
+ en
636
+ " Cycle through matches, use s:jmpchr to store last jump
637
+ let chr = escape(a:char, '.~')
638
+ if match(lines, '\c^'.chr) >= 0
639
+ " If not exists or does but not for the same char
640
+ let pos = match(lines, '\c^'.chr)
641
+ if !exists('s:jmpchr') || ( exists('s:jmpchr') && s:jmpchr[0] != chr )
642
+ let [jmpln, s:jmpchr] = [pos, [chr, pos]]
643
+ elsei exists('s:jmpchr') && s:jmpchr[0] == chr
644
+ " Start of lines
645
+ if s:jmpchr[1] == -1 | let s:jmpchr[1] = pos | en
646
+ let npos = match(lines, '\c^'.chr, s:jmpchr[1] + 1)
647
+ let [jmpln, s:jmpchr] = [npos == -1 ? pos : npos, [chr, npos]]
648
+ en
649
+ keepj exe jmpln + 1
650
+ if s:nolim != 1 | let s:cline = line('.') | en
651
+ if line('$') > winheight(0) | cal s:BuildPrompt(0, s:Focus()) | en
652
+ en
653
+ endf
654
+ " Misc {{{2
655
+ fu! s:PrtClearCache()
656
+ if s:itemtype == 0
657
+ cal ctrlp#clr()
658
+ elsei s:itemtype > 2
659
+ cal ctrlp#clr(s:statypes[s:itemtype][1])
660
+ en
661
+ if s:itemtype == 2
662
+ let g:ctrlp_lines = ctrlp#mrufiles#refresh()
663
+ el
664
+ cal ctrlp#setlines()
665
+ en
666
+ let s:force = 1
667
+ cal s:BuildPrompt(1)
668
+ unl s:force
669
+ endf
670
+
671
+ fu! s:PrtDeleteEnt()
672
+ if s:itemtype == 2
673
+ cal s:PrtDeleteMRU()
674
+ elsei type(s:getextvar('wipe')) == 1
675
+ cal s:delent(s:getextvar('wipe'))
676
+ en
677
+ endf
678
+
679
+ fu! s:PrtDeleteMRU()
680
+ if s:itemtype == 2
681
+ cal s:delent('ctrlp#mrufiles#remove')
682
+ en
683
+ endf
684
+
685
+ fu! s:PrtExit()
686
+ if !has('autocmd') | cal s:Close() | en
687
+ winc p
688
+ endf
689
+
690
+ fu! s:PrtHistory(...)
691
+ if !s:maxhst | retu | en
692
+ let [str, hst, s:matches] = [join(s:prompt, ''), s:hstry, 1]
693
+ " Save to history if not saved before
694
+ let [hst[0], hslen] = [exists('s:hstgot') ? hst[0] : str, len(hst)]
695
+ let idx = exists('s:hisidx') ? s:hisidx + a:1 : a:1
696
+ " Limit idx within 0 and hslen
697
+ let idx = idx < 0 ? 0 : idx >= hslen ? hslen > 1 ? hslen - 1 : 0 : idx
698
+ let s:prompt = [hst[idx], '', '']
699
+ let [s:hisidx, s:hstgot, s:force] = [idx, 1, 1]
700
+ cal s:BuildPrompt(1)
701
+ unl s:force
702
+ endf
703
+ "}}}1
704
+ " * MapKeys() {{{1
705
+ fu! s:MapKeys(...)
706
+ " Normal keys
707
+ let pfunc = a:0 && !a:1 ? 'PrtSelectJump' : 'PrtAdd'
708
+ let dojmp = s:byfname && a:0 && !a:1 ? ', 1' : ''
709
+ let pcmd = "nn \<buffer> \<silent> \<k%s> :\<c-u>cal \<SID>%s(\"%s\"%s)\<cr>"
710
+ let cmd = substitute(pcmd, 'k%s', 'char-%d', '')
711
+ for each in range(32, 126)
712
+ exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'), dojmp)
713
+ endfo
714
+ for each in range(0, 9)
715
+ exe printf(pcmd, each, pfunc, each, dojmp)
716
+ endfo
717
+ for [ke, va] in items(s:kprange)
718
+ exe printf(pcmd, ke, pfunc, va, dojmp)
719
+ endfo
720
+ " Special keys
721
+ if a:0 < 2
722
+ cal call('s:MapSpecs', a:0 && !a:1 ? [1] : [])
723
+ en
724
+ endf
725
+
726
+ fu! s:MapSpecs(...)
727
+ " Correct arrow keys in terminal
728
+ if ( has('termresponse') && match(v:termresponse, "\<ESC>") >= 0 )
729
+ \ || &term =~? '\vxterm|<k?vt|gnome|screen|linux'
730
+ for each in ['\A <up>','\B <down>','\C <right>','\D <left>']
731
+ exe s:lcmap.' <esc>['.each
732
+ endfo
733
+ en
734
+ if a:0
735
+ for ke in s:prtunmaps | for kp in s:prtmaps[ke]
736
+ exe s:lcmap kp '<Nop>'
737
+ endfo | endfo
738
+ el
739
+ for [ke, va] in items(s:prtmaps) | for kp in va
740
+ exe s:lcmap kp ':<c-u>cal <SID>'.ke.'<cr>'
741
+ endfo | endfo
742
+ en
743
+ endf
744
+ " * Toggling {{{1
745
+ fu! s:Focus()
746
+ retu !exists('s:focus') ? 1 : s:focus
747
+ endf
748
+
749
+ fu! s:ToggleFocus()
750
+ let s:focus = !exists('s:focus') || s:focus ? 0 : 1
751
+ cal s:MapKeys(s:focus)
752
+ cal s:BuildPrompt(0, s:focus)
753
+ endf
754
+
755
+ fu! s:ToggleRegex()
756
+ let s:regexp = s:regexp ? 0 : 1
757
+ cal s:PrtSwitcher()
758
+ endf
759
+
760
+ fu! s:ToggleByFname()
761
+ if s:ispath
762
+ let s:byfname = s:byfname ? 0 : 1
763
+ let s:mfunc = s:mfunc()
764
+ cal s:MapKeys(s:Focus(), 1)
765
+ cal s:PrtSwitcher()
766
+ en
767
+ endf
768
+
769
+ fu! s:ToggleType(dir)
770
+ let max = len(g:ctrlp_ext_vars) + 2
771
+ let next = s:walker(max, s:itemtype, a:dir)
772
+ cal ctrlp#syntax()
773
+ cal ctrlp#setlines(next)
774
+ cal s:PrtSwitcher()
775
+ endf
776
+
777
+ fu! s:PrtSwitcher()
778
+ let [s:force, s:matches] = [1, 1]
779
+ cal s:BuildPrompt(1, s:Focus())
780
+ unl s:force
781
+ endf
782
+ " - SetWD() {{{1
783
+ fu! s:SetWD(...)
784
+ let pathmode = s:wpmode
785
+ let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
786
+ if a:0 && strlen(a:1) | if type(a:1)
787
+ cal ctrlp#setdir(a:1) | retu
788
+ el
789
+ let pathmode = a:1
790
+ en | en
791
+ if a:0 < 2
792
+ if match(s:crfile, '\v^<.+>://') >= 0 || !pathmode | retu | en
793
+ if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
794
+ cal ctrlp#setdir(s:crfpath)
795
+ en
796
+ if pathmode == 1 | retu | en
797
+ let markers = ['root.dir', '.git/', '.hg/', '.svn/', '.bzr/', '_darcs/']
798
+ if type(s:rmarkers) == 3 && !empty(s:rmarkers)
799
+ cal extend(markers, s:rmarkers, 0)
800
+ en
801
+ for marker in markers
802
+ cal s:findroot(s:dyncwd, marker, 0, 0)
803
+ if exists('s:foundroot') | brea | en
804
+ endfo
805
+ unl! s:foundroot
806
+ endf
807
+ " * AcceptSelection() {{{1
808
+ fu! ctrlp#acceptfile(mode, line, ...)
809
+ let [md, filpath] = [a:mode, fnamemodify(a:line, ':p')]
810
+ cal s:PrtExit()
811
+ let [bufnr, tail] = [bufnr('^'.filpath.'$'), s:tail()]
812
+ let j2l = a:0 ? a:1 : str2nr(matchstr(tail, '^ +\D*\zs\d\+\ze\D*'))
813
+ if s:jmptobuf && bufnr > 0 && md =~ 'e\|t'
814
+ let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)]
815
+ let buftab = s:jmptobuf > 1 ? s:buftab(bufnr, md) : [0, 0]
816
+ en
817
+ " Switch to existing buffer or open new one
818
+ if exists('jmpb') && bufwinnr > 0 && md != 't'
819
+ exe bufwinnr.'winc w'
820
+ if j2l | cal ctrlp#j2l(j2l) | en
821
+ elsei exists('jmpb') && buftab[0]
822
+ exe 'tabn' buftab[0]
823
+ exe buftab[1].'winc w'
824
+ if j2l | cal ctrlp#j2l(j2l) | en
825
+ el
826
+ " Determine the command to use
827
+ let useb = bufnr > 0 && buflisted(bufnr) && empty(tail)
828
+ let cmd =
829
+ \ md == 't' || s:splitwin == 1 ? ( useb ? 'tab sb' : 'tabe' ) :
830
+ \ md == 'h' || s:splitwin == 2 ? ( useb ? 'sb' : 'new' ) :
831
+ \ md == 'v' || s:splitwin == 3 ? ( useb ? 'vert sb' : 'vne' ) :
832
+ \ call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
833
+ " Reset &switchbuf option
834
+ let [swb, &swb] = [&swb, '']
835
+ " Open new window/buffer
836
+ let args = [cmd, useb ? bufnr : filpath, a:0 ? ' +'.a:1 : tail, useb, j2l]
837
+ cal call('s:openfile', args)
838
+ let &swb = swb
839
+ en
840
+ endf
841
+
842
+ fu! s:SpecInputs(str)
843
+ let spi = !s:itemtype || s:getextvar('specinput') > 0
844
+ if a:str == '..' && spi
845
+ cal s:parentdir(s:dyncwd)
846
+ cal ctrlp#setlines()
847
+ cal s:PrtClear()
848
+ retu 1
849
+ elsei a:str =~ '^[\/]$' && spi
850
+ cal s:SetWD(2, 0)
851
+ cal ctrlp#setlines()
852
+ cal s:PrtClear()
853
+ retu 1
854
+ elsei a:str == '?'
855
+ cal s:PrtExit()
856
+ let hlpwin = &columns > 159 ? '| vert res 80' : ''
857
+ sil! exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0'
858
+ retu 1
859
+ en
860
+ retu 0
861
+ endf
862
+
863
+ fu! s:AcceptSelection(mode)
864
+ let str = join(s:prompt, '')
865
+ if a:mode == 'e' | if s:SpecInputs(str) | retu | en | en
866
+ " Get the selected line
867
+ let line = !empty(s:lines) ? s:lines[line('.') - 1] : ''
868
+ if a:mode != 'e' && s:itemtype < 3 && line == ''
869
+ \ && str !~ '\v^(\.\.|/|\\|\?)$'
870
+ cal s:CreateNewFile(a:mode) | retu
871
+ en
872
+ if empty(line) | retu | en
873
+ " Do something with it
874
+ let actfunc = s:itemtype < 3 ? 'ctrlp#acceptfile' : s:getextvar('accept')
875
+ cal call(actfunc, [a:mode, line])
876
+ endf
877
+ " - CreateNewFile() {{{1
878
+ fu! s:CreateNewFile(...)
879
+ let [md, str] = ['', join(s:prompt, '')]
880
+ if empty(str) | retu | en
881
+ if s:argmap && !a:0
882
+ " Get the extra argument
883
+ let md = s:argmaps(md, 1)
884
+ if md == 'cancel' | retu | en
885
+ en
886
+ let str = s:sanstail(str)
887
+ let [base, fname] = s:headntail(str)
888
+ if fname =~ '^[\/]$' | retu | en
889
+ if exists('s:marked') && len(s:marked)
890
+ " Use the first marked file's path
891
+ let path = fnamemodify(values(s:marked)[0], ':p:h')
892
+ let base = path.s:lash(path).base
893
+ let str = fnamemodify(base.s:lash.fname, ':.')
894
+ en
895
+ if base != '' | if isdirectory(ctrlp#utils#mkdir(base))
896
+ let optyp = str | en | el | let optyp = fname
897
+ en
898
+ if !exists('optyp') | retu | en
899
+ let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()]
900
+ if !stridx(filpath, s:dyncwd) | cal s:insertcache(str) | en
901
+ cal s:PrtExit()
902
+ let cmd = md == 'r' ? ctrlp#normcmd('e') :
903
+ \ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' :
904
+ \ s:newfop =~ '2\|h' || ( a:0 && a:1 == 'h' ) || md == 'h' ? 'new' :
905
+ \ s:newfop =~ '3\|v' || ( a:0 && a:1 == 'v' ) || md == 'v' ? 'vne' :
906
+ \ ctrlp#normcmd('e')
907
+ cal s:openfile(cmd, filpath, tail)
908
+ endf
909
+ " * OpenMulti() {{{1
910
+ fu! s:MarkToOpen()
911
+ if s:bufnr <= 0 || s:opmul == '0'
912
+ \ || ( s:itemtype > 2 && s:getextvar('opmul') != 1 )
913
+ retu
914
+ en
915
+ let line = !empty(s:lines) ? s:lines[line('.') - 1] : ''
916
+ if empty(line) | retu | en
917
+ let filpath = s:ispath ? fnamemodify(line, ':p') : line
918
+ if exists('s:marked') && s:dictindex(s:marked, filpath) > 0
919
+ " Unmark and remove the file from s:marked
920
+ let key = s:dictindex(s:marked, filpath)
921
+ cal remove(s:marked, key)
922
+ if empty(s:marked) | unl s:marked | en
923
+ if has('signs')
924
+ exe 'sign unplace' key 'buffer='.s:bufnr
925
+ en
926
+ el
927
+ " Add to s:marked and place a new sign
928
+ if exists('s:marked')
929
+ let vac = s:vacantdict(s:marked)
930
+ let key = empty(vac) ? len(s:marked) + 1 : vac[0]
931
+ let s:marked = extend(s:marked, { key : filpath })
932
+ el
933
+ let [key, s:marked] = [1, { 1 : filpath }]
934
+ en
935
+ if has('signs')
936
+ exe 'sign place' key 'line='.line('.').' name=ctrlpmark buffer='.s:bufnr
937
+ en
938
+ en
939
+ sil! cal ctrlp#statusline()
940
+ endf
941
+
942
+ fu! s:OpenMulti()
943
+ if !exists('s:marked') || s:opmul == '0' || !s:ispath | retu | en
944
+ " Get the options
945
+ let opts = matchlist(s:opmul, '\v^(\d+)=(\w)=(\w)=$')
946
+ if opts == [] | retu | en
947
+ let [nr, md, ucr] = opts[1:3]
948
+ if s:argmap
949
+ let md = s:argmaps(md)
950
+ if md == 'cancel' | retu | en
951
+ en
952
+ let mkd = values(s:marked)
953
+ cal s:sanstail(join(s:prompt, ''))
954
+ cal s:PrtExit()
955
+ if !nr || md == 'i'
956
+ retu map(mkd, "s:openfile('bad', fnamemodify(v:val, ':.'), '')")
957
+ en
958
+ " Move the cursor to a reusable window
959
+ let [tail, fnesc] = [s:tail(), exists('*fnameescape') && v:version > 701]
960
+ let [emptytail, nwpt] = [empty(tail), exists('g:ctrlp_open_multiple_files')]
961
+ let bufnr = bufnr('^'.mkd[0].'$')
962
+ let useb = bufnr > 0 && buflisted(bufnr) && emptytail
963
+ let fst = call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
964
+ " Check if it's a replaceable buffer
965
+ let repabl = ( empty(bufname('%')) && empty(&l:ft) ) || s:nosplit()
966
+ " Commands for the rest of the files
967
+ let [ic, cmds] = [1, { 'v': ['vert sb', 'vne'], 'h': ['sb', 'new'],
968
+ \ 't': ['tab sb', 'tabe'] }]
969
+ let [swb, &swb] = [&swb, '']
970
+ " Open the files
971
+ for va in mkd
972
+ let bufnr = bufnr('^'.va.'$')
973
+ if bufnr < 0 && getftype(va) == '' | con | en
974
+ let useb = bufnr > 0 && buflisted(bufnr) && emptytail
975
+ let snd = md != '' && has_key(cmds, md) ?
976
+ \ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' )
977
+ let cmd = ic == 1 && ( ucr == 'r' || repabl ) ? fst : snd
978
+ let conds = [( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 ),
979
+ \ nr != '' && nr < ic]
980
+ if conds[nwpt]
981
+ if bufnr <= 0 | if fnesc
982
+ cal s:openfile('bad', fnamemodify(va, ':.'), '')
983
+ el
984
+ cal s:openfile(cmd, va, tail) | sil! hid clo!
985
+ en | en
986
+ el
987
+ cal s:openfile(cmd, useb ? bufnr : va, tail) | let ic += 1
988
+ en
989
+ endfo
990
+ let &swb = swb
991
+ endf
992
+ " ** Helper functions {{{1
993
+ " Sorting {{{2
994
+ fu! ctrlp#complen(...)
995
+ " By length
996
+ let [len1, len2] = [strlen(a:1), strlen(a:2)]
997
+ retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1
998
+ endf
999
+
1000
+ fu! s:compmatlen(...)
1001
+ " By match length
1002
+ let mln1 = s:shortest(s:matchlens(a:1, s:compat))
1003
+ let mln2 = s:shortest(s:matchlens(a:2, s:compat))
1004
+ retu mln1 == mln2 ? 0 : mln1 > mln2 ? 1 : -1
1005
+ endf
1006
+
1007
+ fu! s:comptime(...)
1008
+ " By last modified time
1009
+ let [time1, time2] = [getftime(a:1), getftime(a:2)]
1010
+ retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1
1011
+ endf
1012
+
1013
+ fu! s:compmreb(...)
1014
+ " By last entered time (bufnr)
1015
+ let [id1, id2] = [index(s:mrbs, a:1), index(s:mrbs, a:2)]
1016
+ retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
1017
+ endf
1018
+
1019
+ fu! s:compmref(...)
1020
+ " By last entered time (MRU)
1021
+ let [id1, id2] = [index(g:ctrlp_lines, a:1), index(g:ctrlp_lines, a:2)]
1022
+ retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
1023
+ endf
1024
+
1025
+ fu! s:comparent(...)
1026
+ " By same parent dir
1027
+ if !stridx(s:crfpath, s:dyncwd)
1028
+ let [as1, as2] = [s:dyncwd.s:lash().a:1, s:dyncwd.s:lash().a:2]
1029
+ let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)]
1030
+ if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en
1031
+ if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en
1032
+ retu 0
1033
+ en
1034
+ retu 0
1035
+ endf
1036
+
1037
+ fu! s:compfnlen(...)
1038
+ " By filename length
1039
+ let len1 = strlen(split(a:1, s:lash)[-1])
1040
+ let len2 = strlen(split(a:2, s:lash)[-1])
1041
+ retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1
1042
+ endf
1043
+
1044
+ fu! s:matchlens(str, pat, ...)
1045
+ if empty(a:pat) || index(['^', '$'], a:pat) >= 0 | retu {} | en
1046
+ let st = a:0 ? a:1 : 0
1047
+ let lens = a:0 >= 2 ? a:2 : {}
1048
+ let nr = a:0 >= 3 ? a:3 : 0
1049
+ if nr > 20 | retu {} | en
1050
+ if match(a:str, a:pat, st) >= 0
1051
+ let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)]
1052
+ let lens = extend(lens, { nr : [strlen(mst), mst] })
1053
+ let lens = s:matchlens(a:str, a:pat, mnd, lens, nr + 1)
1054
+ en
1055
+ retu lens
1056
+ endf
1057
+
1058
+ fu! s:shortest(lens)
1059
+ retu min(map(values(a:lens), 'v:val[0]'))
1060
+ endf
1061
+
1062
+ fu! s:mixedsort(...)
1063
+ let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
1064
+ if s:ispath
1065
+ let ms = []
1066
+ if s:height < 21
1067
+ let ms += [s:compfnlen(a:1, a:2)]
1068
+ if s:itemtype !~ '^[12]$' | let ms += [s:comptime(a:1, a:2)] | en
1069
+ if !s:itemtype | let ms += [s:comparent(a:1, a:2)] | en
1070
+ en
1071
+ if s:itemtype =~ '^[12]$'
1072
+ let ms += [s:compmref(a:1, a:2)] | let cln = 0
1073
+ en
1074
+ let ms += [cml, 0, 0, 0]
1075
+ let mp = call('s:multipliers', ms[:3])
1076
+ retu cln + ms[0] * mp[0] + ms[1] * mp[1] + ms[2] * mp[2] + ms[3] * mp[3]
1077
+ en
1078
+ retu cln + cml * 2
1079
+ endf
1080
+
1081
+ fu! s:multipliers(...)
1082
+ let mp0 = !a:1 ? 0 : 2
1083
+ let mp1 = !a:2 ? 0 : 1 + ( !mp0 ? 1 : mp0 )
1084
+ let mp2 = !a:3 ? 0 : 1 + ( !( mp0 + mp1 ) ? 1 : ( mp0 + mp1 ) )
1085
+ let mp3 = !a:4 ? 0 : 1 + ( !( mp0 + mp1 + mp2 ) ? 1 : ( mp0 + mp1 + mp2 ) )
1086
+ retu [mp0, mp1, mp2, mp3]
1087
+ endf
1088
+
1089
+ fu! s:compval(...)
1090
+ retu a:1 - a:2
1091
+ endf
1092
+ " Statusline {{{2
1093
+ fu! ctrlp#statusline()
1094
+ if !exists('s:statypes')
1095
+ let s:statypes = [
1096
+ \ ['files', 'fil'],
1097
+ \ ['buffers', 'buf'],
1098
+ \ ['mru files', 'mru'],
1099
+ \ ]
1100
+ if !empty(g:ctrlp_ext_vars)
1101
+ cal map(copy(g:ctrlp_ext_vars),
1102
+ \ 'add(s:statypes, [ v:val["lname"], v:val["sname"] ])')
1103
+ en
1104
+ en
1105
+ let tps = s:statypes
1106
+ let max = len(tps) - 1
1107
+ let nxt = tps[s:walker(max, s:itemtype, 1)][1]
1108
+ let prv = tps[s:walker(max, s:itemtype, -1)][1]
1109
+ let item = tps[s:itemtype][0]
1110
+ let focus = s:Focus() ? 'prt' : 'win'
1111
+ let byfname = s:byfname ? 'file' : 'path'
1112
+ let marked = s:opmul != '0' ?
1113
+ \ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <->' : ''
1114
+ if s:status != {}
1115
+ let args = [focus, byfname, s:regexp, prv, item, nxt, marked]
1116
+ let &l:stl = call(s:status['main'], args)
1117
+ el
1118
+ let item = '%#CtrlPMode1# '.item.' %*'
1119
+ let focus = '%#CtrlPMode2# '.focus.' %*'
1120
+ let byfname = '%#CtrlPMode1# '.byfname.' %*'
1121
+ let regex = s:regexp ? '%#CtrlPMode2# regex %*' : ''
1122
+ let slider = ' <'.prv.'>={'.item.'}=<'.nxt.'>'
1123
+ let dir = ' %=%<%#CtrlPMode2# '.s:dyncwd.' %*'
1124
+ let &l:stl = focus.byfname.regex.slider.marked.dir
1125
+ en
1126
+ endf
1127
+
1128
+ fu! s:dismrk()
1129
+ retu has('signs') ? len(s:marked) :
1130
+ \ '%<'.join(values(map(copy(s:marked), 'split(v:val, "[\\/]")[-1]')), ', ')
1131
+ endf
1132
+
1133
+ fu! ctrlp#progress(enum, ...)
1134
+ if has('macunix') || has('mac') | sl 1m | en
1135
+ let txt = a:0 ? '(press ctrl-c to abort)' : ''
1136
+ let &l:stl = s:status != {} ? call(s:status['prog'], [a:enum])
1137
+ \ : '%#CtrlPStats# '.a:enum.' %* '.txt.'%=%<%#CtrlPMode2# '.s:dyncwd.' %*'
1138
+ redraws
1139
+ endf
1140
+ " Paths {{{2
1141
+ fu! s:formatline(str)
1142
+ let cond = s:ispath && ( s:winw - 4 ) < s:strwidth(a:str)
1143
+ retu '> '.( cond ? pathshorten(a:str) : a:str )
1144
+ endf
1145
+
1146
+ fu! s:dircompl(be, sd)
1147
+ if a:sd == '' | retu [] | en
1148
+ let [be, sd] = a:be == '' ? [s:dyncwd, a:sd] : [a:be, a:be.s:lash(a:be).a:sd]
1149
+ let dirs = ctrlp#rmbasedir(split(globpath(be, a:sd.'*/'), "\n"))
1150
+ cal filter(dirs, '!match(v:val, escape(sd, ''~$.\''))'
1151
+ \ . ' && match(v:val, ''\v(^|[\/])\.{1,2}[\/]$'') < 0')
1152
+ retu dirs
1153
+ endf
1154
+
1155
+ fu! s:findcommon(items, seed)
1156
+ let [items, id, cmn, ic] = [copy(a:items), strlen(a:seed), '', 0]
1157
+ cal map(items, 'strpart(v:val, id)')
1158
+ for char in split(items[0], '\zs')
1159
+ for item in items[1:]
1160
+ if item[ic] != char | let brk = 1 | brea | en
1161
+ endfo
1162
+ if exists('brk') | brea | en
1163
+ let cmn .= char
1164
+ let ic += 1
1165
+ endfo
1166
+ retu cmn
1167
+ endf
1168
+
1169
+ fu! s:headntail(str)
1170
+ let parts = split(a:str, '[\/]\ze[^\/]\+[\/:]\?$')
1171
+ retu len(parts) == 1 ? ['', parts[0]] : len(parts) == 2 ? parts : []
1172
+ endf
1173
+
1174
+ fu! s:lash(...)
1175
+ retu match(a:0 ? a:1 : s:dyncwd, '[\/]$') < 0 ? s:lash : ''
1176
+ endf
1177
+
1178
+ fu! s:ispathitem()
1179
+ retu s:itemtype < 3 || ( s:itemtype > 2 && s:getextvar('type') == 'path' )
1180
+ endf
1181
+
1182
+ fu! ctrlp#dirnfile(entries)
1183
+ let [items, cwd] = [[[], []], s:dyncwd.s:lash()]
1184
+ for each in a:entries
1185
+ let etype = getftype(each)
1186
+ if s:igntype >= 0 && s:usrign(each, etype) | con | en
1187
+ if etype == 'dir'
1188
+ if s:dotfiles | if match(each, '[\/]\.\{1,2}$') < 0
1189
+ cal add(items[0], each)
1190
+ en | el
1191
+ cal add(items[0], each)
1192
+ en
1193
+ elsei etype == 'link'
1194
+ if s:folsym
1195
+ let isfile = !isdirectory(each)
1196
+ if !s:samerootsyml(each, isfile, cwd)
1197
+ cal add(items[isfile], each)
1198
+ en
1199
+ en
1200
+ elsei etype == 'file'
1201
+ cal add(items[1], each)
1202
+ en
1203
+ endfo
1204
+ retu items
1205
+ endf
1206
+
1207
+ fu! s:usrign(item, type)
1208
+ retu s:igntype == 1 ? a:item =~ s:usrign
1209
+ \ : s:igntype == 4 && has_key(s:usrign, a:type) && s:usrign[a:type] != ''
1210
+ \ ? a:item =~ s:usrign[a:type] : 0
1211
+ endf
1212
+
1213
+ fu! s:samerootsyml(each, isfile, cwd)
1214
+ let resolve = fnamemodify(resolve(a:each), ':p:h')
1215
+ let resolve .= s:lash(resolve)
1216
+ retu !( stridx(resolve, a:cwd) && ( stridx(a:cwd, resolve) || a:isfile ) )
1217
+ endf
1218
+
1219
+ fu! ctrlp#rmbasedir(items)
1220
+ if a:items != [] && !stridx(a:items[0], s:dyncwd)
1221
+ let idx = strlen(s:dyncwd) + ( match(s:dyncwd, '[\/]$') < 0 )
1222
+ retu map(a:items, 'strpart(v:val, idx)')
1223
+ en
1224
+ retu a:items
1225
+ endf
1226
+
1227
+ fu! s:parentdir(curr)
1228
+ let parent = s:getparent(a:curr)
1229
+ if parent != a:curr | cal ctrlp#setdir(parent) | en
1230
+ endf
1231
+
1232
+ fu! s:getparent(item)
1233
+ let parent = substitute(a:item, '[\/][^\/]\+[\/:]\?$', '', '')
1234
+ if parent == '' || match(parent, '[\/]') < 0
1235
+ let parent .= s:lash
1236
+ en
1237
+ retu parent
1238
+ endf
1239
+
1240
+ fu! s:findroot(curr, mark, depth, type)
1241
+ let [depth, notfound] = [a:depth + 1, empty(s:glbpath(a:curr, a:mark, 1))]
1242
+ if !notfound || depth > s:maxdepth
1243
+ if notfound | cal ctrlp#setdir(s:cwd) | en
1244
+ if a:type && depth <= s:maxdepth
1245
+ let s:vcsroot = a:curr
1246
+ elsei !a:type && !notfound
1247
+ cal ctrlp#setdir(a:curr) | let s:foundroot = 1
1248
+ en
1249
+ el
1250
+ let parent = s:getparent(a:curr)
1251
+ if parent != a:curr | cal s:findroot(parent, a:mark, depth, a:type) | en
1252
+ en
1253
+ endf
1254
+
1255
+ fu! s:glbpath(...)
1256
+ let cond = v:version > 702 || ( v:version == 702 && has('patch051') )
1257
+ retu call('globpath', cond ? a:000 : a:000[:1])
1258
+ endf
1259
+
1260
+ fu! ctrlp#fnesc(path)
1261
+ retu exists('*fnameescape') ? fnameescape(a:path) : escape(a:path, " %#*?|<\"\n")
1262
+ endf
1263
+
1264
+ fu! ctrlp#setdir(path, ...)
1265
+ let cmd = a:0 ? a:1 : 'lc!'
1266
+ sil! exe cmd ctrlp#fnesc(a:path)
1267
+ let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
1268
+ endf
1269
+
1270
+ fu! ctrlp#setlcdir()
1271
+ if exists('*haslocaldir')
1272
+ cal ctrlp#setdir(getcwd(), haslocaldir() ? 'lc!' : 'cd!')
1273
+ en
1274
+ endf
1275
+ " Highlighting {{{2
1276
+ fu! ctrlp#syntax()
1277
+ if ctrlp#nosy() | retu | en
1278
+ for [ke, va] in items(s:hlgrps) | cal ctrlp#hicheck('CtrlP'.ke, va) | endfo
1279
+ if !hlexists('CtrlPLinePre')
1280
+ \ && synIDattr(synIDtrans(hlID('Normal')), 'bg') !~ '^-1$\|^$'
1281
+ sil! exe 'hi CtrlPLinePre '.( has("gui_running") ? 'gui' : 'cterm' ).'fg=bg'
1282
+ en
1283
+ sy match CtrlPNoEntries '^ == NO ENTRIES ==$'
1284
+ if hlexists('CtrlPLinePre')
1285
+ sy match CtrlPLinePre '^>'
1286
+ en
1287
+ endf
1288
+
1289
+ fu! s:highlight(pat, grp)
1290
+ if s:matcher != {} | retu | en
1291
+ cal clearmatches()
1292
+ if !empty(a:pat) && s:ispath
1293
+ let pat = s:regexp ? substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g') : a:pat
1294
+ if s:byfname
1295
+ " Match only filename
1296
+ let pat = substitute(pat, '\[\^\(.\{-}\)\]\\{-}', '[^\\/\1]\\{-}', 'g')
1297
+ let pat = substitute(pat, '\$\@<!$', '\\ze[^\\/]*$', 'g')
1298
+ en
1299
+ cal matchadd(a:grp, '\c'.pat)
1300
+ cal matchadd('CtrlPLinePre', '^>')
1301
+ en
1302
+ endf
1303
+
1304
+ fu! s:dohighlight()
1305
+ retu s:mathi[0] && exists('*clearmatches') && !ctrlp#nosy()
1306
+ endf
1307
+ " Prompt history {{{2
1308
+ fu! s:gethistloc()
1309
+ let utilcadir = ctrlp#utils#cachedir()
1310
+ let cache_dir = utilcadir.s:lash(utilcadir).'hist'
1311
+ retu [cache_dir, cache_dir.s:lash(cache_dir).'cache.txt']
1312
+ endf
1313
+
1314
+ fu! s:gethistdata()
1315
+ retu ctrlp#utils#readfile(s:gethistloc()[1])
1316
+ endf
1317
+
1318
+ fu! ctrlp#recordhist()
1319
+ let str = join(s:prompt, '')
1320
+ if empty(str) || !s:maxhst | retu | en
1321
+ let hst = s:hstry
1322
+ if len(hst) > 1 && hst[1] == str | retu | en
1323
+ cal extend(hst, [str], 1)
1324
+ if len(hst) > s:maxhst | cal remove(hst, s:maxhst, -1) | en
1325
+ cal ctrlp#utils#writecache(hst, s:gethistloc()[0], s:gethistloc()[1])
1326
+ endf
1327
+ " Signs {{{2
1328
+ fu! s:unmarksigns()
1329
+ if !s:dosigns() | retu | en
1330
+ for key in keys(s:marked)
1331
+ exe 'sign unplace' key 'buffer='.s:bufnr
1332
+ endfo
1333
+ endf
1334
+
1335
+ fu! s:remarksigns()
1336
+ if !s:dosigns() | retu | en
1337
+ for ic in range(1, len(s:lines))
1338
+ let line = s:ispath ? fnamemodify(s:lines[ic - 1], ':p') : s:lines[ic - 1]
1339
+ let key = s:dictindex(s:marked, line)
1340
+ if key > 0
1341
+ exe 'sign place' key 'line='.ic.' name=ctrlpmark buffer='.s:bufnr
1342
+ en
1343
+ endfo
1344
+ endf
1345
+
1346
+ fu! s:dosigns()
1347
+ retu exists('s:marked') && s:bufnr > 0 && s:opmul != '0' && has('signs')
1348
+ endf
1349
+ " Lists & Dictionaries {{{2
1350
+ fu! s:dictindex(dict, expr)
1351
+ for key in keys(a:dict)
1352
+ if a:dict[key] == a:expr | retu key | en
1353
+ endfo
1354
+ retu -1
1355
+ endf
1356
+
1357
+ fu! s:vacantdict(dict)
1358
+ retu filter(range(1, max(keys(a:dict))), '!has_key(a:dict, v:val)')
1359
+ endf
1360
+
1361
+ fu! s:sublist(l, s, e)
1362
+ retu v:version > 701 ? a:l[(a:s):(a:e)] : s:sublist7071(a:l, a:s, a:e)
1363
+ endf
1364
+
1365
+ fu! s:sublist7071(l, s, e)
1366
+ let [newlist, id, ae] = [[], a:s, a:e == -1 ? len(a:l) - 1 : a:e]
1367
+ wh id <= ae
1368
+ cal add(newlist, get(a:l, id))
1369
+ let id += 1
1370
+ endw
1371
+ retu newlist
1372
+ endf
1373
+ " Buffers {{{2
1374
+ fu! s:buftab(bufnr, md)
1375
+ for tabnr in range(1, tabpagenr('$'))
1376
+ if tabpagenr() == tabnr && a:md == 't' | con | en
1377
+ let buflist = tabpagebuflist(tabnr)
1378
+ if index(buflist, a:bufnr) >= 0
1379
+ for winnr in range(1, tabpagewinnr(tabnr, '$'))
1380
+ if buflist[winnr - 1] == a:bufnr | retu [tabnr, winnr] | en
1381
+ endfo
1382
+ en
1383
+ endfo
1384
+ retu [0, 0]
1385
+ endf
1386
+
1387
+ fu! ctrlp#normcmd(cmd, ...)
1388
+ if s:nosplit() | retu a:cmd | en
1389
+ let norwins = filter(range(1, winnr('$')),
1390
+ \ 'empty(getbufvar(winbufnr(v:val), "&bt"))')
1391
+ for each in norwins
1392
+ let bufnr = winbufnr(each)
1393
+ if empty(bufname(bufnr)) && empty(getbufvar(bufnr, '&ft'))
1394
+ let fstemp = each | brea
1395
+ en
1396
+ endfo
1397
+ let norwin = empty(norwins) ? 0 : norwins[0]
1398
+ if norwin
1399
+ if index(norwins, winnr()) < 0
1400
+ exe ( exists('fstemp') ? fstemp : norwin ).'winc w'
1401
+ en
1402
+ retu a:cmd
1403
+ en
1404
+ retu a:0 ? a:1 : 'bo vne'
1405
+ endf
1406
+
1407
+ fu! s:nosplit()
1408
+ retu !empty(s:nosplit) && match([bufname('%'), &l:ft, &l:bt], s:nosplit) >= 0
1409
+ endf
1410
+
1411
+ fu! s:setupblank()
1412
+ setl noswf nobl nonu nowrap nolist nospell nocuc wfh
1413
+ setl fdc=0 fdl=99 tw=0 bt=nofile bh=unload
1414
+ if v:version > 702
1415
+ setl nornu noudf cc=0
1416
+ en
1417
+ endf
1418
+
1419
+ fu! s:leavepre()
1420
+ if exists('s:bufnr') && s:bufnr == bufnr('%') | bw! | en
1421
+ if s:clrex && !( has('clientserver') && len(split(serverlist(), "\n")) > 1 )
1422
+ cal ctrlp#clra()
1423
+ en
1424
+ endf
1425
+
1426
+ fu! s:checkbuf()
1427
+ if !exists('s:init') && exists('s:bufnr') && s:bufnr > 0
1428
+ exe s:bufnr.'bw!'
1429
+ en
1430
+ endf
1431
+ " Arguments {{{2
1432
+ fu! s:tail()
1433
+ if exists('s:optail') && !empty('s:optail')
1434
+ let tailpref = match(s:optail, '^\s*+') < 0 ? ' +' : ' '
1435
+ retu tailpref.s:optail
1436
+ en
1437
+ retu ''
1438
+ endf
1439
+
1440
+ fu! s:sanstail(str)
1441
+ let [str, pat] = [substitute(a:str, '\\\\', '\', 'g'), '\([^:]\|\\:\)*$']
1442
+ unl! s:optail
1443
+ if match(str, '\\\@<!:'.pat) >= 0
1444
+ let s:optail = matchstr(str, '\\\@<!:\zs'.pat)
1445
+ let str = substitute(str, '\\\@<!:'.pat, '', '')
1446
+ en
1447
+ retu substitute(str, '\\\ze:', '', 'g')
1448
+ endf
1449
+
1450
+ fu! s:argmaps(md, ...)
1451
+ let roh = a:0 ? ['/[r]eplace', 'r'] : ['/h[i]dden', 'i']
1452
+ let str = '[t]ab/[v]ertical/[h]orizontal'.roh[0].'? '
1453
+ let args = [a:md] + ( a:0 ? [a:1] : [] )
1454
+ retu s:choices(str, ['t', 'v', 'h', roh[1]], 's:argmaps', args)
1455
+ endf
1456
+
1457
+ fu! s:insertstr()
1458
+ let str = 'Insert: c[w]ord/c[f]ile/[s]earch/[v]isual/[c]lipboard? '
1459
+ retu s:choices(str, ['w', 'f', 's', 'v', 'c'], 's:insertstr', [])
1460
+ endf
1461
+
1462
+ fu! s:choices(str, choices, func, args)
1463
+ redr
1464
+ echoh MoreMsg
1465
+ echon a:str
1466
+ echoh None
1467
+ let char = nr2char(getchar())
1468
+ if index(a:choices, char) >= 0
1469
+ retu char
1470
+ elsei char =~# "\\v\<Esc>|\<C-c>|\<C-g>|\<C-u>|\<C-w>|\<C-[>"
1471
+ cal s:BuildPrompt(0)
1472
+ retu 'cancel'
1473
+ elsei char =~# "\<CR>" && a:args != []
1474
+ retu a:args[0]
1475
+ en
1476
+ retu call(a:func, a:args)
1477
+ endf
1478
+ " Misc {{{2
1479
+ fu! s:modevar()
1480
+ let s:matchtype = s:mtype()
1481
+ let s:ispath = s:ispathitem()
1482
+ if !s:ispath | let s:byfname = 0 | en
1483
+ let s:mfunc = s:mfunc()
1484
+ let s:nolim = s:getextvar('nolim')
1485
+ let s:dosort = s:getextvar('sort')
1486
+ endf
1487
+
1488
+ fu! s:nosort()
1489
+ retu s:matcher != {} || s:nolim == 1 || ( s:itemtype == 2 && s:mrudef )
1490
+ \ || ( s:itemtype =~ '\v^(1|2)$' && s:prompt == ['', '', ''] ) || !s:dosort
1491
+ endf
1492
+
1493
+ fu! s:narrowable()
1494
+ retu exists('s:act_add') && exists('s:matched') && s:matched != []
1495
+ \ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
1496
+ \ && s:matcher == {}
1497
+ endf
1498
+
1499
+ fu! s:migemo(str)
1500
+ let str = a:str
1501
+ let dict = s:glbpath(&rtp, printf("dict/%s/migemo-dict", &enc), 1)
1502
+ if !len(dict)
1503
+ let dict = s:glbpath(&rtp, "dict/migemo-dict", 1)
1504
+ en
1505
+ if len(dict)
1506
+ let [tokens, str, cmd] = [split(str, '\s'), '', 'cmigemo -v -w %s -d %s']
1507
+ for token in tokens
1508
+ let rtn = system(printf(cmd, shellescape(token), shellescape(dict)))
1509
+ let str .= !v:shell_error && strlen(rtn) > 0 ? '.*'.rtn : token
1510
+ endfo
1511
+ en
1512
+ retu str
1513
+ endf
1514
+
1515
+ fu! s:strwidth(str)
1516
+ retu exists('*strdisplaywidth') ? strdisplaywidth(a:str) : strlen(a:str)
1517
+ endf
1518
+
1519
+ fu! ctrlp#j2l(nr)
1520
+ exe a:nr
1521
+ sil! norm! zvzz
1522
+ endf
1523
+
1524
+ fu! s:maxf(len)
1525
+ retu s:maxfiles && a:len > s:maxfiles ? 1 : 0
1526
+ endf
1527
+
1528
+ fu! s:regexfilter(str)
1529
+ let str = a:str
1530
+ for key in keys(s:fpats) | if match(str, key) >= 0
1531
+ let str = substitute(str, s:fpats[key], '', 'g')
1532
+ en | endfo
1533
+ retu str
1534
+ endf
1535
+
1536
+ fu! s:walker(m, p, d)
1537
+ retu a:d > 0 ? a:p < a:m ? a:p + a:d : 0 : a:p > 0 ? a:p + a:d : a:m
1538
+ endf
1539
+
1540
+ fu! s:delent(rfunc)
1541
+ if a:rfunc == '' | retu | en
1542
+ let [s:force, tbrem] = [1, []]
1543
+ if exists('s:marked')
1544
+ let tbrem = values(s:marked)
1545
+ cal s:unmarksigns()
1546
+ unl s:marked
1547
+ en
1548
+ if tbrem == [] && ( has('dialog_gui') || has('dialog_con') ) &&
1549
+ \ confirm("Wipe all entries?", "&OK\n&Cancel") != 1
1550
+ unl s:force
1551
+ cal s:BuildPrompt(0)
1552
+ retu
1553
+ en
1554
+ let g:ctrlp_lines = call(a:rfunc, [tbrem])
1555
+ cal s:BuildPrompt(1)
1556
+ unl s:force
1557
+ endf
1558
+ " Entering & Exiting {{{2
1559
+ fu! s:getenv()
1560
+ let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
1561
+ let [s:crfile, s:crfpath] = [expand('%:p', 1), expand('%:p:h', 1)]
1562
+ let [s:crword, s:crline] = [expand('<cword>', 1), getline('.')]
1563
+ let [s:winh, s:crcursor] = [min([s:mxheight, &lines]), getpos('.')]
1564
+ let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
1565
+ let s:wpmode = exists('b:ctrlp_working_path_mode')
1566
+ \ ? b:ctrlp_working_path_mode : s:pathmode
1567
+ let [s:mrbs, s:crgfile] = [ctrlp#mrufiles#bufs(), expand('<cfile>', 1)]
1568
+ endf
1569
+
1570
+ fu! s:lastvisual()
1571
+ let cview = winsaveview()
1572
+ let [ovreg, ovtype] = [getreg('v'), getregtype('v')]
1573
+ let [oureg, outype] = [getreg('"'), getregtype('"')]
1574
+ sil! norm! gv"vy
1575
+ let selected = substitute(getreg('v'), '\n', '\\n', 'g')
1576
+ cal setreg('v', ovreg, ovtype)
1577
+ cal setreg('"', oureg, outype)
1578
+ cal winrestview(cview)
1579
+ retu selected
1580
+ endf
1581
+
1582
+ fu! s:log(m)
1583
+ if exists('g:ctrlp_log') && g:ctrlp_log | if a:m
1584
+ let cadir = ctrlp#utils#cachedir()
1585
+ sil! exe 'redi! >' cadir.s:lash(cadir).'ctrlp.log'
1586
+ el
1587
+ sil! redi END
1588
+ en | en
1589
+ endf
1590
+
1591
+ fu! s:buffunc(e)
1592
+ if a:e && has_key(s:buffunc, 'enter')
1593
+ cal call(s:buffunc['enter'], [])
1594
+ elsei !a:e && has_key(s:buffunc, 'exit')
1595
+ cal call(s:buffunc['exit'], [])
1596
+ en
1597
+ endf
1598
+
1599
+ fu! s:openfile(cmd, fid, tail, ...)
1600
+ let cmd = a:cmd =~ '^[eb]$' && &modified ? 'hid '.a:cmd : a:cmd
1601
+ let cmd = cmd =~ '^tab' ? tabpagenr('$').cmd : cmd
1602
+ let j2l = a:0 && a:1 ? a:2 : 0
1603
+ exe cmd.( a:0 && a:1 ? '' : a:tail ) ctrlp#fnesc(a:fid)
1604
+ if j2l
1605
+ exe j2l
1606
+ en
1607
+ if !empty(a:tail) || j2l
1608
+ sil! norm! zvzz
1609
+ en
1610
+ if cmd != 'bad'
1611
+ cal ctrlp#setlcdir()
1612
+ en
1613
+ endf
1614
+
1615
+ fu! s:settype(type)
1616
+ retu a:type < 0 ? exists('s:itemtype') ? s:itemtype : 0 : a:type
1617
+ endf
1618
+ " Matching {{{2
1619
+ fu! s:matchfname(item, pat)
1620
+ retu match(split(a:item, s:lash)[-1], a:pat)
1621
+ endf
1622
+
1623
+ fu! s:matchtabs(item, pat)
1624
+ retu match(split(a:item, '\t\+')[0], a:pat)
1625
+ endf
1626
+
1627
+ fu! s:matchtabe(item, pat)
1628
+ retu match(split(a:item, '\t\+[^\t]\+$')[0], a:pat)
1629
+ endf
1630
+
1631
+ fu! s:mfunc()
1632
+ let mfunc = 'match'
1633
+ if s:byfname && s:ispath
1634
+ let mfunc = 's:matchfname'
1635
+ elsei s:itemtype > 2
1636
+ let matchtypes = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
1637
+ if has_key(matchtypes, s:matchtype)
1638
+ let mfunc = matchtypes[s:matchtype]
1639
+ en
1640
+ en
1641
+ retu mfunc
1642
+ endf
1643
+
1644
+ fu! s:mmode()
1645
+ let matchmodes = {
1646
+ \ 'match': 'full-line',
1647
+ \ 's:matchfname': 'filename-only',
1648
+ \ 's:matchtabs': 'first-non-tab',
1649
+ \ 's:matchtabe': 'until-last-tab',
1650
+ \ }
1651
+ retu matchmodes[s:mfunc]
1652
+ endf
1653
+ " Cache {{{2
1654
+ fu! s:writecache(cache_file)
1655
+ let fwrite = len(g:ctrlp_allfiles) > s:nocache_lim
1656
+ if ( g:ctrlp_newcache || !filereadable(a:cache_file) ) && s:caching || fwrite
1657
+ if fwrite | let s:caching = 1 | en
1658
+ cal ctrlp#utils#writecache(g:ctrlp_allfiles)
1659
+ let g:ctrlp_newcache = 0
1660
+ en
1661
+ endf
1662
+
1663
+ fu! s:insertcache(str)
1664
+ let [data, g:ctrlp_newcache, str] = [g:ctrlp_allfiles, 1, a:str]
1665
+ if strlen(str) <= strlen(data[0])
1666
+ let pos = 0
1667
+ elsei strlen(str) >= strlen(data[-1])
1668
+ let pos = len(data) - 1
1669
+ el
1670
+ let pos = 0
1671
+ for each in data
1672
+ if strlen(each) > strlen(str) | brea | en
1673
+ let pos += 1
1674
+ endfo
1675
+ en
1676
+ cal insert(data, str, pos)
1677
+ cal s:writecache(ctrlp#utils#cachefile())
1678
+ endf
1679
+ " Extensions {{{2
1680
+ fu! s:mtype()
1681
+ retu s:itemtype > 2 ? s:getextvar('type') : 'path'
1682
+ endf
1683
+
1684
+ fu! s:execextvar(key)
1685
+ if !empty(g:ctrlp_ext_vars)
1686
+ cal map(filter(copy(g:ctrlp_ext_vars),
1687
+ \ 'has_key(v:val, a:key)'), 'eval(v:val[a:key])')
1688
+ en
1689
+ endf
1690
+
1691
+ fu! s:getextvar(key)
1692
+ if s:itemtype > 2
1693
+ let vars = g:ctrlp_ext_vars[s:itemtype - 3]
1694
+ retu has_key(vars, a:key) ? vars[a:key] : -1
1695
+ en
1696
+ retu -1
1697
+ endf
1698
+
1699
+ fu! ctrlp#exit()
1700
+ cal s:PrtExit()
1701
+ endf
1702
+
1703
+ fu! ctrlp#prtclear()
1704
+ cal s:PrtClear()
1705
+ endf
1706
+
1707
+ fu! ctrlp#switchtype(id)
1708
+ cal s:ToggleType(a:id - s:itemtype)
1709
+ endf
1710
+
1711
+ fu! ctrlp#nosy()
1712
+ retu !( has('syntax') && exists('g:syntax_on') )
1713
+ endf
1714
+
1715
+ fu! ctrlp#hicheck(grp, defgrp)
1716
+ if !hlexists(a:grp)
1717
+ exe 'hi link' a:grp a:defgrp
1718
+ en
1719
+ endf
1720
+
1721
+ fu! ctrlp#call(func, ...)
1722
+ cal call(a:func, a:000)
1723
+ endf
1724
+ "}}}1
1725
+ " * Initialization {{{1
1726
+ fu! ctrlp#setlines(...)
1727
+ if a:0 | let s:itemtype = a:1 | en
1728
+ cal s:modevar()
1729
+ let types = ['ctrlp#files()', 'ctrlp#buffers()', 'ctrlp#mrufiles#list()']
1730
+ if !empty(g:ctrlp_ext_vars)
1731
+ cal map(copy(g:ctrlp_ext_vars), 'add(types, v:val["init"])')
1732
+ en
1733
+ let g:ctrlp_lines = eval(types[s:itemtype])
1734
+ endf
1735
+
1736
+ fu! ctrlp#init(type, ...)
1737
+ if exists('s:init') | retu | en
1738
+ let [s:matches, s:init] = [1, 1]
1739
+ cal ctrlp#reset()
1740
+ cal s:Open()
1741
+ cal s:SetWD(a:0 ? a:1 : '')
1742
+ cal s:MapKeys()
1743
+ cal ctrlp#syntax()
1744
+ cal ctrlp#setlines(s:settype(a:type))
1745
+ cal s:SetDefTxt()
1746
+ cal s:BuildPrompt(1)
1747
+ endf
1748
+ " - Autocmds {{{1
1749
+ if has('autocmd')
1750
+ aug CtrlPAug
1751
+ au!
1752
+ au BufEnter ControlP cal s:checkbuf()
1753
+ au BufLeave ControlP cal s:Close()
1754
+ au VimLeavePre * cal s:leavepre()
1755
+ aug END
1756
+ en
1757
+
1758
+ fu! s:autocmds()
1759
+ if !has('autocmd') | retu | en
1760
+ if exists('#CtrlPLazy')
1761
+ au! CtrlPLazy
1762
+ en
1763
+ if s:lazy
1764
+ aug CtrlPLazy
1765
+ au!
1766
+ au CursorHold ControlP cal s:ForceUpdate()
1767
+ aug END
1768
+ en
1769
+ endf
1770
+ "}}}
1771
+
1772
+ " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2