add a :NewFactorVocab command to vim plugin

db4
Joe Groff 2009-09-13 15:36:43 -05:00
parent 38ec77f9bd
commit 044139aa88
2 changed files with 23 additions and 3 deletions

View 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,

View 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", "", "")