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

Python REPL IndentationError: unexpected indent #38

Open
kmARC opened this issue May 7, 2015 · 15 comments · May be fixed by #80
Open

Python REPL IndentationError: unexpected indent #38

kmARC opened this issue May 7, 2015 · 15 comments · May be fixed by #80
Assignees

Comments

@kmARC
Copy link

kmARC commented May 7, 2015

Everything works as expected however when sending an indented line, slimux doesn't cut indentation according the first line as I'd expect after looking at slimux/ftplugin/python.vim

The output of :scriptnames lists the ftplugin, so I guess it's loaded. I tried sourcing it manually, still doesn't work.

Test file:

def test():
    print "hello"

:SlimuxREPLSendLine on the second line has the problem.

Vim log (truncated, started vim with -V9):

Executing BufEnter Auto commands for "*"
autocommand if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif

Executing BufEnter Auto commands for "*"
autocommand sil! call s:LocalBrowse(expand("<amatch>"))

Calling shell to execute: "(tmux set-buffer -- '    print "hello"^M') >/tmp/vBj0Yn7/1 2>&1"
Calling shell to execute: "(tmux paste-buffer -t %1) >/tmp/vBj0Yn7/2 2>&1"
Executing CursorMoved Auto commands for "*"
autocommand call eclim#util#ShowCurrentError()

NerdTree before, eclim after, I am not sure whether it should display invoking SlimuxEscape_python.

@dvbuntu
Copy link
Contributor

dvbuntu commented May 7, 2015

Is removing the indentation necessarily behavior you would want? This seems like more of an issue with the Python REPL. I know Ipython used to have this problem with throwing an indentation error when only one line was used (and indented), but it was fixed somewhat recently.

@kmARC
Copy link
Author

kmARC commented May 8, 2015

Isn't this the expected behavior? I think i'ts generally a good idea to "normalize" indentation, regardless what REPL you are using. I tried it with Ubuntu 14.04 default python 2.7.6

@dvbuntu
Copy link
Contributor

dvbuntu commented May 8, 2015

Maybe it's what you want if you happen to be sending the line to a Python REPL, but you could be sending it anywhere. If, for example, you were sending it to another text document open in that tmux pane, you might want to keep the inherent indentation level. There's no way for slimux to know what kind of environment you're sending the line to, so I believe maintaining the indentation is generally correct.

Maybe a compromise would be a setting one could tweak to change the escaping behavior to dedent lines. I'm not familiar with the escaping process in slimux, but that would give you what you're looking for.

@kmARC
Copy link
Author

kmARC commented May 9, 2015

The README states:

It makes it easy to interact with different tmux panes directly from Vim. It has two styles for interacting with panes. REPL and Shell styles. Main difference between these is pane configuration visibility. Each buffer has own configuration for REPL. [...] REPL commands can have custom pre, post and escape hooks. These allows interaction with some more complex REPLs

From this, I would think if I have a python file opened, then a corresponding hook will take care of fixing the indentation.

But even if it's not true, I'd think 99% of people use these kind of tmux copying plugins to interact with REPLs. So in my eyes this is unnecesarily sacrificed functionality just to be general enough.

@slashfoo slashfoo self-assigned this Sep 23, 2015
@slashfoo
Copy link
Collaborator

I think it'd be useful to remove all preceding levels of indentation from all lines up to when one line is found to have reached the position 0.

This would enable people to test blocks of code from within functions etc.

This would address the issue @kmARC ? I'll try to work on a solution for this.

@sunaku
Copy link
Contributor

sunaku commented Sep 23, 2015

👍 Good idea.

@kmARC
Copy link
Author

kmARC commented Sep 23, 2015

@slashfoo, I originally thought that it works like this, so yepp, I'd be happy if this would be implemented :-)

@mindey
Copy link

mindey commented Dec 9, 2015

Good idea, @slashfoo

@slashfoo
Copy link
Collaborator

I haven't had much time to whip something up for this, but it's still on my queue! If anyone can get to it before I can, I'd be happy to test their PR tho :D

@Gullumluvl
Copy link

Hello,
for those who use IPython, you can take advantage of the %cpaste magic function.

I added this in the ftplugin/python.vim :

" Need to send '%cpaste' before pasting, and '--' or Ctrl-D after
function! SlimuxPre_python(target_pane)
    call system("tmux send-keys -t " . a:target_pane . " %cpaste")
    call system("tmux send-keys -t " . a:target_pane . " Enter")
endfunction
function! SlimuxPost_python(target_pane)
    call system("tmux send-keys -t " . a:target_pane . " C-D")
endfunction

@lotabout
Copy link
Contributor

lotabout commented May 28, 2017

I actually had this requirement for a long time and had a working version for years. But I wasn't sure whether it should be included by default or not. Now I think it is the good time to send a PR.

@slashfoo Would you please help to test? Thanks!

@slashfoo
Copy link
Collaborator

Tested that :SlimuxREPLSendLine on the lines of the code snipped below, also tested :SlimuxREPLSendSelection, :SlimuxREPLSendParagraph, and :SlimuxREPLSendBuffer on the python3 repl, anything else that you'd like to test?

  def test():
      print("hello world")

      for i in range(9):
          print(i)

  test()

@zcesur zcesur linked a pull request Feb 5, 2018 that will close this issue
@DavidRV00
Copy link

Hello, are the above PRs ever going to get merged in?

@slagtermaarten
Copy link

Bump, I'd also like to see this :)

@slagtermaarten
Copy link

As a workaround, the IPython console handles indentation well.
I'm starting it up by dropping from IPython import embed; embed() into my script

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

Successfully merging a pull request may close this issue.

9 participants