Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export image #21

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions autoload/slumlord.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ set cpo&vim

" variable {{{1
let g:slumlord_plantuml_jar_path = get(g:, 'slumlord_plantuml_jar_path', expand("<sfile>:p:h") . "/../plantuml.jar")
let g:slumlord_plantuml_include_path = get(g:, 'slumlord_plantuml_include_path', expand("~/.config/plantuml/include/"))
let g:slumlord_asciiart_utf = get(g:, 'slumlord_asciiart_utf', 1)
let s:base_cmd = "java -Dapple.awt.UIElement=true -Dplantuml.include.path=\"". g:slumlord_plantuml_include_path ."\" -splash: -jar ". g:slumlord_plantuml_jar_path ." "

" function {{{1
function! slumlord#updatePreview(args) abort
Expand All @@ -38,7 +40,7 @@ function! slumlord#updatePreview(args) abort
call s:mungeDiagramInTmpFile(tmpfname)
let b:slumlord_preview_fname = fnamemodify(tmpfname, ':r') . '.' . ext

let cmd = "java -Dapple.awt.UIElement=true -splash: -jar ". g:slumlord_plantuml_jar_path ." -charset ". charset ." -t" . type ." ". tmpfname
let cmd = s:base_cmd. " -charset ". charset . " -t" . type ." ". tmpfname

let write = has_key(a:args, 'write') && a:args["write"] == 1
if exists("*jobstart")
Expand All @@ -53,6 +55,11 @@ function! slumlord#updatePreview(args) abort
endif
endfunction

" Export image {{{1
function! slumlord#exportImage(args) abort
call system(s:base_cmd . " -gui " . fnameescape(fnamemodify('%', ":p:h")) . "&")
endfunction

function! s:shouldInsertPreview() abort
"check for 'no-preview flag
if search('^\s*''no-preview', 'wn') > 0
Expand Down Expand Up @@ -214,7 +221,7 @@ function! s:WinUpdater.update(args) abort
endfunction

function s:WinUpdater.__moveToWin() abort
if exists("b:slumlord_bnum")
if exists("b:slumlord_bnum") && bufexists(b:slumlord_bnum)
if bufwinnr(b:slumlord_bnum) != -1
exec bufwinnr(b:slumlord_bnum) . "wincmd w"
else
Expand All @@ -223,8 +230,16 @@ function s:WinUpdater.__moveToWin() abort
else
let prev_bnum = bufnr("")
new
setlocal buftype=nofile
setlocal bufhidden=wipe
setlocal noswapfile
setlocal textwidth=0 " avoid automatic line break
call setbufvar(prev_bnum, "slumlord_bnum", bufnr(""))
let b:slumlord_main_bnum = prev_bnum
call self.__setupWinOpts()
command! -buffer -bar -nargs=0 ExportImage exe bufwinnr(b:slumlord_main_bnum) . "wincmd w" | call slumlord#exportImage({}) | wincmd p
" TODO: allow chaning the mapping through an option
nmap <buffer> <leader>ex :ExportImage<CR>
endif
endfunction

Expand Down
7 changes: 7 additions & 0 deletions ftplugin/plantuml.vim
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ let b:loaded_slumlord=1
let s:save_cpo = &cpo
set cpo&vim

" Mappings {{{1
" TODO: allow chaning the mapping through an option
nmap <buffer> <leader>ex :ExportImage<CR>

" setting {{{1
setlocal nowrap

Expand All @@ -24,6 +28,9 @@ augroup slumlord
autocmd BufWritePre * if &ft =~ 'plantuml' | silent call slumlord#updatePreview({'write': 1}) | endif
augroup END

" command {{{1
command! -buffer -bar -nargs=0 ExportImage call slumlord#exportImage({})

" Outro {{{1
let &cpo = s:save_cpo
unlet s:save_cpo
Expand Down