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

Additional 'return' required when sending indented, commented code to ipython #418

Open
xxyxxyxyx1 opened this issue Feb 13, 2024 · 3 comments

Comments

@xxyxxyxyx1
Copy link

xxyxxyxyx1 commented Feb 13, 2024

I am using kitty+neovim+ipython. When I SlimeParagraphSend to ipython, in most cases, the paragraph runs immediately in ipython. However, if the paragraph ends in an indented line followed by a comment, it does not work and I must manually press 'return' in the ipython interpreter.

Here are some examples to explain the problem. They are equivalent when the indented code is a def(), a for, etc.

# test that works
def test():
    print('test')
# test that doesn't work, I must press 'return' in the ipython interpreter to get the code to run
def test():
    print('test')
# this terminal comment line breaks it

After sending the above paragraph, the ipython interpreter looks like this until I press 'return':

In [1]: # test that doesn't work
   ...: def test():
   ...:     print('test')
   ...: 
   ...: #
   ...: 

Adding a pass (or any other non-comment, non-indented python line) between the indented line and the terminal comment prevents the problem:

# test that works 
def test():
    print('test')
pass 
# adding an extra non-indented, non-comment line prevents the problem

This is inconvenient for me because I use vim folds like #{{{ ... #}}} to organize files, so I often have a terminal #}}} after a function definition.

My relevant vimrc is:

let g:slime_bracketed_paste = 1
let g:slime_target = "kitty"
let g:slime_default_config = {"listen_on": $KITTY_LISTEN_ON}

Any idea where this problem comes from?

@jpalardy
Copy link
Owner

Hi @xxyxxyxyx1

Of all the REPLs out there, python is the one that caused the most problems. I would recommend trying different permutations until you can isolate the problem:

  • slime_bracketed_paste versus not
  • kitty versus not

Let me know what you find and we can iterate.

@xxyxxyxyx1
Copy link
Author

Thank you for the suggestions. Switching from slime_bracketed_paste to slime_python_ipython seems to solve this problem.

slime_python_ipython is inferior in other ways:

  • it is noticeably slower to execute with a long paragraph, as text is written to the interpreter and scrolls by line-by-line
  • the pasted text doesn't have syntax coloring (not really important, as I have colors in vim where editing happens)

For speed, it would be very nice to fix the bracketed paste mode, but this is a usable solution that doesn't require changing the python file itself.

@jpalardy
Copy link
Owner

In the case of python itself, what would it take to fix bracketed mode?

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

2 participants