Skip to content
This repository
Browse code

Use a custom completion function

  • Loading branch information...
commit bedfa3b6c3badc4fa6b734098fb9b89972cdf894 1 parent 10bbbfa
authored September 20, 2012
10  autoload/ctrlp.vim
@@ -1334,6 +1334,16 @@ fu! s:findcommon(items, seed)
1334 1334
 	endfo
1335 1335
 	retu cmn
1336 1336
 endf
  1337
+
  1338
+fu! ctrlp#dircompl(...)
  1339
+	let [hsl, str] = [match(a:1, '[\/]'), '']
  1340
+	let par = substitute(a:1, '[^\/]*$', '', '')
  1341
+	let path = !hsl ? par : hsl > 0 ? getcwd().s:lash().par : getcwd()
  1342
+	for dir in split(globpath(s:fnesc(path, 'g', ','), '*/'), '\n')
  1343
+		let str .= par.split(dir, '[\/]')[-1]."\n"
  1344
+	endfo
  1345
+	retu str
  1346
+endf
1337 1347
 " Misc {{{3
1338 1348
 fu! s:headntail(str)
1339 1349
 	let parts = split(a:str, '[\/]\ze[^\/]\+[\/:]\?$')
11  plugin/ctrlp.vim
@@ -17,8 +17,11 @@ let [g:ctrlp_lines, g:ctrlp_allfiles, g:ctrlp_alltags, g:ctrlp_alldirs,
17 17
 if !exists('g:ctrlp_map') | let g:ctrlp_map = '<c-p>' | en
18 18
 if !exists('g:ctrlp_cmd') | let g:ctrlp_cmd = 'CtrlP' | en
19 19
 
20  
-com! -n=? -com=dir CtrlP         cal ctrlp#init(0, { 'dir': <q-args> })
21  
-com! -n=? -com=dir CtrlPMRUFiles cal ctrlp#init(2, { 'dir': <q-args> })
  20
+com! -n=? -com=custom,ctrlp#dircompl CtrlP
  21
+	\ cal ctrlp#init(0, { 'dir': <q-args> })
  22
+
  23
+com! -n=? -com=custom,ctrlp#dircompl CtrlPMRUFiles
  24
+	\ cal ctrlp#init(2, { 'dir': <q-args> })
22 25
 
23 26
 com! -bar CtrlPBuffer   cal ctrlp#init(1)
24 27
 com! -n=? CtrlPLastMode cal ctrlp#init(-1, { 'args': <q-args> })
@@ -42,7 +45,7 @@ cal ctrlp#mrufiles#init()
42 45
 com! -bar CtrlPTag      cal ctrlp#init(ctrlp#tag#id())
43 46
 com! -bar CtrlPQuickfix cal ctrlp#init(ctrlp#quickfix#id())
44 47
 
45  
-com! -n=? -com=dir CtrlPDir
  48
+com! -n=? -com=custom,ctrlp#dircompl CtrlPDir
46 49
 	\ cal ctrlp#init(ctrlp#dir#id(), { 'dir': <q-args> })
47 50
 
48 51
 com! -n=? -com=buffer CtrlPBufTag
@@ -60,7 +63,7 @@ com! -bar CtrlPChangeAll   cal ctrlp#init(ctrlp#changes#cmd(1))
60 63
 com! -bar CtrlPMixed       cal ctrlp#init(ctrlp#mixed#id())
61 64
 com! -bar CtrlPBookmarkDir cal ctrlp#init(ctrlp#bookmarkdir#id())
62 65
 
63  
-com! -n=? -com=dir CtrlPBookmarkDirAdd
  66
+com! -n=? -com=custom,ctrlp#dircompl CtrlPBookmarkDirAdd
64 67
 	\ cal ctrlp#call('ctrlp#bookmarkdir#add', <q-args>)
65 68
 
66 69
 " vim:ts=2:sw=2:sts=2

0 notes on commit bedfa3b

Please sign in to comment.
Something went wrong with that request. Please try again.