Skip to content

Commit

Permalink
Persistent caching for tag.vim
Browse files Browse the repository at this point in the history
* Change the opening commands to the tag-matchlist commands.
* Stop using taglist() so we don't have to worry about &l:tags.
* Persistent caching for tags.
* Continue kien#27.
  • Loading branch information
kien committed Nov 30, 2011
1 parent d37ab0d commit 8395436
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 34 deletions.
71 changes: 38 additions & 33 deletions autoload/ctrlp/tag.vim
Expand Up @@ -20,58 +20,63 @@ let s:id = g:ctrlp_builtins + len(g:ctrlp_ext_vars)
"}}} "}}}
" Utilities {{{ " Utilities {{{
fu! s:times(tagfiles) fu! s:times(tagfiles)
retu sort(map(copy(a:tagfiles), 'getftime(v:val)'), 's:compval') retu map(copy(a:tagfiles), 'getftime(v:val)')
endf

fu! s:compval(...)
retu a:1 - a:2
endf

fu! s:concat(lst)
let result = ''
for each in a:lst
let result .= each
endfo
retu result
endf endf


fu! s:nodup(lst) fu! s:nodup(lst)
let dict = {} let dict = {}
for each in a:lst for each in a:lst | cal extend(dict, { each : 0 }) | endfo
cal extend(dict, { each : 0 })
endfo
retu keys(dict) retu keys(dict)
endf endf

fu! s:hash224(str)
let [a, b, nHash] = [0x00000800, 0x001fffff, 7]
let hashes = repeat([0], nHash)
for i in range(len(a:str))
let iHash = i % nHash
let hashes[iHash] = hashes[iHash] * a + hashes[iHash] / b
let hashes[iHash] += char2nr(a:str[i])
endfo
retu join(map(hashes, 'printf("%08x", v:val)'), '')
endf
"}}} "}}}
" Public {{{ " Public {{{
fu! ctrlp#tag#init(tagfiles) fu! ctrlp#tag#init(tagfiles)
if empty(a:tagfiles) | retu [] | en if empty(a:tagfiles) | retu [] | en
let tagfiles = sort(s:nodup(a:tagfiles)) let tagfiles = sort(s:nodup(a:tagfiles))
let &l:tags = join(tagfiles, ',') let key = s:hash224(join(tagfiles, ','))
let [tkey, s:ltags] = [s:concat(s:times(tagfiles)), &l:tags] let cadir = ctrlp#utils#cachedir().ctrlp#utils#lash().s:tag_var[3]
let newtags = exists('g:ctrlp_alltags['''.s:ltags.''']') let cafile = cadir.ctrlp#utils#lash().'cache.'.key.'.txt'
\ && keys(g:ctrlp_alltags[s:ltags]) == [tkey] ? 0 : 1 if filereadable(cafile) && max(s:times(tagfiles)) < getftime(cafile)
if newtags if !has_key(g:ctrlp_alltags, key)
let tags = taglist('^.*$') let g:ctrlp_alltags = { key : ctrlp#utils#readfile(cafile) }
let alltags = empty(tags) ? [] en
\ : map(tags, 'v:val["name"]." ".v:val["filename"]') let read_cache = 1
cal extend(g:ctrlp_alltags, { s:ltags : { tkey : alltags } }) el
let g:ctrlp_alltags = { key : [] }
let eval = 'matchstr(v:val, ''^[^!\t][^\t]*\t\+[^\t]\+\ze\t\+'')'
for each in tagfiles
let alltags = filter(map(readfile(each), eval), 'v:val =~# ''\S''')
cal extend(g:ctrlp_alltags[key], alltags)
endfo
let read_cache = 0
en
if !read_cache
cal ctrlp#utils#writecache(g:ctrlp_alltags[key], cadir, cafile)
en en
sy match CtrlPTagFilename '\zs\t.*\ze$' sy match CtrlPTagFilename '\zs\t.*\ze$'
hi link CtrlPTagFilename Comment hi link CtrlPTagFilename Comment
retu g:ctrlp_alltags[s:ltags][tkey] retu g:ctrlp_alltags[key]
endf endf


fu! ctrlp#tag#accept(mode, str) fu! ctrlp#tag#accept(mode, str)
cal ctrlp#exit() cal ctrlp#exit()
let md = a:mode let [md, tg] = [a:mode, split(a:str, '\t[^\t]\+$')[0]]
let cmd = md == 't' ? 'tabnew' : md == 'h' ? 'new' : md == 'v' ? 'vne' let cmd = md == 't' ? 'tab stj' : md == 'h' ? 'stj'
\ : ctrlp#normcmd('ene') \ : md == 'v' ? 'vert stj' : 'tj'
let cmd = cmd == 'ene' && &modified ? 'hid ene' : cmd let cmd = cmd == 'tj' && &modified ? 'hid tj' : cmd
try try
exe cmd exe cmd.' '.tg
let &l:tags = s:ltags
exe 'ta' split(a:str, '\t[^\t]\+$')[0]
cat cat
cal ctrlp#msg("Tag not found.") cal ctrlp#msg("Tag not found.")
endt endt
Expand Down
2 changes: 1 addition & 1 deletion autoload/ctrlp/utils.vim
Expand Up @@ -50,7 +50,7 @@ fu! ctrlp#utils#writecache(lines, ...)
cal ctrlp#utils#mkdir(cache_dir) cal ctrlp#utils#mkdir(cache_dir)
if isdirectory(cache_dir) if isdirectory(cache_dir)
sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile()) sil! cal writefile(a:lines, exists('a:2') ? a:2 : ctrlp#utils#cachefile())
if !exists('a:1') || !exists('a:2') | let g:ctrlp_newcache = 0 | en if !exists('a:1') | let g:ctrlp_newcache = 0 | en
en en
endf endf


Expand Down

0 comments on commit 8395436

Please sign in to comment.