| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  | nmap <silent> <Leader>fi :FactorVocabImpl<CR>
 | 
					
						
							|  |  |  | nmap <silent> <Leader>fd :FactorVocabDocs<CR>
 | 
					
						
							|  |  |  | nmap <silent> <Leader>ft :FactorVocabTests<CR>
 | 
					
						
							| 
									
										
										
										
											2009-09-21 00:10:54 -04:00
										 |  |  | nmap <Leader>fv :FactorVocab<SPACE>
 | 
					
						
							|  |  |  | nmap <Leader>fn :NewFactorVocab<SPACE>
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 22:55:17 -04:00
										 |  |  | if !exists("g:FactorRoot")
 | 
					
						
							|  |  |  |     let g:FactorRoot = "~/factor"
 | 
					
						
							|  |  |  | endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if !exists("g:FactorVocabRoots")
 | 
					
						
							|  |  |  |     let g:FactorVocabRoots = ["core", "basis", "extra", "work"]
 | 
					
						
							|  |  |  | endif
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 16:36:43 -04:00
										 |  |  | if !exists("g:FactorNewVocabRoot")
 | 
					
						
							|  |  |  |     let g:FactorNewVocabRoot = "work"
 | 
					
						
							|  |  |  | endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 23:15:24 -04:00
										 |  |  | command! -nargs=1 -complete=customlist,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
 | 
					
						
							| 
									
										
										
										
											2009-09-13 16:36:43 -04:00
										 |  |  | command! -nargs=1 -complete=customlist,FactorCompleteVocab NewFactorVocab :call MakeFactorVocab("<args>")
 | 
					
						
							| 
									
										
										
										
											2009-09-10 21:24:56 -04:00
										 |  |  | command! FactorVocabImpl  :call GoToFactorVocabImpl()
 | 
					
						
							|  |  |  | command! FactorVocabDocs  :call GoToFactorVocabDocs()
 | 
					
						
							|  |  |  | command! FactorVocabTests :call GoToFactorVocabTests()
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | function! FactorVocabRoot(root)
 | 
					
						
							|  |  |  |     let cwd = getcwd()
 | 
					
						
							|  |  |  |     exe "lcd " fnameescape(g:FactorRoot)
 | 
					
						
							|  |  |  |     let vocabroot = fnamemodify(a:root, ":p")
 | 
					
						
							|  |  |  |     exe "lcd " fnameescape(cwd)
 | 
					
						
							|  |  |  |     return vocabroot
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 23:15:24 -04:00
										 |  |  | function! s:unique(list)
 | 
					
						
							|  |  |  |     let dict = {}
 | 
					
						
							|  |  |  |     for value in a:list
 | 
					
						
							|  |  |  |         let dict[value] = 1
 | 
					
						
							|  |  |  |     endfor
 | 
					
						
							|  |  |  |     return sort(keys(dict))
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 21:24:56 -04:00
										 |  |  | function! FactorCompleteVocab(arglead, cmdline, cursorpos)
 | 
					
						
							| 
									
										
										
										
											2009-09-10 23:15:24 -04:00
										 |  |  |     let vocabs = []
 | 
					
						
							| 
									
										
										
										
											2009-09-10 21:24:56 -04:00
										 |  |  |     let vocablead = substitute(a:arglead, "\\.", "/", "g")
 | 
					
						
							|  |  |  |     for root in g:FactorVocabRoots
 | 
					
						
							|  |  |  |         let vocabroot = FactorVocabRoot(root)
 | 
					
						
							|  |  |  |         let newvocabs = globpath(vocabroot, vocablead . "*")
 | 
					
						
							|  |  |  |         if newvocabs != ""
 | 
					
						
							| 
									
										
										
										
											2009-09-10 23:15:24 -04:00
										 |  |  |             let newvocabsl = split(newvocabs, "\n")
 | 
					
						
							|  |  |  |             let newvocabsl = filter(newvocabsl, 'getftype(v:val) == "dir"')
 | 
					
						
							|  |  |  |             let newvocabsl = map(newvocabsl, 'substitute(v:val, "^\\V" . escape(vocabroot, "\\"), "\\1", "g")')
 | 
					
						
							|  |  |  |             let vocabs += newvocabsl
 | 
					
						
							| 
									
										
										
										
											2009-09-10 21:24:56 -04:00
										 |  |  |         endif
 | 
					
						
							|  |  |  |     endfor
 | 
					
						
							| 
									
										
										
										
											2009-09-10 23:15:24 -04:00
										 |  |  |     let vocabs = s:unique(vocabs)
 | 
					
						
							|  |  |  |     let vocabs = map(vocabs, 'substitute(v:val, "/\\|\\\\", ".", "g")')
 | 
					
						
							| 
									
										
										
										
											2009-09-10 21:24:56 -04:00
										 |  |  |     return vocabs
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 16:36:43 -04:00
										 |  |  | function! FactorVocabFile(root, vocab, mustexist)
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  |     let vocabpath = substitute(a:vocab, "\\.", "/", "g")
 | 
					
						
							|  |  |  |     let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
 | 
					
						
							| 
									
										
										
										
											2011-03-17 12:40:28 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 16:36:43 -04:00
										 |  |  |     if !a:mustexist || getftype(vocabfile) != ""
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  |         return vocabfile
 | 
					
						
							|  |  |  |     else
 | 
					
						
							|  |  |  |         return ""
 | 
					
						
							|  |  |  |     endif
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function! GoToFactorVocab(vocab)
 | 
					
						
							|  |  |  |     for root in g:FactorVocabRoots
 | 
					
						
							| 
									
										
										
										
											2009-09-13 16:36:43 -04:00
										 |  |  |         let vocabfile = FactorVocabFile(root, a:vocab, 1)
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  |         if vocabfile != ""
 | 
					
						
							|  |  |  |             exe "edit " fnameescape(vocabfile)
 | 
					
						
							|  |  |  |             return
 | 
					
						
							|  |  |  |         endif
 | 
					
						
							|  |  |  |     endfor
 | 
					
						
							|  |  |  |     echo "Vocabulary " vocab " not found"
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-13 16:36:43 -04:00
										 |  |  | function! MakeFactorVocab(vocab)
 | 
					
						
							|  |  |  |     let vocabfile = FactorVocabFile(g:FactorNewVocabRoot, a:vocab, 0)
 | 
					
						
							|  |  |  |     echo vocabfile
 | 
					
						
							|  |  |  |     let vocabdir = fnamemodify(vocabfile, ":h")
 | 
					
						
							|  |  |  |     echo vocabdir
 | 
					
						
							|  |  |  |     exe "!mkdir -p " shellescape(vocabdir)
 | 
					
						
							|  |  |  |     exe "edit " fnameescape(vocabfile)
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-09-10 19:41:36 -04:00
										 |  |  | function! FactorFileBase()
 | 
					
						
							|  |  |  |     let filename = expand("%:r")
 | 
					
						
							|  |  |  |     let filename = substitute(filename, "-docs", "", "")
 | 
					
						
							|  |  |  |     let filename = substitute(filename, "-tests", "", "")
 | 
					
						
							|  |  |  |     return filename
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function! GoToFactorVocabImpl()
 | 
					
						
							|  |  |  |     exe "edit " fnameescape(FactorFileBase() . ".factor")
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function! GoToFactorVocabDocs()
 | 
					
						
							|  |  |  |     exe "edit " fnameescape(FactorFileBase() . "-docs.factor")
 | 
					
						
							|  |  |  | endfunction
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function! GoToFactorVocabTests()
 | 
					
						
							|  |  |  |     exe "edit " fnameescape(FactorFileBase() . "-tests.factor")
 | 
					
						
							|  |  |  | endfunction
 |