first commit

This commit is contained in:
skanehira 2020-01-08 16:15:17 +09:00
commit 0bd17c551d
2 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,41 @@
" preview_markdown
" Author: skanehira
" License: MIT
let s:save_cpo = &cpo
set cpo&vim
function! s:echo_err(msg) abort
echohl ErrorMsg
echom 'preview-markdown.vim: ' .. a:msg
echohl None
endfunction
function! preview_markdown#preview() abort
let tmp = tempname()
call writefile(getline(1, "$"), tmp)
if !executable('mdr')
call s:echo_err('not found mdr, please insatll from https://github.com/MichaelMure/mdr')
return
endif
if !has('terminal')
call s:echo_err('this version doesn''t support terminal')
return
endif
call term_start('mdr', {
\ 'in_io': 'file',
\ 'in_name': tmp,
\ 'exit_cb': function('s:remove_tmp', [tmp]),
\ 'term_finish': 'close',
\ })
endfunction
function! s:remove_tmp(tmp, channel, msg) abort
call delete(a:tmp)
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo

View File

@ -0,0 +1,18 @@
" preview_markdown
" Author: skanehira
" License: MIT
if exists('g:loaded_preview_markdown')
finish
endif
let g:loaded_preview_markdown = 1
let s:save_cpo = &cpo
set cpo&vim
command! PreviewMarkdown call preview_markdown#preview()
let &cpo = s:save_cpo
unlet s:save_cpo
" vim:set et: