-
I was trying to use wolframscript inside a snippet. Is there a way to use set_text on an InsertNode and update the text inside the callback using the api? So far, I got this working: ls.add_snippets("tex", {
s({ trig = "math" }, { i(1), t " ", i(0) }, {
callbacks = {
[1] = {
[events.leave] = function(node)
local from_pos, to_pos = node.mark:pos_begin_end_raw()
local lines = vim.api.nvim_buf_get_lines(0, from_pos[1], to_pos[1] + 1, false)
local script = ([[!wolframscript -c "ToString@TeXForm[%s]"]]):format(node:get_text()[1])
local output = vim.split(vim.api.nvim_exec(script, true), "\n")
output = output[#output - 1]
if #lines == 1 then
local p1 = string.sub(lines[1], 1, from_pos[2])
local p2 = string.sub(lines[1], to_pos[2] + 1, #lines[1])
lines[1] = p1 .. output .. p2
end
vim.api.nvim_buf_set_lines(0, from_pos[1], to_pos[1] + 1, false, lines)
vim.api.nvim_win_set_cursor(0, { to_pos[1] + 1, from_pos[2] + #output }) -- nope
end,
},
},
}),
}, {}) |
Beta Was this translation helpful? Give feedback.
Answered by
L3MON4D3
Jun 1, 2022
Replies: 1 comment 3 replies
-
I think we could support a |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
tiagovla
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we could support a
set_text
for insertNode and textNode, it would probably look very much like what you have currently.Is the
win_set_cursor
necessary? Afaict the cursor should be set after jumping.