Can't run marp with neovim jobstart or with plenary.job #562
-
When editing specific files with neovim, I'd like to run marp to compile to pdf on each write. I've written a function below to run marp on the current file. In this case, I'm using plenary.nvim - job to run this command, but I have the same problem with neovim - jobstart. The problem is that marp doesn't finish in the allotted time (10 minutes doesn't seem to be enough). When running an identical marp command in the terminal, it finishes in ~3 seconds. Take a look at input and output below. Terminal command and output
Neovim function using plenary.nvim (in local M = {}
...
function M.compile_with_marp()
local current_dir = vim.fn.expand("%:p:h")
local file_base = vim.fn.expand("%:t:r")
local md_file = current_dir .. "/" .. file_base .. ".md"
local pdf_file = current_dir .. "/" .. file_base .. ".pdf"
local Job = require'plenary.job'
Job:new({
command = 'marp',
--args = { '--help' },
args = { md_file, '--pdf', '--browser-path', '/usr/bin/chromium-browser', '--theme-set', '/home/tyler/Documents/ZK_Journal/themes/', '-o', pdf_file },
cwd = current_dir,
}):sync(60000) -- Timeout in 1 minute and wait for completion. Could use :start instead.
end
...
return M Lua command and output
Also, I've checked a few basic things. Running What could cause this problem? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
I've checked another couple of cases. The simplest case of compilation to html fails only sometimes with a 12 second window. With a 1 minute window, it typically succeeds. function M.compile_with_marp()
local Job = require'plenary.job'
Job:new({
command = 'marp',
args = { 'test.md' },
cwd = '/home/tyler/Documents/ZK_Journal/journal/dune-weekly',
}):sync(12000) -- Timeout in 12 seconds and wait for completion
end The more complicated case of pdf compilation usually fails with a 60 second window. function M.compile_with_marp()
local Job = require'plenary.job'
Job:new({
command = 'marp',
args = { '--pdf', '--browser-path', '/usr/bin/chromium-browser', '-- test.md' },
cwd = '/home/tyler/Documents/ZK_Journal/journal/dune-weekly',
}):sync(60000) -- Timeout in 1 minute and wait for completion
end This is confusing. Does marp-cli maybe use parallel processing in a way that it can't access in neovim? |
Beta Was this translation helpful? Give feedback.
-
Please note that I'm not familiar with Lua and neovim. When Marp CLI detected opening stdin stream, CLI would not begin the conversion until read stdin as Markdown contents and close the stream. If Related:
If not resolved, try to add |
Beta Was this translation helpful? Give feedback.
--no-stdin
is exactly the thing I needed. Thanks so much for the help! Here's the state of my function after fixing it up.And in my config file,