I’ve been working on a proof of concept for working with Kakoune expansions that will work something like the create-context
function in this example.
define-command confirm-file-deletion %{
prompt "Confirm Deletion? (YES/NO)" %{
# %var{text} holds the contents of the user prompt
create-context %var{text} %{
try %{
# is the user input the string yes?
exec _s(?i)^yes$<ret>
delete-file
}
catch %{ try %{
# is the user input the string no? Then exit function.
exec _s(?i)^no$<ret>
} catch %{
# input was invalid, ask for input again
confirm-file-deletion
}
}
}
}
Essentially I want to be able to treat the output of %opt{}, %var{}, %reg{} and %sh{} blocks as if they were a temporary buffer (plus some extra stuff like selecting each str in a declare-option str-list
automatically). The intent is be able to program some basic logic using Kakoune’s text editing primitives and without using the shell. One of the restrictions at the moment is getting the contents of something like %var{selection}
or %sh{find}
into a buffer the same way and while preserving new lines.
Does anyone know a way to achieve this? I’m currently using
exec "i%arg{0}"
inside my create-context
function but because this prints new line literals and not <ret>
everything is one one line. In an ideal world there would probably be something like echo -to-buffer 'temporary-buffer' %arg{0}
.