jpalardy / vim-slime

A vim plugin to give you some slime. (Emacs)
http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/
MIT License
1.9k stars 227 forks source link

Vim-slime not working with IPython #368

Open jlc-backsbag opened 1 year ago

jlc-backsbag commented 1 year ago

I have a problem where when using slime to send any text to an iPython shell, the %cpaste -q gets sent but then the console gets stuck. The only way to get out is with ctrl-c and then I get this error message:

[ins] In [1]: %cpaste -q

^C---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
Cell In[1], line 1
----> 1 get_ipython().run_line_magic('cpaste', '-q')

File ~/.virtualenvs/.DuoPad/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2369, in InteractiveShell.run_line_magic(self, magic_name, line, _stack_depth)
   2367     kwargs['local_ns'] = self.get_local_scope(stack_depth)
   2368 with self.builtin_trap:
-> 2369     result = fn(*args, **kwargs)
   2371 # The code below prevents the output from being displayed
   2372 # when using magics with decodator @output_can_be_silenced
   2373 # when the last Python token in the expression is a ';'.
   2374 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/.virtualenvs/.DuoPad/lib/python3.10/site-packages/IPython/terminal/magics.py:149, in TerminalMagics.cpaste(self, parameter_s)
    146 quiet = ('q' in opts)
    148 sentinel = opts.get('s', u'--')
--> 149 block = '\n'.join(get_pasted_lines(sentinel, quiet=quiet))
    150 self.store_or_execute(block, name, store_history=True)

File ~/.virtualenvs/.DuoPad/lib/python3.10/site-packages/IPython/terminal/magics.py:29, in get_pasted_lines(sentinel, l_input, quiet)
     27 while True:
     28     try:
---> 29         l = l_input(prompt)
     30         if l == sentinel:
     31             return

File ~/.virtualenvs/.DuoPad/lib/python3.10/site-packages/IPython/utils/py3compat.py:48, in input(prompt)
     47 def input(prompt=""):
---> 48     return builtin_mod.input(prompt)

KeyboardInterrupt:

The problem does not occur with iPython 7.31.1, which is the version I ended up downgrading to. A version that it doesn't work in is 8.9.0.

Not sure if this is vim-slime problem or an ipython problem..

jpalardy commented 1 year ago

Hi @jlc-backsbag

Thanks for reporting this ☝️

I'm not a ipython user myself — let's keep this open and see if other users want to chime in.

MadFisa commented 1 year ago

@jlc-backsbag can you try manually typing '--' and press enter (twice if required) after the %cpaste -q?

c-torre commented 1 year ago

I can reproduce OP's error with ipython 8.12.0 and tmux.

Entering -- + Enter after %cpaste -q results in SyntaxError: invalid syntax.

Switching to ipython 7.34.0, the latest ipython 7 version, solved the issue.

c-torre commented 1 year ago

In my case, I have solved it for ipython 8.12.0 by checking https://github.com/jpalardy/vim-slime/tree/main/ftplugin/python i.e., eating a big spoon of RTFM :)

An educated guess for the cause is the tmux+ipython setup. Haven't tried with other multiplexers, though.

The solution was to change let g:slime_python_ipython = 1 to let g:slime_bracketed_paste = 1 in the vim config file. For nvim with a lua config, it's vim.g.slime_bracketed_paste = 1 in init.lua.

@jlc-backsbag maybe this will solve it for you, too :)