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

Indentation error when sending two functions at once with python #455

Open
nickeisenberg opened this issue Feb 28, 2025 · 3 comments
Open

Comments

@nickeisenberg
Copy link

nickeisenberg commented Feb 28, 2025

I am using the vimterminal as my repl and I am getting an indentation error when sending two python functions at once to the repl. For example, with the following script,

def foo():
    return 1
def bar():
    return 1

If I put my cursor over def foo and hit <c-c><c-c> then the following happens in the terminal

>>> def foo():
...     return 1
... def bar():
  File "<stdin>", line 3
    def bar():
    ^^^
SyntaxError: invalid syntax
>>>     return 1
  File "<stdin>", line 1
    return 1
IndentationError: unexpected indent
>>> 
>>> 

I am pretty sure that the issue occurs because python does not have an "indentation" closure like basically every other language. For example, I can send the following to the bash repl just fine.

foo() {
    echo hello
}
bar() {
    echo hello
}

I am pretty sure that this does not cause andissue because bash encloses the indentation in brackets.

I am using the vimterminal as my repl and I am getting an indentation error when sending two python functions at once to the repl. For example, with the following script,

def foo():
    return 1
def bar():
    return 1

If I put my cursor over def foo and hit <c-c><c-c> then the following happens in the terminal

>>> def foo():
...     return 1
... def bar():
  File "<stdin>", line 3
    def bar():
    ^^^
SyntaxError: invalid syntax
>>>     return 1
  File "<stdin>", line 1
    return 1
IndentationError: unexpected indent
>>> 
>>> 

I am pretty sure that the issue occurs because python does not have an "indentation" closure like basically every other language. For example, I can send the following to the bash repl just fine.

foo() {
    echo hello
}
bar() {
    echo hello
}

I am pretty sure that this does not cause andissue because bash encloses the indentation in brackets.

I am actually one of the maintainers of iron.nvim, which is a neovim repl plugin, and I had this same problem with python there. I had to write a very python specific formatter to send lines of code

EDIT:
Also I should add that I just realized that this does not happen on my linux machine, only on mac while using the mac terminal. So the problem most likely has to do with mac and its terminal. Ill leave this issue here for a second as maybe you have a quick solution but if not, feel free to close the issue.

@jpalardy
Copy link
Owner

Hi @nickeisenberg

Python has been a constant pain, when it comes to paste text 😃

Have you tried bracketed_paste, does it change anything? (here)

It's very curious that this happens only on your mac 🤔

You can experiment with this code to see if that would do what you want ...

Let me know what you find.

@nickeisenberg
Copy link
Author

nickeisenberg commented Feb 28, 2025

My quick fix for this is to use ipython instead of the standard python repl in the mac terminal. I tried bracketed_paste but it did not seem to work.

I actually remember having problems on the mac terminal with iron.nvim too and I also had to use ipython there.

When I have some free time, I can try to mess around a little with the vimscript formatter you have, but i'm fine with using ipython in the meantime. Feel free to close this issue if you want!

@jpalardy
Copy link
Owner

This will auto-close on inactivity, so I'll leave it around.

Ping me if you converge on a solution 👍

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