Append code block results to markdown document
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:
```python
print('Hello, World!')
```
_Result:_
```plain
Hello, World!
```
This way you can save the output for sharing/publishing, similar to Orgmode or Jupyter Notebooks.
You could keep virtual text on but have this as a compile step for your individual cells. As I imagine such a feature should be exempt from REPL capabilities, otherwise it could cause some problems.
Linking that here while I try to find some free time https://github.com/michaelb/sniprun/issues/111#issuecomment-963051868
#153 adds supports for multiple code blocs in one selection, meaning that you can now do even :%SnipRun (in markdown or orgmode) and have sensible outputs. (one per code bloc)
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