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 if !exists("g:FactorNewVocabRoot")
14 let g:FactorNewVocabRoot = "work"
17 command! -nargs=1 -complete=customlist,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
18 command! -nargs=1 -complete=customlist,FactorCompleteVocab NewFactorVocab :call MakeFactorVocab("<args>")
19 command! FactorVocabImpl :call GoToFactorVocabImpl()
20 command! FactorVocabDocs :call GoToFactorVocabDocs()
21 command! FactorVocabTests :call GoToFactorVocabTests()
23 function! FactorVocabRoot(root)
25 exe "lcd " fnameescape(g:FactorRoot)
26 let vocabroot = fnamemodify(a:root, ":p")
27 exe "lcd " fnameescape(cwd)
31 function! s:unique(list)
36 return sort(keys(dict))
39 function! FactorCompleteVocab(arglead, cmdline, cursorpos)
41 let vocablead = substitute(a:arglead, "\\.", "/", "g")
42 for root in g:FactorVocabRoots
43 let vocabroot = FactorVocabRoot(root)
44 let newvocabs = globpath(vocabroot, vocablead . "*")
46 let newvocabsl = split(newvocabs, "\n")
47 let newvocabsl = filter(newvocabsl, 'getftype(v:val) == "dir"')
48 let newvocabsl = map(newvocabsl, 'substitute(v:val, "^\\V" . escape(vocabroot, "\\"), "\\1", "g")')
49 let vocabs += newvocabsl
52 let vocabs = s:unique(vocabs)
53 let vocabs = map(vocabs, 'substitute(v:val, "/\\|\\\\", ".", "g")')
57 function! FactorVocabFile(root, vocab, mustexist)
58 let vocabpath = substitute(a:vocab, "\\.", "/", "g")
59 let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
61 if !a:mustexist || getftype(vocabfile) != ""
68 function! GoToFactorVocab(vocab)
69 for root in g:FactorVocabRoots
70 let vocabfile = FactorVocabFile(root, a:vocab, 1)
72 exe "edit " fnameescape(vocabfile)
76 echo "Vocabulary " vocab " not found"
79 function! MakeFactorVocab(vocab)
80 let vocabfile = FactorVocabFile(g:FactorNewVocabRoot, a:vocab, 0)
82 let vocabdir = fnamemodify(vocabfile, ":h")
84 exe "!mkdir -p " shellescape(vocabdir)
85 exe "edit " fnameescape(vocabfile)
88 function! FactorFileBase()
89 let filename = expand("%:r")
90 let filename = substitute(filename, "-docs", "", "")
91 let filename = substitute(filename, "-tests", "", "")
95 function! GoToFactorVocabImpl()
96 exe "edit " fnameescape(FactorFileBase() . ".factor")
99 function! GoToFactorVocabDocs()
100 exe "edit " fnameescape(FactorFileBase() . "-docs.factor")
103 function! GoToFactorVocabTests()
104 exe "edit " fnameescape(FactorFileBase() . "-tests.factor")