707
|
1 " =============================================================================
|
|
2 " File: autoload/ctrlp.vim
|
|
3 " Description: Fuzzy file, buffer, mru, tag, etc finder.
|
|
4 " Author: CtrlP Dev Team
|
|
5 " Original: Kien Nguyen <github.com/kien>
|
|
6 " Version: 1.80
|
|
7 " =============================================================================
|
|
8
|
|
9 " ** Static variables {{{1
|
|
10 " s:ignore() {{{2
|
|
11 fu! s:ignore()
|
|
12 let igdirs = [
|
|
13 \ '\.git',
|
|
14 \ '\.hg',
|
|
15 \ '\.svn',
|
|
16 \ '_darcs',
|
|
17 \ '\.bzr',
|
|
18 \ '\.cdv',
|
|
19 \ '\~\.dep',
|
|
20 \ '\~\.dot',
|
|
21 \ '\~\.nib',
|
|
22 \ '\~\.plst',
|
|
23 \ '\.pc',
|
|
24 \ '_MTN',
|
|
25 \ 'blib',
|
|
26 \ 'CVS',
|
|
27 \ 'RCS',
|
|
28 \ 'SCCS',
|
|
29 \ '_sgbak',
|
|
30 \ 'autom4te\.cache',
|
|
31 \ 'cover_db',
|
|
32 \ '_build',
|
|
33 \ ]
|
|
34 let igfiles = [
|
|
35 \ '\~$',
|
|
36 \ '#.+#$',
|
|
37 \ '[._].*\.swp$',
|
|
38 \ 'core\.\d+$',
|
|
39 \ '\.exe$',
|
|
40 \ '\.so$',
|
|
41 \ '\.bak$',
|
|
42 \ '\.png$',
|
|
43 \ '\.jpg$',
|
|
44 \ '\.gif$',
|
|
45 \ '\.zip$',
|
|
46 \ '\.rar$',
|
|
47 \ '\.tar\.gz$',
|
|
48 \ ]
|
|
49 retu {
|
|
50 \ 'dir': '\v[\/]('.join(igdirs, '|').')$',
|
|
51 \ 'file': '\v'.join(igfiles, '|'),
|
|
52 \ }
|
|
53 endf
|
|
54 " Script local vars {{{2
|
|
55 let [s:pref, s:bpref, s:opts, s:new_opts, s:lc_opts] =
|
|
56 \ ['g:ctrlp_', 'b:ctrlp_', {
|
|
57 \ 'abbrev': ['s:abbrev', {}],
|
|
58 \ 'arg_map': ['s:argmap', 0],
|
|
59 \ 'buffer_func': ['s:buffunc', {}],
|
|
60 \ 'by_filename': ['s:byfname', 0],
|
|
61 \ 'custom_ignore': ['s:usrign', s:ignore()],
|
|
62 \ 'default_input': ['s:deftxt', 0],
|
|
63 \ 'dont_split': ['s:nosplit', 'netrw'],
|
|
64 \ 'dotfiles': ['s:showhidden', 0],
|
|
65 \ 'extensions': ['s:extensions', []],
|
|
66 \ 'follow_symlinks': ['s:folsym', 0],
|
|
67 \ 'highlight_match': ['s:mathi', [1, 'CtrlPMatch']],
|
|
68 \ 'jump_to_buffer': ['s:jmptobuf', 'Et'],
|
|
69 \ 'key_loop': ['s:keyloop', 0],
|
|
70 \ 'lazy_update': ['s:lazy', 0],
|
|
71 \ 'match_func': ['s:matcher', {}],
|
|
72 \ 'match_window': ['s:mw', ''],
|
|
73 \ 'match_window_bottom': ['s:mwbottom', 1],
|
|
74 \ 'match_window_reversed': ['s:mwreverse', 1],
|
|
75 \ 'max_depth': ['s:maxdepth', 40],
|
|
76 \ 'max_files': ['s:maxfiles', 10000],
|
|
77 \ 'max_height': ['s:mxheight', 10],
|
|
78 \ 'max_history': ['s:maxhst', exists('+hi') ? &hi : 20],
|
|
79 \ 'mruf_default_order': ['s:mrudef', 0],
|
|
80 \ 'open_func': ['s:openfunc', {}],
|
|
81 \ 'open_multi': ['s:opmul', '1v'],
|
|
82 \ 'open_new_file': ['s:newfop', 'v'],
|
|
83 \ 'prompt_mappings': ['s:urprtmaps', 0],
|
|
84 \ 'regexp_search': ['s:regexp', 0],
|
|
85 \ 'root_markers': ['s:rmarkers', []],
|
|
86 \ 'split_window': ['s:splitwin', 0],
|
|
87 \ 'status_func': ['s:status', {}],
|
|
88 \ 'tabpage_position': ['s:tabpage', 'ac'],
|
|
89 \ 'use_caching': ['s:caching', 1],
|
|
90 \ 'user_command': ['s:usrcmd', ''],
|
|
91 \ 'validate': ['s:validate', ''],
|
|
92 \ 'working_path_mode': ['s:pathmode', 'ra'],
|
|
93 \ 'line_prefix': ['s:lineprefix', '> '],
|
|
94 \ 'open_single_match': ['s:opensingle', []],
|
|
95 \ 'brief_prompt': ['s:brfprt', 0],
|
|
96 \ 'match_current_file': ['s:matchcrfile', 0],
|
|
97 \ 'match_natural_name': ['s:matchnatural', 0],
|
|
98 \ 'compare_lim': ['s:compare_lim', 0],
|
|
99 \ 'bufname_mod': ['s:bufname_mod', ':t'],
|
|
100 \ 'bufpath_mod': ['s:bufpath_mod', ':~:.:h'],
|
|
101 \ 'formatline_func': ['s:flfunc', 's:formatline(v:val)'],
|
|
102 \ 'user_command_async': ['s:usrcmdasync', 0],
|
|
103 \ }, {
|
|
104 \ 'open_multiple_files': 's:opmul',
|
|
105 \ 'regexp': 's:regexp',
|
|
106 \ 'reuse_window': 's:nosplit',
|
|
107 \ 'show_hidden': 's:showhidden',
|
|
108 \ 'switch_buffer': 's:jmptobuf',
|
|
109 \ }, {
|
|
110 \ 'root_markers': 's:rmarkers',
|
|
111 \ 'user_command': 's:usrcmd',
|
|
112 \ 'working_path_mode': 's:pathmode',
|
|
113 \ }]
|
|
114
|
|
115 " Global options
|
|
116 let s:glbs = { 'magic': 1, 'to': 1, 'tm': 0, 'sb': 1, 'hls': 0, 'im': 0,
|
|
117 \ 'report': 9999, 'sc': 0, 'ss': 0, 'siso': 0, 'mfd': 200, 'ttimeout': 0,
|
|
118 \ 'gcr': 'a:blinkon0', 'ic': 1, 'lmap': '', 'mousef': 0, 'imd': 1 }
|
|
119
|
|
120 " Keymaps
|
|
121 let [s:lcmap, s:prtmaps] = ['nn <buffer> <silent>', {
|
|
122 \ 'PrtBS()': ['<bs>', '<c-]>'],
|
|
123 \ 'PrtDelete()': ['<del>'],
|
|
124 \ 'PrtDeleteWord()': ['<c-w>'],
|
|
125 \ 'PrtClear()': ['<c-u>'],
|
|
126 \ 'PrtSelectMove("j")': ['<c-j>', '<down>'],
|
|
127 \ 'PrtSelectMove("k")': ['<c-k>', '<up>'],
|
|
128 \ 'PrtSelectMove("t")': ['<Home>', '<kHome>'],
|
|
129 \ 'PrtSelectMove("b")': ['<End>', '<kEnd>'],
|
|
130 \ 'PrtSelectMove("u")': ['<PageUp>', '<kPageUp>'],
|
|
131 \ 'PrtSelectMove("d")': ['<PageDown>', '<kPageDown>'],
|
|
132 \ 'PrtHistory(-1)': ['<c-n>'],
|
|
133 \ 'PrtHistory(1)': ['<c-p>'],
|
|
134 \ 'AcceptSelection("e")': ['<cr>', '<2-LeftMouse>'],
|
|
135 \ 'AcceptSelection("h")': ['<c-x>', '<c-cr>', '<c-s>'],
|
|
136 \ 'AcceptSelection("t")': ['<c-t>'],
|
|
137 \ 'AcceptSelection("v")': ['<c-v>', '<RightMouse>'],
|
|
138 \ 'ToggleFocus()': ['<s-tab>'],
|
|
139 \ 'ToggleRegex()': ['<c-r>'],
|
|
140 \ 'ToggleByFname()': ['<c-d>'],
|
|
141 \ 'ToggleType(1)': ['<c-f>', '<c-up>'],
|
|
142 \ 'ToggleType(-1)': ['<c-b>', '<c-down>'],
|
|
143 \ 'PrtExpandDir()': ['<tab>'],
|
|
144 \ 'PrtInsert("c")': ['<MiddleMouse>', '<insert>'],
|
|
145 \ 'PrtInsert()': ['<c-\>'],
|
|
146 \ 'PrtCurStart()': ['<c-a>'],
|
|
147 \ 'PrtCurEnd()': ['<c-e>'],
|
|
148 \ 'PrtCurLeft()': ['<c-h>', '<left>', '<c-^>'],
|
|
149 \ 'PrtCurRight()': ['<c-l>', '<right>'],
|
|
150 \ 'PrtClearCache()': ['<F5>'],
|
|
151 \ 'PrtDeleteEnt()': ['<F7>'],
|
|
152 \ 'CreateNewFile()': ['<c-y>'],
|
|
153 \ 'MarkToOpen()': ['<c-z>'],
|
|
154 \ 'OpenMulti()': ['<c-o>'],
|
|
155 \ 'YankLine()': [],
|
|
156 \ 'PrtExit()': ['<esc>', '<c-c>', '<c-g>'],
|
|
157 \ }]
|
|
158
|
|
159 if !has('gui_running')
|
|
160 cal add(s:prtmaps['PrtBS()'], remove(s:prtmaps['PrtCurLeft()'], 0))
|
|
161 en
|
|
162
|
|
163 let s:ficounts = {}
|
|
164
|
|
165 let s:ccex = s:pref.'clear_cache_on_exit'
|
|
166
|
|
167 " Regexp
|
|
168 let s:fpats = {
|
|
169 \ '^\(\\|\)\|\(\\|\)$': '\\|',
|
|
170 \ '^\\\(zs\|ze\|<\|>\)': '^\\\(zs\|ze\|<\|>\)',
|
|
171 \ '^\S\*$': '\*',
|
|
172 \ '^\S\\?$': '\\?',
|
|
173 \ }
|
|
174
|
|
175 let s:has_conceal = has('conceal')
|
|
176 let s:bufnr_width = 3
|
|
177
|
|
178 " Keypad
|
|
179 let s:kprange = {
|
|
180 \ 'Plus': '+',
|
|
181 \ 'Minus': '-',
|
|
182 \ 'Divide': '/',
|
|
183 \ 'Multiply': '*',
|
|
184 \ 'Point': '.',
|
|
185 \ }
|
|
186
|
|
187 " Highlight groups
|
|
188 let s:hlgrps = {
|
|
189 \ 'NoEntries': 'Error',
|
|
190 \ 'Mode1': 'Character',
|
|
191 \ 'Mode2': 'LineNr',
|
|
192 \ 'Stats': 'Function',
|
|
193 \ 'Match': 'Identifier',
|
|
194 \ 'PrtBase': 'Comment',
|
|
195 \ 'PrtText': 'Normal',
|
|
196 \ 'PrtCursor': 'Constant',
|
|
197 \ 'BufferNr': 'Constant',
|
|
198 \ 'BufferInd': 'Normal',
|
|
199 \ 'BufferHid': 'Comment',
|
|
200 \ 'BufferHidMod': 'String',
|
|
201 \ 'BufferVis': 'Normal',
|
|
202 \ 'BufferVisMod': 'Identifier',
|
|
203 \ 'BufferCur': 'Question',
|
|
204 \ 'BufferCurMod': 'WarningMsg',
|
|
205 \ 'BufferPath': 'Comment',
|
|
206 \ }
|
|
207
|
|
208 " lname, sname of the basic(non-extension) modes
|
|
209 let s:types = ['fil', 'buf', 'mru']
|
|
210 if !exists('g:ctrlp_types')
|
|
211 let g:ctrlp_types = s:types
|
|
212 el
|
|
213 call filter(g:ctrlp_types, "index(['fil', 'buf', 'mru'], v:val)!=-1")
|
|
214 en
|
|
215 let g:ctrlp_builtins = len(g:ctrlp_types)-1
|
|
216
|
|
217 let s:coretype_names = {
|
|
218 \ 'fil' : 'files',
|
|
219 \ 'buf' : 'buffers',
|
|
220 \ 'mru' : 'mru files',
|
|
221 \ }
|
|
222
|
|
223 let s:coretypes = map(copy(g:ctrlp_types), '[s:coretype_names[v:val], v:val]')
|
|
224
|
|
225 " Get the options {{{2
|
|
226 fu! s:opts(...)
|
|
227 unl! s:usrign s:usrcmd s:urprtmaps
|
|
228 for each in ['byfname', 'regexp', 'extensions'] | if exists('s:'.each)
|
|
229 let {each} = s:{each}
|
|
230 en | endfo
|
|
231 for [ke, va] in items(s:opts)
|
|
232 let {va[0]} = exists(s:pref.ke) ? {s:pref.ke} : va[1]
|
|
233 endfo
|
|
234 unl va
|
|
235 for [ke, va] in items(s:new_opts)
|
|
236 let {va} = {exists(s:pref.ke) ? s:pref.ke : va}
|
|
237 endfo
|
|
238 unl va
|
|
239 for [ke, va] in items(s:lc_opts)
|
|
240 if exists(s:bpref.ke)
|
|
241 unl {va}
|
|
242 let {va} = {s:bpref.ke}
|
|
243 en
|
|
244 endfo
|
|
245 " Match window options
|
|
246 cal s:match_window_opts()
|
|
247 " One-time values
|
|
248 if a:0 && a:1 != {}
|
|
249 unl va
|
|
250 for [ke, va] in items(a:1)
|
|
251 let opke = substitute(ke, '\(\w:\)\?ctrlp_', '', '')
|
|
252 if has_key(s:lc_opts, opke)
|
|
253 let sva = s:lc_opts[opke]
|
|
254 unl {sva}
|
|
255 let {sva} = va
|
|
256 en
|
|
257 endfo
|
|
258 en
|
|
259 for each in ['byfname', 'regexp'] | if exists(each)
|
|
260 let s:{each} = {each}
|
|
261 en | endfo
|
|
262 if !exists('g:ctrlp_tilde_homedir') | let g:ctrlp_tilde_homedir = 0 | en
|
|
263 if !exists('g:ctrlp_newcache') | let g:ctrlp_newcache = 0 | en
|
|
264 let s:maxdepth = min([s:maxdepth, 100])
|
|
265 let s:glob = s:showhidden ? '.*\|*' : '*'
|
|
266 let s:igntype = empty(s:usrign) ? -1 : type(s:usrign)
|
|
267 let s:lash = ctrlp#utils#lash()
|
|
268 if s:keyloop
|
|
269 let [s:lazy, s:glbs['imd']] = [0, 0]
|
|
270 en
|
|
271 if s:lazy
|
|
272 cal extend(s:glbs, { 'ut': ( s:lazy > 1 ? s:lazy : 250 ) })
|
|
273 en
|
|
274 " Extensions
|
|
275 if !( exists('extensions') && extensions == s:extensions )
|
|
276 for each in s:extensions
|
|
277 exe 'ru autoload/ctrlp/'.each.'.vim'
|
|
278 endfo
|
|
279 en
|
|
280 " Keymaps
|
|
281 if type(s:urprtmaps) == 4
|
|
282 cal extend(s:prtmaps, s:urprtmaps)
|
|
283 en
|
|
284 endf
|
|
285
|
|
286 fu! s:match_window_opts()
|
|
287 let s:mw_pos =
|
|
288 \ s:mw =~ 'top\|bottom' ? matchstr(s:mw, 'top\|bottom') :
|
|
289 \ exists('g:ctrlp_match_window_bottom') ? ( s:mwbottom ? 'bottom' : 'top' )
|
|
290 \ : 'bottom'
|
|
291 let s:mw_order =
|
|
292 \ s:mw =~ 'order:[^,]\+' ? matchstr(s:mw, 'order:\zs[^,]\+') :
|
|
293 \ exists('g:ctrlp_match_window_reversed') ? ( s:mwreverse ? 'btt' : 'ttb' )
|
|
294 \ : 'btt'
|
|
295 let s:mw_max =
|
|
296 \ s:mw =~ 'max:[^,]\+' ? str2nr(matchstr(s:mw, 'max:\zs\d\+')) :
|
|
297 \ exists('g:ctrlp_max_height') ? s:mxheight
|
|
298 \ : 10
|
|
299 let s:mw_min =
|
|
300 \ s:mw =~ 'min:[^,]\+' ? str2nr(matchstr(s:mw, 'min:\zs\d\+')) : 1
|
|
301 let [s:mw_max, s:mw_min] = [max([s:mw_max, 1]), max([s:mw_min, 1])]
|
|
302 let s:mw_min = min([s:mw_min, s:mw_max])
|
|
303 let s:mw_res =
|
|
304 \ s:mw =~ 'results:[^,]\+' ? str2nr(matchstr(s:mw, 'results:\zs\d\+'))
|
|
305 \ : min([s:mw_max, &lines])
|
|
306 endf
|
|
307 "}}}1
|
|
308 " * Open & Close {{{1
|
|
309 fu! s:Open()
|
|
310 cal s:log(1)
|
|
311 cal s:getenv()
|
|
312 cal s:execextvar('enter')
|
|
313 sil! exe 'keepa' ( s:mw_pos == 'top' ? 'to' : 'bo' ) '1new ControlP'
|
|
314 cal s:buffunc(1)
|
|
315 let [s:bufnr, s:winw] = [bufnr('%'), winwidth(0)]
|
|
316 let [s:focus, s:prompt] = [1, ['', '', '']]
|
|
317 abc <buffer>
|
|
318 if !exists('s:hstry')
|
|
319 let hst = filereadable(s:gethistloc()[1]) ? s:gethistdata() : ['']
|
|
320 let s:hstry = empty(hst) || !s:maxhst ? [''] : hst
|
|
321 en
|
|
322 for [ke, va] in items(s:glbs) | if exists('+'.ke)
|
|
323 sil! exe 'let s:glb_'.ke.' = &'.ke.' | let &'.ke.' = '.string(va)
|
|
324 en | endfo
|
|
325 if s:opmul != '0' && has('signs')
|
|
326 sign define ctrlpmark text=+> texthl=CtrlPMark
|
|
327 hi def link CtrlPMark Search
|
|
328 en
|
|
329 cal s:setupblank()
|
|
330 endf
|
|
331
|
|
332 fu! s:Close()
|
|
333 if has('patch-9.0.0115') && exists('s:cmdheight')
|
|
334 let &cmdheight = s:cmdheight
|
|
335 unlet s:cmdheight
|
|
336 en
|
|
337 cal s:async_glob_abort(0)
|
|
338 cal s:buffunc(0)
|
|
339 if winnr('$') == 1
|
|
340 bw!
|
|
341 el
|
|
342 try | bun!
|
|
343 cat | clo! | endt
|
|
344 cal s:unmarksigns()
|
|
345 en
|
|
346 for key in keys(s:glbs) | if exists('+'.key)
|
|
347 sil! exe 'let &'.key.' = s:glb_'.key
|
|
348 en | endfo
|
|
349 if exists('s:glb_acd') | let &acd = s:glb_acd | en
|
|
350 let g:ctrlp_lines = []
|
|
351 if s:winres[1] >= &lines && s:winres[2] == winnr('$')
|
|
352 exe s:winres[0].s:winres[0]
|
|
353 en
|
|
354 unl! s:focus s:hisidx s:hstgot s:marked s:statypes s:init s:savestr
|
|
355 \ s:mrbs s:did_exp
|
|
356 cal ctrlp#recordhist()
|
|
357 cal s:execextvar('exit')
|
|
358 cal s:log(0)
|
|
359 let v:errmsg = s:ermsg
|
|
360 ec
|
|
361 endf
|
|
362 " * Clear caches {{{1
|
|
363 fu! ctrlp#clr(...)
|
|
364 let [s:matches, g:ctrlp_new{ a:0 ? a:1 : 'cache' }] = [1, 1]
|
|
365 endf
|
|
366
|
|
367 fu! ctrlp#clra()
|
|
368 let cadir = ctrlp#utils#cachedir()
|
|
369 if isdirectory(cadir)
|
|
370 let cafiles = split(s:glbpath(s:fnesc(cadir, 'g', ','), '**', 1), "\n")
|
|
371 let eval = '!isdirectory(v:val) && v:val !~ ''\v[\/]cache[.a-z]+$|\.log$'''
|
|
372 sil! cal map(s:ifilter(cafiles, eval), 'delete(v:val)')
|
|
373 en
|
|
374 cal ctrlp#clr()
|
|
375 endf
|
|
376
|
|
377 fu! s:Reset(args)
|
|
378 let opts = has_key(a:args, 'opts') ? [a:args['opts']] : []
|
|
379 cal call('s:opts', opts)
|
|
380 cal s:autocmds()
|
|
381 cal ctrlp#utils#opts()
|
|
382 cal s:execextvar('opts')
|
|
383 endf
|
|
384 " * Files {{{1
|
|
385 fu! ctrlp#files()
|
|
386 let cafile = ctrlp#utils#cachefile()
|
|
387 if g:ctrlp_newcache || !filereadable(cafile) || s:nocache(cafile)
|
|
388 let [lscmd, s:initcwd, g:ctrlp_allfiles] = [s:lsCmd(), s:dyncwd, []]
|
|
389 " Get the list of files
|
|
390 if empty(lscmd)
|
|
391 if !ctrlp#igncwd(s:dyncwd)
|
|
392 cal s:InitCustomFuncs()
|
|
393 cal s:GlobPath(s:fnesc(s:dyncwd, 'g', ','), 0)
|
|
394 cal s:CloseCustomFuncs()
|
|
395 en
|
|
396 el
|
|
397 sil! cal ctrlp#progress('Indexing...')
|
|
398 try | cal s:UserCmd(lscmd)
|
|
399 cat | retu [] | endt
|
|
400 en
|
|
401 " Remove base directory
|
|
402 cal ctrlp#rmbasedir(g:ctrlp_allfiles)
|
|
403 if !s:compare_lim || len(g:ctrlp_allfiles) <= s:compare_lim
|
|
404 cal sort(g:ctrlp_allfiles, 'ctrlp#complen')
|
|
405 en
|
|
406 cal s:writecache(cafile)
|
|
407 let catime = getftime(cafile)
|
|
408 el
|
|
409 let catime = getftime(cafile)
|
|
410 if !( exists('s:initcwd') && s:initcwd == s:dyncwd )
|
|
411 \ || get(s:ficounts, s:dyncwd, [0, catime])[1] != catime
|
|
412 let s:initcwd = s:dyncwd
|
|
413 let g:ctrlp_allfiles = ctrlp#utils#readfile(cafile)
|
|
414 en
|
|
415 en
|
|
416 cal extend(s:ficounts, { s:dyncwd : [len(g:ctrlp_allfiles), catime] })
|
|
417 retu g:ctrlp_allfiles
|
|
418 endf
|
|
419
|
|
420 fu! s:InitCustomFuncs()
|
|
421 if s:igntype == 4 && get(s:usrign, 'func-init', '') != ''
|
|
422 exe call(s:usrign['func-init'], [])
|
|
423 en
|
|
424 endf
|
|
425
|
|
426 fu! s:CloseCustomFuncs()
|
|
427 if s:igntype == 4 && get(s:usrign, 'func-close', '') != ''
|
|
428 exe call(s:usrign['func-close'], [])
|
|
429 en
|
|
430 endf
|
|
431
|
|
432 if has('patch-8.2-0995') && get(g:, 'ctrlp_use_readdir', 1)
|
|
433 fu! s:GlobPath(dirs, depth)
|
|
434 let entries = []
|
|
435 let dirs = substitute(a:dirs, '\\\([%# ]\)', '\1', 'g')
|
|
436 for e in split(dirs, ',')
|
|
437 try
|
|
438 let files = readdir(e, '1', {'sort': 'none'})
|
|
439 if !s:showhidden | cal filter(files, 'v:val[0] != "."') | en
|
|
440 let entries += map(files, 'e.s:lash.v:val')
|
|
441 cat
|
|
442 endt
|
|
443 endfo
|
|
444 let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1]
|
|
445 if &wig != '' | cal filter(dnf[1], 'glob(v:val) != ""') | en
|
|
446 let g:ctrlp_allfiles += dnf[1]
|
|
447 if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
|
|
448 sil! cal ctrlp#progress(len(g:ctrlp_allfiles), 1)
|
|
449 cal s:GlobPath(join(dnf[0], ','), depth)
|
|
450 en
|
|
451 endf
|
|
452 el
|
|
453 fu! s:GlobPath(dirs, depth)
|
|
454 let entries = split(globpath(a:dirs, s:glob), "\n")
|
|
455 let [dnf, depth] = [ctrlp#dirnfile(entries), a:depth + 1]
|
|
456 let g:ctrlp_allfiles += dnf[1]
|
|
457 if !empty(dnf[0]) && !s:maxf(len(g:ctrlp_allfiles)) && depth <= s:maxdepth
|
|
458 sil! cal ctrlp#progress(len(g:ctrlp_allfiles), 1)
|
|
459 cal s:GlobPath(join(map(dnf[0], 's:fnesc(v:val, "g", ",")'), ','), depth)
|
|
460 en
|
|
461 endf
|
|
462 en
|
|
463
|
|
464 fu! s:async_glob_update_progress(timer)
|
|
465 let s:must_wait = 0
|
|
466 if exists('s:focus') && get(s:, 'setlines_post_ended', 0)
|
|
467 cal s:ForceUpdate()
|
|
468 en
|
|
469 if exists('s:timer')
|
|
470 sil! cal ctrlp#statusline()
|
|
471 en
|
|
472
|
|
473 if !exists('s:job')
|
|
474 call s:stop_timer_if_exists()
|
|
475 en
|
|
476 endf
|
|
477
|
|
478 fu! s:async_glob_on_stdout(job, data, ...)
|
|
479 if type(a:data) ==# type([])
|
|
480 let g:ctrlp_allfiles += filter(a:data, 'v:val !=# ""')
|
|
481 el
|
|
482 let g:ctrlp_allfiles += [a:data]
|
|
483 en
|
|
484 endf
|
|
485
|
|
486 fu! s:async_glob_on_exit(...)
|
|
487 let s:must_wait = 0
|
|
488 if exists('s:job')
|
|
489 unl s:job
|
|
490 en
|
|
491 cal s:stop_timer_if_exists()
|
|
492 if exists('s:focus') && get(s:, 'setlines_post_ended', 0)
|
|
493 sil! cal ctrlp#statusline()
|
|
494 cal s:ForceUpdate()
|
|
495 en
|
|
496 endf
|
|
497
|
|
498 fu! s:async_glob_abort(upd)
|
|
499 cal s:stop_job_if_exists()
|
|
500 cal s:stop_timer_if_exists()
|
|
501 if a:upd
|
|
502 cal s:ForceUpdate()
|
|
503 en
|
|
504 endf
|
|
505
|
|
506 fu! s:stop_timer_if_exists()
|
|
507 if exists('s:timer')
|
|
508 cal timer_stop(s:timer)
|
|
509 unl s:timer
|
|
510 en
|
|
511 endf
|
|
512
|
|
513 fu! s:stop_job_if_exists()
|
|
514 if exists('s:job')
|
|
515 if !has('nvim')
|
|
516 cal job_stop(s:job)
|
|
517 el
|
|
518 cal jobstop(s:job)
|
|
519 en
|
|
520 unl s:job
|
|
521 en
|
|
522 endf
|
|
523
|
|
524 fu! s:safe_printf(format, ...)
|
|
525 try
|
|
526 retu call('printf', [a:format] + a:000)
|
|
527 cat
|
|
528 retu a:format
|
|
529 endt
|
|
530 endf
|
|
531
|
|
532 fu! s:UserCmd(lscmd)
|
|
533 let [path, lscmd] = [s:dyncwd, a:lscmd]
|
|
534 let do_ign =
|
|
535 \ type(s:usrcmd) == 4 && get(s:usrcmd, 'ignore', 0)
|
|
536 if do_ign && ctrlp#igncwd(s:cwd) | retu | en
|
|
537 if exists('+ssl') && &ssl && &shell !~ 'sh'
|
|
538 let [ssl, &ssl, path] = [&ssl, 0, tr(path, '/', '\')]
|
|
539 en
|
|
540 if (has('win32') || has('win64')) && match(&shellcmdflag, "/") != -1
|
|
541 let lscmd = substitute(lscmd, '\v(^|\&\&\s*)\zscd (/d)@!', 'cd /d ', '')
|
|
542 en
|
|
543 let path = exists('*shellescape') ? shellescape(path) : path
|
|
544 if (has('win32') || has('win64')) && match(&shell, 'sh') != -1
|
|
545 let path = tr(path, '\', '/')
|
|
546 en
|
|
547 if s:usrcmdasync && (v:version >= 800 || has('nvim')) && (exists('*job_start') || exists('*jobstart'))
|
|
548 cal s:stop_job_if_exists()
|
|
549 let g:ctrlp_allfiles = []
|
|
550 let s:must_wait = 1
|
|
551 let argv = [&shell, &shellcmdflag, printf(lscmd, path)]
|
|
552 if !has('nvim')
|
|
553 let s:job = job_start(argv, {
|
|
554 \ 'out_cb': function('s:async_glob_on_stdout'),
|
|
555 \ 'exit_cb': function('s:async_glob_on_exit')
|
|
556 \ })
|
|
557 el
|
|
558 let s:job = jobstart(argv, {
|
|
559 \ 'on_stdout': function('s:async_glob_on_stdout'),
|
|
560 \ 'on_exit': function('s:async_glob_on_exit')
|
|
561 \ })
|
|
562 en
|
|
563 let s:timer = timer_start(250, function('s:async_glob_update_progress'), {'repeat': -1})
|
|
564 while s:must_wait
|
|
565 sleep 50m
|
|
566 endwhile
|
|
567 elsei has('patch-7.4-597') && !(has('win32') || has('win64'))
|
|
568 let g:ctrlp_allfiles = systemlist(s:safe_printf(lscmd, path))
|
|
569 el
|
|
570 let g:ctrlp_allfiles = split(system(s:safe_printf(lscmd, path)), "\n")
|
|
571 en
|
|
572 if exists('+ssl') && exists('ssl')
|
|
573 let &ssl = ssl
|
|
574 cal map(g:ctrlp_allfiles, 'tr(v:val, "\\", "/")')
|
|
575 en
|
|
576 if exists('s:vcscmd') && s:vcscmd
|
|
577 cal map(g:ctrlp_allfiles, 'tr(v:val, "/", "\\")')
|
|
578 en
|
|
579 if do_ign
|
|
580 if !empty(s:usrign)
|
|
581 let g:ctrlp_allfiles = ctrlp#dirnfile(g:ctrlp_allfiles)[1]
|
|
582 en
|
|
583 if &wig != ''
|
|
584 cal filter(g:ctrlp_allfiles, 'glob(v:val) != ""')
|
|
585 en
|
|
586 en
|
|
587 endf
|
|
588
|
|
589 fu! s:lsCmd()
|
|
590 let cmd = s:usrcmd
|
|
591 if type(cmd) == 1
|
|
592 retu cmd
|
|
593 elsei type(cmd) == 3 && len(cmd) >= 2 && cmd[:1] != ['', '']
|
|
594 if s:findroot(s:dyncwd, cmd[0], 0, 1) == []
|
|
595 retu len(cmd) == 3 ? cmd[2] : ''
|
|
596 en
|
|
597 let s:vcscmd = s:lash == '\'
|
|
598 retu cmd[1]
|
|
599 elsei type(cmd) == 4 && ( has_key(cmd, 'types') || has_key(cmd, 'fallback') )
|
|
600 let fndroot = []
|
|
601 if get(cmd, 'types', {}) != {}
|
|
602 let [markrs, cmdtypes] = [[], values(cmd['types'])]
|
|
603 for pair in cmdtypes
|
|
604 cal add(markrs, pair[0])
|
|
605 endfo
|
|
606 let fndroot = s:findroot(s:dyncwd, markrs, 0, 1)
|
|
607 en
|
|
608 if fndroot == []
|
|
609 retu get(cmd, 'fallback', '')
|
|
610 en
|
|
611 for pair in cmdtypes
|
|
612 if pair[0] == fndroot[0] | brea | en
|
|
613 endfo
|
|
614 let s:vcscmd = s:lash == '\'
|
|
615 retu pair[1]
|
|
616 en
|
|
617 endf
|
|
618 " - Buffers {{{1
|
|
619 fu! s:bufparts(bufnr)
|
|
620 let idc = (a:bufnr == bufnr('#') ? '#' : '') " alternative
|
|
621 let idc .= (getbufvar(a:bufnr, '&mod') ? '+' : '') " modified
|
|
622 let idc .= (getbufvar(a:bufnr, '&ma') ? '' : '-') " nomodifiable
|
|
623 let idc .= (getbufvar(a:bufnr, '&ro') ? '=' : '') " readonly
|
|
624
|
|
625 " flags for highlighting
|
|
626 let hiflags = (bufwinnr(a:bufnr) != -1 ? '*' : '') " visible
|
|
627 let hiflags .= (getbufvar(a:bufnr, '&mod') ? '+' : '') " modified
|
|
628 let hiflags .= (a:bufnr == s:crbufnr ? '!' : '') " current
|
|
629
|
|
630 let bname = bufname(a:bufnr)
|
|
631 let bname = (bname == '' ? '[No Name]' : fnamemodify(bname, s:bufname_mod))
|
|
632
|
|
633 let bpath = empty(s:bufpath_mod) ? '' : fnamemodify(bufname(a:bufnr), s:bufpath_mod).s:lash()
|
|
634
|
|
635 retu [idc, hiflags, bname, bpath]
|
|
636 endf
|
|
637 fu! ctrlp#buffers(...)
|
|
638 let ids = sort(filter(range(1, bufnr('$')), '(empty(getbufvar(v:val, "&bt"))'
|
|
639 \ .' || s:isterminal(v:val)) && getbufvar(v:val, "&bl")'), 's:compmreb')
|
|
640 if a:0 && a:1 == 'id'
|
|
641 retu ids
|
|
642 el
|
|
643 let bufs = [[], []]
|
739
|
644 if s:matcher != {} && !s:matchcrfile
|
|
645 call filter(ids, 'v:val != s:crbufnr')
|
|
646 en
|
707
|
647 for id in ids
|
|
648 let bname = bufname(id)
|
|
649 let ebname = bname == ''
|
|
650 let fname = fnamemodify(ebname ? '['.id.'*No Name]' : bname, ':.')
|
|
651 cal add(bufs[ebname], fname)
|
|
652 endfo
|
|
653 retu bufs[0] + bufs[1]
|
|
654 en
|
|
655 endf
|
|
656 " * MatchedItems() {{{1
|
|
657 fu! s:MatchIt(items, pat, limit, exc)
|
|
658 let [lines, id] = [[], 0]
|
|
659 let pat =
|
|
660 \ s:byfname() ? map(split(a:pat, '^[^;]\+\\\@<!\zs;', 1), 's:martcs.v:val')
|
|
661 \ : s:martcs.a:pat
|
|
662 for item in a:items
|
|
663 let id += 1
|
|
664 try
|
|
665 if (s:matchcrfile || !( s:ispath && item ==# a:exc )) &&
|
|
666 \call(s:mfunc, [item, pat]) >= 0
|
|
667 let lines += [item]
|
|
668 en
|
|
669 cat | brea | endt
|
|
670 if a:limit > 0 && len(lines) >= a:limit | brea | en
|
|
671 endfo
|
|
672 let s:mdata = [s:dyncwd, s:itemtype, s:regexp, s:sublist(a:items, id, -1)]
|
|
673 retu lines
|
|
674 endf
|
|
675
|
|
676 fu! s:MatchedItems(items, pat, limit)
|
|
677 let exc = exists('s:crfilerel') ? s:crfilerel : ''
|
|
678 let items = s:narrowable() ? s:matched + s:mdata[3] : a:items
|
|
679 let matcher = s:getextvar('matcher')
|
|
680 if empty(matcher) || type(matcher) != 4 || !has_key(matcher, 'match')
|
|
681 unl matcher
|
|
682 let matcher = s:matcher
|
|
683 en
|
|
684 if matcher != {}
|
|
685 let argms =
|
|
686 \ get(matcher, 'arg_type', '') == 'dict' ? [{
|
|
687 \ 'items': items,
|
|
688 \ 'str': a:pat,
|
|
689 \ 'limit': a:limit,
|
|
690 \ 'mmode': s:mmode(),
|
|
691 \ 'ispath': s:ispath,
|
|
692 \ 'crfile': exc,
|
|
693 \ 'regex': s:regexp,
|
|
694 \ }] : [items, a:pat, a:limit, s:mmode(), s:ispath, exc, s:regexp]
|
|
695 let lines = call(matcher['match'], argms, matcher)
|
|
696 el
|
|
697 let lines = s:MatchIt(items, a:pat, a:limit, exc)
|
|
698 en
|
|
699 let s:matches = len(lines)
|
|
700 unl! s:did_exp
|
|
701 retu lines
|
|
702 endf
|
|
703
|
|
704 fu! s:SplitPattern(str)
|
|
705 let str = a:str
|
|
706 let s:savestr = str
|
|
707 if s:regexp
|
|
708 let pat = s:regexfilter(str)
|
|
709 el
|
|
710 let lst = split(str, '\zs')
|
|
711 if exists('+ssl') && !&ssl
|
|
712 cal map(lst, 'escape(v:val, ''\'')')
|
|
713 en
|
|
714 for each in ['^', '$', '.']
|
|
715 cal map(lst, 'escape(v:val, each)')
|
|
716 endfo
|
|
717 en
|
|
718 if exists('lst')
|
|
719 let pat = ''
|
|
720 if !empty(lst)
|
|
721 if s:byfname() && index(lst, ';') > 0
|
|
722 let fbar = index(lst, ';')
|
|
723 let lst_1 = s:sublist(lst, 0, fbar - 1)
|
|
724 let lst_2 = len(lst) - 1 > fbar ? s:sublist(lst, fbar + 1, -1) : ['']
|
|
725 let pat = s:buildpat(lst_1).';'.s:buildpat(lst_2)
|
|
726 el
|
|
727 let pat = s:buildpat(lst)
|
|
728 en
|
|
729 en
|
|
730 en
|
|
731 retu escape(pat, '~')
|
|
732 endf
|
|
733 " * BuildPrompt() {{{1
|
|
734 fu! s:Render(lines, pat)
|
|
735 let [&ma, lines, s:res_count] = [1, a:lines, len(a:lines)]
|
|
736 let height = min([max([s:mw_min, s:res_count]), s:winmaxh])
|
|
737 let pat = s:byfname() ? split(a:pat, '^[^;]\+\\\@<!\zs;', 1)[0] : a:pat
|
|
738 let cur_cmd = 'keepj norm! '.( s:mw_order == 'btt' ? 'G' : 'gg' ).'1|'
|
|
739
|
|
740 " Setup the match window
|
|
741 sil! exe '%d _ | res' height
|
|
742 " Print the new items
|
|
743 if empty(lines)
|
|
744 let [s:matched, s:lines] = [[], []]
|
|
745 let lines = [' == NO ENTRIES ==']
|
|
746 cal setline(1, s:offset(lines, height - 1))
|
|
747 setl noma nocul
|
|
748 exe cur_cmd
|
|
749 cal s:unmarksigns()
|
|
750 if s:dohighlight() | cal clearmatches() | en
|
|
751 retu
|
|
752 en
|
|
753 let s:matched = copy(lines)
|
|
754 " Sorting
|
|
755 if !s:nosort()
|
|
756 let s:compat = s:martcs.pat
|
|
757 if has('patch-8.1-0')
|
|
758 cal sort(lines, function('s:mixedsort2', [s:curtype()]))
|
|
759 el
|
|
760 cal sort(lines, 's:mixedsort')
|
|
761 en
|
|
762 unl s:compat
|
|
763 en
|
|
764 if s:mw_order == 'btt' | cal reverse(lines) | en
|
|
765 let s:lines = copy(lines)
|
|
766 if s:nolim == 0 && len(lines) > height
|
|
767 let lines = lines[:height-1]
|
|
768 en
|
|
769 if has('patch-8.1-0') && s:flfunc ==# 's:formatline(v:val)'
|
|
770 cal map(lines, function('s:formatline2', [s:curtype()]))
|
|
771 el
|
|
772 cal map(lines, s:flfunc)
|
|
773 en
|
|
774 cal setline(1, s:offset(lines, height))
|
|
775 cal s:unmarksigns()
|
|
776 cal s:remarksigns()
|
|
777 " Highlighting
|
|
778 if s:dohighlight()
|
|
779 cal s:highlight(pat, s:mathi[1])
|
|
780 en
|
|
781 setl noma cul
|
|
782 exe cur_cmd
|
|
783 endf
|
|
784
|
|
785 fu! s:Update(str)
|
|
786 " Get the previous string if existed
|
|
787 let oldstr = exists('s:savestr') ? s:savestr : ''
|
|
788 " Get the new string sans tail
|
|
789 let str = s:sanstail(a:str)
|
|
790 " Stop if the string's unchanged
|
|
791 if str == oldstr && !empty(str) && !exists('s:force') | retu | en
|
|
792 " Optionally send the string to a custom validate function
|
|
793 if s:validate != '' | let str = call(s:validate, [str]) | en
|
|
794 let s:martcs = &scs && str =~ '\u' ? '\C' : ''
|
|
795 let pat = s:matcher == {} ? s:SplitPattern(str) : str
|
|
796 let lines = s:nolim == 1 && empty(str) ? copy(g:ctrlp_lines)
|
|
797 \ : s:MatchedItems(g:ctrlp_lines, pat, s:mw_res)
|
|
798 if empty(str) | cal clearmatches() | en
|
|
799 cal s:Render(lines, pat)
|
|
800 retu lines
|
|
801 endf
|
|
802
|
|
803 fu! s:ForceUpdate()
|
|
804 let pos = exists('*getcurpos') ? getcurpos() : getpos('.')
|
|
805 sil! cal s:Update(escape(s:getinput(), '\'))
|
|
806 cal setpos('.', pos)
|
|
807 endf
|
|
808
|
|
809 fu! s:BuildPrompt(upd)
|
|
810 let base = ( s:regexp ? 'r' : '>' ).( s:byfname() ? 'd' : '>' ).'> '
|
|
811 let str = escape(s:getinput(), '\')
|
|
812 let lazy = str == '' || exists('s:force') || !has('autocmd') ? 0 : s:lazy
|
|
813 if a:upd && !lazy && ( s:matches || s:regexp || exists('s:did_exp')
|
|
814 \ || str =~ '\(\\\(<\|>\)\|[*|]\)\|\(\\\:\([^:]\|\\:\)*$\)' )
|
|
815 sil! cal s:Update(str)
|
|
816 en
|
|
817 sil! cal ctrlp#statusline()
|
|
818 " Toggling
|
|
819 let [hiactive, hicursor, base] = s:focus
|
|
820 \ ? ['CtrlPPrtText', 'CtrlPPrtCursor', base]
|
|
821 \ : ['CtrlPPrtBase', 'CtrlPPrtBase', tr(base, '>', '-')]
|
|
822 let hibase = 'CtrlPPrtBase'
|
|
823 " Build it
|
|
824 redr
|
|
825 let prt = copy(s:prompt)
|
|
826 cal map(prt, 'escape(v:val, ''"\'')')
|
|
827 exe 'echoh' hibase '| echon "'.base.'"
|
|
828 \ | echoh' hiactive '| echon "'.prt[0].'"
|
|
829 \ | echoh' hicursor '| echon "'.prt[1].'"
|
|
830 \ | echoh' hiactive '| echon "'.prt[2].'" | echoh None'
|
|
831 " Append the cursor at the end
|
|
832 if empty(prt[1]) && s:focus
|
|
833 exe 'echoh' hibase '| echon "_" | echoh None'
|
|
834 en
|
|
835 if a:upd
|
|
836 cal s:NotifySearch()
|
|
837 en
|
|
838 endf
|
|
839 " - SetDefTxt() {{{1
|
|
840 fu! s:SetDefTxt()
|
|
841 if s:deftxt == '0' || ( s:deftxt == 1 && !s:ispath ) | retu | en
|
|
842 let txt = s:deftxt
|
|
843 if !type(txt)
|
|
844 let path = s:crfpath.s:lash(s:crfpath)
|
|
845 let txt = txt && !stridx(path, s:dyncwd) ? ctrlp#rmbasedir([path])[0] : ''
|
|
846 en
|
|
847 let s:prompt[0] = txt
|
|
848 endf
|
|
849 " ** Prt Actions {{{1
|
|
850 " Editing {{{2
|
|
851 fu! s:PrtClear()
|
|
852 if !s:focus | retu | en
|
|
853 unl! s:hstgot
|
|
854 let [s:prompt, s:matches] = [['', '', ''], 1]
|
|
855 cal s:BuildPrompt(1)
|
|
856 endf
|
|
857
|
|
858 fu! s:PrtAdd(char)
|
|
859 unl! s:hstgot
|
|
860 let s:act_add = 1
|
|
861 let s:prompt[0] .= a:char
|
|
862 cal s:BuildPrompt(1)
|
|
863 unl s:act_add
|
|
864 endf
|
|
865
|
|
866 fu! s:PrtBS()
|
|
867 if !s:focus | retu | en
|
|
868 if empty(s:prompt[0]) && s:brfprt != 0
|
|
869 cal s:PrtExit()
|
|
870 retu
|
|
871 en
|
|
872 unl! s:hstgot
|
|
873 let [s:prompt[0], s:matches] = [substitute(s:prompt[0], '.$', '', ''), 1]
|
|
874 cal s:BuildPrompt(1)
|
|
875 endf
|
|
876
|
|
877 fu! s:PrtDelete()
|
|
878 if !s:focus | retu | en
|
|
879 unl! s:hstgot
|
|
880 let [prt, s:matches] = [s:prompt, 1]
|
|
881 let prt[1] = matchstr(prt[2], '^.')
|
|
882 let prt[2] = substitute(prt[2], '^.', '', '')
|
|
883 cal s:BuildPrompt(1)
|
|
884 endf
|
|
885
|
|
886 fu! s:PrtDeleteWord()
|
|
887 if !s:focus | retu | en
|
|
888 unl! s:hstgot
|
|
889 let [str, s:matches] = [s:prompt[0], 1]
|
|
890 let str = str =~ '\W\w\+$' ? matchstr(str, '^.\+\W\ze\w\+$')
|
|
891 \ : str =~ '\w\W\+$' ? matchstr(str, '^.\+\w\ze\W\+$')
|
|
892 \ : str =~ '\s\+$' ? matchstr(str, '^.*\S\ze\s\+$')
|
|
893 \ : str =~ '\v^(\S+|\s+)$' ? '' : str
|
|
894 let s:prompt[0] = str
|
|
895 cal s:BuildPrompt(1)
|
|
896 endf
|
|
897
|
|
898 fu! s:PrtInsert(...)
|
|
899 if !s:focus | retu | en
|
|
900 let type = !a:0 ? '' : a:1
|
|
901 if !a:0
|
|
902 let type = s:insertstr()
|
|
903 if type == 'cancel' | retu | en
|
|
904 en
|
|
905 if type ==# 'r'
|
|
906 let regcont = s:getregs()
|
|
907 if regcont < 0 | retu | en
|
|
908 en
|
|
909 unl! s:hstgot
|
|
910 let s:act_add = 1
|
|
911 let s:prompt[0] .= type ==# 'w' ? s:crword
|
|
912 \ : type ==# 'f' ? s:crgfile
|
|
913 \ : type ==# 's' ? s:regisfilter('/')
|
|
914 \ : type ==# 'v' ? s:crvisual
|
|
915 \ : type ==# 'c' ? s:regisfilter('+')
|
|
916 \ : type ==# 'r' ? regcont : ''
|
|
917 cal s:BuildPrompt(1)
|
|
918 unl s:act_add
|
|
919 endf
|
|
920
|
|
921 fu! s:PrtExpandDir()
|
|
922 if !s:focus | retu | en
|
|
923 let str = s:getinput('c')
|
|
924 if str =~ '\v^\@(cd|lc[hd]?|chd)\s.+' && s:spi
|
|
925 let hasat = split(str, '\v^\@(cd|lc[hd]?|chd)\s*\zs')
|
|
926 let str = get(hasat, 1, '')
|
|
927 if str =~# '\v^[~$]\i{-}[\/]?|^#(\<?\d+)?:(p|h|8|\~|\.|g?s+)'
|
|
928 let str = expand(s:fnesc(str, 'g'))
|
|
929 elsei str =~# '\v^(\%|\<c\h{4}\>):(p|h|8|\~|\.|g?s+)'
|
|
930 let spc = str =~# '^%' ? s:crfile
|
|
931 \ : str =~# '^<cfile>' ? s:crgfile
|
|
932 \ : str =~# '^<cword>' ? s:crword
|
|
933 \ : str =~# '^<cWORD>' ? s:crnbword : ''
|
|
934 let pat = '(:(p|h|8|\~|\.|g?s(.)[^\3]*\3[^\3]*\3))+'
|
|
935 let mdr = matchstr(str, '\v^[^:]+\zs'.pat)
|
|
936 let nmd = matchstr(str, '\v^[^:]+'.pat.'\zs.{-}$')
|
|
937 let str = fnamemodify(s:fnesc(spc, 'g'), mdr).nmd
|
|
938 en
|
|
939 en
|
|
940 if str == '' | retu | en
|
|
941 unl! s:hstgot
|
|
942 let s:act_add = 1
|
|
943 let [base, seed] = s:headntail(str)
|
|
944 if str =~# '^[\/]'
|
|
945 let base = expand('/').base
|
|
946 en
|
|
947 let dirs = s:dircompl(base, seed)
|
|
948 if len(dirs) == 1
|
|
949 let str = dirs[0]
|
|
950 elsei len(dirs) > 1
|
|
951 let str .= s:findcommon(dirs, str)
|
|
952 en
|
|
953 let s:prompt[0] = exists('hasat') ? hasat[0].str : str
|
|
954 cal s:BuildPrompt(1)
|
|
955 unl s:act_add
|
|
956 endf
|
|
957 " Movement {{{2
|
|
958 fu! s:PrtCurLeft()
|
|
959 if !s:focus | retu | en
|
|
960 let prt = s:prompt
|
|
961 if !empty(prt[0])
|
|
962 let s:prompt = [substitute(prt[0], '.$', '', ''), matchstr(prt[0], '.$'),
|
|
963 \ prt[1] . prt[2]]
|
|
964 en
|
|
965 cal s:BuildPrompt(0)
|
|
966 endf
|
|
967
|
|
968 fu! s:PrtCurRight()
|
|
969 if !s:focus | retu | en
|
|
970 let prt = s:prompt
|
|
971 let s:prompt = [prt[0] . prt[1], matchstr(prt[2], '^.'),
|
|
972 \ substitute(prt[2], '^.', '', '')]
|
|
973 cal s:BuildPrompt(0)
|
|
974 endf
|
|
975
|
|
976 fu! s:PrtCurStart()
|
|
977 if !s:focus | retu | en
|
|
978 let str = join(s:prompt, '')
|
|
979 let s:prompt = ['', matchstr(str, '^.'), substitute(str, '^.', '', '')]
|
|
980 cal s:BuildPrompt(0)
|
|
981 endf
|
|
982
|
|
983 fu! s:PrtCurEnd()
|
|
984 if !s:focus | retu | en
|
|
985 let s:prompt = [join(s:prompt, ''), '', '']
|
|
986 cal s:BuildPrompt(0)
|
|
987 endf
|
|
988
|
|
989 fu! s:PrtSelectMove(dir)
|
|
990 let wht = winheight(0)
|
|
991 let dirs = {'t': 'gg','b': 'G','j': 'j','k': 'k','u': wht.'k','d': wht.'j'}
|
|
992 exe 'keepj norm!' dirs[a:dir]
|
|
993 let pos = exists('*getcurpos') ? getcurpos() : getpos('.')
|
|
994 cal s:BuildPrompt(0)
|
|
995 cal setpos('.', pos)
|
|
996 endf
|
|
997
|
|
998 fu! s:PrtSelectJump(char)
|
|
999 let lines = copy(s:lines)
|
|
1000 if s:byfname()
|
|
1001 cal map(lines, 'split(v:val, ''[\/]\ze[^\/]\+$'')[-1]')
|
|
1002 en
|
|
1003 " Cycle through matches, use s:jmpchr to store last jump
|
|
1004 let chr = escape(matchstr(a:char, '^.'), '.~')
|
|
1005 let smartcs = &scs && chr =~ '\u' ? '\C' : ''
|
|
1006 if match(lines, smartcs.'^'.chr) >= 0
|
|
1007 " If not exists or does but not for the same char
|
|
1008 let pos = match(lines, smartcs.'^'.chr)
|
|
1009 if !exists('s:jmpchr') || ( exists('s:jmpchr') && s:jmpchr[0] != chr )
|
|
1010 let [jmpln, s:jmpchr] = [pos, [chr, pos]]
|
|
1011 elsei exists('s:jmpchr') && s:jmpchr[0] == chr
|
|
1012 " Start of lines
|
|
1013 if s:jmpchr[1] == -1 | let s:jmpchr[1] = pos | en
|
|
1014 let npos = match(lines, smartcs.'^'.chr, s:jmpchr[1] + 1)
|
|
1015 let [jmpln, s:jmpchr] = [npos == -1 ? pos : npos, [chr, npos]]
|
|
1016 en
|
|
1017 exe 'keepj norm!' ( jmpln + 1 ).'G'
|
|
1018 let pos = exists('*getcurpos') ? getcurpos() : getpos('.')
|
|
1019 cal s:BuildPrompt(0)
|
|
1020 cal setpos('.', pos)
|
|
1021 en
|
|
1022 endf
|
|
1023 " Misc {{{2
|
|
1024 fu! s:PrtFocusMap(char)
|
|
1025 cal call(( s:focus ? 's:PrtAdd' : 's:PrtSelectJump' ), [a:char])
|
|
1026 endf
|
|
1027
|
|
1028 fu! s:PrtClearCache()
|
|
1029 let ct = s:curtype()
|
|
1030 if ct == 'fil'
|
|
1031 cal ctrlp#clr()
|
|
1032 elsei s:itemtype >= len(s:coretypes)
|
|
1033 cal ctrlp#clr(s:statypes[s:itemtype][1])
|
|
1034 en
|
|
1035 if ct == 'mru'
|
|
1036 let g:ctrlp_lines = ctrlp#mrufiles#refresh()
|
|
1037 el
|
|
1038 cal ctrlp#setlines()
|
|
1039 en
|
|
1040 let s:force = 1
|
|
1041 cal s:BuildPrompt(1)
|
|
1042 unl s:force
|
|
1043 endf
|
|
1044
|
|
1045 fu! s:PrtDeleteEnt()
|
|
1046 let ct = s:curtype()
|
|
1047 if ct == 'mru'
|
|
1048 cal s:PrtDeleteMRU()
|
|
1049 elsei ct == 'buf'
|
|
1050 cal s:delbuf()
|
|
1051 elsei type(s:getextvar('wipe')) == 1
|
|
1052 cal s:delent(s:getextvar('wipe'))
|
|
1053 en
|
|
1054 endf
|
|
1055
|
|
1056 fu! s:PrtDeleteMRU()
|
|
1057 if s:curtype() == 'mru'
|
|
1058 cal s:delent('ctrlp#mrufiles#remove')
|
|
1059 en
|
|
1060 endf
|
|
1061
|
|
1062 fu! s:PrtExit()
|
|
1063 let bw = bufwinnr('%')
|
|
1064 exe bufwinnr(s:bufnr).'winc w'
|
|
1065 if bufnr('%') == s:bufnr && bufname('%') == 'ControlP'
|
|
1066 noa cal s:Close()
|
|
1067 noa winc p
|
|
1068 els
|
|
1069 exe bw.'winc w'
|
|
1070 en
|
|
1071 endf
|
|
1072
|
|
1073 fu! s:PrtHistory(...)
|
|
1074 if !s:focus || !s:maxhst | retu | en
|
|
1075 let [str, hst, s:matches] = [join(s:prompt, ''), s:hstry, 1]
|
|
1076 " Save to history if not saved before
|
|
1077 let [hst[0], hslen] = [exists('s:hstgot') ? hst[0] : str, len(hst)]
|
|
1078 let idx = exists('s:hisidx') ? s:hisidx + a:1 : a:1
|
|
1079 " Limit idx within 0 and hslen
|
|
1080 let idx = idx < 0 ? 0 : idx >= hslen ? hslen > 1 ? hslen - 1 : 0 : idx
|
|
1081 let s:prompt = [hst[idx], '', '']
|
|
1082 let [s:hisidx, s:hstgot, s:force] = [idx, 1, 1]
|
|
1083 cal s:BuildPrompt(1)
|
|
1084 unl s:force
|
|
1085 endf
|
|
1086 "}}}1
|
|
1087 " * Mappings {{{1
|
|
1088 fu! s:MapNorms()
|
|
1089 if exists('s:nmapped') && s:nmapped == s:bufnr | retu | en
|
|
1090 let pcmd = "nn \<buffer> \<silent> \<k%s> :\<c-u>cal \<SID>%s(\"%s\")\<cr>"
|
|
1091 let cmd = substitute(pcmd, 'k%s', 'char-%d', '')
|
|
1092 let pfunc = 'PrtFocusMap'
|
|
1093 let ranges = [32, 33, 125, 126] + range(35, 91) + range(93, 123)
|
|
1094 for each in [34, 92, 124]
|
|
1095 exe printf(cmd, each, pfunc, escape(nr2char(each), '"|\'))
|
|
1096 endfo
|
|
1097 for each in ranges
|
|
1098 exe printf(cmd, each, pfunc, nr2char(each))
|
|
1099 endfo
|
|
1100 for each in range(0, 9)
|
|
1101 exe printf(pcmd, each, pfunc, each)
|
|
1102 endfo
|
|
1103 for [ke, va] in items(s:kprange)
|
|
1104 exe printf(pcmd, ke, pfunc, va)
|
|
1105 endfo
|
|
1106 let s:nmapped = s:bufnr
|
|
1107 endf
|
|
1108
|
|
1109 fu! s:MapSpecs()
|
|
1110 if !( exists('s:smapped') && s:smapped == s:bufnr )
|
|
1111 " Correct arrow keys in terminal
|
|
1112 if ( has('termresponse') && v:termresponse =~ "\<ESC>" )
|
|
1113 \ || &term =~? '\vxterm|<k?vt|gnome|screen|linux|ansi|tmux|alacritty|st(-[-a-z0-9]*)?(\:tc)?$'
|
|
1114 for each in ['\A <up>','\B <down>','\C <right>','\D <left>']
|
|
1115 exe s:lcmap.' <esc>['.each
|
|
1116 endfo
|
|
1117 en
|
|
1118 en
|
|
1119 for [ke, va] in items(s:prtmaps) | for kp in va
|
|
1120 exe s:lcmap kp ':<c-u>cal <SID>'.ke.'<cr>'
|
|
1121 endfo | endfo
|
|
1122 let s:smapped = s:bufnr
|
|
1123 endf
|
|
1124
|
|
1125 fu! s:KeyLoop()
|
|
1126 let [t_ve, guicursor] = [&t_ve, &guicursor]
|
|
1127 wh exists('s:init') && s:keyloop
|
|
1128 try
|
|
1129 set t_ve=
|
|
1130 if guicursor != ''
|
|
1131 set guicursor=a:NONE
|
|
1132 en
|
|
1133 let nr = getchar()
|
|
1134 fina
|
|
1135 let &t_ve = t_ve
|
|
1136 let &guicursor = guicursor
|
|
1137 endt
|
|
1138 let chr = !type(nr) ? nr2char(nr) : nr
|
|
1139 if nr >=# 0x20
|
|
1140 cal s:PrtFocusMap(chr)
|
|
1141 el
|
|
1142 let cmd = matchstr(maparg(chr), ':<C-U>\zs.\+\ze<CR>$')
|
|
1143 try
|
|
1144 exe ( cmd != '' ? cmd : 'norm '.chr )
|
|
1145 cat
|
|
1146 endt
|
|
1147 en
|
|
1148 endw
|
|
1149 endf
|
|
1150 " * Toggling {{{1
|
|
1151 fu! s:ToggleFocus()
|
|
1152 let s:focus = !s:focus
|
|
1153 cal s:BuildPrompt(0)
|
|
1154 endf
|
|
1155
|
|
1156 fu! s:ToggleRegex()
|
|
1157 let s:regexp = !s:regexp
|
|
1158 cal s:PrtSwitcher()
|
|
1159 endf
|
|
1160
|
|
1161 fu! s:ToggleByFname()
|
|
1162 if s:ispath
|
|
1163 let s:byfname = !s:byfname
|
|
1164 let s:mfunc = s:mfunc()
|
|
1165 cal s:PrtSwitcher()
|
|
1166 en
|
|
1167 endf
|
|
1168
|
|
1169 fu! s:ToggleType(dir)
|
|
1170 cal s:async_glob_abort(1)
|
|
1171 let max = len(g:ctrlp_ext_vars) + len(s:coretypes) - 1
|
|
1172 let next = s:walker(max, s:itemtype, a:dir)
|
|
1173 cal ctrlp#setlines(next)
|
|
1174 cal ctrlp#syntax()
|
|
1175 cal s:PrtSwitcher()
|
|
1176 endf
|
|
1177
|
|
1178 fu! s:ToggleKeyLoop()
|
|
1179 let s:keyloop = !s:keyloop
|
|
1180 if exists('+imd')
|
|
1181 let &imd = !s:keyloop
|
|
1182 en
|
|
1183 if s:keyloop
|
|
1184 let [&ut, s:lazy] = [0, 0]
|
|
1185 cal s:KeyLoop()
|
|
1186 elsei has_key(s:glbs, 'ut')
|
|
1187 let [&ut, s:lazy] = [s:glbs['ut'], 1]
|
|
1188 en
|
|
1189 endf
|
|
1190
|
|
1191 fu! s:ToggleMRURelative()
|
|
1192 cal ctrlp#mrufiles#tgrel()
|
|
1193 cal s:PrtClearCache()
|
|
1194 endf
|
|
1195
|
|
1196 fu! s:PrtSwitcher()
|
|
1197 let [s:force, s:matches] = [1, 1]
|
|
1198 cal s:BuildPrompt(1)
|
|
1199 unl s:force
|
|
1200 endf
|
|
1201 " - SetWD() {{{1
|
|
1202 fu! s:SetWD(args)
|
|
1203 if has_key(a:args, 'args') && stridx(a:args['args'], '--dir') >= 0
|
|
1204 \ && exists('s:dyncwd')
|
|
1205 cal ctrlp#setdir(s:dyncwd) | retu
|
|
1206 en
|
|
1207 if get(a:args, 'dir', '') != ''
|
|
1208 cal ctrlp#setdir(a:args['dir']) | retu
|
|
1209 en
|
|
1210 let pmodes = get(a:args, 'mode', s:pathmode)
|
|
1211 let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
|
|
1212 if (!type(pmodes))
|
|
1213 let pmodes =
|
|
1214 \ pmodes == 0 ? '' :
|
|
1215 \ pmodes == 1 ? 'a' :
|
|
1216 \ pmodes == 2 ? 'r' :
|
|
1217 \ 'c'
|
|
1218 en
|
|
1219 let spath = pmodes =~ 'd' ? s:dyncwd : pmodes =~ 'w' ? s:cwd : s:crfpath
|
|
1220 for pmode in split(pmodes, '\zs')
|
|
1221 if ctrlp#setpathmode(pmode, spath) | retu | en
|
|
1222 endfo
|
|
1223 endf
|
|
1224 " * AcceptSelection() {{{1
|
|
1225 fu! ctrlp#acceptfile(...)
|
|
1226 let useb = 0
|
|
1227 if a:0 == 1 && type(a:1) == 4
|
|
1228 let [md, line] = [a:1['action'], a:1['line']]
|
|
1229 let atl = get(a:1, 'tail', '')
|
|
1230 el
|
|
1231 let [md, line] = [a:1, a:2]
|
|
1232 let atl = a:0 > 2 ? a:3 : ''
|
|
1233 en
|
|
1234 if !type(line)
|
|
1235 let [filpath, bufnr, useb] = [line, line, 1]
|
|
1236 el
|
|
1237 let [bufnr, filpath] = s:bufnrfilpath(line)
|
|
1238 if bufnr == filpath
|
|
1239 let useb = 1
|
|
1240 en
|
|
1241 en
|
|
1242 cal s:PrtExit()
|
|
1243 let tail = s:tail()
|
|
1244 let j2l = atl != '' ? atl : matchstr(tail, '^ +\zs\d\+$')
|
|
1245 let openmyself = bufnr == bufnr('%')
|
|
1246 if bufnr > 0 && ( !empty(s:jmptobuf) && s:jmptobuf =~ md )
|
|
1247 \ && !( md == 'e' && openmyself )
|
|
1248 let [jmpb, bufwinnr] = [1, bufwinnr(bufnr)]
|
|
1249 let buftab = ( s:jmptobuf =~# '[tTVH]' || s:jmptobuf > 1 )
|
|
1250 \ ? s:buftab(bufnr, md) : [0, 0]
|
|
1251 en
|
|
1252 " Switch to existing buffer or open new one
|
|
1253 if exists('jmpb') && bufwinnr > 0
|
|
1254 \ && !( md == 't' && ( s:jmptobuf !~# toupper(md) || buftab[0] ) )
|
|
1255 exe bufwinnr.'winc w'
|
|
1256 if j2l | cal ctrlp#j2l(j2l) | en
|
|
1257 elsei exists('jmpb') && buftab[0]
|
|
1258 \ && !( md =~ '[evh]' && s:jmptobuf !~# toupper(md) )
|
|
1259 exe 'tabn' buftab[0]
|
|
1260 exe buftab[1].'winc w'
|
|
1261 if j2l | cal ctrlp#j2l(j2l) | en
|
|
1262 el
|
|
1263 " Determine the command to use
|
|
1264 let useb = bufnr > 0 && ( buflisted(bufnr) || openmyself ) && ( empty(tail) || useb )
|
|
1265 let cmd =
|
|
1266 \ md == 't' || s:splitwin == 1 ? ( useb ? 'tab sb' : 'tabe' ) :
|
|
1267 \ md == 'h' || s:splitwin == 2 ? ( useb ? 'sb' : 'new' ) :
|
|
1268 \ md == 'v' || s:splitwin == 3 ? ( useb ? 'vert sb' : 'vne' ) :
|
|
1269 \ &bt == 'help' && openmyself ? 'b' :
|
|
1270 \ call('ctrlp#normcmd', useb ? ['b', 'bo vert sb'] : ['e'])
|
|
1271 " Reset &switchbuf option
|
|
1272 let [swb, &swb] = [&swb, '']
|
|
1273 " Open new window/buffer
|
|
1274 let [fid, tail] = [( useb ? bufnr : filpath ), ( atl != '' ? ' +'.atl : tail )]
|
|
1275 let args = [cmd, fid, tail, 1, [useb, j2l]]
|
|
1276 cal call('s:openfile', args)
|
|
1277 let &swb = swb
|
|
1278 en
|
|
1279 endf
|
|
1280
|
|
1281 fu! s:SpecInputs(str)
|
|
1282 if a:str =~ '\v^(\.\.([\/]\.\.)*[\/]?[.\/]*)$' && s:spi
|
|
1283 let cwd = s:dyncwd
|
|
1284 cal ctrlp#setdir(a:str =~ '^\.\.\.*$' ?
|
|
1285 \ '../'.repeat('../', strlen(a:str) - 2) : a:str)
|
|
1286 if cwd != s:dyncwd | cal ctrlp#setlines() | en
|
|
1287 cal s:PrtClear()
|
|
1288 retu 1
|
|
1289 elsei a:str == s:lash && s:spi
|
|
1290 cal s:SetWD({ 'mode': 'rd' })
|
|
1291 cal ctrlp#setlines()
|
|
1292 cal s:PrtClear()
|
|
1293 retu 1
|
|
1294 elsei a:str =~ '^@.\+' && s:spi
|
|
1295 retu s:at(a:str)
|
|
1296 elsei a:str == '?'
|
|
1297 cal s:PrtExit()
|
|
1298 let hlpwin = &columns > 159 ? '| vert res 80' : ''
|
|
1299 sil! exe 'bo vert h ctrlp-mappings' hlpwin '| norm! 0'
|
|
1300 retu 1
|
|
1301 en
|
|
1302 retu 0
|
|
1303 endf
|
|
1304
|
|
1305 fu! s:AcceptSelection(action)
|
|
1306 let [md, icr] = [a:action[0], match(a:action, 'r') >= 0]
|
|
1307 let subm = icr || ( !icr && md == 'e' )
|
|
1308 if !subm && s:OpenMulti(md) != -1 | retu | en
|
|
1309 let str = s:getinput()
|
|
1310 if subm | if s:SpecInputs(str) | retu | en | en
|
|
1311 " Get the selected line
|
|
1312 let line = ctrlp#getcline()
|
|
1313 if !subm && s:curtype() != 'fil' && line == '' && line('.') > s:offset
|
|
1314 \ && str !~ '\v^(\.\.([\/]\.\.)*[\/]?[.\/]*|/|\\|\?|\@.+)$'
|
|
1315 cal s:CreateNewFile(md) | retu
|
|
1316 en
|
|
1317 if empty(line) | retu | en
|
|
1318 " Do something with it
|
|
1319 if s:openfunc != {} && has_key(s:openfunc, s:ctype)
|
|
1320 let actfunc = s:openfunc[s:ctype]
|
|
1321 let type = get(s:openfunc, 'arg_type', 'list')
|
|
1322 el
|
|
1323 if s:itemtype < len(s:coretypes)
|
|
1324 let [actfunc, type] = ['ctrlp#acceptfile', 'dict']
|
|
1325 el
|
|
1326 let [actfunc, exttype] = [s:getextvar('accept'), s:getextvar('act_farg')]
|
|
1327 let type = exttype == 'dict' ? exttype : 'list'
|
|
1328 en
|
|
1329 en
|
|
1330 let actargs = type == 'dict' ? [{ 'action': md, 'line': line, 'icr': icr, 'input': str}]
|
|
1331 \ : [md, line]
|
|
1332 cal call(actfunc, actargs)
|
|
1333 endf
|
|
1334 " - CreateNewFile() {{{1
|
|
1335 fu! s:CreateNewFile(...)
|
|
1336 let [md, str] = ['', s:getinput('n')]
|
|
1337 if empty(str) | retu | en
|
|
1338 if s:argmap && !a:0
|
|
1339 " Get the extra argument
|
|
1340 let md = s:argmaps(md, 1)
|
|
1341 if md == 'cancel' | retu | en
|
|
1342 en
|
|
1343 let str = s:sanstail(str)
|
|
1344 let [base, fname] = s:headntail(str)
|
|
1345 if fname =~ '^[\/]$' | retu | en
|
|
1346 if exists('s:marked') && len(s:marked)
|
|
1347 " Use the first marked file's path
|
|
1348 let path = fnamemodify(values(s:marked)[0], ':p:h')
|
|
1349 let base = path.s:lash(path).base
|
|
1350 let str = fnamemodify(base.s:lash.fname, ':.')
|
|
1351 en
|
|
1352 if base != '' | if isdirectory(ctrlp#utils#mkdir(base))
|
|
1353 let optyp = str | en | el | let optyp = fname
|
|
1354 en
|
|
1355 if !exists('optyp') | retu | en
|
|
1356 let [filpath, tail] = [fnamemodify(optyp, ':p'), s:tail()]
|
|
1357 if !stridx(filpath, s:dyncwd) | cal s:insertcache(str) | en
|
|
1358 cal s:PrtExit()
|
|
1359 let cmd = md == 'r' ? ctrlp#normcmd('e') :
|
|
1360 \ s:newfop =~ '1\|t' || ( a:0 && a:1 == 't' ) || md == 't' ? 'tabe' :
|
|
1361 \ s:newfop =~ '2\|h' || ( a:0 && a:1 == 'h' ) || md == 'h' ? 'new' :
|
|
1362 \ s:newfop =~ '3\|v' || ( a:0 && a:1 == 'v' ) || md == 'v' ? 'vne' :
|
|
1363 \ ctrlp#normcmd('e')
|
|
1364 cal s:openfile(cmd, filpath, tail, 1)
|
|
1365 endf
|
|
1366 " * OpenMulti() {{{1
|
|
1367 fu! s:MarkToOpen()
|
|
1368 let ct = s:curtype()
|
|
1369 if s:bufnr <= 0 || s:opmul == '0'
|
|
1370 \ || ( s:itemtype >= len(s:coretypes) && s:getextvar('opmul') != 1 )
|
|
1371 retu
|
|
1372 en
|
|
1373 let line = ctrlp#getcline()
|
|
1374
|
|
1375 " Do not allow to mark modified or current buffer
|
|
1376 let bufnr = s:bufnrfilpath(line)[0]
|
|
1377 if (ct == 'buf' && s:delbufcond(bufnr))
|
|
1378 retu
|
|
1379 en
|
|
1380
|
|
1381 if empty(line) | retu | en
|
|
1382 let filpath = s:ispath ? fnamemodify(line, ':p') : line
|
|
1383 if exists('s:marked') && s:dictindex(s:marked, filpath) > 0
|
|
1384 " Unmark and remove the file from s:marked
|
|
1385 let key = s:dictindex(s:marked, filpath)
|
|
1386 cal remove(s:marked, key)
|
|
1387 if empty(s:marked) | unl s:marked | en
|
|
1388 if has('signs')
|
|
1389 exe 'sign unplace' key 'buffer='.s:bufnr
|
|
1390 en
|
|
1391 el
|
|
1392 " Add to s:marked and place a new sign
|
|
1393 if exists('s:marked')
|
|
1394 let vac = s:vacantdict(s:marked)
|
|
1395 let key = empty(vac) ? len(s:marked) + 1 : vac[0]
|
|
1396 cal extend(s:marked, { key : filpath })
|
|
1397 el
|
|
1398 let [key, s:marked] = [1, { 1 : filpath }]
|
|
1399 en
|
|
1400 if has('signs')
|
|
1401 exe 'sign place' key 'line='.line('.').' name=ctrlpmark buffer='.s:bufnr
|
|
1402 en
|
|
1403 en
|
|
1404 sil! cal ctrlp#statusline()
|
|
1405 redr
|
|
1406 endf
|
|
1407
|
|
1408 fu! s:OpenMulti(...)
|
|
1409 let has_marked = exists('s:marked')
|
|
1410 if ( !has_marked && a:0 ) || s:opmul == '0' || !s:ispath
|
|
1411 \ || ( s:itemtype >= len(s:coretypes) && s:getextvar('opmul') != 1 )
|
|
1412 retu -1
|
|
1413 en
|
|
1414 " Get the options
|
|
1415 let [nr, md] = [matchstr(s:opmul, '\d\+'), matchstr(s:opmul, '[thvi]')]
|
|
1416 let [ur, jf] = [s:opmul =~ 'r', s:opmul =~ 'j']
|
|
1417 let md = a:0 ? a:1 : ( md == '' ? 'v' : md )
|
|
1418 let nopt = exists('g:ctrlp_open_multiple_files')
|
|
1419 if !has_marked
|
|
1420 let line = ctrlp#getcline()
|
|
1421 if line == '' | retu | en
|
|
1422 let marked = { 1 : fnamemodify(line, ':p') }
|
|
1423 let [nr, ur, jf, nopt] = ['1', 0, 0, 1]
|
|
1424 en
|
|
1425 if ( s:argmap || !has_marked ) && !a:0
|
|
1426 let md = s:argmaps(md, !has_marked ? 2 : 0)
|
|
1427 if md == 'c'
|
|
1428 cal s:unmarksigns()
|
|
1429 unl! s:marked
|
|
1430 cal s:BuildPrompt(0)
|
|
1431 elsei !has_marked && md =~ '[axd]'
|
|
1432 retu s:OpenNoMarks(md, line)
|
|
1433 en
|
|
1434 if md =~ '\v^c(ancel)?$' | retu | en
|
|
1435 let nr = nr == '0' ? ( nopt ? '' : '1' ) : nr
|
|
1436 let ur = !has_marked && md == 'r' ? 1 : ur
|
|
1437 en
|
|
1438 let mkd = values(has_marked ? s:marked : marked)
|
|
1439 cal s:sanstail(join(s:prompt, ''))
|
|
1440 cal s:PrtExit()
|
|
1441 if nr == '0' || md == 'i'
|
|
1442 retu map(mkd, "s:openfile('bad', v:val, '', 0)")
|
|
1443 en
|
|
1444 let tail = s:tail()
|
|
1445 let [emptytail, bufnr] = [empty(tail), bufnr('^'.mkd[0].'$')]
|
|
1446 let useb = bufnr > 0 && buflisted(bufnr) && emptytail
|
|
1447 " Move to a replaceable window
|
|
1448 let ncmd = ( useb ? ['b', 'bo vert sb'] : ['e', 'bo vne'] )
|
|
1449 \ + ( ur ? [] : ['ignruw'] )
|
|
1450 let fst = call('ctrlp#normcmd', ncmd)
|
|
1451 " Check if the current window has a replaceable buffer
|
|
1452 let repabl = !( md == 't' && !ur ) && empty(bufname('%')) && empty(&l:ft)
|
|
1453 " Commands for the rest of the files
|
|
1454 let [ic, cmds] = [1, { 'v': ['vert sb', 'vne'], 'h': ['sb', 'new'],
|
|
1455 \ 't': ['tab sb', 'tabe'] }]
|
|
1456 let [swb, &swb] = [&swb, '']
|
|
1457 if md == 't' && ctrlp#tabcount() < tabpagenr()
|
|
1458 let s:tabct = ctrlp#tabcount()
|
|
1459 en
|
|
1460 " Open the files
|
|
1461 for va in mkd
|
|
1462 let bufnr = bufnr('^'.va.'$')
|
|
1463 if bufnr < 0 && getftype(va) == '' | con | en
|
|
1464 let useb = bufnr > 0 && buflisted(bufnr) && emptytail
|
|
1465 let snd = md != '' && has_key(cmds, md) ?
|
|
1466 \ ( useb ? cmds[md][0] : cmds[md][1] ) : ( useb ? 'vert sb' : 'vne' )
|
|
1467 let cmd = ic == 1 && ( !( !ur && fst =~ '^[eb]$' ) || repabl ) ? fst : snd
|
|
1468 let conds = [( nr != '' && nr > 1 && nr < ic ) || ( nr == '' && ic > 1 ),
|
|
1469 \ nr != '' && nr < ic]
|
|
1470 if conds[nopt]
|
|
1471 if !buflisted(bufnr) | cal s:openfile('bad', va, '', 0) | en
|
|
1472 el
|
|
1473 cal s:openfile(cmd, useb ? bufnr : va, tail, ic == 1)
|
|
1474 if jf | if ic == 1
|
|
1475 let crpos = [tabpagenr(), winnr()]
|
|
1476 el
|
|
1477 let crpos[0] += tabpagenr() <= crpos[0]
|
|
1478 let crpos[1] += winnr() <= crpos[1]
|
|
1479 en | en
|
|
1480 let ic += 1
|
|
1481 en
|
|
1482 endfo
|
|
1483 if jf && exists('crpos') && ic > 2
|
|
1484 exe ( md == 't' ? 'tabn '.crpos[0] : crpos[1].'winc w' )
|
|
1485 en
|
|
1486 let &swb = swb
|
|
1487 unl! s:tabct
|
|
1488 endf
|
|
1489
|
|
1490 fu! s:YankLine(...)
|
|
1491 let @" = s:getinput()
|
|
1492 let has_marked = exists('s:marked')
|
|
1493 if !has_marked
|
|
1494 let line = ctrlp#getcline()
|
|
1495 if line == '' | retu | en
|
|
1496 let marked = { 1 : fnamemodify(line, ':p') }
|
|
1497 en
|
|
1498 let @" = join(values(has_marked ? s:marked : marked), "\n")
|
|
1499 cal s:PrtExit()
|
|
1500 endf
|
|
1501
|
|
1502 fu! s:OpenNoMarks(md, line)
|
|
1503 if a:md == 'a'
|
|
1504 let [s:marked, key] = [{}, 1]
|
|
1505 for line in s:lines
|
|
1506 cal extend(s:marked, { key : fnamemodify(line, ':p') })
|
|
1507 let key += 1
|
|
1508 endfo
|
|
1509 cal s:remarksigns()
|
|
1510 cal s:BuildPrompt(0)
|
|
1511 elsei a:md == 'x'
|
|
1512 let type = get(s:openfunc, 'arg_type', 'dict')
|
|
1513 let argms = type == 'dict' ? [{ 'action': a:md, 'line': a:line }]
|
|
1514 \ : [a:md, a:line]
|
|
1515 cal call(s:openfunc[s:ctype], argms, s:openfunc)
|
|
1516 elsei a:md == 'd'
|
|
1517 let dir = fnamemodify(a:line, ':h')
|
|
1518 if isdirectory(dir)
|
|
1519 cal ctrlp#setdir(dir)
|
|
1520 cal ctrlp#switchtype(0)
|
|
1521 cal ctrlp#recordhist()
|
|
1522 cal s:PrtClear()
|
|
1523 en
|
|
1524 en
|
|
1525 endf
|
|
1526 " ** Helper functions {{{1
|
|
1527 " Sorting {{{2
|
|
1528 fu! ctrlp#complen(...)
|
|
1529 " By length
|
|
1530 let [len1, len2] = [strlen(a:1), strlen(a:2)]
|
|
1531 retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1
|
|
1532 endf
|
|
1533
|
|
1534 fu! s:compmatlen(...)
|
|
1535 " By match length
|
|
1536 let mln1 = s:shortest(s:matchlens(a:1, s:compat))
|
|
1537 let mln2 = s:shortest(s:matchlens(a:2, s:compat))
|
|
1538 retu mln1 == mln2 ? 0 : mln1 > mln2 ? 1 : -1
|
|
1539 endf
|
|
1540
|
|
1541 fu! s:comptime(...)
|
|
1542 " By last modified time
|
|
1543 let [time1, time2] = [getftime(a:1), getftime(a:2)]
|
|
1544 retu time1 == time2 ? 0 : time1 < time2 ? 1 : -1
|
|
1545 endf
|
|
1546
|
|
1547 fu! s:compmreb(...)
|
|
1548 " By last entered time (bufnr)
|
|
1549 let [id1, id2] = [index(s:mrbs, a:1), index(s:mrbs, a:2)]
|
|
1550 if id1 == id2
|
|
1551 retu 0
|
|
1552 en
|
|
1553 if id1 < 0
|
|
1554 retu 1
|
|
1555 en
|
|
1556 if id2 < 0
|
|
1557 retu -1
|
|
1558 en
|
|
1559 retu id1 > id2 ? 1 : -1
|
|
1560 endf
|
|
1561
|
|
1562 fu! s:compmref(...)
|
|
1563 " By last entered time (MRU)
|
|
1564 let [id1, id2] = [index(g:ctrlp_lines, a:1), index(g:ctrlp_lines, a:2)]
|
|
1565 retu id1 == id2 ? 0 : id1 > id2 ? 1 : -1
|
|
1566 endf
|
|
1567
|
|
1568 fu! s:comparent(...)
|
|
1569 " By same parent dir
|
|
1570 if !stridx(s:crfpath, s:dyncwd)
|
|
1571 let [as1, as2] = [s:dyncwd.s:lash().a:1, s:dyncwd.s:lash().a:2]
|
|
1572 let [loc1, loc2] = [s:getparent(as1), s:getparent(as2)]
|
|
1573 if loc1 == s:crfpath && loc2 != s:crfpath | retu -1 | en
|
|
1574 if loc2 == s:crfpath && loc1 != s:crfpath | retu 1 | en
|
|
1575 retu 0
|
|
1576 en
|
|
1577 retu 0
|
|
1578 endf
|
|
1579
|
|
1580 fu! s:compfnlen(...)
|
|
1581 " By filename length
|
|
1582 let len1 = strlen(split(a:1, s:lash)[-1])
|
|
1583 let len2 = strlen(split(a:2, s:lash)[-1])
|
|
1584 retu len1 == len2 ? 0 : len1 > len2 ? 1 : -1
|
|
1585 endf
|
|
1586
|
|
1587 fu! s:matchlens(str, pat, ...)
|
|
1588 if empty(a:pat) || index(['^', '$'], a:pat) >= 0 | retu {} | en
|
|
1589 let st = a:0 ? a:1 : 0
|
|
1590 let lens = a:0 >= 2 ? a:2 : {}
|
|
1591 let nr = a:0 >= 3 ? a:3 : 0
|
|
1592 if nr > 20 | retu {} | en
|
|
1593 if match(a:str, a:pat, st) >= 0
|
|
1594 let [mst, mnd] = [matchstr(a:str, a:pat, st), matchend(a:str, a:pat, st)]
|
|
1595 cal extend(lens, { nr : [strlen(mst), mst] })
|
|
1596 let lens = s:matchlens(a:str, a:pat, mnd, lens, nr + 1)
|
|
1597 en
|
|
1598 retu lens
|
|
1599 endf
|
|
1600
|
|
1601 fu! s:shortest(lens)
|
|
1602 retu min(map(values(a:lens), 'v:val[0]'))
|
|
1603 endf
|
|
1604
|
|
1605 fu! s:mixedsort2(ct, ...)
|
|
1606 if a:ct == 'buf'
|
|
1607 let pat = '[\/]\?\[\d\+\*No Name\]$'
|
|
1608 if a:1 =~# pat && a:2 =~# pat | retu 0
|
|
1609 elsei a:1 =~# pat | retu 1
|
|
1610 elsei a:2 =~# pat | retu -1 | en
|
|
1611 en
|
|
1612 let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
|
|
1613 if s:ispath
|
|
1614 let ms = []
|
|
1615 if s:res_count < 21
|
|
1616 let ms += [s:compfnlen(a:1, a:2)]
|
|
1617 if a:ct !~ '^\(buf\|mru\)$' | let ms += [s:comptime(a:1, a:2)] | en
|
|
1618 if !s:itemtype | let ms += [s:comparent(a:1, a:2)] | en
|
|
1619 en
|
|
1620 if a:ct =~ '^\(buf\|mru\)$'
|
|
1621 let ms += [s:compmref(a:1, a:2)]
|
|
1622 let cln = cml ? cln : 0
|
|
1623 en
|
|
1624 let ms += [cml, 0, 0, 0]
|
|
1625 let mp = call('s:multipliers', ms[:3])
|
|
1626 retu cln + ms[0] * mp[0] + ms[1] * mp[1] + ms[2] * mp[2] + ms[3] * mp[3]
|
|
1627 en
|
|
1628 retu cln + cml * 2
|
|
1629 endf
|
|
1630
|
|
1631 fu! s:mixedsort(...)
|
|
1632 let ct = s:curtype()
|
|
1633 if ct == 'buf'
|
|
1634 let pat = '[\/]\?\[\d\+\*No Name\]$'
|
|
1635 if a:1 =~# pat && a:2 =~# pat | retu 0
|
|
1636 elsei a:1 =~# pat | retu 1
|
|
1637 elsei a:2 =~# pat | retu -1 | en
|
|
1638 en
|
|
1639 let [cln, cml] = [ctrlp#complen(a:1, a:2), s:compmatlen(a:1, a:2)]
|
|
1640 if s:ispath
|
|
1641 let ms = []
|
|
1642 if s:res_count < 21
|
|
1643 let ms += [s:compfnlen(a:1, a:2)]
|
|
1644 if ct !~ '^\(buf\|mru\)$' | let ms += [s:comptime(a:1, a:2)] | en
|
|
1645 if !s:itemtype | let ms += [s:comparent(a:1, a:2)] | en
|
|
1646 en
|
|
1647 if ct =~ '^\(buf\|mru\)$'
|
|
1648 let ms += [s:compmref(a:1, a:2)]
|
|
1649 let cln = cml ? cln : 0
|
|
1650 en
|
|
1651 let ms += [cml, 0, 0, 0]
|
|
1652 let mp = call('s:multipliers', ms[:3])
|
|
1653 retu cln + ms[0] * mp[0] + ms[1] * mp[1] + ms[2] * mp[2] + ms[3] * mp[3]
|
|
1654 en
|
|
1655 retu cln + cml * 2
|
|
1656 endf
|
|
1657
|
|
1658 fu! s:multipliers(...)
|
|
1659 let mp0 = !a:1 ? 0 : 2
|
|
1660 let mp1 = !a:2 ? 0 : 1 + ( !mp0 ? 1 : mp0 )
|
|
1661 let mp2 = !a:3 ? 0 : 1 + ( !( mp0 + mp1 ) ? 1 : ( mp0 + mp1 ) )
|
|
1662 let mp3 = !a:4 ? 0 : 1 + ( !( mp0 + mp1 + mp2 ) ? 1 : ( mp0 + mp1 + mp2 ) )
|
|
1663 retu [mp0, mp1, mp2, mp3]
|
|
1664 endf
|
|
1665
|
|
1666 fu! s:compval(...)
|
|
1667 retu a:1 - a:2
|
|
1668 endf
|
|
1669 " Statusline {{{2
|
|
1670 fu! ctrlp#statusline()
|
|
1671 if !exists('s:statypes')
|
|
1672 let s:statypes = copy(s:coretypes)
|
|
1673 if !empty(g:ctrlp_ext_vars)
|
|
1674 cal map(copy(g:ctrlp_ext_vars),
|
|
1675 \ 'add(s:statypes, [ v:val["lname"], v:val["sname"] ])')
|
|
1676 en
|
|
1677 en
|
|
1678 let tps = s:statypes
|
|
1679 let max = len(tps) - 1
|
|
1680 let nxt = tps[s:walker(max, s:itemtype, 1)][1]
|
|
1681 let prv = tps[s:walker(max, s:itemtype, -1)][1]
|
|
1682 let s:ctype = tps[s:itemtype][0]
|
|
1683 let focus = s:focus ? 'prt' : 'win'
|
|
1684 let byfname = s:ispath ? s:byfname ? 'file' : 'path' : 'line'
|
|
1685 let marked = s:opmul != '0' ?
|
|
1686 \ exists('s:marked') ? ' <'.s:dismrk().'>' : ' <->' : ''
|
|
1687 if s:status != {}
|
|
1688 let argms =
|
|
1689 \ get(s:status, 'arg_type', '') == 'dict' ? [{
|
|
1690 \ 'focus': focus,
|
|
1691 \ 'byfname': byfname,
|
|
1692 \ 'regex': s:regexp,
|
|
1693 \ 'prev': prv,
|
|
1694 \ 'item': s:ctype,
|
|
1695 \ 'next': nxt,
|
|
1696 \ 'marked': marked,
|
|
1697 \ }] : [focus, byfname, s:regexp, prv, s:ctype, nxt, marked]
|
|
1698 let &l:stl = call(s:status['main'], argms, s:status)
|
|
1699 el
|
|
1700 let item = '%#CtrlPMode1# '.s:ctype.' %*'
|
|
1701 let focus = '%#CtrlPMode2# '.focus.' %*'
|
|
1702 let byfname = '%#CtrlPMode1# '.byfname.' %*'
|
|
1703 let regex = s:regexp ? '%#CtrlPMode2# regex %*' : ''
|
|
1704 let slider = ' <'.prv.'>={'.item.'}=<'.nxt.'>'
|
|
1705 let dir = ' %=%<%#CtrlPMode2# %{getcwd()} %*'
|
|
1706 let &l:stl = focus.byfname.regex.slider.marked.dir
|
|
1707 if exists('s:timer')
|
|
1708 let &l:stl = '%#CtrlPStats# '.len(g:ctrlp_allfiles).' '.&l:stl
|
|
1709 en
|
|
1710 en
|
|
1711 endf
|
|
1712
|
|
1713 fu! s:dismrk()
|
|
1714 retu has('signs') ? len(s:marked) :
|
|
1715 \ '%<'.join(values(map(copy(s:marked), 'split(v:val, "[\\/]")[-1]')), ', ')
|
|
1716 endf
|
|
1717
|
|
1718 fu! ctrlp#progress(enum, ...)
|
|
1719 if has('macunix') || has('mac') | sl 1m | en
|
|
1720 let txt = a:0 ? '(press ctrl-c to abort)' : ''
|
|
1721 if s:status != {}
|
|
1722 let argms = get(s:status, 'arg_type', '') == 'dict'
|
|
1723 \ ? [{ 'str': a:enum }] : [a:enum]
|
|
1724 let &l:stl = call(s:status['prog'], argms, s:status)
|
|
1725 el
|
|
1726 let &l:stl = '%#CtrlPStats# '.a:enum.' %* '.txt.'%=%<%#CtrlPMode2# %{getcwd()} %*'
|
|
1727 en
|
|
1728 redraws
|
|
1729 endf
|
|
1730 " *** Paths {{{2
|
|
1731 " Line formatting {{{3
|
|
1732 fu! s:formatline(str)
|
|
1733 let str = a:str
|
|
1734 let ct = s:curtype()
|
|
1735 if ct == 'buf'
|
|
1736 let bufnr = s:bufnrfilpath(str)[0]
|
|
1737 let parts = s:bufparts(bufnr)
|
|
1738 let str = printf('%'.s:bufnr_width.'s', bufnr)
|
|
1739 if s:has_conceal && has('syntax_items')
|
|
1740 let str .= printf(' %-13s %s%-36s',
|
|
1741 \ '<bi>'.parts[0].'</bi>',
|
|
1742 \ '<bn>'.parts[1], '{'.parts[2].'}</bn>')
|
|
1743 if (!empty(s:bufpath_mod))
|
|
1744 let str .= printf(' %s', '<bp>'.parts[3].'</bp>')
|
|
1745 en
|
|
1746 el
|
|
1747 let str .= printf(' %-5s %-30s',
|
|
1748 \ parts[0],
|
|
1749 \ parts[2])
|
|
1750 if (!empty(s:bufpath_mod))
|
|
1751 let str .= printf(' %s', parts[3])
|
|
1752 en
|
|
1753 en
|
|
1754 en
|
|
1755 let cond = ct != 'buf' &&s:ispath && ( s:winw - 4 ) < s:strwidth(str)
|
|
1756 retu s:lineprefix.( cond ? s:pathshorten(str) : str )
|
|
1757 endf
|
|
1758
|
|
1759 fu! s:formatline2(ct, key, str)
|
|
1760 let str = a:str
|
|
1761 if a:ct == 'buf'
|
|
1762 let bufnr = s:bufnrfilpath(str)[0]
|
|
1763 let parts = s:bufparts(bufnr)
|
|
1764 let str = printf('%'.s:bufnr_width.'s', bufnr)
|
|
1765 if s:has_conceal && has('syntax_items')
|
|
1766 let str .= printf(' %-13s %s%-36s',
|
|
1767 \ '<bi>'.parts[0].'</bi>',
|
|
1768 \ '<bn>'.parts[1], '{'.parts[2].'}</bn>')
|
|
1769 if (!empty(s:bufpath_mod))
|
|
1770 let str .= printf(' %s', '<bp>'.parts[3].'</bp>')
|
|
1771 en
|
|
1772 el
|
|
1773 let str .= printf(' %-5s %-30s',
|
|
1774 \ parts[0],
|
|
1775 \ parts[2])
|
|
1776 if (!empty(s:bufpath_mod))
|
|
1777 let str .= printf(' %s', parts[3])
|
|
1778 en
|
|
1779 en
|
|
1780 retu s:lineprefix.str
|
|
1781 en
|
|
1782 let cond = s:ispath && ( s:winw - 4 ) < strchars(str)
|
|
1783 retu s:lineprefix.( cond ? s:pathshorten(str) : str )
|
|
1784 endf
|
|
1785
|
|
1786 if exists('*strchars') && exists('*strcharpart')
|
|
1787 fu! s:pathshorten(str)
|
|
1788 retu strcharpart(a:str, 0, 9).'...'.strcharpart(a:str, strchars(a:str) - s:winw + 16)
|
|
1789 endf
|
|
1790 el
|
|
1791 fu! s:pathshorten(str)
|
|
1792 retu matchstr(a:str, '^.\{9}').'...'
|
|
1793 \ .matchstr(a:str, '.\{'.( s:winw - 16 ).'}$')
|
|
1794 endf
|
|
1795 en
|
|
1796
|
|
1797 fu! s:offset(lines, height)
|
|
1798 let s:offset = s:mw_order == 'btt' ? ( a:height - s:res_count ) : 0
|
|
1799 retu s:offset > 0 ? ( repeat([''], s:offset) + a:lines ) : a:lines
|
|
1800 endf
|
|
1801 " Directory completion {{{3
|
|
1802 fu! s:dircompl(be, sd)
|
|
1803 if a:sd == '' | retu [] | en
|
|
1804 if a:be == ''
|
|
1805 let [be, sd] = [s:dyncwd, a:sd]
|
|
1806 el
|
|
1807 let be = a:be.s:lash(a:be)
|
|
1808 let sd = be.a:sd
|
|
1809 en
|
|
1810 let dirs = split(globpath(s:fnesc(be, 'g', ','), a:sd.'*/'), "\n")
|
|
1811 if a:be == ''
|
|
1812 let dirs = ctrlp#rmbasedir(dirs)
|
|
1813 en
|
|
1814 cal filter(dirs, '!match(v:val, escape(sd, ''~$.\''))'
|
|
1815 \ . ' && v:val !~ ''\v(^|[\/])\.{1,2}[\/]$''')
|
|
1816 retu dirs
|
|
1817 endf
|
|
1818
|
|
1819 fu! s:findcommon(items, seed)
|
|
1820 let [items, id, cmn, ic] = [copy(a:items), strlen(a:seed), '', 0]
|
|
1821 cal map(items, 'strpart(v:val, id)')
|
|
1822 for char in split(items[0], '\zs')
|
|
1823 for item in items[1:]
|
|
1824 if item[ic] != char | let brk = 1 | brea | en
|
|
1825 endfo
|
|
1826 if exists('brk') | brea | en
|
|
1827 let cmn .= char
|
|
1828 let ic += 1
|
|
1829 endfo
|
|
1830 retu cmn
|
|
1831 endf
|
|
1832 " Misc {{{3
|
|
1833 fu! s:headntail(str)
|
|
1834 let parts = split(a:str, '[\/]\ze[^\/]\+[\/:]\?$')
|
|
1835 retu len(parts) == 1 ? ['', parts[0]] : len(parts) == 2 ? parts : []
|
|
1836 endf
|
|
1837
|
|
1838 fu! s:lash(...)
|
|
1839 retu ( a:0 ? a:1 : s:dyncwd ) !~ '[\/]$' ? s:lash : ''
|
|
1840 endf
|
|
1841
|
|
1842 fu! s:ispathitem()
|
|
1843 retu s:itemtype < len(s:coretypes) || s:getextvar('type') == 'path'
|
|
1844 endf
|
|
1845
|
|
1846 fu! ctrlp#igncwd(cwd)
|
|
1847 retu ctrlp#utils#glob(a:cwd, 0) == '' ||
|
|
1848 \ ( s:igntype >= 0 && s:usrign(a:cwd, getftype(a:cwd)) )
|
|
1849 endf
|
|
1850
|
|
1851 fu! ctrlp#dirnfile(entries)
|
|
1852 let [items, cwd] = [[[], []], s:dyncwd.s:lash()]
|
|
1853 for each in a:entries
|
|
1854 let etype = getftype(each)
|
|
1855 if s:igntype >= 0 && s:usrign(each, etype) | con | en
|
|
1856 if etype == 'dir'
|
|
1857 if s:showhidden | if each !~ '[\/]\.\{1,2}$'
|
|
1858 let items[0] += [each]
|
|
1859 en | el
|
|
1860 let items[0] += [each]
|
|
1861 en
|
|
1862 elsei etype == 'link'
|
|
1863 if s:folsym
|
|
1864 let isfile = !isdirectory(each)
|
|
1865 if s:folsym == 2 || !s:samerootsyml(each, isfile, cwd)
|
|
1866 let items[isfile] += [each]
|
|
1867 en
|
|
1868 en
|
|
1869 elsei etype == 'file'
|
|
1870 let items[1] += [each]
|
|
1871 en
|
|
1872 endfo
|
|
1873 retu items
|
|
1874 endf
|
|
1875
|
|
1876 fu! s:usrign(item, type)
|
|
1877 if s:igntype == 1 | retu a:item =~ s:usrign | en
|
|
1878 if s:igntype == 2 | retu call(s:usrign, [a:item, a:type]) | en
|
|
1879 if s:igntype == 4
|
|
1880 if get(s:usrign, a:type, '') != ''
|
|
1881 retu a:item =~ s:usrign[a:type]
|
|
1882 elsei get(s:usrign, 'func', '') != ''
|
|
1883 retu call(s:usrign['func'], [a:item, a:type])
|
|
1884 en
|
|
1885 en
|
|
1886 retu 0
|
|
1887 endf
|
|
1888
|
|
1889 fu! s:samerootsyml(each, isfile, cwd)
|
|
1890 let resolve = fnamemodify(resolve(a:each), ':p:h')
|
|
1891 let resolve .= s:lash(resolve)
|
|
1892 retu !( stridx(resolve, a:cwd) && ( stridx(a:cwd, resolve) || a:isfile ) )
|
|
1893 endf
|
|
1894
|
|
1895 fu! ctrlp#rmbasedir(items)
|
|
1896 if a:items == []
|
|
1897 retu a:items
|
|
1898 en
|
|
1899 let cwd = s:dyncwd.s:lash()
|
|
1900 let first = a:items[0]
|
|
1901 if has('win32') || has('win64')
|
|
1902 let cwd = tr(cwd, '\', '/')
|
|
1903 let first = tr(first, '\', '/')
|
|
1904 en
|
|
1905 if !stridx(first, cwd)
|
|
1906 let idx = strlen(cwd)
|
|
1907 retu map(a:items, 'strpart(v:val, idx)')
|
|
1908 en
|
|
1909 retu a:items
|
|
1910 endf
|
|
1911 " Working directory {{{3
|
|
1912 fu! s:getparent(item)
|
|
1913 let parent = substitute(a:item, '[\/][^\/]\+[\/:]\?$', '', '')
|
|
1914 if parent == '' || parent !~ '[\/]'
|
|
1915 let parent .= s:lash
|
|
1916 en
|
|
1917 retu parent
|
|
1918 endf
|
|
1919
|
|
1920 fu! s:findroot(curr, mark, depth, type)
|
|
1921 let [depth, fnd] = [a:depth + 1, 0]
|
|
1922 if type(a:mark) == 1
|
|
1923 let fnd = s:glbpath(s:fnesc(a:curr, 'g', ','), a:mark, 1) != ''
|
|
1924 elsei type(a:mark) == 3
|
|
1925 for markr in a:mark
|
|
1926 if s:glbpath(s:fnesc(a:curr, 'g', ','), markr, 1) != ''
|
|
1927 let fnd = 1
|
|
1928 brea
|
|
1929 en
|
|
1930 endfo
|
|
1931 en
|
|
1932 if fnd
|
|
1933 if !a:type | cal ctrlp#setdir(a:curr) | en
|
|
1934 retu [exists('markr') ? markr : a:mark, a:curr]
|
|
1935 elsei depth > s:maxdepth
|
|
1936 cal ctrlp#setdir(s:cwd)
|
|
1937 el
|
|
1938 let parent = s:getparent(a:curr)
|
|
1939 if parent != a:curr
|
|
1940 retu s:findroot(parent, a:mark, depth, a:type)
|
|
1941 en
|
|
1942 en
|
|
1943 retu []
|
|
1944 endf
|
|
1945
|
|
1946 fu! ctrlp#setpathmode(pmode, ...)
|
|
1947 if a:pmode == 'c' || ( a:pmode == 'a' && stridx(s:crfpath, s:cwd) < 0 )
|
|
1948 if exists('+acd') | let [s:glb_acd, &acd] = [&acd, 0] | en
|
|
1949 cal ctrlp#setdir(s:crfpath)
|
|
1950 retu 1
|
|
1951 elsei a:pmode == 'r'
|
|
1952 let spath = a:0 ? a:1 : s:crfpath
|
|
1953 let markers = ['.git', '.hg', '.svn', '.bzr', '_darcs']
|
|
1954 if type(s:rmarkers) == 3 && !empty(s:rmarkers)
|
|
1955 if s:findroot(spath, s:rmarkers, 0, 0) != [] | retu 1 | en
|
|
1956 cal filter(markers, 'index(s:rmarkers, v:val) < 0')
|
|
1957 let markers = s:rmarkers + markers
|
|
1958 en
|
|
1959 if s:findroot(spath, markers, 0, 0) != [] | retu 1 | en
|
|
1960 en
|
|
1961 retu 0
|
|
1962 endf
|
|
1963
|
|
1964 fu! ctrlp#setdir(path, ...)
|
|
1965 let cmd = a:0 ? a:1 : 'lc!'
|
|
1966 sil! exe cmd s:fnesc(a:path, 'c')
|
|
1967 let [s:crfilerel, s:dyncwd] = [fnamemodify(s:crfile, ':.'), getcwd()]
|
|
1968 endf
|
|
1969 " Fallbacks {{{3
|
|
1970 fu! s:glbpath(...)
|
|
1971 retu call('ctrlp#utils#globpath', a:000)
|
|
1972 endf
|
|
1973
|
|
1974 fu! s:fnesc(...)
|
|
1975 retu call('ctrlp#utils#fnesc', a:000)
|
|
1976 endf
|
|
1977
|
|
1978 fu! ctrlp#setlcdir()
|
|
1979 if exists('*haslocaldir')
|
|
1980 cal ctrlp#setdir(getcwd(), haslocaldir() ? 'lc!' : 'cd!')
|
|
1981 en
|
|
1982 endf
|
|
1983 " Highlighting {{{2
|
|
1984 fu! ctrlp#syntax()
|
|
1985 if ctrlp#nosy() | retu | en
|
|
1986 for [ke, va] in items(s:hlgrps) | cal ctrlp#hicheck('CtrlP'.ke, va) | endfo
|
|
1987 let bgColor=synIDattr(synIDtrans(hlID('Normal')), 'bg')
|
|
1988 if bgColor !~ '^-1$\|^$'
|
|
1989 sil! exe 'hi CtrlPLinePre guifg='.bgColor.' ctermfg='.bgColor
|
|
1990 en
|
|
1991 sy match CtrlPNoEntries '^ == NO ENTRIES ==$'
|
|
1992 if hlexists('CtrlPLinePre')
|
|
1993 exe "sy match CtrlPLinePre '^".escape(get(g:, 'ctrlp_line_prefix', '>'),'^$.*~\')."'"
|
|
1994 en
|
|
1995
|
|
1996 if s:curtype() == 'buf' && s:has_conceal
|
|
1997 sy region CtrlPBufferNr matchgroup=CtrlPLinePre start='^>\s\+' end='\s'
|
|
1998 sy region CtrlPBufferInd concealends matchgroup=Ignore start='<bi>' end='</bi>'
|
|
1999 sy region CtrlPBufferRegion concealends matchgroup=Ignore start='<bn>' end='</bn>'
|
|
2000 \ contains=CtrlPBufferHid,CtrlPBufferHidMod,CtrlPBufferVis,CtrlPBufferVisMod,CtrlPBufferCur,CtrlPBufferCurMod
|
|
2001 sy region CtrlPBufferHid concealends matchgroup=Ignore start='\s*{' end='}' contained
|
|
2002 sy region CtrlPBufferHidMod concealends matchgroup=Ignore start='+\s*{' end='}' contained
|
|
2003 sy region CtrlPBufferVis concealends matchgroup=Ignore start='\*\s*{' end='}' contained
|
|
2004 sy region CtrlPBufferVisMod concealends matchgroup=Ignore start='\*+\s*{' end='}' contained
|
|
2005 sy region CtrlPBufferCur concealends matchgroup=Ignore start='\*!\s*{' end='}' contained
|
|
2006 sy region CtrlPBufferCurMod concealends matchgroup=Ignore start='\*+!\s*{' end='}' contained
|
|
2007 sy region CtrlPBufferPath concealends matchgroup=Ignore start='<bp>' end='</bp>'
|
|
2008 en
|
|
2009 endf
|
|
2010
|
|
2011 fu! s:highlight(pat, grp)
|
|
2012 if s:matcher != {} | retu | en
|
|
2013 cal clearmatches()
|
|
2014 if !empty(a:pat) && s:ispath
|
|
2015 if s:regexp
|
|
2016 let pat = substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g')
|
|
2017 cal matchadd(a:grp, ( s:martcs == '' ? '\c' : '\C' ).pat)
|
|
2018 el
|
|
2019 let pat = a:pat
|
|
2020
|
|
2021 " get original characters so we can rebuild pat
|
|
2022 let chars = split(pat, '\[\^\\\?.\]\\{-}')
|
|
2023
|
|
2024 " Build a pattern like /a.*b.*c/ from abc (but with .\{-} non-greedy
|
|
2025 " matchers instead)
|
|
2026 let pat = join(chars, '.\{-}')
|
|
2027 " Ensure we match the last version of our pattern
|
|
2028 let ending = '\(.*'.pat.'\)\@!'
|
|
2029 " Case sensitive?
|
|
2030 let beginning = ( s:martcs == '' ? '\c' : '\C' ).'^.*'
|
|
2031 if s:byfname()
|
|
2032 " Make sure there are no slashes in our match
|
|
2033 let beginning = beginning.'\([^\/]*$\)\@='
|
|
2034 en
|
|
2035
|
|
2036 for i in range(len(chars))
|
|
2037 " Surround our current target letter with \zs and \ze so it only
|
|
2038 " actually matches that one letter, but has all preceding and trailing
|
|
2039 " letters as well.
|
|
2040 " \zsa.*b.*c
|
|
2041 " a\(\zsb\|.*\zsb)\ze.*c
|
|
2042 let charcopy = copy(chars)
|
|
2043 if i == 0
|
|
2044 let charcopy[i] = '\zs'.charcopy[i].'\ze'
|
|
2045 let middle = join(charcopy, '.\{-}')
|
|
2046 el
|
|
2047 let before = join(charcopy[0:i-1], '.\{-}')
|
|
2048 let after = join(charcopy[i+1:-1], '.\{-}')
|
|
2049 let c = charcopy[i]
|
|
2050 " for abc, match either ab.\{-}c or a.*b.\{-}c in that order
|
|
2051 let cpat = '\(\zs'.c.'\|'.'.*\zs'.c.'\)\ze.*'
|
|
2052 let middle = before.cpat.after
|
|
2053 en
|
|
2054
|
|
2055 " Now we matchadd for each letter, the basic form being:
|
|
2056 " ^.*\zsx\ze.*$, but with our pattern we built above for the letter,
|
|
2057 " and a negative lookahead ensuring that we only highlight the last
|
|
2058 " occurrence of our letters. We also ensure that our matcher is case
|
|
2059 " insensitive or sensitive depending.
|
|
2060 cal matchadd(a:grp, beginning.middle.ending)
|
|
2061 endfo
|
|
2062 en
|
|
2063
|
|
2064 cal matchadd('CtrlPLinePre', '^>')
|
|
2065 elseif !empty(a:pat) && s:regexp &&
|
|
2066 \ exists('g:ctrlp_regex_always_higlight') &&
|
|
2067 \ g:ctrlp_regex_always_higlight
|
|
2068 let pat = substitute(a:pat, '\\\@<!\^', '^> \\zs', 'g')
|
|
2069 cal matchadd(a:grp, ( s:martcs == '' ? '\c' : '\C').pat)
|
|
2070 en
|
|
2071 endf
|
|
2072
|
|
2073 fu! s:dohighlight()
|
|
2074 retu s:mathi[0] && exists('*clearmatches') && !ctrlp#nosy()
|
|
2075 endf
|
|
2076 " Prompt history {{{2
|
|
2077 fu! s:gethistloc()
|
|
2078 let utilcadir = ctrlp#utils#cachedir()
|
|
2079 let cache_dir = utilcadir.s:lash(utilcadir).'hist'
|
|
2080 retu [cache_dir, cache_dir.s:lash(cache_dir).'cache.txt']
|
|
2081 endf
|
|
2082
|
|
2083 fu! s:gethistdata()
|
|
2084 retu ctrlp#utils#readfile(s:gethistloc()[1])
|
|
2085 endf
|
|
2086
|
|
2087 fu! ctrlp#recordhist()
|
|
2088 let str = join(s:prompt, '')
|
|
2089 if empty(str) || !s:maxhst | retu | en
|
|
2090 let hst = s:hstry
|
|
2091 if len(hst) > 1 && hst[1] == str | retu | en
|
|
2092 cal extend(hst, [str], 1)
|
|
2093 if len(hst) > s:maxhst | cal remove(hst, s:maxhst, -1) | en
|
|
2094 cal ctrlp#utils#writecache(hst, s:gethistloc()[0], s:gethistloc()[1])
|
|
2095 endf
|
|
2096 " Signs {{{2
|
|
2097 fu! s:unmarksigns()
|
|
2098 if !s:dosigns() | retu | en
|
|
2099 for key in keys(s:marked)
|
|
2100 exe 'sign unplace' key 'buffer='.s:bufnr
|
|
2101 endfo
|
|
2102 endf
|
|
2103
|
|
2104 fu! s:remarksigns()
|
|
2105 if !s:dosigns() | retu | en
|
|
2106 for ic in range(1, len(s:lines))
|
|
2107 let line = s:ispath ? fnamemodify(s:lines[ic - 1], ':p') : s:lines[ic - 1]
|
|
2108 let key = s:dictindex(s:marked, line)
|
|
2109 if key > 0
|
|
2110 exe 'sign place' key 'line='.ic.' name=ctrlpmark buffer='.s:bufnr
|
|
2111 en
|
|
2112 endfo
|
|
2113 endf
|
|
2114
|
|
2115 fu! s:dosigns()
|
|
2116 retu exists('s:marked') && s:bufnr > 0 && s:opmul != '0' && has('signs')
|
|
2117 endf
|
|
2118 " Lists & Dictionaries {{{2
|
|
2119 fu! s:ifilter(list, str)
|
|
2120 let [rlist, estr] = [[], substitute(a:str, 'v:val', 'each', 'g')]
|
|
2121 for each in a:list
|
|
2122 try
|
|
2123 if eval(estr)
|
|
2124 let rlist += [each]
|
|
2125 en
|
|
2126 cat | con | endt
|
|
2127 endfo
|
|
2128 retu rlist
|
|
2129 endf
|
|
2130
|
|
2131 fu! s:dictindex(dict, expr)
|
|
2132 for key in keys(a:dict)
|
|
2133 if a:dict[key] ==# a:expr | retu key | en
|
|
2134 endfo
|
|
2135 retu -1
|
|
2136 endf
|
|
2137
|
|
2138 fu! s:vacantdict(dict)
|
|
2139 retu filter(range(1, max(keys(a:dict))), '!has_key(a:dict, v:val)')
|
|
2140 endf
|
|
2141
|
|
2142 fu! s:sublist(l, s, e)
|
|
2143 retu v:version > 701 ? a:l[(a:s):(a:e)] : s:sublist7071(a:l, a:s, a:e)
|
|
2144 endf
|
|
2145
|
|
2146 fu! s:sublist7071(l, s, e)
|
|
2147 let [newlist, id, ae] = [[], a:s, a:e == -1 ? len(a:l) - 1 : a:e]
|
|
2148 wh id <= ae
|
|
2149 let newlist += [get(a:l, id)]
|
|
2150 let id += 1
|
|
2151 endw
|
|
2152 retu newlist
|
|
2153 endf
|
|
2154 " Buffers {{{2
|
|
2155 fu! s:buftab(bufnr, md)
|
|
2156 for tabnr in range(1, tabpagenr('$'))
|
|
2157 if tabpagenr() == tabnr && a:md == 't' | con | en
|
|
2158 let buflist = tabpagebuflist(tabnr)
|
|
2159 if index(buflist, a:bufnr) >= 0
|
|
2160 for winnr in range(1, tabpagewinnr(tabnr, '$'))
|
|
2161 if buflist[winnr - 1] == a:bufnr | retu [tabnr, winnr] | en
|
|
2162 endfo
|
|
2163 en
|
|
2164 endfo
|
|
2165 retu [0, 0]
|
|
2166 endf
|
|
2167
|
|
2168 fu! s:bufwins(bufnr)
|
|
2169 let winns = 0
|
|
2170 for tabnr in range(1, tabpagenr('$'))
|
|
2171 let winns += count(tabpagebuflist(tabnr), a:bufnr)
|
|
2172 endfo
|
|
2173 retu winns
|
|
2174 endf
|
|
2175
|
|
2176 fu! s:isabs(path)
|
|
2177 if (has('win32') || has('win64'))
|
|
2178 retu a:path =~ '^\([a-zA-Z]:\)\{-}[/\\]'
|
|
2179 el
|
|
2180 retu a:path =~ '^[/\\]'
|
|
2181 en
|
|
2182 endf
|
|
2183
|
|
2184 fu! s:bufnrfilpath(line)
|
739
|
2185 if s:isabs(a:line) || a:line =~ '^\~[/\\]' || a:line =~ '^\w\+:\/\/'
|
707
|
2186 let filpath = a:line
|
|
2187 el
|
|
2188 let filpath = s:dyncwd.s:lash().a:line
|
|
2189 en
|
|
2190 let filpath = fnamemodify(filpath, ':p')
|
|
2191 let bufnr = bufnr('^'.fnameescape(filpath).'$')
|
|
2192 if (!filereadable(filpath) && bufnr < 1)
|
|
2193 if (a:line =~ '[\/]\?\[\d\+\*No Name\]$')
|
|
2194 let bufnr = str2nr(matchstr(a:line, '[\/]\?\[\zs\d\+\ze\*No Name\]$'))
|
|
2195 let filpath = bufnr
|
|
2196 els
|
|
2197 let bufnr = bufnr(a:line)
|
|
2198 retu [bufnr, a:line]
|
|
2199 en
|
|
2200 en
|
|
2201 retu [bufnr, filpath]
|
|
2202 endf
|
|
2203
|
|
2204 fu! ctrlp#normcmd(cmd, ...)
|
|
2205 let buftypes = [ 'quickfix', 'help', 'nofile' ]
|
|
2206 if a:0 < 2 && s:nosplit() | retu a:cmd | en
|
|
2207 let norwins = filter(range(1, winnr('$')),
|
|
2208 \ 'index(buftypes, getbufvar(winbufnr(v:val), "&bt")) == -1 || s:isterminal(winbufnr(v:val))')
|
|
2209 for each in norwins
|
|
2210 let bufnr = winbufnr(each)
|
|
2211 if empty(bufname(bufnr)) && empty(getbufvar(bufnr, '&ft'))
|
|
2212 let fstemp = each | brea
|
|
2213 en
|
|
2214 endfo
|
|
2215 let norwin = empty(norwins) ? 0 : norwins[0]
|
|
2216 if norwin
|
|
2217 if index(norwins, winnr()) < 0
|
|
2218 exe ( exists('fstemp') ? fstemp : norwin ).'winc w'
|
|
2219 en
|
|
2220 retu a:cmd
|
|
2221 en
|
|
2222 retu a:0 ? a:1 : 'bo vne'
|
|
2223 endf
|
|
2224
|
|
2225 fu! ctrlp#modfilecond(w)
|
|
2226 retu &mod && !&hid && &bh != 'hide' && s:bufwins(bufnr('%')) == 1 && !&cf &&
|
|
2227 \ ( ( !&awa && a:w ) || filewritable(fnamemodify(bufname('%'), ':p')) != 1 )
|
|
2228 endf
|
|
2229
|
|
2230 fu! s:nosplit()
|
|
2231 retu !empty(s:nosplit) && match([bufname('%'), &l:ft, &l:bt], s:nosplit) >= 0
|
|
2232 endf
|
|
2233
|
|
2234 fu! s:setupblank()
|
|
2235 setl noswf nonu nobl nowrap nolist nospell nocuc wfh
|
|
2236 setl fdc=0 fdl=99 tw=0 bt=nofile bh=unload
|
|
2237 if v:version > 702
|
|
2238 setl nornu noudf cc=0
|
|
2239 en
|
|
2240 if s:has_conceal
|
|
2241 setl cole=2 cocu=nc
|
|
2242 en
|
|
2243 endf
|
|
2244
|
|
2245 fu! s:leavepre()
|
|
2246 if exists('s:bufnr') && s:bufnr == bufnr('%') | bw! | en
|
|
2247 if !( exists(s:ccex) && !{s:ccex} )
|
|
2248 \ && !( has('clientserver') && len(split(serverlist(), "\n")) > 1 )
|
|
2249 cal ctrlp#clra()
|
|
2250 en
|
|
2251 endf
|
|
2252
|
|
2253 fu! s:checkbuf()
|
|
2254 if !exists('s:init') && exists('s:bufnr') && s:bufnr > 0
|
|
2255 exe s:bufnr.'bw!'
|
|
2256 en
|
|
2257 endf
|
|
2258
|
|
2259 fu! s:iscmdwin()
|
|
2260 let [ermsg, v:errmsg] = [v:errmsg, '']
|
|
2261 sil! noa winc p
|
|
2262 sil! noa winc p
|
|
2263 let [v:errmsg, ermsg] = [ermsg, v:errmsg]
|
|
2264 retu ermsg =~ '^E11:'
|
|
2265 endf
|
|
2266 " Arguments {{{2
|
|
2267 fu! s:at(str)
|
|
2268 if a:str =~ '\v^\@(cd|lc[hd]?|chd).*'
|
|
2269 let str = substitute(a:str, '\v^\@(cd|lc[hd]?|chd)\s*', '', '')
|
|
2270 if str == '' | retu 1 | en
|
|
2271 let str = str =~ '^%:.\+' ? fnamemodify(s:crfile, str[1:]) : str
|
|
2272 let path = fnamemodify(expand(str, 1), ':p')
|
|
2273 if isdirectory(path)
|
|
2274 if path != s:dyncwd
|
|
2275 cal ctrlp#setdir(path)
|
|
2276 cal ctrlp#setlines()
|
|
2277 en
|
|
2278 cal ctrlp#recordhist()
|
|
2279 cal s:PrtClear()
|
|
2280 en
|
|
2281 retu 1
|
|
2282 en
|
|
2283 retu 0
|
|
2284 endf
|
|
2285
|
|
2286 fu! s:tail()
|
|
2287 if exists('s:optail') && !empty('s:optail')
|
|
2288 let tailpref = s:optail !~ '^\s*+' ? ' +' : ' '
|
|
2289 retu tailpref.s:optail
|
|
2290 en
|
|
2291 retu ''
|
|
2292 endf
|
|
2293
|
|
2294 fu! s:sanstail(str)
|
|
2295 let str = s:spi ?
|
|
2296 \ substitute(a:str, '^\(@.*$\|\\\\\ze@\|\.\.\zs[.\/]\+$\)', '', 'g') : a:str
|
|
2297 let [str, pat] = [substitute(str, '\\\\', '\', 'g'), '\([^:]\|\\:\)*$']
|
|
2298 unl! s:optail
|
|
2299 if str =~ '\\\@<!:'.pat
|
|
2300 let s:optail = matchstr(str, '\\\@<!:\zs'.pat)
|
|
2301 let str = substitute(str, '\\\@<!:'.pat, '', '')
|
|
2302 en
|
|
2303 retu substitute(str, '\\\ze:', '', 'g')
|
|
2304 endf
|
|
2305
|
|
2306 fu! s:argmaps(md, i)
|
|
2307 let roh = [
|
|
2308 \ ['Open Multiple Files', '/h[i]dden/[c]lear', ['i', 'c']],
|
|
2309 \ ['Create a New File', '/[r]eplace', ['r']],
|
|
2310 \ ['Open Selected', '/[r]eplace', ['r', 'd', 'a']],
|
|
2311 \ ]
|
|
2312 if a:i == 2
|
|
2313 if !buflisted(bufnr('^'.fnamemodify(ctrlp#getcline(), ':p').'$'))
|
|
2314 let roh[2][1] .= '/h[i]dden'
|
|
2315 let roh[2][2] += ['i']
|
|
2316 en
|
|
2317 if s:openfunc != {} && has_key(s:openfunc, s:ctype)
|
|
2318 let roh[2][1] .= '/e[x]ternal'
|
|
2319 let roh[2][2] += ['x']
|
|
2320 en
|
|
2321 en
|
|
2322 let str = roh[a:i][0].': [t]ab/[v]ertical/[h]orizontal'.roh[a:i][1].'? '
|
|
2323 retu s:choices(str, ['t', 'v', 'h'] + roh[a:i][2], 's:argmaps', [a:md, a:i])
|
|
2324 endf
|
|
2325
|
|
2326 fu! s:insertstr()
|
|
2327 let str = 'Insert: c[w]ord/c[f]ile/[s]earch/[v]isual/[c]lipboard/[r]egister? '
|
|
2328 retu s:choices(str, ['w', 'f', 's', 'v', 'c', 'r'], 's:insertstr', [])
|
|
2329 endf
|
|
2330
|
|
2331 fu! s:textdialog(str)
|
|
2332 redr | echoh MoreMsg | echon a:str | echoh None
|
|
2333 retu nr2char(getchar())
|
|
2334 endf
|
|
2335
|
|
2336 fu! s:choices(str, choices, func, args)
|
|
2337 let char = s:textdialog(a:str)
|
|
2338 if index(a:choices, char) >= 0
|
|
2339 retu char
|
|
2340 elsei char =~# "\\v\<Esc>|\<C-c>|\<C-g>|\<C-u>|\<C-w>|\<C-[>"
|
|
2341 cal s:BuildPrompt(0)
|
|
2342 retu 'cancel'
|
|
2343 elsei char =~# "\<CR>" && a:args != []
|
|
2344 retu a:args[0]
|
|
2345 en
|
|
2346 retu call(a:func, a:args)
|
|
2347 endf
|
|
2348
|
|
2349 fu! s:getregs()
|
|
2350 let char = s:textdialog('Insert from register: ')
|
|
2351 if char =~# "\\v\<Esc>|\<C-c>|\<C-g>|\<C-u>|\<C-w>|\<C-[>"
|
|
2352 cal s:BuildPrompt(0)
|
|
2353 retu -1
|
|
2354 elsei char =~# "\<CR>"
|
|
2355 retu s:getregs()
|
|
2356 en
|
|
2357 retu s:regisfilter(char)
|
|
2358 endf
|
|
2359
|
|
2360 fu! s:regisfilter(reg)
|
|
2361 retu substitute(getreg(a:reg), "[\t\n]", ' ', 'g')
|
|
2362 endf
|
|
2363 " Misc {{{2
|
|
2364 fu! s:modevar()
|
|
2365 let s:matchtype = s:mtype()
|
|
2366 let s:ispath = s:ispathitem()
|
|
2367 let s:mfunc = s:mfunc()
|
|
2368 let s:nolim = s:getextvar('nolim')
|
|
2369 let s:dosort = s:getextvar('sort')
|
|
2370 let s:spi = !s:itemtype || s:getextvar('specinput') > 0
|
|
2371 endf
|
|
2372
|
|
2373 fu! s:nosort()
|
|
2374 let ct = s:curtype()
|
|
2375 retu s:matcher != {} || s:nolim == 1 || ( ct == 'mru' && s:mrudef )
|
|
2376 \ || ( ct =~ '^\(buf\|mru\)$' && s:prompt == ['', '', ''] ) || !s:dosort
|
|
2377 endf
|
|
2378
|
|
2379 fu! s:byfname()
|
|
2380 retu s:curtype() != 'buf' && s:ispath && s:byfname
|
|
2381 endf
|
|
2382
|
|
2383 fu! s:narrowable()
|
|
2384 retu exists('s:act_add') && exists('s:matched') && s:matched != []
|
|
2385 \ && exists('s:mdata') && s:mdata[:2] == [s:dyncwd, s:itemtype, s:regexp]
|
|
2386 \ && s:matcher == {} && !exists('s:did_exp')
|
|
2387 endf
|
|
2388
|
|
2389 fu! s:getinput(...)
|
|
2390 let [prt, spi] = [s:prompt, ( a:0 ? a:1 : '' )]
|
|
2391 if s:abbrev != {}
|
|
2392 let gmd = get(s:abbrev, 'gmode', '')
|
|
2393 let str = ( gmd =~ 't' && !a:0 ) || spi == 'c' ? prt[0] : join(prt, '')
|
|
2394 if gmd =~ 't' && gmd =~ 'k' && !a:0 && matchstr(str, '.$') =~ '\k'
|
|
2395 retu join(prt, '')
|
|
2396 en
|
|
2397 let [pf, rz] = [( s:byfname() ? 'f' : 'p' ), ( s:regexp ? 'r' : 'z' )]
|
|
2398 for dict in s:abbrev['abbrevs']
|
|
2399 let dmd = get(dict, 'mode', '')
|
|
2400 let pat = escape(dict['pattern'], '~')
|
|
2401 if ( dmd == '' || ( dmd =~ pf && dmd =~ rz && !a:0 )
|
|
2402 \ || dmd =~ '['.spi.']' ) && str =~ pat
|
|
2403 let [str, s:did_exp] = [join(split(str, pat, 1), dict['expanded']), 1]
|
|
2404 en
|
|
2405 endfo
|
|
2406 if gmd =~ 't' && !a:0
|
|
2407 let prt[0] = str
|
|
2408 el
|
|
2409 retu str
|
|
2410 en
|
|
2411 en
|
|
2412 retu spi == 'c' ? prt[0] : join(prt, '')
|
|
2413 endf
|
|
2414
|
|
2415 if exists('*strdisplaywidth')
|
|
2416 fu! s:strwidth(str)
|
|
2417 retu strdisplaywidth(a:str)
|
|
2418 endf
|
|
2419 el
|
|
2420 fu! s:strwidth(str)
|
|
2421 retu strlen(a:str)
|
|
2422 endf
|
|
2423 en
|
|
2424
|
|
2425 fu! ctrlp#j2l(nr)
|
|
2426 exe 'norm!' a:nr.'G'
|
|
2427 sil! norm! zvzz
|
|
2428 endf
|
|
2429
|
|
2430 fu! s:maxf(len)
|
|
2431 retu s:maxfiles && a:len > s:maxfiles
|
|
2432 endf
|
|
2433
|
|
2434 fu! s:regexfilter(str)
|
|
2435 let str = a:str
|
|
2436 for key in keys(s:fpats) | if str =~ key
|
|
2437 let str = substitute(str, s:fpats[key], '', 'g')
|
|
2438 en | endfo
|
|
2439 retu str
|
|
2440 endf
|
|
2441
|
|
2442 fu! s:walker(m, p, d)
|
|
2443 retu a:d >= 0 ? a:p < a:m ? a:p + a:d : 0 : a:p > 0 ? a:p + a:d : a:m
|
|
2444 endf
|
|
2445
|
|
2446 fu! s:delent(rfunc)
|
|
2447 if a:rfunc == '' | retu | en
|
|
2448 let [s:force, tbrem] = [1, []]
|
|
2449 if exists('s:marked')
|
|
2450 let tbrem = values(s:marked)
|
|
2451 cal s:unmarksigns()
|
|
2452 unl s:marked
|
|
2453 en
|
|
2454 if tbrem == [] && ( has('dialog_gui') || has('dialog_con') ) &&
|
|
2455 \ confirm("Wipe all entries?", "&OK\n&Cancel") != 1
|
|
2456 unl s:force
|
|
2457 cal s:BuildPrompt(0)
|
|
2458 retu
|
|
2459 en
|
|
2460 let g:ctrlp_lines = call(a:rfunc, [tbrem])
|
|
2461 cal s:BuildPrompt(1)
|
|
2462 unl s:force
|
|
2463 endf
|
|
2464
|
|
2465 fu! s:delbufcond(bufnr)
|
|
2466 retu getbufvar(a:bufnr, "&mod") || a:bufnr == s:crbufnr
|
|
2467 endf
|
|
2468
|
|
2469 fu! s:delbuf()
|
|
2470 let lines = []
|
|
2471 if exists('s:marked')
|
|
2472 let lines = values(s:marked)
|
|
2473 cal s:unmarksigns()
|
|
2474 unl s:marked
|
|
2475 el
|
|
2476 let lines += [ctrlp#getcline()]
|
|
2477 en
|
|
2478 for line in lines
|
|
2479 let bufnr = s:bufnrfilpath(line)[0]
|
|
2480 if (s:delbufcond(bufnr))
|
|
2481 con
|
|
2482 en
|
|
2483 exe 'bd '. bufnr
|
|
2484 endfo
|
|
2485 cal s:PrtClearCache()
|
|
2486 endf
|
|
2487
|
|
2488 fu! s:isterminal(buf)
|
|
2489 retu getbufvar(a:buf, "&bt") == "terminal"
|
|
2490 endf
|
|
2491 " Entering & Exiting {{{2
|
|
2492 fu! s:getenv()
|
|
2493 let [s:cwd, s:winres] = [getcwd(), [winrestcmd(), &lines, winnr('$')]]
|
|
2494 let [s:crword, s:crnbword] = [expand('<cword>', 1), expand('<cWORD>', 1)]
|
|
2495 let [s:crgfile, s:crline] = [expand('<cfile>', 1), getline('.')]
|
|
2496 let [s:winmaxh, s:crcursor] = [min([s:mw_max, &lines]), getpos('.')]
|
|
2497 let [s:crbufnr, s:crvisual] = [bufnr('%'), s:lastvisual()]
|
|
2498 let s:crfile = bufname('%') == ''
|
|
2499 \ ? '['.s:crbufnr.'*No Name]' : expand('%:p', 1)
|
|
2500 let s:crfpath = expand('%:p:h', 1)
|
|
2501 let s:mrbs = ctrlp#mrufiles#bufs()
|
|
2502 endf
|
|
2503
|
|
2504 fu! s:lastvisual()
|
|
2505 let cview = winsaveview()
|
|
2506 let [ovreg, ovtype] = [getreg('v'), getregtype('v')]
|
|
2507 let [oureg, outype] = [getreg('"'), getregtype('"')]
|
|
2508 sil! norm! gV"vy
|
|
2509 let selected = s:regisfilter('v')
|
|
2510 cal setreg('v', ovreg, ovtype)
|
|
2511 cal setreg('"', oureg, outype)
|
|
2512 cal winrestview(cview)
|
|
2513 retu selected
|
|
2514 endf
|
|
2515
|
|
2516 fu! s:log(m)
|
|
2517 if exists('g:ctrlp_log') && g:ctrlp_log | if a:m
|
|
2518 let cadir = ctrlp#utils#cachedir()
|
|
2519 let apd = g:ctrlp_log > 1 ? '>' : ''
|
|
2520 sil! exe 'redi! >'.apd cadir.s:lash(cadir).'ctrlp.log'
|
|
2521 el
|
|
2522 sil! redi END
|
|
2523 en | en
|
|
2524 endf
|
|
2525
|
|
2526 fu! s:buffunc(e)
|
|
2527 if a:e && has_key(s:buffunc, 'enter')
|
|
2528 cal call(s:buffunc['enter'], [], s:buffunc)
|
|
2529 elsei !a:e && has_key(s:buffunc, 'exit')
|
|
2530 cal call(s:buffunc['exit'], [], s:buffunc)
|
|
2531 en
|
|
2532 endf
|
|
2533
|
|
2534 fu! s:openfile(cmd, fid, tail, chkmod, ...)
|
|
2535 let cmd = a:cmd
|
|
2536 if a:chkmod && cmd =~ '^[eb]$' && ctrlp#modfilecond(!( cmd == 'b' && &aw ))
|
|
2537 let cmd = cmd == 'b' ? 'sb' : 'sp'
|
|
2538 en
|
|
2539 let cmd = cmd =~ '^tab' ? ctrlp#tabcount().cmd : cmd
|
|
2540 let j2l = a:0 && a:1[0] ? a:1[1] : 0
|
|
2541 exe cmd.( a:0 && a:1[0] ? '' : a:tail ) s:fnesc(a:fid, 'f')
|
|
2542 if j2l
|
|
2543 cal ctrlp#j2l(j2l)
|
|
2544 en
|
|
2545 if !empty(a:tail)
|
|
2546 sil! norm! zvzz
|
|
2547 en
|
|
2548 if cmd != 'bad'
|
|
2549 cal ctrlp#setlcdir()
|
|
2550 en
|
|
2551 endf
|
|
2552
|
|
2553 fu! ctrlp#tabcount()
|
|
2554 if exists('s:tabct')
|
|
2555 let tabct = s:tabct
|
|
2556 let s:tabct += 1
|
|
2557 elsei !type(s:tabpage)
|
|
2558 let tabct = s:tabpage
|
|
2559 elsei type(s:tabpage) == 1
|
|
2560 let tabpos =
|
|
2561 \ s:tabpage =~ 'c' ? tabpagenr() :
|
|
2562 \ s:tabpage =~ 'f' ? 1 :
|
|
2563 \ s:tabpage =~ 'l' ? tabpagenr('$') :
|
|
2564 \ tabpagenr()
|
|
2565 let tabct =
|
|
2566 \ s:tabpage =~ 'a' ? tabpos :
|
|
2567 \ s:tabpage =~ 'b' ? tabpos - 1 :
|
|
2568 \ tabpos
|
|
2569 en
|
|
2570 retu tabct < 0 ? 0 : tabct
|
|
2571 endf
|
|
2572
|
|
2573 fu! s:settype(type)
|
|
2574 retu a:type < 0 ? exists('s:itemtype') ? s:itemtype : 0 : a:type
|
|
2575 endf
|
|
2576 " Matching {{{2
|
|
2577 fu! s:matchfname(item, pat)
|
|
2578 let parts = split(a:item, '[\/]\ze[^\/]\+$')
|
|
2579 let mfn = match(parts[-1], a:pat[0])
|
|
2580 retu len(a:pat) == 1 ? mfn : len(a:pat) == 2 ?
|
|
2581 \ ( mfn >= 0 && ( len(parts) == 2 ? match(parts[0], a:pat[1]) : -1 ) >= 0
|
|
2582 \ ? 0 : -1 ) : -1
|
|
2583 endf
|
|
2584
|
|
2585 fu! s:matchbuf(item, pat)
|
|
2586 let bufnr = s:bufnrfilpath(a:item)[0]
|
|
2587 let parts = s:bufparts(bufnr)
|
|
2588 let item = s:byfname ? parts[2] : bufnr.parts[0].parts[2].s:lash().parts[3]
|
|
2589 retu match(item, a:pat)
|
|
2590 endf
|
|
2591
|
|
2592 fu! s:matchtabs(item, pat)
|
|
2593 retu match(split(a:item, '\t\+')[0], a:pat)
|
|
2594 endf
|
|
2595
|
|
2596 fu! s:matchtabe(item, pat)
|
|
2597 retu match(split(a:item, '\t\+[^\t]\+$')[0], a:pat)
|
|
2598 endf
|
|
2599
|
|
2600 fu! s:buildpat(lst)
|
|
2601 let pat = a:lst[0]
|
|
2602 if s:matchnatural == 1
|
|
2603 for item in range(1, len(a:lst) - 1)
|
|
2604 let c = a:lst[item - 1]
|
|
2605 let pat .= (c == '/' ? '[^/]\{-}' : '[^'.c.'/]\{-}').a:lst[item]
|
|
2606 endfo
|
|
2607 els
|
|
2608 for item in range(1, len(a:lst) - 1)
|
|
2609 let pat .= '[^'.a:lst[item - 1].']\{-}'.a:lst[item]
|
|
2610 endfo
|
|
2611 en
|
|
2612 retu pat
|
|
2613 endf
|
|
2614
|
|
2615 fu! s:curtype()
|
|
2616 retu s:CurTypeName()[1]
|
|
2617 endf
|
|
2618
|
|
2619 fu! s:mfunc()
|
|
2620 let mfunc = 'match'
|
|
2621 if s:byfname()
|
|
2622 let mfunc = 's:matchfname'
|
|
2623 elsei s:curtype() == 'buf'
|
|
2624 let mfunc = 's:matchbuf'
|
|
2625 elsei s:itemtype >= len(s:coretypes)
|
|
2626 let matchtypes = { 'tabs': 's:matchtabs', 'tabe': 's:matchtabe' }
|
|
2627 if has_key(matchtypes, s:matchtype)
|
|
2628 let mfunc = matchtypes[s:matchtype]
|
|
2629 en
|
|
2630 en
|
|
2631 retu mfunc
|
|
2632 endf
|
|
2633
|
|
2634 fu! s:mmode()
|
|
2635 let matchmodes = {
|
|
2636 \ 'match': 'full-line',
|
|
2637 \ 's:matchfname': 'filename-only',
|
|
2638 \ 's:matchbuf': 'full-line',
|
|
2639 \ 's:matchtabs': 'first-non-tab',
|
|
2640 \ 's:matchtabe': 'until-last-tab',
|
|
2641 \ }
|
|
2642 retu matchmodes[s:mfunc]
|
|
2643 endf
|
|
2644 " Cache {{{2
|
|
2645 fu! s:writecache(cafile)
|
|
2646 if ( g:ctrlp_newcache || !filereadable(a:cafile) ) && !s:nocache()
|
|
2647 cal ctrlp#utils#writecache(g:ctrlp_allfiles)
|
|
2648 let g:ctrlp_newcache = 0
|
|
2649 en
|
|
2650 endf
|
|
2651
|
|
2652 fu! s:nocache(...)
|
|
2653 if !s:caching
|
|
2654 retu 1
|
|
2655 elsei s:caching > 1
|
|
2656 if !( exists(s:ccex) && !{s:ccex} ) || has_key(s:ficounts, s:dyncwd)
|
|
2657 retu get(s:ficounts, s:dyncwd, [0, 0])[0] < s:caching
|
|
2658 elsei a:0 && filereadable(a:1)
|
|
2659 retu len(ctrlp#utils#readfile(a:1)) < s:caching
|
|
2660 en
|
|
2661 retu 1
|
|
2662 en
|
|
2663 retu 0
|
|
2664 endf
|
|
2665
|
|
2666 fu! s:insertcache(str)
|
|
2667 let [data, g:ctrlp_newcache, str] = [g:ctrlp_allfiles, 1, a:str]
|
|
2668 if data == [] || strlen(str) <= strlen(data[0])
|
|
2669 let pos = 0
|
|
2670 elsei strlen(str) >= strlen(data[-1])
|
|
2671 let pos = len(data) - 1
|
|
2672 el
|
|
2673 let pos = 0
|
|
2674 for each in data
|
|
2675 if strlen(each) > strlen(str) | brea | en
|
|
2676 let pos += 1
|
|
2677 endfo
|
|
2678 en
|
|
2679 cal insert(data, str, pos)
|
|
2680 cal s:writecache(ctrlp#utils#cachefile())
|
|
2681 endf
|
|
2682 " Extensions {{{2
|
|
2683 fu! s:mtype()
|
|
2684 retu s:itemtype >= len(s:coretypes) ? s:getextvar('type') : 'path'
|
|
2685 endf
|
|
2686
|
|
2687 fu! s:execextvar(key)
|
|
2688 if !empty(g:ctrlp_ext_vars)
|
|
2689 cal map(filter(copy(g:ctrlp_ext_vars),
|
|
2690 \ 'has_key(v:val, a:key)'), 'eval(v:val[a:key])')
|
|
2691 en
|
|
2692 endf
|
|
2693
|
|
2694 fu! s:getextvar(key)
|
|
2695 if s:itemtype >= len(s:coretypes) && len(g:ctrlp_ext_vars) > 0
|
|
2696 let vars = g:ctrlp_ext_vars[s:itemtype - len(s:coretypes)]
|
|
2697 if has_key(vars, a:key)
|
|
2698 retu vars[a:key]
|
|
2699 en
|
|
2700 en
|
|
2701 retu get(g:, 'ctrlp_' . s:matchtype . '_' . a:key, -1)
|
|
2702 endf
|
|
2703
|
|
2704 fu! ctrlp#getcline()
|
|
2705 let [linenr, offset] = [line('.'), ( s:offset > 0 ? s:offset : 0 )]
|
|
2706 retu !empty(s:lines) && !( offset && linenr <= offset )
|
|
2707 \ ? s:lines[linenr - 1 - offset] : ''
|
|
2708 endf
|
|
2709
|
|
2710 fu! ctrlp#getmarkedlist()
|
|
2711 retu exists('s:marked') ? values(s:marked) : []
|
|
2712 endf
|
|
2713
|
|
2714 fu! ctrlp#clearmarkedlist()
|
|
2715 let s:marked = {}
|
|
2716 endf
|
|
2717
|
|
2718 fu! ctrlp#input()
|
|
2719 retu s:getinput()
|
|
2720 endf
|
|
2721
|
|
2722 fu! ctrlp#exit()
|
|
2723 cal s:PrtExit()
|
|
2724 endf
|
|
2725
|
|
2726 fu! ctrlp#prtclear()
|
|
2727 cal s:PrtClear()
|
|
2728 endf
|
|
2729
|
|
2730 fu! ctrlp#switchtype(id)
|
|
2731 cal s:ToggleType(a:id - s:itemtype)
|
|
2732 endf
|
|
2733
|
|
2734 fu! ctrlp#nosy()
|
|
2735 retu !( has('syntax') && exists('g:syntax_on') )
|
|
2736 endf
|
|
2737
|
|
2738 fu! s:hiupdate()
|
|
2739 for [ke, va] in items(s:hlgrps)
|
|
2740 let ke = 'CtrlP' . ke
|
|
2741 if hlexists(ke)
|
|
2742 exe 'hi link' ke va
|
|
2743 en
|
|
2744 endfo
|
|
2745 endf
|
|
2746
|
|
2747 fu! ctrlp#hicheck(grp, defgrp)
|
|
2748 if !hlexists(a:grp)
|
|
2749 exe 'hi link' a:grp a:defgrp
|
|
2750 en
|
|
2751 endf
|
|
2752
|
|
2753 fu! ctrlp#call(func, ...)
|
|
2754 retu call(a:func, a:000)
|
|
2755 endf
|
|
2756
|
|
2757 fu! ctrlp#getvar(var)
|
|
2758 retu {a:var}
|
|
2759 endf
|
|
2760 "}}}1
|
|
2761 " * Initialization {{{1
|
|
2762 fu! s:setlines_pre(...)
|
|
2763 if a:0 | let s:itemtype = a:1 | en
|
|
2764 cal s:modevar()
|
|
2765 let s:setlines_post_ended = 0
|
|
2766 let g:ctrlp_lines = []
|
|
2767 endf
|
|
2768
|
|
2769 fu! s:setlines_post()
|
|
2770 let inits = {'fil': 'ctrlp#files()', 'buf': 'ctrlp#buffers()', 'mru': 'ctrlp#mrufiles#list()'}
|
|
2771 let types = map(copy(g:ctrlp_types), 'inits[v:val]')
|
|
2772 if !empty(g:ctrlp_ext_vars)
|
|
2773 cal map(copy(g:ctrlp_ext_vars), 'add(types, v:val["init"])')
|
|
2774 en
|
|
2775 let g:ctrlp_lines = eval(types[s:itemtype])
|
|
2776 let s:setlines_post_ended = 1
|
|
2777 endf
|
|
2778
|
|
2779 fu! ctrlp#setlines(...)
|
|
2780 cal call('s:setlines_pre', a:000)
|
|
2781 cal s:setlines_post()
|
|
2782 endf
|
|
2783
|
|
2784 " Returns [lname, sname]
|
|
2785 fu! s:CurTypeName()
|
|
2786 if s:itemtype < len(s:coretypes)
|
|
2787 retu filter(copy(s:coretypes), 'v:val[1]==g:ctrlp_types[s:itemtype]')[0]
|
|
2788 el
|
|
2789 retu [s:getextvar("lname"), s:getextvar('sname')]
|
|
2790 en
|
|
2791 endfu
|
|
2792
|
|
2793 fu! s:ExitIfSingleCandidate()
|
|
2794 if len(s:Update(s:prompt[0])) == 1
|
|
2795 call s:AcceptSelection('e')
|
|
2796 call ctrlp#exit()
|
|
2797 retu 1
|
|
2798 en
|
|
2799 retu 0
|
|
2800 endfu
|
|
2801
|
|
2802 fu! s:IsBuiltin()
|
|
2803 let builtins = ['tag', 'dir', 'bft', 'rts', 'bkd', 'lns', 'chs', 'mix', 'udo', 'qfx']
|
|
2804 let curtype = s:getextvar('sname')
|
|
2805 retu s:itemtype < len(s:coretypes) || index(builtins, curtype) > -1
|
|
2806 endfu
|
|
2807
|
|
2808 fu! s:DetectFileType(type, ft)
|
|
2809 if s:IsBuiltin() || empty(a:ft) || a:ft ==# 'ctrlp'
|
|
2810 retu 'ctrlp'
|
|
2811 el
|
|
2812 retu 'ctrlp.' . a:ft
|
|
2813 en
|
|
2814 endfu
|
|
2815
|
|
2816 fu! ctrlp#init(type, ...)
|
|
2817 if exists('s:init') || s:iscmdwin() | retu | en
|
|
2818 let [s:ermsg, v:errmsg] = [v:errmsg, '']
|
|
2819 let [s:matches, s:init] = [1, 1]
|
|
2820 cal s:Reset(a:0 ? a:1 : {})
|
|
2821 noa cal s:Open()
|
|
2822 cal s:SetWD(a:0 ? a:1 : {})
|
|
2823 cal s:MapNorms()
|
|
2824 cal s:MapSpecs()
|
|
2825 if empty(g:ctrlp_types) && empty(g:ctrlp_ext_vars)
|
|
2826 call ctrlp#exit()
|
|
2827 retu
|
|
2828 en
|
|
2829 if type(a:type) == 0
|
|
2830 let type = a:type
|
|
2831 el
|
|
2832 let type = index(g:ctrlp_types, a:type)
|
|
2833 if type == -1
|
|
2834 call ctrlp#exit()
|
|
2835 retu
|
|
2836 en
|
|
2837 en
|
|
2838 " Fixed issue ctrlpvim/ctrlp.vim#463 : Opening 'ctrlp' in certain modes
|
|
2839 " (':CtrlPBufTag', ':CtrlPLine') seems to trigger a partially deffective
|
|
2840 " intialisation (for example, syntax highlighting not working as expected).
|
|
2841 " Fix: ctrlp#setlines() split in two, as the second part (now in
|
|
2842 " s:setlines_post()) seems to need '&filetype', and s:DetectFileType() seems
|
|
2843 " to need the first part of the old ctrlp#setlines() (now in
|
|
2844 " s:setlines_pre()).
|
|
2845 cal s:setlines_pre(s:settype(type))
|
|
2846 let &filetype = s:DetectFileType(type, &filetype)
|
|
2847 cal s:setlines_post()
|
|
2848 cal ctrlp#syntax()
|
|
2849 cal s:SetDefTxt()
|
|
2850 let curName = s:CurTypeName()
|
|
2851 let shouldExitSingle = index(s:opensingle, curName[0])>=0 || index(s:opensingle, curName[1])>=0
|
|
2852 if shouldExitSingle && s:ExitIfSingleCandidate()
|
|
2853 retu 0
|
|
2854 en
|
|
2855
|
|
2856 if has('patch-9.0.0115') && &cmdheight == 0
|
|
2857 let s:cmdheight = &cmdheight
|
|
2858 set cmdheight=1
|
|
2859 en
|
|
2860 cal s:BuildPrompt(1)
|
|
2861 if s:keyloop | cal s:KeyLoop() | en
|
|
2862 retu 1
|
|
2863 endf
|
|
2864
|
|
2865 " - Events {{{1
|
|
2866 fu! s:NotifySearch()
|
|
2867 let l:cb = s:getextvar('search')
|
|
2868 if l:cb != -1
|
|
2869 cal eval(l:cb)
|
|
2870 en
|
|
2871 endf
|
|
2872
|
|
2873 fu! ctrlp#update(...)
|
|
2874 cal s:ForceUpdate()
|
|
2875 if a:0 | cal s:BuildPrompt(a:1) | en
|
|
2876 endf
|
|
2877
|
|
2878 " - Autocmds {{{1
|
|
2879 if has('autocmd')
|
|
2880 aug CtrlPAug
|
|
2881 au!
|
|
2882 au BufEnter ControlP cal s:checkbuf()
|
|
2883 au BufLeave ControlP noa cal s:Close()
|
|
2884 au VimLeavePre * cal s:leavepre()
|
|
2885 au ColorScheme * cal s:hiupdate()
|
|
2886 aug END
|
|
2887 en
|
|
2888
|
|
2889 fu! s:autocmds()
|
|
2890 if !has('autocmd') | retu | en
|
|
2891 if exists('#CtrlPLazy')
|
|
2892 au! CtrlPLazy
|
|
2893 en
|
|
2894 if s:lazy
|
|
2895 aug CtrlPLazy
|
|
2896 au!
|
|
2897 au CursorHold ControlP cal s:ForceUpdate()
|
|
2898 aug END
|
|
2899 en
|
|
2900 endf
|
|
2901 "}}}
|
|
2902
|
|
2903 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2
|