]> gitweb.factorcode.org Git - factor.git/blob - misc/vim/plugin/factor.vim
vim plugin for factor, with shortcuts for opening vocabs and switching between implem...
[factor.git] / misc / vim / plugin / factor.vim
1 nmap <silent> <Leader>fi :FactorVocabImpl<CR>
2 nmap <silent> <Leader>fd :FactorVocabDocs<CR>
3 nmap <silent> <Leader>ft :FactorVocabTests<CR>
4
5 let g:FactorRoot = "/Users/joe/Documents/Code/others/factor"
6 let g:FactorVocabRoots = ["core", "basis", "extra", "work", "/Users/joe/Documents/Code/Factor"]
7
8 command! -nargs=1 FactorVocab      :call GoToFactorVocab("<args>")
9 command!          FactorVocabImpl  :call GoToFactorVocabImpl()
10 command!          FactorVocabDocs  :call GoToFactorVocabDocs()
11 command!          FactorVocabTests :call GoToFactorVocabTests()
12
13 function! FactorVocabRoot(root)
14     let cwd = getcwd()
15     exe "lcd " fnameescape(g:FactorRoot)
16     let vocabroot = fnamemodify(a:root, ":p")
17     exe "lcd " fnameescape(cwd)
18     return vocabroot
19 endfunction
20
21 function! FactorVocabFile(root, vocab)
22     let vocabpath = substitute(a:vocab, "\\.", "/", "g")
23     let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
24     
25     if getftype(vocabfile) != ""
26         return vocabfile
27     else
28         return ""
29     endif
30 endfunction
31
32 function! GoToFactorVocab(vocab)
33     for root in g:FactorVocabRoots
34         let vocabfile = FactorVocabFile(root, a:vocab)
35         if vocabfile != ""
36             exe "edit " fnameescape(vocabfile)
37             return
38         endif
39     endfor
40     echo "Vocabulary " vocab " not found"
41 endfunction
42
43 function! FactorFileBase()
44     let filename = expand("%:r")
45     let filename = substitute(filename, "-docs", "", "")
46     let filename = substitute(filename, "-tests", "", "")
47     return filename
48 endfunction
49
50 function! GoToFactorVocabImpl()
51     exe "edit " fnameescape(FactorFileBase() . ".factor")
52 endfunction
53
54 function! GoToFactorVocabDocs()
55     exe "edit " fnameescape(FactorFileBase() . "-docs.factor")
56 endfunction
57
58 function! GoToFactorVocabTests()
59     exe "edit " fnameescape(FactorFileBase() . "-tests.factor")
60 endfunction