luk400 / vim-jukit

Jupyter-Notebook inspired Neovim/Vim Plugin
MIT License
587 stars 23 forks source link

import sys command not escaping double quotes #111

Closed code-jumper closed 7 months ago

code-jumper commented 8 months ago

Using neovim on windows 10 + powershell. vim-jukit plugin installed with lazy. My intention is to have a jupyter notebook-like experience thru (neo)vim

when pressing <leader>os to output split, first the following message appears in the nvim status line:

[vim-jukit] invalid version number encountered: [] [7, 3, 0] Press ENTER or type command to continue

then the following:

` PS C:\Users\$USER\repos\jupyter_projs\py_testin g> ipython3 -i -c "import sys;sys.path.append(\ "C:\Users\$USER\AppData\Local\nvim-data\l azy\vim-jukit\helpers\");import matplotlib.py plot as plt;from matplotlib_show_wrapper import show_wrapper;plt.show = show_wrapper(plt.show, 1);plt.show.annotations[\"save_dpi\"] = 15 0;from IPython import get_ipython;__shell = get _ipython();shell.run_line_magic(\"load_ext\", \"jukit_run\");shell.run_linemagic(\"jukit init\", \"C:\Users\$USER\repos\jupyter_proj s\py_testing\py_testing1.1.ipynb 2 --max_size =20\");" Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 4 202 3, 23:49:59) [MSC v.1934 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for mo re information IPython 8.13.2 -- An enhanced Interactive Pytho n. Type '?' for help. Cell In[1], line 1 import sys;sys.path.append(" C:\Users\$US ER\AppData\Local\nvim-data\lazy\vim-jukit\ \helpers);import ^ SyntaxError: unterminated string literal (detec ted at line 1)

In [1]: `

Basically, it looks like the " is not being escaped with the \. the first double quote before import starts the string, and then the double quote before the C: drive is closing the string.

ipython3 -i -c "import sys;sys.path.append(\"C:\\Users\\$USER\\AppData\\Local\\nvim-data\\lazy\\vim-jukit\\helpers\")

I've read that you can't escape double quotes in some cases with cmd but not sure if that is correct or applicable to this.

I've also been digging thru the vim-jukit files and think I've found where the commands passed to ipython are located when calling <leader>os (C:/Users/$USER/AppData/Local/nvim-data/lazy/vim-jukit/autoload/jukit/splits.vim)

I think the pertinent code block in this file is:

` if use_ipy let pyfile_ws_sub = substitute(escape(expand('%:p'), '\'), ' ', '', 'g') let store_png = g:jukit_hist_use_ueberzug ? ' --store_png' : '' let cmd = cmd . "from IPython import get_ipython;" . "__shell = get_ipython();" . 'shell.run_line_magic("load_ext", "jukit_run");' . 'shell.run_line_magic("jukit_init", "' . pyfile_ws_sub . ' ' . g:jukit_in_style . ' --max_size=' . g:jukit_max_size . store_png . ueberzug_opt . '");' if !g:jukit_debug && !g:_jukit_is_windows let cmd = cmd . '__shell.run_line_magic("clear", "");' endif endif

if g:_jukit_is_windows
    let cmd = shell_cmd . " -i -c \"" . substitute(cmd, '"', g:_jukit_win_escape_char . '"', 'g') . "\""
    return cmd
else
    let cmd = shell_cmd . " -i -c '" . cmd . "'"
    return cmd
endif

`

but I'm a bit lost with what's going on here

Is there a way to get the double quote escaped? Or am I looking for the solution in the wrong place?

Thanks

code-jumper commented 7 months ago

I had powershell as default terminal for vim (vim.opt.shell = 'powershell.exe'), removing this from vimrc solved the issue, works fine with default terminal