kiyoon / jupynium.nvim

Selenium-automated Jupyter Notebook that is synchronised with NeoVim in real-time.
MIT License
520 stars 15 forks source link

Untitled.ipynb artifacts #62

Closed sho-87 closed 1 year ago

sho-87 commented 1 year ago

Currently, every time you sync a ju file it will instantly create an artifact Untitled.ipynb file in the working directory. What this means is that the user must go in and clean up after themselves, otherwise the directory will be littered with old files, and can get especially bad if user is syncing multiple files at the same time

image

I think it's currently intended for Jupynium to create untitled files on sync, but might be worth re-evaluating this workflow following the discussions in #44

Possible solutions might be:

kiyoon commented 1 year ago

I thought about finding the correct filename by default, but since it shouldn't delete the file without noticing, it should ask if the file already exists.

This may not be ideal for people who want to just use a tmp dir to sync. In that case you don't care about overwriting so the current behaviour is more desirable for some people.

So I need to probably change the default to find the correct filename, and then still add an option to make untitled names.

I can do something like

:JupyniumStartSync [filename / tab_idx / --untitled] and if the argument is not provided, it just finds the file with the same name. If the argument is --untitled it will be like the current behaviour.

sho-87 commented 1 year ago

that would make sense

another option might be to use the system tmp directory so it doesnt clutter the working directory, and will get wiped on reboot. and have a setting to opt in to filename syncing (although like you said, maybe that should just be the default anyway)

kiyoon commented 1 year ago

See #23 if you want to just open the notebook server to the temp dir. The only problem is that it won't keep the notebook's directory the same as the file, so if you want to have some file operations you want to use absolute paths

kiyoon commented 1 year ago

Does this solution with different notebook dir work for you? Or you'd still want to make :JupyniumStartSync default to the current file name?

sho-87 commented 1 year ago

I didnt think about the issue of notebook and ju file having different directories. I think in this case syncing to the current filename ipynb would be nice to avoid clutter

kiyoon commented 1 year ago

Hi, sorry for taking so long to respond. I suppose this is already possible.

If you start sync with a name, it will open the file instead of creating a new notebook. If you want to sync with a current name, it is as simple as

filename_wo_ext = vim.fn.expand "%:r:r"
vim.cmd([[JupyniumStartSync ]] .. filename_wo_ext)

It is not an officially supported API (so it might change in the future), but you can also use a lua function

---Start synchronising the buffer with the ipynb file
---@param bufnr integer buffer number
---@param ipynb_filename string name of the ipynb file
---@param ask boolean whether to ask for confirmation
function Jupynium_start_sync(bufnr, ipynb_filename, ask)

So you can do something like

filename_wo_ext = vim.fn.expand "%:r:r"
Jupynium_start_sync(0, filename_wo_ext, false)
sho-87 commented 1 year ago

ah yes, thats a nice simple solution. will use that from now on!