Open silversquirl opened 1 year ago
For reference, tools like kakoune-remote-control work the same way:
It'd be nice if kak -p
were effectively a simple client that sent stdin as commands, and printed :echo
output to stdout. Unfortunately, Kakoune's client-server protocol doesn't communicate :echo
output separately, it sends all the text that would be displayed on-screen by a terminal client, which is presumably why it works the way it currently does.
It would be nearly as nice if Kakoune had some built-in implementation of the "make temp file, tell server to echo to temp file, read temp file, delete temp file" dance.
Kakoune is designed to integrate with other Unix tools, but it's a lot more comfortable if it's orchestrating the interaction, rather than letting other things interact with it.
This is definitely a pain point that needs to be solved. An third alternative solution would be to extend the command/response fifo system to allow long-lived ones, which would reduce the example to:
echo "echo -to-file $kak_response_fifo %val{buflist}" > $kak_command_fifo
buflist=$(cat $kak_response_fifo)
This could be slightly improved by keeping a map of command to response fifo in Kakoune:
echo "echo -to-response-fifo %val{buflist}" > $kak_command_fifo
buflist=$(cat $kak_response_fifo)
I do like the idea of outputing whatever is echo'd from kak -p
however it can lead to some ambiguity:
echo "eval -client foo %{ echo %val{selections} }" | kak -p
. I guess we could add yet another switch to echo to control that.
We could also introduce a `kak -expand
I do like the idea of outputing whatever is echo'd from
kak -p
however it can lead to some ambiguity:echo "eval -client foo %{ echo %val{selections} }" | kak -p
.
That ambiguity already exists with :fail
:
printf "%s" "eval -client client %{ fail blah }" | kak -p session
kak -p
does not show the failure message and does not exit with a non-zero exit code, the intended client does not show the failure message, it only winds up in the *debug*
buffer. Of course, sending fail blah
directly to kak -p
has exactly the same result so in that sense at least it's consistent.
Perhaps a /proc like virtual file system e.g. bufflist=$(cat /kak/$systemid/$clientid/buflist/quoted)
Feature
Currently it's very annoying to get data out of a kakoune session remotely. The best I could come up with is something like this:
That's a lot to simply get the value of
%val{buflist}
into a shell variable.There are a couple of possible solutions:
-f
work together with-c
. This would allow doing something likebuflist="$(kak -c "$session" -f ':reg dquote %val{buflist}<ret><a-p>a<ret>' </dev/null)"
instead of the above (dependent on #4879 being fixed). Note that this has a slightly different output format compared to the above, as it's line-separated rather than NUL-separated.-p
to write to stdout. The simplest option here is probably having-p
open an empty scratch buffer and write its contents to stdout when stdin is closed.Usecase
This is useful for writing scripts that remotely interact with kakoune. For example, I recently wrote a small Python script that had to run a command in every kakoune session on the machine and read back a value.