Refactor vim compile functions

This commit is contained in:
Marty Oehme 2020-02-03 22:10:11 +01:00
parent 92376839a4
commit 6b79eeef5d
4 changed files with 49 additions and 29 deletions

View file

@ -242,9 +242,13 @@ nnoremap <silent> <localleader>cc :CiteRef<cr>
" map <leader>cm to insert markdown prettified citation
nnoremap <silent> <localleader>cm :CiteMarkdown<cr>
" p to comPile a document (or file, works for some languages like go/python/c)
" pp to comPile a document (or file, works for some languages like go/python/c)
" o to open the resulting document (mostly for pdfs)
" P to comPile *and* open a doc
nnoremap <localleader>po :CompileOpen<cr>
nnoremap <localleader>pp :CompileDoc<cr>
nnoremap <localleader>PP :CompileDocAndOpen<cr>
" po to comPile *and* open a doc
" and all the same in uppercase for verbose output
nnoremap <localleader>pp :DocCompile<cr>
nnoremap <localleader>PP :DocCompile!<cr>
nnoremap <localleader>po :DocCompileOpen<cr>
nnoremap <localleader>PO :DocCompileOpen!<cr>
nnoremap <localleader>o :DocOpen<cr>
nnoremap <localleader>O :DocOpen!<cr>

View file

@ -1,22 +0,0 @@
function CompileDoc()
:execute(":w!")
:execute(":!compile \"%\"")
endfunction
function CompileDocNoOutput()
:execute(":w!")
:execute(":silent !compile \"%\"")
endfunction
function CompiledOpen()
:execute(":silent !open-compiled \"%\"")
endfunction
function CompileDocAndOpen()
call CompileDocNoOutput()
call CompiledOpen()
endfunction
command CompileDoc call CompileDoc()
command CompileOpen call CompiledOpen()
command CompileDocAndOpen call CompileDocAndOpen()

View file

@ -0,0 +1,25 @@
function s:_compile(verbose, ...)
:execute(":w!")
if a:verbose
execute "!" . "compile" . " " . "%" . " " . join(a:000)
else
silent "!" . "compile" . " " . "%" . " " . join(a:000)
endif
endfunction
function s:_open(verbose, ...)
if a:verbose
execute "!" . "open-compiled" . " " . "%" . " " . join(a:000)
else
silent "!" . "open-compiled" . " " . "%" . " " . join(a:000)
endif
endfunction
function s:_compileopen(verbose, ...)
call s:_compile(<bang>0, <f-args>)
call s:_open(<bang>0, <f-args>)
endfunction
command -bang -nargs=* DocCompile call s:_compile(<bang>0, <f-args>)
command -bang -nargs=* DocCompileOpen call s:_compileopen(<bang>0, <f-args>)
command -bang -nargs=* DocOpen call s:_open(<bang>0, <f-args>)