Open daephx opened 2 years ago
Linking that here while I try to find some free time https://github.com/michaelb/sniprun/issues/111#issuecomment-963051868
There's no support for modifying the buffer in the meantime though, so it doesn't do what you want. With the VirtualText display option, it looks okay-ish, but nothing is inserted nor savable in the file..
Alright thanks for the consideration, that sounds interesting in the mean time. I'll take a look when I get a moment!
Hey! So I've been trying to get similar functionality by copying the output to the *
buffer to be able to paste with p
. Here's what I have so far:
{
"michaelb/sniprun",
cmd = "SnipRun",
branch = "master",
build = "sh install.sh",
config = function()
require("sniprun").setup {
-- your options
}
end,
keys = {
{ "<leader>sr", "<cmd>:redir @* | :SnipRun | redir END<cr>", mode = { "n" }, desc = "SnipRun" },
{ "<leader>sr", "<cmd>:redir @* | :'<,'>SnipRun | redir END<cr>", mode = { "v" }, desc = "SnipRun" },
{ "<leader>sc", "<Plug>SnipClose", desc = "SnipClose" },
},
},
This works so far but I'd like to add ```plain\n{msg}\n```
around the message. Here's what I tried so far, but I'm having some trouble:
{
"<leader>sr",
function()
vim.cmd "redir @a | SnipRun | redir END"
local a = vim.fn.getreg "a"
vim.fn.setreg("b", a)
end,
mode = { "n" },
desc = "SnipRun",
},
This doesn't look like it's writing to the correct register, and when I check the a
register with :reg
it looks like it's empty. Wondering if y'all are experiencing similar issues. It also tried stuff with nvim_exec
and nvim_command
but had similar results.
It may be something with my neovim config itself. Pretty new to this deep configuration so let me know if I'm missing something obvious 😄 .
Hi! You're charting mostly unexplored terrain, but if your current solution works somehow, well I see no reason to change it
The 'clean' approach would be to use the API 's register_listener to create your own (lua) function to handle output however you want. It should also be relatively easy to customize the output to get wrapped with "plain\n{msg}\n
" or whatever you want and continue using the rest of your scripts
It's a bit late but here's my take on this
local api_listener = function(d)
if vim.bo.filetype ~= "markdown" then
return
end
if d.status ~= "ok" or d.message == "" then
return
end
local output = string.format("```plain\n%s\n```\n", d.message)
vim.fn.setreg('"', output)
end
require("sniprun.api").register_listener(api_listener)
As an extension to #50: Much like the the orgmode screenshot supplied, is it possible to have a display option, specifically for source code blocks in markup where the result is printed to the document itself?
Example:
Result: