Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vim-slime not working with IPython #368

Open
jlc-backsbag opened this issue Mar 7, 2023 · 4 comments
Open

Vim-slime not working with IPython #368

jlc-backsbag opened this issue Mar 7, 2023 · 4 comments

Comments

@jlc-backsbag
Copy link

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
Copy link
Owner

jpalardy commented Mar 7, 2023

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
Copy link

MadFisa commented Apr 18, 2023

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

@c-torre
Copy link

c-torre commented Apr 19, 2023

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
Copy link

c-torre commented Apr 21, 2023

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants