Open Lun4m opened 3 years ago
How exactly are you envisioning this? I feel like there are two ways:
\ric
(for some fictional text object ic
) to run that cell (you could also map this to some other keybinding, of course);While the second option does sound attractive, it scares me -- we'd need to continuously check for where cells should be, which promises to be costly (unless we use that "new" nvim_buf_attach, but I have no idea how that works and it may still be a bit complicated). Or we can try to use treesitter, but I feel like you are thinking of delimiters which are not captured by treesitter (e.g., #:begin
and #:end
in Python).
As I mentioned in the first closed issue, I've been using nvim-ipy and there you can define a customizable cell delimiter with
let g:ipy_celldef = '^##'
.
I guess in this case the background highlight won't be that necessary since you already know where the cell starts and ends.
But I don't know if that's easily removable.
Also in practice I think you only need to evaluate where the delimeters are when you run :MagmaReevaluateCell
.
Anyway this is a very marginal feature request (mostly for preserving the "muscle memory" from the previous plugin I was using) since magma manages cell identification quite well!
This seems to me that what @Lun4m is asking is in essence close what jupytext is providing. There are many formats that allow isomorphic transformation from text to jupyter-notebook. My prefered format is the one used in the quarto project, I think using those formats for delimiters would make sense.
My proposal would be simply to add a configurable cell delimiter, to not add highlighting for this, and only change MagmaReevaluateCell
to add a extmark cell with all lines inbetween the delimiters if it is run outside of an extmark cell (or error if no delimiters are found, basically the behavior it has right now if outside of a cell).
I would love to implement this based on https://github.com/bfredl/nvim-ipy, if you agree to it @dccsillag.
@tbung Yeah, that seems like a great idea actually. Go ahead.
Any progress on this @tbung?
I have something working in lua in my dotfiles but didn't have the time yet to clean it up and translate it to python due to work. I might get around to it later this week. Until then you can check out these two files for a working solution:
https://github.com/tbung/dotfiles/blob/main/.config/nvim/lua/tbung/jupyter.lua https://github.com/tbung/dotfiles/blob/main/.config/nvim/after/ftplugin/python.lua
Would it be possible to have manual cell delimeters? Something like: