-
-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Append code block results to markdown document #152
Comments
Linking that here while I try to find some free time |
#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. |
Hey! So I've been trying to get similar functionality by copying the output to the {
"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 {
"<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 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! 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 " |
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:
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.
The text was updated successfully, but these errors were encountered: