-
I'd like to make a snippet that gives you choices like c(1, t"today", t"tomorrow", t"next week") But then after I leave the choice node, whichever choice was selected is transformed into the actual date. I've played around with function nodes and callbacks, but I'm not sure how to force a function node to re-compute from within a callback. Is this something I could do? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Mhhh implementing this exactly as you state is difficult because you'd have to put the choiceNode inside a dynamicNode to change it, and updating from inside the dynamicNode is currently forbidden. But I have another suggestion that should be similarly good: As I understand it, you're essentially using the choiceNode to put easily readable labels to less-readable dates. local function date_at(when)
return d(1, function()
local out = vim.system({"date", "--iso-8601", "-d", when}):wait()
-- remove trailing \n
local datestring = out.stdout:sub(1,-2)
return sn(nil, {i(1), t(datestring)}, {node_ext_opts = {active = { virt_text = {{when, "Comment"}} }}})
end)
end
s("date", {
c(1, {
date_at("today"),
date_at("tomorrow"),
date_at("next week"),
})
}) (note that this does not work on current master, you need the patches in 1751837434.mp4 |
Beta Was this translation helpful? Give feedback.
Mhhh implementing this exactly as you state is difficult because you'd have to put the choiceNode inside a dynamicNode to change it, and updating from inside the dynamicNode is currently forbidden.
But I have another suggestion that should be similarly good: As I understand it, you're essentially using the choiceNode to put easily readable labels to less-readable dates.
I'd implement this by using
ext_opts
to show this readable lable, while just switching between the already-correct choices: