Allow interrupting nREPL connection

Closes #30.
This commit is contained in:
Tim Pope 2013-01-10 23:09:54 -05:00
parent 7a36f4e8b8
commit 286a1f6c47

View File

@ -204,6 +204,7 @@ endif
python << EOF python << EOF
import vim import vim
import select
import socket import socket
import string import string
import re import re
@ -223,13 +224,16 @@ def foreplay_let(var, value):
def foreplay_repl_interact(): def foreplay_repl_interact():
buffer = '' buffer = ''
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(16.0)
try:
host = vim.eval('self.host') host = vim.eval('self.host')
port = int(vim.eval('self.port')) port = int(vim.eval('self.port'))
s.settimeout(8)
try:
s.connect((host, port)) s.connect((host, port))
s.setblocking(1)
s.sendall(vim.eval('payload')) s.sendall(vim.eval('payload'))
while True: while True:
while len(select.select([s], [], [], 0.1)[0]) == 0:
vim.eval('getchar(1)')
body = s.recv(8192) body = s.recv(8192)
if re.search("=> $", body) != None: if re.search("=> $", body) != None:
raise Exception("not an nREPL server: upgrade to Leiningen 2") raise Exception("not an nREPL server: upgrade to Leiningen 2")