paste into ipython console precedes copy of the current cell
argapost opened this issue · 5 comments
Hi and thank you for this awesome plugin!
I have installed in my local machine nvim + vim-slime + vim-ipython-cell and everything works properly.
When I move my setup to a remote machine via ssh, where I don't have root access so I install everything locally, I get the following bug:
When I execute a cell, vim-ipython-cell first pastes whatever is in the clipboard to the python console and after that it copies the code within the cell. So instead of executing the current cell, I execute the previous cell and so on.
It's like the copying and the pasting are running asynchronously and the paste into ipython console finishes before the copy of the cell.
If you have any ideas about what might be wrong, I will be grateful.
Thank you in advance.
(P.S I have installed xclip from source locally)
Hi, thanks for your nice comment. The issue you're encountering sounds very strange. Here are some things you could try:
- Do you encounter the same issue in regular vim?
- The plugin will try to copy the cell using vim/nvim, and if that fails, use an external program. In your case it should use nvim, but just to make sure, you can try to:
-
In
vim-ipython-cell/python/ipython_cell.py
, comment out lines 146-147:# if not copy_successful: # _copy_to_clipboard_external(string, prefer_program)
Does copying still work?
-
If it still works, try to change line 145 (without uncommenting lines 146-147) to:
copy_successful = _copy_to_clipboard_external(string)
(change
_copy_to_clipboard_internal
to_copy_to_clipboard_external
.)Does the behavior change now, or is it still the same?
-
You could also try to include a delay by adding
import time
near the top of the file with the other imports and then add e.g.time.sleep(1)
at the end of the_copy_to_clipboard
function (line 148). Try e.g. a really long delay (e.g.5
for 5 seconds). Does that help? -
You could also try to call the copy function twice by duplicating the
_copy_to_clipboard
call on line 51 (I don't see why this would help, but who knows...).
-
Thank you very much for your quick and extensive response!
If I comment 146-147 yes it still works so I change 145 to:
copy_successful = _copy_to_clipboard_external(string)
and indeed this fixed my issue!
So what does this mean? Should I leave it with the external?
I put the sleep command in line 409 before the slimesend and it fixed my issue as well, while I reverted back to
copy_successful = _copy_to_clipboard_internal(string)
So as I understand the nvim copy is, for some reason, very slow and the slimesend runs first. So the copy to clipboard and the slimesend are running asynchronously? Shouldn't the slimesend wait for the copy?
Hm, that's strange. The plugin itself it not asynchronous, but maybe nvim itself calls the external clipboard program asynchronously, and there's a delay before the system clipboard is updated? Do you use any other clipboard programs like CopyQ? It's mention as potentially causing issues in neovim/neovim#11804. Do you use Wayland?
In any case, I've added an option to prefer using an external clipboard program, which should fix the issue for you. Please update the plugin and add the following to your configuration file:
let g:ipython_cell_prefer_external_copy = 1
I'll close the issue for now, feel free to reopen it if the issue persists.
No, i don't use copyq nor Wayland. It's a supercomputer where I ssh from my local machine the connection can be a bit slow sometimes I don't know if that plays any role.
Anyway, I updated the plugin and now it works smoothly. Thank you very much for your quick solution