Skip to content

Commit 4afefa7

Browse files
committed
Add an interrupt mapping for Racket, fixes #213
1 parent 49a0048 commit 4afefa7

File tree

5 files changed

+55
-5
lines changed

5 files changed

+55
-5
lines changed

doc/conjure-client-racket-stdio.txt

+9
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ options relevant to these mappings.
3737

3838
<localleader>cS Stop any existing Racket REPL.
3939

40+
<localleader>ei Send an interrupt signal to the REPL. Useful for
41+
hanging processes or unbalanced parenthesis.
42+
4043
==============================================================================
4144
CONFIGURATION *conjure-client-racket-stdio-configuration*
4245

@@ -53,6 +56,12 @@ All configuration can be set as described in |conjure-configuration|.
5356
Stop any existing Racket REPL.
5457
Default: `"cS"`
5558

59+
*g:conjure#client#racket#stdio#mapping#interrupt*
60+
`g:conjure#client#racket#stdio#mapping#interrupt`
61+
Send an interrupt signal to the REPL. Useful for hanging processes
62+
or unbalanced parenthesis.
63+
Default: `"ei"`
64+
5665
*g:conjure#client#racket#stdio#command*
5766
`g:conjure#client#racket#stdio#command`
5867
Command used to start the Racket REPL, you can modify this to add

fnl/conjure/client/racket/stdio.fnl

+13-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
{:racket
1616
{:stdio
1717
{:mapping {:start "cs"
18-
:stop "cS"}
18+
:stop "cS"
19+
:interrupt "ei"}
1920
:command "racket"
2021
:prompt_pattern "\n?[\"%w%-./_]*> "}}}})
2122

@@ -65,6 +66,15 @@
6566
(a.run! display-result msgs))
6667
{:batch? true}))))
6768

69+
(defn interrupt []
70+
(with-repl-or-warn
71+
(fn [repl]
72+
(log.append ["; Sending interrupt signal."] {:break? true})
73+
74+
;; SIGINT C-c
75+
;; https://github.com/Olical/conjure/issues/213
76+
(repl.send-signal 2))))
77+
6878
(defn eval-file [opts]
6979
(eval-str (a.assoc opts :code (.. ",require-reloadable " opts.file-path))))
7080

@@ -135,7 +145,8 @@
135145

136146
(defn on-filetype []
137147
(mapping.buf :n :RktStart (cfg [:mapping :start]) *module-name* :start)
138-
(mapping.buf :n :RktStop (cfg [:mapping :stop]) *module-name* :stop))
148+
(mapping.buf :n :RktStop (cfg [:mapping :stop]) *module-name* :stop)
149+
(mapping.buf :n :RktInterrupt (cfg [:mapping :interrupt]) *module-name* :interrupt))
139150

140151
(defn on-exit []
141152
(stop))

fnl/conjure/remote/stdio.fnl

+5
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@
108108
(next-in-queue)
109109
nil)
110110

111+
(fn send-signal [signal]
112+
(uv.process_kill repl.handle signal)
113+
nil)
114+
111115
(let [{: cmd : args} (parse-cmd opts.cmd)
112116
(handle pid-or-err)
113117
(uv.spawn cmd {:stdio [stdin stdout stderr]
@@ -129,6 +133,7 @@
129133
:pid pid-or-err
130134
:send send
131135
:opts opts
136+
:send-signal send-signal
132137
:destroy destroy}))
133138
(do
134139
(client.schedule #(opts.on-error pid-or-err))

lua/conjure/client/racket/stdio.lua

+23-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ local text = _local_0_[9]
4848
local _2amodule_2a = _0_
4949
local _2amodule_name_2a = "conjure.client.racket.stdio"
5050
do local _ = ({nil, _0_, nil, {{nil}, nil, nil, nil}})[2] end
51-
config.merge({client = {racket = {stdio = {command = "racket", mapping = {start = "cs", stop = "cS"}, prompt_pattern = "\n?[\"%w%-./_]*> "}}}})
51+
config.merge({client = {racket = {stdio = {command = "racket", mapping = {interrupt = "ei", start = "cs", stop = "cS"}, prompt_pattern = "\n?[\"%w%-./_]*> "}}}})
5252
local cfg
5353
do
5454
local v_0_ = config["get-in-fn"]({"client", "racket", "stdio"})
@@ -189,6 +189,26 @@ do
189189
t_0_["eval-str"] = v_0_
190190
eval_str = v_0_
191191
end
192+
local interrupt
193+
do
194+
local v_0_
195+
do
196+
local v_0_0
197+
local function interrupt0()
198+
local function _3_(repl)
199+
log.append({"; Sending interrupt signal."}, {["break?"] = true})
200+
return repl["send-signal"](2)
201+
end
202+
return with_repl_or_warn(_3_)
203+
end
204+
v_0_0 = interrupt0
205+
_0_["interrupt"] = v_0_0
206+
v_0_ = v_0_0
207+
end
208+
local t_0_ = (_0_)["aniseed/locals"]
209+
t_0_["interrupt"] = v_0_
210+
interrupt = v_0_
211+
end
192212
local eval_file
193213
do
194214
local v_0_
@@ -349,7 +369,8 @@ do
349369
local v_0_0
350370
local function on_filetype0()
351371
mapping.buf("n", "RktStart", cfg({"mapping", "start"}), _2amodule_name_2a, "start")
352-
return mapping.buf("n", "RktStop", cfg({"mapping", "stop"}), _2amodule_name_2a, "stop")
372+
mapping.buf("n", "RktStop", cfg({"mapping", "stop"}), _2amodule_name_2a, "stop")
373+
return mapping.buf("n", "RktInterrupt", cfg({"mapping", "interrupt"}), _2amodule_name_2a, "interrupt")
353374
end
354375
v_0_0 = on_filetype0
355376
_0_["on-filetype"] = v_0_0

lua/conjure/remote/stdio.lua

+5-1
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ do
205205
next_in_queue()
206206
return nil
207207
end
208+
local function send_signal(signal)
209+
uv.process_kill(repl.handle, signal)
210+
return nil
211+
end
208212
local _let_0_ = parse_cmd(opts.cmd)
209213
local args = _let_0_["args"]
210214
local cmd = _let_0_["cmd"]
@@ -216,7 +220,7 @@ do
216220
return opts["on-success"]()
217221
end
218222
client.schedule(_3_)
219-
return a["merge!"](repl, {destroy = destroy, handle = handle, opts = opts, pid = pid_or_err, send = send})
223+
return a["merge!"](repl, {["send-signal"] = send_signal, destroy = destroy, handle = handle, opts = opts, pid = pid_or_err, send = send})
220224
else
221225
local function _3_()
222226
return opts["on-error"](pid_or_err)

0 commit comments

Comments
 (0)