annotate vim/vimfiles/bundle/ctrlp.vim/autoload/ctrlp/mrufiles.vim @ 7:86e0ac713642

Re-added the latest ctrlp.vim plugin. The ctrlp.vim commit was e61e7d5b801ade5fcefeab3aca75c1f37d54bdf1.
author Brian Neal <bgneal@gmail.com>
date Sun, 29 Apr 2012 16:20:31 -0500
parents
children
rev   line source
bgneal@7 1 " =============================================================================
bgneal@7 2 " File: autoload/ctrlp/mrufiles.vim
bgneal@7 3 " Description: Most Recently Used Files extension
bgneal@7 4 " Author: Kien Nguyen <github.com/kien>
bgneal@7 5 " =============================================================================
bgneal@7 6
bgneal@7 7 " Static variables {{{1
bgneal@7 8 let [s:mrbs, s:mrufs] = [[], []]
bgneal@7 9
bgneal@7 10 fu! ctrlp#mrufiles#opts()
bgneal@7 11 let [pref, opts] = ['g:ctrlp_mruf_', {
bgneal@7 12 \ 'max': ['s:max', 250],
bgneal@7 13 \ 'include': ['s:in', ''],
bgneal@7 14 \ 'exclude': ['s:ex', ''],
bgneal@7 15 \ 'case_sensitive': ['s:cseno', 1],
bgneal@7 16 \ 'relative': ['s:re', 0],
bgneal@7 17 \ }]
bgneal@7 18 for [ke, va] in items(opts)
bgneal@7 19 let [{va[0]}, {pref.ke}] = [pref.ke, exists(pref.ke) ? {pref.ke} : va[1]]
bgneal@7 20 endfo
bgneal@7 21 endf
bgneal@7 22 cal ctrlp#mrufiles#opts()
bgneal@7 23 " Utilities {{{1
bgneal@7 24 fu! s:excl(fn)
bgneal@7 25 retu !empty({s:ex}) && a:fn =~# {s:ex}
bgneal@7 26 endf
bgneal@7 27
bgneal@7 28 fu! s:mergelists()
bgneal@7 29 let diskmrufs = ctrlp#utils#readfile(ctrlp#mrufiles#cachefile())
bgneal@7 30 cal filter(diskmrufs, 'index(s:mrufs, v:val) < 0')
bgneal@7 31 let mrufs = s:mrufs + diskmrufs
bgneal@7 32 retu s:chop(mrufs)
bgneal@7 33 endf
bgneal@7 34
bgneal@7 35 fu! s:chop(mrufs)
bgneal@7 36 if len(a:mrufs) > {s:max} | cal remove(a:mrufs, {s:max}, -1) | en
bgneal@7 37 retu a:mrufs
bgneal@7 38 endf
bgneal@7 39
bgneal@7 40 fu! s:reformat(mrufs)
bgneal@7 41 if {s:re}
bgneal@7 42 let cwd = exists('+ssl') ? tr(getcwd(), '/', '\') : getcwd()
bgneal@7 43 cal filter(a:mrufs, '!stridx(v:val, cwd)')
bgneal@7 44 en
bgneal@7 45 retu map(a:mrufs, 'fnamemodify(v:val, ":.")')
bgneal@7 46 endf
bgneal@7 47
bgneal@7 48 fu! s:record(bufnr)
bgneal@7 49 if s:locked | retu | en
bgneal@7 50 let bufnr = a:bufnr + 0
bgneal@7 51 if bufnr <= 0 | retu | en
bgneal@7 52 let bufname = bufname(bufnr)
bgneal@7 53 if empty(bufname) | retu | en
bgneal@7 54 let fn = fnamemodify(bufname, ':p')
bgneal@7 55 let fn = exists('+ssl') ? tr(fn, '/', '\') : fn
bgneal@7 56 cal filter(s:mrbs, 'v:val != bufnr')
bgneal@7 57 cal insert(s:mrbs, bufnr)
bgneal@7 58 if ( !empty({s:in}) && fn !~# {s:in} ) || ( !empty({s:ex}) && fn =~# {s:ex} )
bgneal@7 59 \ || !empty(&bt) || !filereadable(fn) | retu
bgneal@7 60 en
bgneal@7 61 cal filter(s:mrufs, 'v:val !='.( {s:cseno} ? '#' : '?' ).' fn')
bgneal@7 62 cal insert(s:mrufs, fn)
bgneal@7 63 endf
bgneal@7 64
bgneal@7 65 fu! s:savetofile(mrufs)
bgneal@7 66 cal ctrlp#utils#writecache(a:mrufs, s:cadir, s:cafile)
bgneal@7 67 endf
bgneal@7 68 " Public {{{1
bgneal@7 69 fu! ctrlp#mrufiles#refresh(...)
bgneal@7 70 let s:mrufs = s:mergelists()
bgneal@7 71 cal filter(s:mrufs, '!empty(ctrlp#utils#glob(v:val, 1)) && !s:excl(v:val)')
bgneal@7 72 if exists('+ssl')
bgneal@7 73 cal map(s:mrufs, 'tr(v:val, "/", "\\")')
bgneal@7 74 cal filter(s:mrufs, 'count(s:mrufs, v:val) == 1')
bgneal@7 75 en
bgneal@7 76 cal s:savetofile(s:mrufs)
bgneal@7 77 retu a:0 && a:1 == 'raw' ? [] : s:reformat(copy(s:mrufs))
bgneal@7 78 endf
bgneal@7 79
bgneal@7 80 fu! ctrlp#mrufiles#remove(files)
bgneal@7 81 let s:mrufs = []
bgneal@7 82 if a:files != []
bgneal@7 83 let s:mrufs = s:mergelists()
bgneal@7 84 cal filter(s:mrufs, 'index(a:files, v:val, 0, '.(!{s:cseno}).') < 0')
bgneal@7 85 en
bgneal@7 86 cal s:savetofile(s:mrufs)
bgneal@7 87 retu s:reformat(copy(s:mrufs))
bgneal@7 88 endf
bgneal@7 89
bgneal@7 90 fu! ctrlp#mrufiles#list(...)
bgneal@7 91 retu a:0 ? a:1 == 'raw' ? s:mergelists() : 0 : s:reformat(s:mergelists())
bgneal@7 92 endf
bgneal@7 93
bgneal@7 94 fu! ctrlp#mrufiles#bufs()
bgneal@7 95 retu s:mrbs
bgneal@7 96 endf
bgneal@7 97
bgneal@7 98 fu! ctrlp#mrufiles#cachefile()
bgneal@7 99 if !exists('s:cadir') || !exists('s:cafile')
bgneal@7 100 let s:cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().'mru'
bgneal@7 101 let s:cafile = s:cadir.ctrlp#utils#lash().'cache.txt'
bgneal@7 102 en
bgneal@7 103 retu s:cafile
bgneal@7 104 endf
bgneal@7 105
bgneal@7 106 fu! ctrlp#mrufiles#init()
bgneal@7 107 if !has('autocmd') | retu | en
bgneal@7 108 let s:locked = 0
bgneal@7 109 aug CtrlPMRUF
bgneal@7 110 au!
bgneal@7 111 au BufAdd,BufEnter,BufLeave,BufUnload * cal s:record(expand('<abuf>', 1))
bgneal@7 112 au QuickFixCmdPre *vimgrep* let s:locked = 1
bgneal@7 113 au QuickFixCmdPost *vimgrep* let s:locked = 0
bgneal@7 114 au VimLeavePre * cal s:savetofile(s:mergelists())
bgneal@7 115 aug END
bgneal@7 116 endf
bgneal@7 117 "}}}
bgneal@7 118
bgneal@7 119 " vim:fen:fdm=marker:fmr={{{,}}}:fdl=0:fdc=1:ts=2:sw=2:sts=2