Code Monkey home page Code Monkey logo

Comments (1)

comrumino avatar comrumino commented on June 4, 2024 2

Patch using Python to provide EXITCODE, CMD, STDOUT, and STDERR:

diff --git a/plugin/vim-markdown-preview.vim b/plugin/vim-markdown-preview.vim
index 082c69f..10f41d1 100644
--- a/plugin/vim-markdown-preview.vim
+++ b/plugin/vim-markdown-preview.vim
@@ -58,20 +58,42 @@ if !exists("g:vim_markdown_preview_hotkey")
     let g:vim_markdown_preview_hotkey='<C-p>'
 endif
 
+function! s:PyPopen(cmd)
+    let l:pinfo = { 'exitcode': 2, 'stdout': '', 'stderr': 'default err:' }
+py3 << EOPY
+import vim, subprocess
+cmd = vim.eval("a:cmd")
+pinfo = vim.eval("l:pinfo")
+proc = subprocess.Popen([cmd], stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True, shell=True)
+exit_code = str(proc.wait()).replace("'", "&apos;")
+stdout = proc.stdout.read().decode().replace("'", "&apos;")
+stderr = proc.stderr.read().decode().replace("'", "&apos;")
+vim.command(f"let pinfo.exitcode = '{exit_code}'")
+vim.command(f"let pinfo.stdout = '{stdout}'")
+vim.command(f"let pinfo.stderr = '{stderr}'")
+EOPY
+    return l:pinfo
+endfunction
+
 function! Vim_Markdown_Preview()
   let b:curr_file = expand('%:p')
-
+  let l:cmd = ''
   if g:vim_markdown_preview_github == 1
-    call system('grip "' . b:curr_file . '" --export /tmp/vim-markdown-preview.html --title vim-markdown-preview.html')
+    let l:cmd = 'grip "' . b:curr_file . '" --export /tmp/vim-markdown-preview.html --title vim-markdown-preview.html'
   elseif g:vim_markdown_preview_perl == 1
-    call system('Markdown.pl "' . b:curr_file . '" > /tmp/vim-markdown-preview.html')
+    let l:cmd = 'Markdown.pl "' . b:curr_file . '" > /tmp/vim-markdown-preview.html'
   elseif g:vim_markdown_preview_pandoc == 1
-    call system('pandoc --standalone "' . b:curr_file . '" > /tmp/vim-markdown-preview.html')
+
+    let l:cmd = 'pandoc --standalone "' . b:curr_file . '" > /tmp/vim-markdown-preview.html'
   else
-    call system('markdown "' . b:curr_file . '" > /tmp/vim-markdown-preview.html')
+    let l:cmd = 'markdown "' . b:curr_file . '" > /tmp/vim-markdown-preview.html'
   endif
-  if v:shell_error
-    echo 'Please install the necessary requirements: https://github.com/JamshedVesuna/vim-markdown-preview#requirements'
+  let l:pinfo = s:PyPopen(l:cmd)
+  if l:pinfo.exitcode != 0
+    echo 'Please install check necessary requirements: https://github.com/JamshedVesuna/vim-markdown-preview#requirements'
+    echo 'EXITCODE,CMD: '.l:pinfo.exitcode.','.l:cmd
+    echo 'STDOUT: '.l:pinfo.stdout
+    echo 'STDERR: '.l:pinfo.stderr
   endif
 
   if g:vmp_osname == 'unix'

After applying the patch, if PyPopen fails within Vim_Markdown_Preview the output looks like so

Please install check necessary requirements: https://github.com/JamshedVesuna/vim-markdown-preview#require
ments
EXITCODE,CMD: 127,pandoc --standalone "/home/archie/README.md" > /tmp/vim-markdown-preview.html
STDOUT:
STDERR: pandoc: error while loading shared libraries: libHSQuickCheck-2.13.2-F1caelbelL24B6NyiafVp6-ghc8.8
.1.so: cannot open shared object file: No such file or directory

from vim-markdown-preview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.