Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 63a1609

Browse files
committed
Fix problem where sending big chunk of text would silently fail.
Tmux seems to have a max past buffer size. So split big chunk into smaller pieces
1 parent 6e414e2 commit 63a1609

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

ftplugin/python/pyutils.vim

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def run_tmux_python_chunk():
2121
without python complaining about indentation.
2222
"""
2323
r = vim.current.range
24+
#vim.command("echo 'Range : %i %i'" % (r.start, r.end))
2425
# Count indentation on first selected line
2526
firstline = vim.current.buffer[r.start]
2627
nindent = 0
@@ -29,12 +30,15 @@ def run_tmux_python_chunk():
2930
nindent += 1
3031
else:
3132
break
32-
#vim.command("echo '%i'" % nindent)
33+
# vim.command("echo '%i'" % nindent)
3334

3435
# Shift the whole text by nindent spaces (so the first line has 0 indent)
3536
lines = vim.current.buffer[r.start:r.end+1]
36-
pat = '\s'*nindent
37-
lines = "\n".join([re.sub('^%s'%pat, '', l) for l in lines])
37+
if nindent > 0:
38+
pat = '\s'*nindent
39+
lines = "\n".join([re.sub('^%s'%pat, '', l) for l in lines])
40+
else:
41+
lines = "\n".join(lines)
3842

3943
# Add empty newline at the end
4044
lines += "\n\n"
@@ -53,7 +57,15 @@ def run_tmux_python_chunk():
5357
vim.command(':call Send_to_Tmux("\%cpaste\n")')
5458
lines = lines.replace('\\', '\\\\')
5559
lines = lines.replace('"', '\\"')
56-
vim.command(':call Send_to_Tmux("%s")' % lines)
60+
#vim.command("echo 'sending to tslime length : %i'"%len(lines))
61+
# Tmux doesn't like big paste-buffer (the limit is somewhere between 2000
62+
# and 3000 bytes).
63+
bufsize = 2000
64+
for i in xrange(0, len(lines), bufsize):
65+
linepiece = lines[i:i+bufsize]
66+
vim.command(':call Send_to_Tmux("%s")' % linepiece)
67+
68+
#vim.command(':call Send_to_Tmux("%s")' % lines)
5769
vim.command(':call Send_to_Tmux("\n--\n")')
5870
else:
5971
set_register('+', lines)

0 commit comments

Comments
 (0)