annotate vim/vimfiles/autoload/ctrlp/dir.vim @ 0:48859d9c82c5

Initial commit, based on settings used at work (minus NERD tree & some tagging plugins).
author Brian Neal <bgneal@gmail.com>
date Tue, 03 Jan 2012 20:53:13 -0600
parents
children 92af3257a261
rev   line source
bgneal@0 1 " =============================================================================
bgneal@0 2 " File: autoload/ctrlp/dir.vim
bgneal@0 3 " Description: Directory extension
bgneal@0 4 " Author: Kien Nguyen <github.com/kien>
bgneal@0 5 " =============================================================================
bgneal@0 6
bgneal@0 7 " Init {{{1
bgneal@0 8 if exists('g:loaded_ctrlp_dir') && g:loaded_ctrlp_dir
bgneal@0 9 fini
bgneal@0 10 en
bgneal@0 11 let [g:loaded_ctrlp_dir, g:ctrlp_newdir] = [1, 0]
bgneal@0 12
bgneal@0 13 let s:ars = [
bgneal@0 14 \ 's:folsym',
bgneal@0 15 \ 's:dotfiles',
bgneal@0 16 \ 's:maxdepth',
bgneal@0 17 \ 's:maxfiles',
bgneal@0 18 \ 's:compare_lim',
bgneal@0 19 \ 's:glob',
bgneal@0 20 \ ]
bgneal@0 21
bgneal@0 22 let s:dir_var = ['ctrlp#dir#init('.join(s:ars, ', ').')', 'ctrlp#dir#accept',
bgneal@0 23 \ 'dirs', 'dir']
bgneal@0 24
bgneal@0 25 let g:ctrlp_ext_vars = exists('g:ctrlp_ext_vars') && !empty(g:ctrlp_ext_vars)
bgneal@0 26 \ ? add(g:ctrlp_ext_vars, s:dir_var) : [s:dir_var]
bgneal@0 27
bgneal@0 28 let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
bgneal@0 29 " Utilities {{{1
bgneal@0 30 fu! s:globdirs(dirs, depth)
bgneal@0 31 let entries = split(globpath(a:dirs, s:glob), "\n")
bgneal@0 32 if !s:folsym
bgneal@0 33 let entries = filter(entries, 'getftype(v:val) != "link"')
bgneal@0 34 en
bgneal@0 35 let ftrfunc = s:dotfiles ? 'ctrlp#dirfilter(v:val)' : 'isdirectory(v:val)'
bgneal@0 36 let alldirs = filter(entries, ftrfunc)
bgneal@0 37 cal extend(g:ctrlp_alldirs, alldirs)
bgneal@0 38 let depth = a:depth + 1
bgneal@0 39 if !empty(g:ctrlp_alldirs) && !s:max(len(g:ctrlp_alldirs), s:maxfiles)
bgneal@0 40 \ && depth <= s:maxdepth
bgneal@0 41 sil! cal ctrlp#progress(len(g:ctrlp_alldirs))
bgneal@0 42 cal s:globdirs(join(alldirs, ','), depth)
bgneal@0 43 en
bgneal@0 44 endf
bgneal@0 45
bgneal@0 46 fu! s:max(len, max)
bgneal@0 47 retu a:max && a:len > a:max ? 1 : 0
bgneal@0 48 endf
bgneal@0 49 " Public {{{1
bgneal@0 50 fu! ctrlp#dir#init(...)
bgneal@0 51 let s:cwd = getcwd()
bgneal@0 52 for each in range(len(s:ars))
bgneal@0 53 exe 'let' s:ars[each] '=' string(eval('a:'.(each + 1)))
bgneal@0 54 endfo
bgneal@0 55 let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:dir_var[3]
bgneal@0 56 let cafile = cadir.ctrlp#utils#lash().ctrlp#utils#cachefile(s:dir_var[3])
bgneal@0 57 if g:ctrlp_newdir || !filereadable(cafile)
bgneal@0 58 let g:ctrlp_alldirs = []
bgneal@0 59 cal s:globdirs(s:cwd, 0)
bgneal@0 60 cal ctrlp#rmbasedir(g:ctrlp_alldirs)
bgneal@0 61 let read_cache = 0
bgneal@0 62 el
bgneal@0 63 let g:ctrlp_alldirs = ctrlp#utils#readfile(cafile)
bgneal@0 64 let read_cache = 1
bgneal@0 65 en
bgneal@0 66 if len(g:ctrlp_alldirs) <= s:compare_lim
bgneal@0 67 cal sort(g:ctrlp_alldirs, 'ctrlp#complen')
bgneal@0 68 en
bgneal@0 69 if !read_cache
bgneal@0 70 cal ctrlp#utils#writecache(g:ctrlp_alldirs, cadir, cafile)
bgneal@0 71 let g:ctrlp_newdir = 0
bgneal@0 72 en
bgneal@0 73 retu g:ctrlp_alldirs
bgneal@0 74 endf
bgneal@0 75
bgneal@0 76 fu! ctrlp#dir#accept(mode, str)
bgneal@0 77 let path = a:mode == 'h' ? getcwd() : s:cwd.ctrlp#utils#lash().a:str
bgneal@0 78 if a:mode =~ 't\|v\|h'
bgneal@0 79 cal ctrlp#exit()
bgneal@0 80 en
bgneal@0 81 cal ctrlp#setdir(path, a:mode =~ 't\|h' ? 'chd!' : 'lc!')
bgneal@0 82 if a:mode == 'e'
bgneal@0 83 sil! cal ctrlp#statusline()
bgneal@0 84 cal ctrlp#setlines(s:id)
bgneal@0 85 cal ctrlp#recordhist()
bgneal@0 86 cal ctrlp#prtclear()
bgneal@0 87 en
bgneal@0 88 endf
bgneal@0 89
bgneal@0 90 fu! ctrlp#dir#id()
bgneal@0 91 retu s:id
bgneal@0 92 endf
bgneal@0 93 "}}}
bgneal@0 94
bgneal@0 95 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2