forked from kien/ctrlp.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathctrlp.vim
More file actions
2337 lines (2183 loc) · 62.8 KB
/
Copy pathctrlp.vim
File metadata and controls
2337 lines (2183 loc) · 62.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" =============================================================================
" File: autoload/ctrlp.vim
" Description: Fuzzy file, buffer, mru, tag, etc finder.
" Author: Kien Nguyen <github.com/kien>
" Version: 1.79
" =============================================================================
" ** Static variables {{{1
" s:ignore() {{{2
fu! s:ignore()
let igdirs = [
\ '\.git',
\ '\.hg',
\ '\.svn',
\ '_darcs',
\ '\.bzr',
\ '\.cdv',
\ '\~\.dep',
\ '\~\.dot',
\ '\~\.nib',
\ '\~\.plst',
\ '\.pc',
\ '_MTN',
\ 'blib',
\ 'CVS',
\ 'RCS',
\ 'SCCS',
\ '_sgbak',
\ 'autom4te\.cache',
\ 'cover_db',
\ '_build',
\ ]
let igfiles = [
\ '\~$',
\ '#.+#$',
\ '[._].*\.swp$',
\ 'core\.\d+$',
\ '\.exe$',
\ '\.so$',
\ '\.bak$',
\ '\.png$',
\ '\.jpg$',
\ '\.gif$',
\ '\.zip$',
\ '\.rar$',
\ '\.tar\.gz$',
\ ]
retu {
\ 'dir': '\v[\/]('.join(igdirs, '|').')$',
\ 'file': '\v'.join(igfiles, '|'),
\ }
endf
" Script local vars {{{2
let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] =
\ ['g:ctrlp_', 'b:ctrlp_', {
\ 'abbrev': ['s:abbrev', {}],
\ 'arg_map': ['s:argmap', 0],
\ 'buffer_func': ['s:buffunc', {}],
\ 'by_filename': ['s:byfname', 0],
\ 'custom_ignore': ['s:usrign', s:ignore()],
\ 'default_input': ['s:deftxt', 0],
\ 'dont_split': ['s:nosplit', 'netrw'],
\ 'dotfiles': ['s:showhidden', 0],
\ 'extensions': ['s:extensions', []],
\ 'follow_symlinks': ['s:folsym', 0],
\ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
\ 'jump_to_buffer': ['s:jmptobuf', 'Et'],
\ 'key_loop': ['s:keyloop', 0],
\ 'lazy_update': ['s:lazy', 0],
\ 'match_func': ['s:matcher', {}],
\ 'match_window': ['s:mw', ''],
\ 'match_window_bottom': ['s:mwbottom', 1],
\ 'match_window_reversed': ['s:mwreverse', 1],
\ 'max_depth': ['s:maxdepth', 40],
\ 'max_files': ['s:maxfiles', 10000],
\ 'max_height': ['s:mxheight', 10],
\ 'max_history': ['s:maxhst', exists('+hi') ? &hi : 20],
\ 'mruf_default_order': ['s:mrudef', 0],
\ 'open_func': ['s:openfunc', {}],
\ 'open_multi': ['s:opmul', '1v'],
\ 'open_new_file': ['s:newfop', 'v'],
\ 'prompt_mappings': ['s:urprtmaps', 0],
\ 'regexp_search': ['s:regexp', 0],
\ 'root_markers': ['s:rmarkers', []],
\ 'split_window': ['s:splitwin', 0],
\ 'status_func': ['s:status', {}],
\ 'tabpage_position': ['s:tabpage', 'ac'],
\ 'use_caching': ['s:caching', 1],
\ 'use_migemo': ['s:migemo', 0],
\ 'user_command': ['s:usrcmd', ''],
\ 'working_path_mode': ['s:pathmode', 'ra'],
\ }, {
\ 'open_multiple_files': 's:opmul',
\ 'regexp': 's:regexp',
\ 'reuse_window': 's:nosplit',
\ 'show_hidden': 's:showhidden',
\ 'switch_buffer': 's:jmptobuf',
\ }, {
\ 'root_markers': 's:rmarkers',
\ 'user_command': 's:usrcmd',
\ 'working_path_mode': 's:pathmode',
\ }]
" Global options
let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
\ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'ttimeout': 0,
\ 'gcr': 'a:blinkon0', 'ic': 1, 'lmap': '', 'mousef': 0, 'imd': 1 }
" Keymaps
let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
\ 'PrtBS()': ['<bs>', '<c-]>'],
\ 'PrtDelete()': ['<del>'],
\ 'PrtDeleteWord()': ['<c-w>'],
\ 'PrtClear()': ['<c-u>'],
\ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
\ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
\ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
\ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
\ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
\ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
\ 'PrtHistory(-1)': ['<c-n>'],
\ 'PrtHistory(1)': ['<c-p>'],
\ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
\ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
\ 'AcceptSelection("t")': ['<c-t>'],
\ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
\ 'ToggleFocus()': ['<s-tab>'],
\ 'ToggleRegex()': ['<c-r>'],
\ 'ToggleByFname()': ['<c-d>'],
\ 'ToggleType(1)': ['<c-f>', '<c-up>'],
\ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
\ 'PrtExpandDir()': ['<tab>'],
\ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>'],
\ 'PrtInsert()': ['<c-\>'],
\ 'PrtCurStart()': ['<c-a>'],
\ 'PrtCurEnd()': ['<c-e>'],
\ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
\ 'PrtCurRight()': ['<c-l>', '<right>'],
\ 'PrtClearCache()': ['<F5>'],
\ 'PrtDeleteEnt()': ['<F7>'],
\ 'CreateNewFile()': ['<c-y>'],
\ 'MarkToOpen()': ['<c-z>'],
\ 'OpenMulti()': ['<c-o>'],
\ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
\ 'PrtNoop()': ['<c-/>'],
\ }]
let s:scriptpath = expand('<sfile>:p:h')
let s:pymatcher = 0
if has('autocmd') && has('python')
py import sys
exe 'python sys.path.insert( 0, "' . escape(s:scriptpath, '\') . '/../python" )'
py from ctrlp.matcher import CtrlPMatcher
py ctrlp = CtrlPMatcher()
let s:pymatcher = 1
en
if !has('gui_running')
cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
en
let s:compare_lim = 3000
let s:ficounts = {}
let s:ccex = s:pref.'clear_cache_on_exit'
" Regexp
let s:fpats = {
\ '^\(\\|\)\|\(\\|\)$': '\\|',
\ '^\\\(zs\|ze\|<\|>\)': '^\\\(zs\|ze\|<\|>\)',
\ '^\S\*$': '\*',
\ '^\S\\?$': '\\?',
\ }
" Keypad
let s:kprange = {
\ 'Plus': '+',
\ 'Minus': '-',
\ 'Divide': '/',
\ 'Multiply': '*',
\ 'Point': '.',
\ }
" Highlight groups
let s:hlgrps = {
\ 'NoEntries': 'Error',
\ 'Mode1': 'Character',
\ 'Mode2': 'LineNr',
\ 'Stats': 'Function',
\ 'Match': 'Identifier',
\ 'PrtBase': 'Comment',
\ 'PrtText': 'Normal',
\ 'PrtCursor': 'Constant',
\ }
" Get the options {{{2
fu! s:opts(...)
unl! s:usrign s:usrcmd s:urprtmaps
for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each)
let {each} = s:{each}
en | endfo
for [ke, va] in items(s:opts)
let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1]
endfo
unl va
for [ke, va] in items(s:new_opts)
let {va} = {exists(s:pref.ke) ? s:pref.ke : va}
endfo
unl va
for [ke, va] in items(s:lc_opts)
if exists(s:bpref.ke)
unl {va}
let {va} = {s:bpref.ke}
en
endfo
" Match window options
cal s:match_window_opts()
" One-time values
if a:0 && a:1 != {}
unl va
for [ke, va] in items(a:1)
let opke = substitute(ke, '\(\w:\)\?ctrlp_', '', '')
if has_key(s:lc_opts, opke)
let sva = s:lc_opts[opke]
unl {sva}
let {sva} = va
en
endfo
en
for each in ['byfname', 'regexp'] | if exists(each)
let s:{each} = {each}
en | endfo
if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
let s:maxdepth = min([s:maxdepth, 100])
let s:glob = s:showhidden ? '.*\|*' : '*'
let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
let s:lash = ctrlp#utils#lash()
if s:keyloop
let [s:lazy, s:glbs['imd']] = [0, 0]
en
if s:lazy
cal extend(s:glbs, { 'ut': ( s:lazy > 1 ? s:lazy : 250 ) })
en
" Extensions
if !( exists('extensions') && extensions == s:extensions )
for each in s:extensions
exe 'ru autoload/ctrlp/'.each.'.vim'
endfo
en
" Keymaps
if type(s:urprtmaps) == 4
cal extend(s:prtmaps, s:urprtmaps)
en
endf
fu! s:match_window_opts()
let s:mw_pos =
\ s:mw =~ 'top\|bottom' ? matchstr(s:mw, 'top\|bottom') :
\ exists('g:ctrlp_match_window_bottom') ? ( s:mwbottom ? 'bottom' : 'top' )
\ : 'bottom'
let s:mw_order =
\ s:mw =~ 'order:[^,]\+' ? matchstr(s:mw, 'order:\zs[^,]\+') :
\ exists('g:ctrlp_match_window_reversed') ? ( s:mwreverse ? 'btt' : 'ttb' )
\ : 'btt'
let s:mw_max =
\ s:mw =~ 'max:[^,]\+' ? str2nr(matchstr(s:mw, 'max:\zs\d\+')) :
\ exists('g:ctrlp_max_height') ? s:mxheight
\ : 10
let s:mw_min =
\ s:mw =~ 'min:[^,]\+' ? str2nr(matchstr(s:mw, 'min:\zs\d\+')) : 1
let [s:mw_max, s:mw_min] = [max([s:mw_max, 1]), max([s:mw_min, 1])]
let s:mw_min = min([s:mw_min, s:mw_max])
let s:mw_res =
\ s:mw =~ 'results:[^,]\+' ? str2nr(matchstr(s:mw, 'results:\zs\d\+'))
\ : min([s:mw_max, &lines])
let s:mw_res = max([s:mw_res, 1])
endf
"}}}1
" * Open & Close {{{1
fu! s:Open()
cal s:log(1)
cal s:getenv()
cal s:execextvar('enter')
sil! exe 'keepa' ( s:mw_pos == 'top' ? 'to' : 'bo' ) '1new ControlP'
cal s:buffunc(1)
let [s:bufnr, s:winw] = [bufnr('%'), winwidth(0)]
let [s:focus, s:prompt] = [1, ['', '', '']]
abc <buffer>
if !exists('s:hstry')
let hst = filereadable(s:gethistloc()[1]) ? s:gethistdata() : ['']
let s:hstry = empty(hst) || !s:maxhst ? [''] : hst
en
for [ke, va] in items(s:glbs) | if exists('+'.ke)
sil! exe 'let s:glb_'.ke.' = &'.ke.' | let &'.ke.' = '.string(va)
en | endfo
if s:opmul != '0' && has('signs')
sign define ctrlpmark text=+> texthl=Search
en
cal s:setupblank()
endf
fu! s:Close()
cal s:buffunc(0)
if winnr('$') == 1
bw!
el
try | bun!
cat | clo! | endt
cal s:unmarksigns()
en
for key in keys(s:glbs) | if exists('+'.key)
sil! exe 'let &'.key.' = s:glb_'.key
en | endfo
if exists('s:glb_acd') | let &acd = s:glb_acd | en
let g:ctrlp_lines = []
if s:winres[1] >= &lines && s:winres[2] == winnr('$')
exe s:winres[0].s:winres[0]
en
unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:cline s:init s:savestr
\ s:mrbs s:did_exp
cal ctrlp#recordhist()
cal s:execextvar('exit')
cal s:log(0)
let v:errmsg = s:ermsg
ec
endf
" * Clear caches {{{1
fu! ctrlp#clr(...)
let [s:matches, g:ctrlp_new{ a:0 ? a:1 : 'cache' }] = [1, 1]
endf
fu! ctrlp#clra()
let cadir = ctrlp#utils#cachedir()
if isdirectory(cadir)
let cafiles = split(s:glbpath(s:fnesc(cadir, 'g', ','), '**', 1), "\n")
let eval = '!isdirectory(v:val) && v:val !~ ''\v[\/]cache[.a-z]+$|\.log$'''
sil! cal map(s:ifilter(cafiles, eval), 'delete(v:val)')
en
cal ctrlp#clr()
endf
fu! s:Reset(args)
let opts = has_key(a:args, 'opts') ? [a:args['opts']] : []
cal call('s:opts', opts)
cal s:autocmds()
cal ctrlp#utils#opts()
cal s:execextvar('opts')
endf
" * Files {{{1
fu! ctrlp#files()
let cafile = ctrlp#utils#cachefile()
if g:ctrlp_newcache || !filereadable(cafile) || s:nocache(cafile)
let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
" Get the list of files
if empty(lscmd)
if !ctrlp#igncwd(s:dyncwd)
cal s:GlobPath(s:fnesc(s:dyncwd, 'g', ','), 0)
en
el
sil! cal ctrlp#progress('Indexing...')
try | cal s:UserCmd(lscmd)
cat | retu [] | endt
en
" Remove base directory
cal ctrlp#rmbasedir(g:ctrlp_allfiles)
if len(g:ctrlp_allfiles) <= s:compare_lim
cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
en
cal s:writecache(cafile)
let catime = getftime(cafile)
el
let catime = getftime(cafile)
if !( exists('s:initcwd') && s:initcwd == s:dyncwd )
\ || get(s:ficounts, s:dyncwd, [0, catime])[1] != catime
let s:initcwd = s:dyncwd
let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
en
en
cal extend(s:ficounts, { s:dyncwd : [len(g:ctrlp_allfiles), catime] })
retu g:ctrlp_allfiles
endf
fu! s:GlobPath(dirs, depth)
let entries = split(globpath(a:dirs, s:glob), "\n")
let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1]
cal extend(g:ctrlp_allfiles, dnf[1])
if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
sil! cal ctrlp#progress(len(g:ctrlp_allfiles), 1)
cal s:GlobPath(join(map(dnf[0], 's:fnesc(v:val, "g", ",")'), ','), depth)
en
endf
fu! s:UserCmd(lscmd)
let [path, lscmd] = [s:dyncwd, a:lscmd]
let do_ign =
\ type(s:usrcmd) == 4 && has_key(s:usrcmd, 'ignore') && s:usrcmd['ignore']
if do_ign && ctrlp#igncwd(s:cwd) | retu | en
if exists('+ssl') && &ssl
let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')]
en
if has('win32') || has('win64')
let lscmd = substitute(lscmd, '\v(^|\&\&\s*)\zscd (/d)@!', 'cd /d ', '')
en
let path = exists('*shellescape') ? shellescape(path) : path
let g:ctrlp_allfiles = split(system(printf(lscmd, path)), "\n")
if exists('+ssl') && exists('ssl')
let &ssl = ssl
cal map(g:ctrlp_allfiles, 'tr(v:val, "\\", "/")')
en
if exists('s:vcscmd') && s:vcscmd
cal map(g:ctrlp_allfiles, 'tr(v:val, "/", "\\")')
en
if do_ign
if !empty(s:usrign)
let g:ctrlp_allfiles = ctrlp#dirnfile(g:ctrlp_allfiles)[1]
en
if &wig != ''
cal filter(g:ctrlp_allfiles, 'glob(v:val) != ""')
en
en
endf
fu! s:lsCmd()
let cmd = s:usrcmd
if type(cmd) == 1
retu cmd
elsei type(cmd) == 3 && len(cmd) >= 2 && cmd[:1] != ['', '']
if s:findroot(s:dyncwd, cmd[0], 0, 1) == []
retu len(cmd) == 3 ? cmd[2] : ''
en
let s:vcscmd = s:lash == '\'
retu cmd[1]
elsei type(cmd) == 4 && ( has_key(cmd, 'types') || has_key(cmd, 'fallback') )
let fndroot = []
if has_key(cmd, 'types') && cmd['types'] != {}
let [markrs, cmdtypes] = [[], values(cmd['types'])]
for pair in cmdtypes
cal add(markrs, pair[0])
endfo
let fndroot = s:findroot(s:dyncwd, markrs, 0, 1)
en
if fndroot == []
retu has_key(cmd, 'fallback') ? cmd['fallback'] : ''
en
for pair in cmdtypes
if pair[0] == fndroot[0] | brea | en
endfo
let s:vcscmd = s:lash == '\'
retu pair[1]
en
endf
" - Buffers {{{1
fu! ctrlp#buffers(...)
let ids = sort(filter(range(1, bufnr('$')), 'empty(getbufvar(v:val, "&bt"))'
\ .' && getbufvar(v:val, "&bl")'), 's:compmreb')
if a:0 && a:1 == 'id'
retu ids
el
let bufs = [[], []]
for id in ids
let bname = bufname(id)
let ebname = bname == ''
let fname = fnamemodify(ebname ? '['.id.'*No Name]' : bname, ':.')
cal add(bufs[ebname], fname)
endfo
retu bufs[0] + bufs[1]
en
endf
" * MatchedItems() {{{1
fu! s:MatchIt(items, pat, limit, exc)
let [lines, id] = [[], 0]
let pat =
\ s:byfname() ? map(split(a:pat, '^[^;]\+\\\@<!\zs;', 1), 's:martcs.v:val')
\ : s:martcs.a:pat
for item in a:items
let id += 1
try | if !( s:ispath && item == a:exc ) && call(s:mfunc, [item, pat]) >= 0
cal add(lines, item)
en | cat | brea | endt
if a:limit > 0 && len(lines) >= a:limit | brea | en
endfo
cal ctrlp#process(lines, a:pat, 0, s:sublist(a:items, id, -1))
endf
fu! s:MatchedItems(items, pat, limit)
let exc = exists('s:crfilerel') ? s:crfilerel : ''
let items = s:narrowable() ? s:matched + s:mdata[3] : a:items
if s:matcher != {}
let argms =
\ has_key(s:matcher, 'arg_type') && s:matcher['arg_type'] == 'dict' ? [{
\ 'items': items,
\ 'str': a:pat,
\ 'limit': a:limit,
\ 'mmode': s:mmode(),
\ 'ispath': s:ispath,
\ 'crfile': exc,
\ 'regex': s:regexp,
\ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp]
call(s:matcher['match'], argms, s:matcher)
elsei s:pymatcher && s:lazy > 1
py <<EOPYTHON
ctrlp.filter(vim.bindeval('items'), vim.bindeval('a:pat'),
vim.bindeval('a:limit'), vim.bindeval('s:mmode()'),
vim.bindeval('s:ispath'), vim.bindeval('exc'),
vim.bindeval('s:regexp'))
EOPYTHON
el
cal s:MatchIt(items, a:pat, a:limit, exc)
en
endf
fu! s:SplitPattern(str)
let str = a:str
if s:migemo && s:regexp && len(str) > 0 && executable('cmigemo')
let str = s:migemo(str)
en
let s:savestr = str
if s:regexp
let pat = s:regexfilter(str)
el
let lst = split(str, '\zs')
if exists('+ssl') && !&ssl
cal map(lst, 'escape(v:val, ''\'')')
en
for each in ['^', '$', '.']
cal map(lst, 'escape(v:val, each)')
endfo
en
if exists('lst')
let pat = ''
if !empty(lst)
if s:byfname() && index(lst, ';') > 0
let fbar = index(lst, ';')
let lst_1 = s:sublist(lst, 0, fbar - 1)
let lst_2 = len(lst) - 1 > fbar ? s:sublist(lst, fbar + 1, -1) : ['']
let pat = s:buildpat(lst_1).';'.s:buildpat(lst_2)
el
let pat = s:buildpat(lst)
en
en
en
retu escape(pat, '~')
endf
" * BuildPrompt() {{{1
fu! s:Render(lines, pat)
let [&ma, lines, s:res_count] = [1, a:lines, len(a:lines)]
let height = min([max([s:mw_min, s:res_count]), s:winmaxh])
let pat = s:byfname() ? split(a:pat, '^[^;]\+\\\@<!\zs;', 1)[0] : a:pat
let cur_cmd = 'keepj norm! '.( s:mw_order == 'btt' ? 'G' : 'gg' ).'1|'
" Setup the match window
sil! exe '%d _ | res' height
" Print the new items
if empty(lines)
let [s:matched, s:lines] = [[], []]
let lines = [' == NO ENTRIES ==']
cal setline(1, s:offset(lines, height - 1))
setl noma nocul
exe cur_cmd
cal s:unmarksigns()
if s:dohighlight() | cal clearmatches() | en
retu
en
let s:matched = copy(lines)
" Sorting
if !s:nosort()
let s:compat = s:martcs.pat
cal sort(lines, 's:mixedsort')
unl s:compat
en
if s:mw_order == 'btt' | cal reverse(lines) | en
let s:lines = copy(lines)
cal map(lines, 's:formatline(v:val)')
cal setline(1, s:offset(lines, height))
setl noma cul
exe cur_cmd
cal s:unmarksigns()
cal s:remarksigns()
if exists('s:cline') && s:nolim != 1
cal cursor(s:cline, 1)
en
" Highlighting
if s:dohighlight()
cal s:highlight(pat, s:mathi[1])
en
endf
fu! s:Update(str)
" Get the previous string if existed
let oldstr = exists('s:savestr') ? s:savestr : ''
" Get the new string sans tail
let str = s:sanstail(a:str)
" Stop if the string's unchanged
if str == oldstr && !empty(str) && !exists('s:force')
\ && (!has_key(s:matcher, 'force_update') || s:matcher['force_update'] == 1)
\ && (!s:pymatcher || s:lazy < 2)
retu
en
let s:martcs = &scs && str =~ '\u' ? '\C' : ''
let pat = str
if s:matcher == {} && (!s:pymatcher || s:lazy < 2)
let pat = s:SplitPattern(str)
en
if s:nolim == 1 && empty(str)
cal s:Render(copy(g:ctrlp_lines), pat)
else
cal s:MatchedItems(g:ctrlp_lines, pat, s:mw_res)
endf
fu! s:ForceUpdate()
sil! cal s:Update(escape(s:getinput(), '\'))
endf
fu! s:BuildPrompt(upd)
let base = ( s:regexp ? 'r' : '>' ).( s:byfname() ? 'd' : '>' ).'> '
let str = escape(s:getinput(), '\')
let lazy = str == '' || exists('s:force') || !has('autocmd') ? 0 : s:lazy
if a:upd && !lazy && ( s:matches || s:regexp || exists('s:did_exp')
\ || str =~ '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)' )
sil! cal s:Update(str)
en
sil! cal ctrlp#statusline()
" Toggling
let [hiactive, hicursor, base] = s:focus
\ ? ['CtrlPPrtText', 'CtrlPPrtCursor', base]
\ : ['CtrlPPrtBase', 'CtrlPPrtBase', tr(base, '>', '-')]
let hibase = 'CtrlPPrtBase'
" Build it
redr
let prt = copy(s:prompt)
cal map(prt, 'escape(v:val, ''"\'')')
exe 'echoh' hibase '| echon "'.base.'"
\ | echoh' hiactive '| echon "'.prt[0].'"
\ | echoh' hicursor '| echon "'.prt[1].'"
\ | echoh' hiactive '| echon "'.prt[2].'" | echoh None'
" Append the cursor at the end
if empty(prt[1]) && s:focus
exe 'echoh' hibase '| echon "_" | echoh None'
en
endf
" - SetDefTxt() {{{1
fu! s:SetDefTxt()
if s:deftxt == '0' || ( s:deftxt == 1 && !s:ispath ) | retu | en
let txt = s:deftxt
if !type(txt)
let path = s:crfpath.s:lash(s:crfpath)
let txt = txt && !stridx(path, s:dyncwd) ? ctrlp#rmbasedir([path])[0] : ''
en
let s:prompt[0] = txt
endf
" ** Prt Actions {{{1
" Editing {{{2
fu! s:PrtClear()
if !s:focus | retu | en
unl! s:hstgot
let [s:prompt, s:matches] = [['', '', ''], 1]
cal s:BuildPrompt(1)
endf
fu! s:PrtAdd(char)
unl! s:hstgot
let s:act_add = 1
let s:prompt[0] .= a:char
cal s:BuildPrompt(1)
unl s:act_add
endf
fu! s:PrtBS()
if !s:focus | retu | en
unl! s:hstgot
let [s:prompt[0], s:matches] = [substitute(s:prompt[0], '.$', '', ''), 1]
cal s:BuildPrompt(1)
endf
fu! s:PrtDelete()
if !s:focus | retu | en
unl! s:hstgot
let [prt, s:matches] = [s:prompt, 1]
let prt[1] = matchstr(prt[2], '^.')
let prt[2] = substitute(prt[2], '^.', '', '')
cal s:BuildPrompt(1)
endf
fu! s:PrtDeleteWord()
if !s:focus | retu | en
unl! s:hstgot
let [str, s:matches] = [s:prompt[0], 1]
let str = str =~ '\W\w\+$' ? matchstr(str, '^.\+\W\ze\w\+$')
\ : str =~ '\w\W\+$' ? matchstr(str, '^.\+\w\ze\W\+$')
\ : str =~ '\s\+$' ? matchstr(str, '^.*\S\ze\s\+$')
\ : str =~ '\v^(\S+|\s+)$' ? '' : str
let s:prompt[0] = str
cal s:BuildPrompt(1)
endf
fu! s:PrtInsert(...)
if !s:focus | retu | en
let type = !a:0 ? '' : a:1
if !a:0
let type = s:insertstr()
if type == 'cancel' | retu | en
en
if type ==# 'r'
let regcont = s:getregs()
if regcont < 0 | retu | en
en
unl! s:hstgot
let s:act_add = 1
let s:prompt[0] .= type ==# 'w' ? s:crword
\ : type ==# 'f' ? s:crgfile
\ : type ==# 's' ? s:regisfilter('/')
\ : type ==# 'v' ? s:crvisual
\ : type ==# 'c' ? s:regisfilter('+')
\ : type ==# 'r' ? regcont : ''
cal s:BuildPrompt(1)
unl s:act_add
endf
fu! s:PrtExpandDir()
if !s:focus | retu | en
let str = s:getinput('c')
if str =~ '\v^\@(cd|lc[hd]?|chd)\s.+' && s:spi
let hasat = split(str, '\v^\@(cd|lc[hd]?|chd)\s*\zs')
let str = get(hasat, 1, '')
if str =~# '\v^[~$]\i{-}[\/]?|^#(\<?\d+)?:(p|h|8|\~|\.|g?s+)'
let str = expand(s:fnesc(str, 'g'))
elsei str =~# '\v^(\%|\<c\h{4}\>):(p|h|8|\~|\.|g?s+)'
let spc = str =~# '^%' ? s:crfile
\ : str =~# '^<cfile>' ? s:crgfile
\ : str =~# '^<cword>' ? s:crword
\ : str =~# '^<cWORD>' ? s:crnbword : ''
let pat = '(:(p|h|8|\~|\.|g?s(.)[^\3]*\3[^\3]*\3))+'
let mdr = matchstr(str, '\v^[^:]+\zs'.pat)
let nmd = matchstr(str, '\v^[^:]+'.pat.'\zs.{-}$')
let str = fnamemodify(s:fnesc(spc, 'g'), mdr).nmd
en
en
if str == '' | retu | en
unl! s:hstgot
let s:act_add = 1
let [base, seed] = s:headntail(str)
if str =~# '^[\/]'
let base = expand('/').base
en
let dirs = s:dircompl(base, seed)
if len(dirs) == 1
let str = dirs[0]
elsei len(dirs) > 1
let str .= s:findcommon(dirs, str)
en
let s:prompt[0] = exists('hasat') ? hasat[0].str : str
cal s:BuildPrompt(1)
unl s:act_add
endf
" Movement {{{2
fu! s:PrtCurLeft()
if !s:focus | retu | en
let prt = s:prompt
if !empty(prt[0])
let s:prompt = [substitute(prt[0], '.$', '', ''), matchstr(prt[0], '.$'),
\ prt[1] . prt[2]]
en
cal s:BuildPrompt(0)
endf
fu! s:PrtCurRight()
if !s:focus | retu | en
let prt = s:prompt
let s:prompt = [prt[0] . prt[1], matchstr(prt[2], '^.'),
\ substitute(prt[2], '^.', '', '')]
cal s:BuildPrompt(0)
endf
fu! s:PrtCurStart()
if !s:focus | retu | en
let str = join(s:prompt, '')
let s:prompt = ['', matchstr(str, '^.'), substitute(str, '^.', '', '')]
cal s:BuildPrompt(0)
endf
fu! s:PrtCurEnd()
if !s:focus | retu | en
let s:prompt = [join(s:prompt, ''), '', '']
cal s:BuildPrompt(0)
endf
fu! s:PrtSelectMove(dir)
let wht = winheight(0)
let dirs = {'t': 'gg','b': 'G','j': 'j','k': 'k','u': wht.'k','d': wht.'j'}
exe 'keepj norm!' dirs[a:dir]
if s:nolim != 1 | let s:cline = line('.') | en
if line('$') > winheight(0) | cal s:BuildPrompt(0) | en
endf
fu! s:PrtSelectJump(char)
let lines = copy(s:lines)
if s:byfname()
cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
en
" Cycle through matches, use s:jmpchr to store last jump
let chr = escape(matchstr(a:char, '^.'), '.~')
let smartcs = &scs && chr =~ '\u' ? '\C' : ''
if match(lines, smartcs.'^'.chr) >= 0
" If not exists or does but not for the same char
let pos = match(lines, smartcs.'^'.chr)
if !exists('s:jmpchr') || ( exists('s:jmpchr') && s:jmpchr[0] != chr )
let [jmpln, s:jmpchr] = [pos, [chr, pos]]
elsei exists('s:jmpchr') && s:jmpchr[0] == chr
" Start of lines
if s:jmpchr[1] == -1 | let s:jmpchr[1] = pos | en
let npos = match(lines, smartcs.'^'.chr, s:jmpchr[1] + 1)
let [jmpln, s:jmpchr] = [npos == -1 ? pos : npos, [chr, npos]]
en
exe 'keepj norm!' ( jmpln + 1 ).'G'
if s:nolim != 1 | let s:cline = line('.') | en
if line('$') > winheight(0) | cal s:BuildPrompt(0) | en
en
endf
" Misc {{{2
fu! s:PrtFocusMap(char)
cal call(( s:focus ? 's:PrtAdd' : 's:PrtSelectJump' ), [a:char])
endf
fu! s:PrtClearCache()
if s:itemtype == 0
cal ctrlp#clr()
elsei s:itemtype > 2
cal ctrlp#clr(s:statypes[s:itemtype][1])
en
if s:itemtype == 2
let g:ctrlp_lines = ctrlp#mrufiles#refresh()
el
cal ctrlp#setlines()
en
let s:force = 1
cal s:BuildPrompt(1)
unl s:force
endf
fu! s:PrtDeleteEnt()
if s:itemtype == 2
cal s:PrtDeleteMRU()
elsei type(s:getextvar('wipe')) == 1
cal s:delent(s:getextvar('wipe'))
en
endf
fu! s:PrtDeleteMRU()
if s:itemtype == 2
cal s:delent('ctrlp#mrufiles#remove')
en
endf
fu! s:PrtExit()
if bufnr('%') == s:bufnr && bufname('%') == 'ControlP'
noa cal s:Close()
noa winc p
en
endf
fu! s:PrtNoop()
endf
fu! s:PrtHistory(...)
if !s:focus || !s:maxhst | retu | en
let [str, hst, s:matches] = [join(s:prompt, ''), s:hstry, 1]
" Save to history if not saved before
let [hst[0], hslen] = [exists('s:hstgot') ? hst[0] : str, len(hst)]
let idx = exists('s:hisidx') ? s:hisidx + a:1 : a:1
" Limit idx within 0 and hslen
let idx = idx < 0 ? 0 : idx >= hslen ? hslen > 1 ? hslen - 1 : 0 : idx
let s:prompt = [hst[idx], '', '']
let [s:hisidx, s:hstgot, s:force] = [idx, 1, 1]
cal s:BuildPrompt(1)
unl s:force
endf
"}}}1
" * Mappings {{{1
fu! s:MapNorms()
if exists('s:nmapped') && s:nmapped == s:bufnr | retu | en
let pcmd = "nn \<buffer> \<silent> \<k%s> :\<c-u>cal \<SID>%s(\"%s\")\<cr>"
let cmd = substitute(pcmd, 'k%s', 'char-%d', '')
let pfunc = 'PrtFocusMap'
let ranges = [32, 33, 125, 126] + range(35, 91) + range(93, 123)
for each in [34, 92, 124]
exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'))
endfo
for each in ranges
exe printf(cmd, each, pfunc, nr2char(each))
endfo
for each in range(0, 9)
exe printf(pcmd, each, pfunc, each)
endfo
for [ke, va] in items(s:kprange)
exe printf(pcmd, ke, pfunc, va)
endfo
let s:nmapped = s:bufnr
endf
fu! s:MapSpecs()
if !( exists('s:smapped') && s:smapped == s:bufnr )
" Correct arrow keys in terminal
if ( has('termresponse') && v:termresponse =~ "\<ESC>" )
\ || &term =~? '\vxterm|<k?vt|gnome|screen|linux|ansi'
for each in ['\A <up>','\B <down>','\C <right>','\D <left>']
exe s:lcmap.' <esc>['.each
endfo
en
en
for [ke, va] in items(s:prtmaps) | for kp in va
exe s:lcmap kp ':<c-u>cal <SID>'.ke.'<cr>'
endfo | endfo
let s:smapped = s:bufnr
endf
fu! s:KeyLoop()
wh exists('s:init') && s:keyloop
redr
let nr = getchar()
let chr = !type(nr) ? nr2char(nr) : nr
if nr >=# 0x20
cal s:PrtFocusMap(chr)
el
let cmd = matchstr(maparg(chr), ':<C-U>\zs.\+\ze<CR>$')
exe ( cmd != '' ? cmd : 'norm '.chr )
en
endw
endf
" * Toggling {{{1
fu! s:ToggleFocus()
let s:focus = !s:focus
cal s:BuildPrompt(0)
endf
fu! s:ToggleRegex()
let s:regexp = !s:regexp
cal s:PrtSwitcher()
endf
fu! s:ToggleByFname()
if s:ispath
let s:byfname = !s:byfname
let s:mfunc = s:mfunc()
cal s:PrtSwitcher()
en
endf
fu! s:ToggleType(dir)
let max = len(g:ctrlp_ext_vars) + 2
let next = s:walker(max, s:itemtype, a:dir)
cal ctrlp#syntax()
cal ctrlp#setlines(next)
cal s:PrtSwitcher()
endf
fu! s:ToggleKeyLoop()
let s:keyloop = !s:keyloop
if exists('+imd')
let &imd = !s:keyloop
en
if s:keyloop
let [&ut, s:lazy] = [0, 0]
cal s:KeyLoop()
elsei has_key(s:glbs, 'ut')
let [&ut, s:lazy] = [s:glbs['ut'], 1]
en
endf
fu! s:ToggleMRURelative()
cal ctrlp#mrufiles#tgrel()
cal s:PrtClearCache()
endf
fu! s:PrtSwitcher()
let [s:force, s:matches] = [1, 1]
cal s:BuildPrompt(1)
unl s:force
endf
" - SetWD() {{{1
fu! s:SetWD(args)
if has_key(a:args, 'args') && stridx(a:args['args'], '--dir') >= 0
\ && exists('s:dyncwd')
cal ctrlp#setdir(s:dyncwd) | retu
en
if has_key(a:args, 'dir') && a:args['dir'] != ''
cal ctrlp#setdir(a:args['dir']) | retu
en
let pmode = has_key(a:args, 'mode') ? a:args['mode'] : s:pathmode
let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
if s:crfile =~ '^.\+://' | retu | en
if pmode =~ 'c' || ( pmode =~ 'a' && stridx(s:crfpath, s:cwd) < 0 )
\ || ( !type(pmode) && pmode )
if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
cal ctrlp#setdir(s:crfpath)
en
if pmode =~ 'r' || pmode == 2
let markers = ['.git', '.hg', '.svn', '.bzr', '_darcs']
let spath = pmode =~ 'd' ? s:dyncwd : pmode =~ 'w' ? s:cwd : s:crfpath
if type(s:rmarkers) == 3 && !empty(s:rmarkers)