completion for :FactorVocab vim function

db4
Joe Groff 2009-09-10 20:24:56 -05:00
parent 1a5b62238c
commit 5e4751db64
1 changed files with 19 additions and 4 deletions

View File

@ -5,7 +5,7 @@ nmap <silent> <Leader>ft :FactorVocabTests<CR>
let g:FactorRoot = "/Users/joe/Documents/Code/others/factor" let g:FactorRoot = "/Users/joe/Documents/Code/others/factor"
let g:FactorVocabRoots = ["core", "basis", "extra", "work", "/Users/joe/Documents/Code/Factor"] let g:FactorVocabRoots = ["core", "basis", "extra", "work", "/Users/joe/Documents/Code/Factor"]
command! -nargs=1 FactorVocab :call GoToFactorVocab("<args>") command! -nargs=1 -complete=custom,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
command! FactorVocabImpl :call GoToFactorVocabImpl() command! FactorVocabImpl :call GoToFactorVocabImpl()
command! FactorVocabDocs :call GoToFactorVocabDocs() command! FactorVocabDocs :call GoToFactorVocabDocs()
command! FactorVocabTests :call GoToFactorVocabTests() command! FactorVocabTests :call GoToFactorVocabTests()
@ -18,6 +18,21 @@ function! FactorVocabRoot(root)
return vocabroot return vocabroot
endfunction endfunction
function! FactorCompleteVocab(arglead, cmdline, cursorpos)
let vocabs = ""
let vocablead = substitute(a:arglead, "\\.", "/", "g")
for root in g:FactorVocabRoots
let vocabroot = FactorVocabRoot(root)
let newvocabs = globpath(vocabroot, vocablead . "*")
if newvocabs != ""
let newvocabs = substitute(newvocabs, "\\(^\\|\\n\\)\\V" . escape(vocabroot, "\\"), "\\1", "g")
let newvocabs = substitute(newvocabs, "/\\|\\\\", ".", "g")
let vocabs .= newvocabs . "\n"
endif
endfor
return vocabs
endfunction
function! FactorVocabFile(root, vocab) function! FactorVocabFile(root, vocab)
let vocabpath = substitute(a:vocab, "\\.", "/", "g") let vocabpath = substitute(a:vocab, "\\.", "/", "g")
let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor" let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"