]> gitweb.factorcode.org Git - factor.git/commitdiff
add a :NewFactorVocab command to vim plugin
authorJoe Groff <arcata@gmail.com>
Sun, 13 Sep 2009 20:36:43 +0000 (15:36 -0500)
committerJoe Groff <arcata@gmail.com>
Sun, 13 Sep 2009 20:36:43 +0000 (15:36 -0500)
misc/vim/README
misc/vim/plugin/factor.vim

index 0a11654f158fcd5da9e0ee9157ef15d4d041492f..db7e4f09a3d90506b6fc7f80fa9a82dae8d79953 100644 (file)
@@ -24,6 +24,8 @@ navigating Factor source:
     :FactorVocab factor.vocab.name
         Opens the source file implementing the "factor.vocab.name"
         vocabulary.
+    :NewFactorVocab factor.vocab.name
+        Creates a new factor vocabulary under the working vocabulary root.
     :FactorVocabImpl
         Opens the main implementation file for the current vocabulary
         (name.factor).  The keyboard shortcut "\fi" is bound to this
@@ -46,6 +48,10 @@ variables in your vimrc file:
         This variable should be set to a list of Factor vocabulary roots.
         The paths may be either relative to g:FactorRoot or absolute paths.
         The default value is ["core", "basis", "extra", "work"].
+    g:FactorNewVocabRoot
+        This variable should be set to the vocabulary root in which
+        vocabularies created with NewFactorVocab should be created. The
+        default value is "work".
 
 Note: The syntax-highlighting file is automatically generated to include the
 names of all the vocabularies Factor knows about. To regenerate it manually,
index 61a587aa426f8c4e3ec068f29238d74eb4a640ec..aedae9770f9cb22dddac57d2258fc47e6f902de1 100644 (file)
@@ -10,7 +10,12 @@ if !exists("g:FactorVocabRoots")
     let g:FactorVocabRoots = ["core", "basis", "extra", "work"]
 endif
 
+if !exists("g:FactorNewVocabRoot")
+    let g:FactorNewVocabRoot = "work"
+endif
+
 command! -nargs=1 -complete=customlist,FactorCompleteVocab FactorVocab :call GoToFactorVocab("<args>")
+command! -nargs=1 -complete=customlist,FactorCompleteVocab NewFactorVocab :call MakeFactorVocab("<args>")
 command! FactorVocabImpl  :call GoToFactorVocabImpl()
 command! FactorVocabDocs  :call GoToFactorVocabDocs()
 command! FactorVocabTests :call GoToFactorVocabTests()
@@ -49,11 +54,11 @@ function! FactorCompleteVocab(arglead, cmdline, cursorpos)
     return vocabs
 endfunction
 
-function! FactorVocabFile(root, vocab)
+function! FactorVocabFile(root, vocab, mustexist)
     let vocabpath = substitute(a:vocab, "\\.", "/", "g")
     let vocabfile = FactorVocabRoot(a:root) . vocabpath . "/" . fnamemodify(vocabpath, ":t") . ".factor"
     
-    if getftype(vocabfile) != ""
+    if !a:mustexist || getftype(vocabfile) != ""
         return vocabfile
     else
         return ""
@@ -62,7 +67,7 @@ endfunction
 
 function! GoToFactorVocab(vocab)
     for root in g:FactorVocabRoots
-        let vocabfile = FactorVocabFile(root, a:vocab)
+        let vocabfile = FactorVocabFile(root, a:vocab, 1)
         if vocabfile != ""
             exe "edit " fnameescape(vocabfile)
             return
@@ -71,6 +76,15 @@ function! GoToFactorVocab(vocab)
     echo "Vocabulary " vocab " not found"
 endfunction
 
+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
+
 function! FactorFileBase()
     let filename = expand("%:r")
     let filename = substitute(filename, "-docs", "", "")