Open kmARC opened 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.
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
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.
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.
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.
:+1: Good idea.
@slashfoo, I originally thought that it works like this, so yepp, I'd be happy if this would be implemented :-)
Good idea, @slashfoo
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
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
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!
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()
Hello, are the above PRs ever going to get merged in?
Bump, I'd also like to see this :)
As a workaround, the IPython console handles indentation well.
I'm starting it up by dropping from IPython import embed; embed()
into my script
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:
:SlimuxREPLSendLine
on the second line has the problem.Vim log (truncated, started vim with -V9):
NerdTree before, eclim after, I am not sure whether it should display invoking SlimuxEscape_python.