1 nmap <silent> <Leader>fi :FactorVocabImpl<CR>
2 nmap <silent> <Leader>fd :FactorVocabDocs<CR>
3 nmap <silent> <Leader>ft :FactorVocabTests<CR>
4 nmap <Leader>fv :FactorVocab<SPACE>
5 nmap <Leader>fn :NewFactorVocab<SPACE>
7 if !exists("g:FactorRoot")
8 let g:FactorRoot = "~/factor"
11 if !exists("g:FactorVocabRoots")
12 let g:FactorVocabRoots = ["core", "basis", "extra", "work"]
15 if !exists("g:FactorNewVocabRoot")
16 let g:FactorNewVocabRoot = "work"
19 command! -nargs=1 -complete=customlist,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
20 command! -nargs=1 -complete=customlist,FactorCompleteVocab NewFactorVocab :call MakeFactorVocab("<args>")
21 command! FactorVocabImpl :call GoToFactorVocabImpl()
22 command! FactorVocabDocs :call GoToFactorVocabDocs()
23 command! FactorVocabTests :call GoToFactorVocabTests()
25 function! FactorVocabRoot(root)
27 exe "lcd " fnameescape(g:FactorRoot)
28 let vocabroot = fnamemodify(a:root, ":p")
29 exe "lcd " fnameescape(cwd)
33 function! s:unique(list)
38 return sort(keys(dict))
41 function! FactorCompleteVocab(arglead, cmdline, cursorpos)
43 let vocablead = substitute(a:arglead, "\\.", "/", "g")
44 for root in g:FactorVocabRoots
45 let vocabroot = FactorVocabRoot(root)
46 let newvocabs = globpath(vocabroot, vocablead . "*")
48 let newvocabsl = split(newvocabs, "\n")
49 let newvocabsl = filter(newvocabsl, 'getftype(v:val) == "dir"')
50 let newvocabsl = map(newvocabsl, 'substitute(v:val, "^\\V" . escape(vocabroot, "\\"), "\\1", "g")')
51 let vocabs += newvocabsl
54 let vocabs = s:unique(vocabs)
55 let vocabs = map(vocabs, 'substitute(v:val, "/\\|\\\\", ".", "g")')
59 function! FactorVocabFile(root, vocab, mustexist)
60 let vocabpath = substitute(a:vocab, "\\.", "/", "g")
61 let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
63 if !a:mustexist || getftype(vocabfile) != ""
70 function! GoToFactorVocab(vocab)
71 for root in g:FactorVocabRoots
72 let vocabfile = FactorVocabFile(root, a:vocab, 1)
74 exe "edit " fnameescape(vocabfile)
78 echo "Vocabulary " vocab " not found"
81 function! MakeFactorVocab(vocab)
82 let vocabfile = FactorVocabFile(g:FactorNewVocabRoot, a:vocab, 0)
84 let vocabdir = fnamemodify(vocabfile, ":h")
86 exe "!mkdir -p " shellescape(vocabdir)
87 exe "edit " fnameescape(vocabfile)
90 function! FactorFileBase()
91 let filename = expand("%:r")
92 let filename = substitute(filename, "-docs", "", "")
93 let filename = substitute(filename, "-tests", "", "")
97 function! GoToFactorVocabImpl()
98 exe "edit " fnameescape(FactorFileBase() . ".factor")
101 function! GoToFactorVocabDocs()
102 exe "edit " fnameescape(FactorFileBase() . "-docs.factor")
105 function! GoToFactorVocabTests()
106 exe "edit " fnameescape(FactorFileBase() . "-tests.factor")