1 nmap <silent> <Leader>fi :FactorVocabImpl<CR>
2 nmap <silent> <Leader>fd :FactorVocabDocs<CR>
3 nmap <silent> <Leader>ft :FactorVocabTests<CR>
5 if !exists("g:FactorRoot")
6 let g:FactorRoot = "~/factor"
9 if !exists("g:FactorVocabRoots")
10 let g:FactorVocabRoots = ["core", "basis", "extra", "work"]
13 command! -nargs=1 -complete=customlist,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
14 command! FactorVocabImpl :call GoToFactorVocabImpl()
15 command! FactorVocabDocs :call GoToFactorVocabDocs()
16 command! FactorVocabTests :call GoToFactorVocabTests()
18 function! FactorVocabRoot(root)
20 exe "lcd " fnameescape(g:FactorRoot)
21 let vocabroot = fnamemodify(a:root, ":p")
22 exe "lcd " fnameescape(cwd)
26 function! s:unique(list)
31 return sort(keys(dict))
34 function! FactorCompleteVocab(arglead, cmdline, cursorpos)
36 let vocablead = substitute(a:arglead, "\\.", "/", "g")
37 for root in g:FactorVocabRoots
38 let vocabroot = FactorVocabRoot(root)
39 let newvocabs = globpath(vocabroot, vocablead . "*")
41 let newvocabsl = split(newvocabs, "\n")
42 let newvocabsl = filter(newvocabsl, 'getftype(v:val) == "dir"')
43 let newvocabsl = map(newvocabsl, 'substitute(v:val, "^\\V" . escape(vocabroot, "\\"), "\\1", "g")')
44 let vocabs += newvocabsl
47 let vocabs = s:unique(vocabs)
48 let vocabs = map(vocabs, 'substitute(v:val, "/\\|\\\\", ".", "g")')
52 function! FactorVocabFile(root, vocab)
53 let vocabpath = substitute(a:vocab, "\\.", "/", "g")
54 let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
56 if getftype(vocabfile) != ""
63 function! GoToFactorVocab(vocab)
64 for root in g:FactorVocabRoots
65 let vocabfile = FactorVocabFile(root, a:vocab)
67 exe "edit " fnameescape(vocabfile)
71 echo "Vocabulary " vocab " not found"
74 function! FactorFileBase()
75 let filename = expand("%:r")
76 let filename = substitute(filename, "-docs", "", "")
77 let filename = substitute(filename, "-tests", "", "")
81 function! GoToFactorVocabImpl()
82 exe "edit " fnameescape(FactorFileBase() . ".factor")
85 function! GoToFactorVocabDocs()
86 exe "edit " fnameescape(FactorFileBase() . "-docs.factor")
89 function! GoToFactorVocabTests()
90 exe "edit " fnameescape(FactorFileBase() . "-tests.factor")