This bridge runs a python shell in the background and can send selections through the shell. This way you can do calculations while keeping memory of previous variables, so this enables you to use variables in later calculations.
It has some quirks because I read the output using a while read loop, I’m still looking for a better way, any suggestions?
Any feedback is welcome.
Edit: Quirks have been resolved due to the suggestion of @Screwtapello
Python is itself a scripting language that can evaluate code, so you could move a bunch of logic from shell to Python. That is, your Kakoune script could include a Python snippet that executes an infinite loop of:
open the input FIFO for reading, and read the entire contents
if writing to the output FIFO generates an error, exit
Piping code from Kakoune would look something like:
cat output-fifo & # start reading the output, so Python can safely write
cat > input-fifo & # send the input to Python
wait # do not continue until the communication is complete
To tell the Python repl to exit, just write any expression to the input fifo, without setting up a reader on the output fifo. When the repl tries to print the result of the expression, the write fails, and it should exit.
and use it then to call your python script. Because users may install your plugin to different location, e.g. I know that at least one guy is using .cache directory for plug.kak plugin installation path for some reason.
What do you think about a command to toggle the log fifo, rather than an option and hooks?
And a command to return the result in a new line below, instead of replacing the selection? Maybe call it python-bridge-below or something. I think, ideally, a plugin like this would follow the behavior of the p and R keys.
And some nitpicks:
Why do you shell out for initializing the options in pyhon-bridge.kak?
The README says python_bridge_folder is an option you can set, but it’s hidden in the script. IMO people won’t need to set that option, so you can remove that line from the README.