Currently, we can have multiple buffers associated with each running kernel, but we can only have one running kernel per buffer.
In some cases (ie. when running code in a notebook file like quarto), it's possible to have multiple code cells with different languages, and you may want to run them both.
The current best way to do that would be to run all the code in language one, switch kernels (and lose all the language one output), then run all the code in language two.
implementation
Implementing this would require changes to some core areas of Molten. It is 100% necessary that the current way of using the plugin does not change at all.
initialization
My first thought was to create another variant of :MoltenInit
similar to how we have :MoltenInit shared <kernel>
we could have :MoltenInit add <kernel>
to add a new kernel to the current buffer.
But after thinking about it a little more, why not just change the default behavior of :MoltenInit <kernel>
when there is already a kernel running. I know this could be seen as a breaking change, but initializing twice was never supported, it was just undefined behavior.
running code
This then begs the question of how does Molten know which kernel to send the code to for a command like :MoltenEvaluateLine
?
Solution:
MoltenEvaluate*
commands take an optional kernel
param
- if there is only one kernel attached to the buffer, send the code to that kernel
- if there is more than one kernel attached to the current buffer, prompt the user to select which one they should send that code to
save/load
Saving a molten buffer currently saves a single kernel name. We would have to move the kernel information into each code cell, and then restore this information separately as well.
OR
We could only save one kernel at a time.. this would probably be a worse user experience, but at the same time a much easier change to implement, and a less breaking change. I'm also not really sure that people would be using this command anyway given that no one using Magma had filed an issue about it being broken for months
other commands
All of these commands are affected in the same way: they need to take a kernel name, or prompt the user if there's more than one kernel and no name is specified.
:MoltenInterrupt
:MoltenRestart
MoltenDeinit
is a special case. I'm going to have this one shut down an entire buffer and everything associated with it for the time being. I might change this before this feature releases. But for ease of development, I don't foresee people caring that much about shutting down one kernel at a time.
autocommands
Autocommands like (de)init(pre/post) could potentially be called more than once now. I think this is just something that has to be documented. There should be a way to call the autocommand callback with an argument that's the name of the kernel that was (de)initialized.
enter output
This command would become very problematic if there were to be more than one code cell active at a time. In order to prevent this, we should make sure that code cells from different kernels cannot overlap. This is something that would have to be checked each time code is run.