esamattis / slimux

SLIME inspired tmux integration plugin for Vim
http://esa-matti.suuronen.org/blog/2012/04/19/slimux-tmux-plugin-for-vim/
Other
217 stars 52 forks source link

Python REPL IndentationError: unexpected indent #38

Open kmARC opened 9 years ago

kmARC commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

:+1: Good idea.

kmARC commented 9 years ago

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

mindey commented 8 years ago

Good idea, @slashfoo

slashfoo commented 8 years ago

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 commented 8 years ago

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 commented 7 years ago

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 commented 7 years ago

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()
DavidRV00 commented 4 years ago

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

slagtermaarten commented 4 years ago

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

slagtermaarten commented 4 years ago

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