Refactor vim compile functions
This commit is contained in:
parent
92376839a4
commit
6b79eeef5d
4 changed files with 49 additions and 29 deletions
|
@ -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>
|
||||
|
|
|
@ -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()
|
25
nvim/.config/nvim/plugin/personal/doccompile.vim
Normal file
25
nvim/.config/nvim/plugin/personal/doccompile.vim
Normal 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>)
|
|
@ -7,8 +7,18 @@
|
|||
#
|
||||
# Compiles .tex. groff (.mom, .ms), .rmd, .md. Opens .sent files as sent
|
||||
# presentations. Runs scripts based on extention or shebang
|
||||
#
|
||||
# Expects the file to compile as first argument.
|
||||
# Desired output format(s) can be specified in optional arguments following.
|
||||
|
||||
file=$(readlink -f "$1")
|
||||
printf "file: %s\n" "$file"
|
||||
|
||||
if [ "$#" -gt 1 ]; then
|
||||
shift
|
||||
formats="$*"
|
||||
fi
|
||||
|
||||
dir=$(dirname "$file")
|
||||
base="${file%.*}"
|
||||
|
||||
|
@ -28,14 +38,17 @@ textype() {
|
|||
}
|
||||
|
||||
sendtoRmd() {
|
||||
ifinstalled R && echo "require(rmarkdown); render('$1')" | R -q --vanilla
|
||||
# v removed for too much magic that can break; simply input pdf_document if you want it
|
||||
# formats=$(echo "$formats" | perl -pe 's/([\w-]+)(?<!_document)\b/"\1_document"/gm' | tr ' ' ',')
|
||||
printf "formats: %s\n" "$formats"
|
||||
ifinstalled R && echo "require(rmarkdown); render('$1', c($formats))" | R -q --vanilla
|
||||
}
|
||||
|
||||
case "$file" in
|
||||
*\.ms) refer -PS -e "$file" | groff -me -ms -kept -T pdf >"$base".pdf ;;
|
||||
*\.mom) refer -PS -e "$file" | groff -mom -kept -T pdf >"$base".pdf ;;
|
||||
*\.[0-9]) refer -PS -e "$file" | groff -mandoc -T pdf >"$base".pdf ;;
|
||||
*\.[Rr]md | *\.md | *\.mkd | *\.markdown) sendtoRmd "$file" ;;
|
||||
*\.[Rr]md | *\.md | *\.mkd | *\.markdown) sendtoRmd "$file" "$formats" ;;
|
||||
*\.tex) textype "$file" ;;
|
||||
*config.h) sudo make install ;;
|
||||
*\.c) cc "$file" -o "$base" && "$base" ;;
|
||||
|
|
Loading…
Reference in a new issue