From f7a7851810d85123e62d72d4599fd0d01d93d979 Mon Sep 17 00:00:00 2001 From: Songli Yu <39717545+ysl2@users.noreply.github.com> Date: Mon, 16 Jan 2023 19:09:57 +0800 Subject: [PATCH 1/3] Pin default shell to cmd.exe on windows. Fix path seprator for windows. --- plugin/mdip.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plugin/mdip.vim b/plugin/mdip.vim index 5f61c08..db5970b 100644 --- a/plugin/mdip.vim +++ b/plugin/mdip.vim @@ -89,6 +89,11 @@ function! s:SaveFileTMPLinux(imgdir, tmpname) abort endfunction function! s:SaveFileTMPWin32(imgdir, tmpname) abort + let shell_bak = &shell + let shellcmdflag_bak = &shellcmdflag + let &shell = 'cmd.exe' + let &shellcmdflag = '/s /c' + let tmpfile = a:imgdir . '\' . a:tmpname . '.png' let tmpfile = substitute(tmpfile, '\\ ', ' ', 'g') @@ -99,6 +104,10 @@ function! s:SaveFileTMPWin32(imgdir, tmpname) abort let clip_command = "powershell -nologo -noprofile -noninteractive -sta \"".clip_command. "\"" silent call system(clip_command) + + let &shell = shell_bak + let &shellcmdflag = shellcmdflag_bak + if v:shell_error == 1 return 1 else @@ -194,7 +203,7 @@ function! g:LatexPasteImage(relpath) endfunction function! g:EmptyPasteImage(relpath) - execute "normal! i" . a:relpath + execute "normal! i" . a:relpath endfunction let g:PasteImageFunction = 'g:MarkdownPasteImage' @@ -228,7 +237,8 @@ function! mdip#MarkdownClipboardImage() else " let relpath = s:SaveNewFile(g:mdip_imgdir, tmpfile) let extension = split(tmpfile, '\.')[-1] - let relpath = g:mdip_imgdir_intext . '/' . g:mdip_tmpname . '.' . extension + let sep = has('win32') ? '\' : '/' + let relpath = g:mdip_imgdir_intext . sep . g:mdip_tmpname . '.' . extension if call(get(g:, 'PasteImageFunction'), [relpath]) return endif From eb552346aafc661e4f50654eb82c514dd15aef05 Mon Sep 17 00:00:00 2001 From: Songli Yu <39717545+ysl2@users.noreply.github.com> Date: Mon, 16 Jan 2023 20:32:21 +0800 Subject: [PATCH 2/3] Backup original shell, use cmd.exe, and restore original shell (for windows). --- plugin/mdip.vim | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugin/mdip.vim b/plugin/mdip.vim index db5970b..2a45f1c 100644 --- a/plugin/mdip.vim +++ b/plugin/mdip.vim @@ -237,8 +237,7 @@ function! mdip#MarkdownClipboardImage() else " let relpath = s:SaveNewFile(g:mdip_imgdir, tmpfile) let extension = split(tmpfile, '\.')[-1] - let sep = has('win32') ? '\' : '/' - let relpath = g:mdip_imgdir_intext . sep . g:mdip_tmpname . '.' . extension + let relpath = g:mdip_imgdir_intext . '/' . g:mdip_tmpname . '.' . extension if call(get(g:, 'PasteImageFunction'), [relpath]) return endif From 32abe3b45d8cf8db3f56db4125f446a69ab12578 Mon Sep 17 00:00:00 2001 From: ysl2 Date: Thu, 4 Apr 2024 15:25:36 +0800 Subject: [PATCH 3/3] Add typst support. --- plugin/mdip.vim | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/plugin/mdip.vim b/plugin/mdip.vim index 2a45f1c..629ac8a 100644 --- a/plugin/mdip.vim +++ b/plugin/mdip.vim @@ -149,8 +149,13 @@ function! s:SaveNewFile(imgdir, tmpfile) let extension = split(a:tmpfile, '\.')[-1] let reldir = g:mdip_imgdir let cnt = 0 - let filename = a:imgdir . '/' . g:mdip_imgname . cnt . '.' . extension - let relpath = reldir . '/' . g:mdip_imgname . cnt . '.' . extension + if empty(g:mdip_imgname) + let filename = a:imgdir . '/' . g:mdip_imgname . cnt . '.' . extension + let relpath = reldir . '/' . g:mdip_imgname . cnt . '.' . extension + else + let filename = a:imgdir . '/' . cnt . '.' . extension + let relpath = reldir . '/' . cnt . '.' . extension + endif while filereadable(filename) call system('diff ' . a:tmpfile . ' ' . filename) if !v:shell_error @@ -158,8 +163,13 @@ function! s:SaveNewFile(imgdir, tmpfile) return relpath endif let cnt += 1 - let filename = a:imgdir . '/' . g:mdip_imgname . cnt . '.' . extension - let relpath = reldir . '/' . g:mdip_imgname . cnt . '.' . extension + if empty(g:mdip_imgname) + let filename = a:imgdir . '/' . g:mdip_imgname . cnt . '.' . extension + let relpath = reldir . '/' . g:mdip_imgname . cnt . '.' . extension + else + let filename = a:imgdir . '/' . cnt . '.' . extension + let relpath = reldir . '/' . cnt . '.' . extension + endif endwhile if filereadable(a:tmpfile) call rename(a:tmpfile, filename) @@ -202,8 +212,16 @@ function! g:LatexPasteImage(relpath) execute "normal! ve\" endfunction +function! g:TypstPasteImage(relpath) + let ipos = getcurpos() + execute "normal! iimage(\"" . a:relpath . "\")" + call setpos('.', ipos) +endfunction + function! g:EmptyPasteImage(relpath) + let ipos = getcurpos() execute "normal! i" . a:relpath + call setpos('.', ipos) endfunction let g:PasteImageFunction = 'g:MarkdownPasteImage' @@ -221,7 +239,11 @@ function! mdip#MarkdownClipboardImage() " change temp-file-name and image-name let g:mdip_tmpname = s:InputName() if empty(g:mdip_tmpname) - let g:mdip_tmpname = g:mdip_imgname . '_' . s:RandomName() + if empty(g:mdip_imgname) + let g:mdip_tmpname = s:RandomName() + else + let g:mdip_tmpname = g:mdip_imgname . '_' . s:RandomName() + endif endif let testpath = workdir . '/' . g:mdip_tmpname . '.png' if filereadable(testpath) == 0