]> gitweb.factorcode.org Git - factor.git/blobdiff - misc/vim/plugin/factor.vim
Fix vocabulary swithcing commands
[factor.git] / misc / vim / plugin / factor.vim
index cbe316a0e694f03a2771eb46b6149ee14dc6cc9b..9df38dbf0ff8bd5e71478ad37bd6f98c586c2034 100644 (file)
@@ -1,80 +1,50 @@
+" Location:     plugin/factor.vim
+
 nmap <silent> <Leader>fi :FactorVocabImpl<CR>
 nmap <silent> <Leader>fd :FactorVocabDocs<CR>
 nmap <silent> <Leader>ft :FactorVocabTests<CR>
+nmap <Leader>fv :FactorVocab<SPACE>
+nmap <Leader>fn :NewFactorVocab<SPACE>
 
-if !exists("g:FactorRoot")
-    let g:FactorRoot = "~/factor"
+if !exists('g:FactorResourcePath')
+    let g:FactorResourcePath = '~/factor/'
 endif
 
-if !exists("g:FactorVocabRoots")
-    let g:FactorVocabRoots = ["core", "basis", "extra", "work"]
+if !exists('g:FactorDefaultVocabRoots')
+    let g:FactorDefaultVocabRoots = ['resource:core', 'resource:basis', 'resource:extra', 'resource:work']
 endif
+" let g:FactorAdditionalVocabRoots = ... " see autoload/factor.vim
+unlet! g:FactorVocabRoots
 
-command! -nargs=1 -complete=custom,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
-command! FactorVocabImpl  :call GoToFactorVocabImpl()
-command! FactorVocabDocs  :call GoToFactorVocabDocs()
-command! FactorVocabTests :call GoToFactorVocabTests()
+if !exists('*FactorNewVocabRoot') | function! FactorNewVocabRoot() abort
+    return 'resource:work'
+endfunction | endif
 
-function! FactorVocabRoot(root)
-    let cwd = getcwd()
-    exe "lcd " fnameescape(g:FactorRoot)
-    let vocabroot = fnamemodify(a:root, ":p")
-    exe "lcd " fnameescape(cwd)
-    return vocabroot
-endfunction
-
-function! FactorCompleteVocab(arglead, cmdline, cursorpos)
-    let vocabs = ""
-    let vocablead = substitute(a:arglead, "\\.", "/", "g")
-    for root in g:FactorVocabRoots
-        let vocabroot = FactorVocabRoot(root)
-        let newvocabs = globpath(vocabroot, vocablead . "*")
-        if newvocabs != ""
-            let newvocabs = substitute(newvocabs, "\\(^\\|\\n\\)\\V" . escape(vocabroot, "\\"), "\\1", "g")
-            let newvocabs = substitute(newvocabs, "/\\|\\\\", ".", "g")
-            let vocabs .= newvocabs . "\n"
-        endif
-    endfor
-    return vocabs
-endfunction
-
-function! FactorVocabFile(root, vocab)
-    let vocabpath = substitute(a:vocab, "\\.", "/", "g")
-    let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
-    
-    if getftype(vocabfile) != ""
-        return vocabfile
-    else
-        return ""
-    endif
-endfunction
-
-function! GoToFactorVocab(vocab)
-    for root in g:FactorVocabRoots
-        let vocabfile = FactorVocabFile(root, a:vocab)
-        if vocabfile != ""
-            exe "edit " fnameescape(vocabfile)
-            return
-        endif
-    endfor
-    echo "Vocabulary " vocab " not found"
-endfunction
+command! -bar -bang -range=1 -nargs=1 -complete=customlist,factor#complete_vocab_glob FactorVocab
+            \ execute factor#go_to_vocab_command(<count>,"edit<bang>",<q-args>)
+command! -bar -bang -range=1 -nargs=1 -complete=customlist,factor#complete_vocab_glob NewFactorVocab
+            \ execute factor#make_vocab_command(<count>,"edit<bang>",<q-args>)
+command! -bar FactorVocabImpl :call GoToFactorVocabImpl()
+command! -bar FactorVocabDocs :call GoToFactorVocabDocs()
+command! -bar FactorVocabTests :call GoToFactorVocabTests()
 
 function! FactorFileBase()
-    let filename = expand("%:r")
-    let filename = substitute(filename, "-docs", "", "")
-    let filename = substitute(filename, "-tests", "", "")
+    let filename = expand('%:r')
+    let filename = substitute(filename, '-docs', '', '')
+    let filename = substitute(filename, '-tests', '', '')
     return filename
 endfunction
 
 function! GoToFactorVocabImpl()
-    exe "edit " fnameescape(FactorFileBase() . ".factor")
+    exe 'edit ' fnameescape(FactorFileBase() . '.factor')
 endfunction
 
 function! GoToFactorVocabDocs()
-    exe "edit " fnameescape(FactorFileBase() . "-docs.factor")
+    exe 'edit ' fnameescape(FactorFileBase() . '-docs.factor')
 endfunction
 
 function! GoToFactorVocabTests()
-    exe "edit " fnameescape(FactorFileBase() . "-tests.factor")
+    exe 'edit ' fnameescape(FactorFileBase() . '-tests.factor')
 endfunction
+
+" vim:sw=4:et: