I am trying to use options with names depending on user input ( that is, argument to a command), since there is no arrays or other collection types in kakoune.
So far I have been able to create such options with
declare-option str “bridge_%arg{1}_pid”
and when I call
my-command AAA
I get an option named bridge_AAA_pid
However I don’t know how to use the content of the created option, in either %{} or %sh{} blocks.
So far I’ve tried
define-command -override test-pid -params 1 %{
echo %opt{bridge_%arg{1}pid}
echo %opt{bridge"%arg{1}“pid}
echo %opt{"bridge%arg{1}pid"}
echo %opt"{bridge%arg{1}pid}"
echo "%opt{bridge%arg{1}_pid}”
}
test-pid AAA
but none of them worked.
Unlike POSIX shell, which has multiple expansion passes and thus frequently allows things to be expanded more times than the programmer expects, Kakoune is very careful to only ever expand things once, unless you ask for it specifically. That means you can’t do the kind of thing you’re trying to do deliberately, but it also means you can’t do it accidentally, so overall I think it’s a win.
If you want multiple rounds of expansion, you’re going to need to use the eval command, something like this: