Skip to content

Commit 50a7654

Browse files
authored
Merge pull request #520 from julienvincent/context-override
Allow overriding opts context in eval-str
2 parents e28f36f + 5314007 commit 50a7654

File tree

2 files changed

+65
-61
lines changed

2 files changed

+65
-61
lines changed

fnl/conjure/eval.fnl

+4-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,10 @@
9292
(with-last-result-hook opts))))
9393

9494
(defn- assoc-context [opts]
95-
(set opts.context
96-
(or nvim.b.conjure#context
97-
(extract.context)))
95+
(when (not opts.context)
96+
(set opts.context
97+
(or nvim.b.conjure#context
98+
(extract.context))))
9899
opts)
99100

100101
(defn- client-exec-fn [action f-name base-opts]

lua/conjure/eval.lua

+61-58
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,15 @@ local function file()
9494
end
9595
_2amodule_2a["file"] = file
9696
local function assoc_context(opts)
97-
opts.context = (nvim.b["conjure#context"] or extract.context())
97+
if not opts.context then
98+
opts.context = (nvim.b["conjure#context"] or extract.context())
99+
else
100+
end
98101
return opts
99102
end
100103
_2amodule_locals_2a["assoc-context"] = assoc_context
101104
local function client_exec_fn(action, f_name, base_opts)
102-
local function _9_(opts)
105+
local function _10_(opts)
103106
local opts0 = a.merge(opts, base_opts, {action = action, ["file-path"] = extract["file-path"]()})
104107
assoc_context(opts0)
105108
opts0.preview = preview(opts0)
@@ -108,30 +111,30 @@ local function client_exec_fn(action, f_name, base_opts)
108111
else
109112
end
110113
if opts0["jumping?"] then
111-
local function _11_()
114+
local function _12_()
112115
do
113116
local win = nvim.get_current_win()
114117
local buf = nvim.get_current_buf()
115118
nvim.fn.settagstack(win, {items = {{tagname = opts0.code, bufnr = buf, from = a.concat({buf}, nvim.win_get_cursor(win), {0}), matchnr = 0}}}, "a")
116119
end
117120
return nu.normal("m'")
118121
end
119-
pcall(_11_)
122+
pcall(_12_)
120123
else
121124
end
122125
return client.call(f_name, opts0)
123126
end
124-
return _9_
127+
return _10_
125128
end
126129
_2amodule_locals_2a["client-exec-fn"] = client_exec_fn
127130
local function apply_gsubs(code)
128131
if code then
129-
local function _16_(code0, _13_)
130-
local _arg_14_ = _13_
131-
local name = _arg_14_[1]
132-
local _arg_15_ = _arg_14_[2]
133-
local pat = _arg_15_[1]
134-
local rep = _arg_15_[2]
132+
local function _17_(code0, _14_)
133+
local _arg_15_ = _14_
134+
local name = _arg_15_[1]
135+
local _arg_16_ = _arg_15_[2]
136+
local pat = _arg_16_[1]
137+
local rep = _arg_16_[2]
135138
local ok_3f, val_or_err = pcall(string.gsub, code0, pat, rep)
136139
if ok_3f then
137140
return val_or_err
@@ -140,7 +143,7 @@ local function apply_gsubs(code)
140143
return code0
141144
end
142145
end
143-
return a.reduce(_16_, code, a["kv-pairs"]((nvim.b["conjure#eval#gsubs"] or nvim.g["conjure#eval#gsubs"])))
146+
return a.reduce(_17_, code, a["kv-pairs"]((nvim.b["conjure#eval#gsubs"] or nvim.g["conjure#eval#gsubs"])))
144147
else
145148
return nil
146149
end
@@ -150,23 +153,23 @@ local function eval_str(opts)
150153
highlight_range(opts.range)
151154
event.emit("eval", "str")
152155
a.update(opts, "code", apply_gsubs)
153-
local function _19_()
156+
local function _20_()
154157
if opts["passive?"] then
155158
return opts
156159
else
157160
return with_last_result_hook(opts)
158161
end
159162
end
160-
client_exec_fn("eval", "eval-str")(_19_())
163+
client_exec_fn("eval", "eval-str")(_20_())
161164
return nil
162165
end
163166
_2amodule_2a["eval-str"] = eval_str
164167
local function wrap_emit(name, f)
165-
local function _20_(...)
168+
local function _21_(...)
166169
event.emit(name)
167170
return f(...)
168171
end
169-
return _20_
172+
return _21_
170173
end
171174
_2amodule_2a["wrap-emit"] = wrap_emit
172175
local doc_str = wrap_emit("doc", client_exec_fn("doc", "doc-str"))
@@ -176,9 +179,9 @@ do end (_2amodule_locals_2a)["def-str"] = def_str
176179
local function current_form(extra_opts)
177180
local form = extract.form({})
178181
if form then
179-
local _let_21_ = form
180-
local content = _let_21_["content"]
181-
local range = _let_21_["range"]
182+
local _let_22_ = form
183+
local content = _let_22_["content"]
184+
local range = _let_22_["range"]
182185
eval_str(a.merge({code = content, range = range, origin = "current-form"}, extra_opts))
183186
return form
184187
else
@@ -191,14 +194,14 @@ local function replace_form()
191194
local win = nvim.tabpage_get_win(0)
192195
local form = extract.form({})
193196
if form then
194-
local _let_23_ = form
195-
local content = _let_23_["content"]
196-
local range = _let_23_["range"]
197-
local function _24_(result)
197+
local _let_24_ = form
198+
local content = _let_24_["content"]
199+
local range = _let_24_["range"]
200+
local function _25_(result)
198201
buffer["replace-range"](buf, range, result)
199202
return editor["go-to"](win, a["get-in"](range, {"start", 1}), a.inc(a["get-in"](range, {"start", 2})))
200203
end
201-
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _24_})
204+
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _25_})
202205
return form
203206
else
204207
return nil
@@ -208,9 +211,9 @@ _2amodule_2a["replace-form"] = replace_form
208211
local function root_form()
209212
local form = extract.form({["root?"] = true})
210213
if form then
211-
local _let_26_ = form
212-
local content = _let_26_["content"]
213-
local range = _let_26_["range"]
214+
local _let_27_ = form
215+
local content = _let_27_["content"]
216+
local range = _let_27_["range"]
214217
return eval_str({code = content, range = range, origin = "root-form"})
215218
else
216219
return nil
@@ -221,10 +224,10 @@ local function marked_form(mark)
221224
local comment_prefix = client.get("comment-prefix")
222225
local mark0 = (mark or extract["prompt-char"]())
223226
local ok_3f, err = nil, nil
224-
local function _28_()
227+
local function _29_()
225228
return editor["go-to-mark"](mark0)
226229
end
227-
ok_3f, err = pcall(_28_)
230+
ok_3f, err = pcall(_29_)
228231
if ok_3f then
229232
current_form({origin = str.join({"marked-form [", mark0, "]"})})
230233
editor["go-back"]()
@@ -238,13 +241,13 @@ local function insert_result_comment(tag, input)
238241
local buf = nvim.win_get_buf(0)
239242
local comment_prefix = (config["get-in"]({"eval", "comment_prefix"}) or client.get("comment-prefix"))
240243
if input then
241-
local _let_30_ = input
242-
local content = _let_30_["content"]
243-
local range = _let_30_["range"]
244-
local function _31_(result)
244+
local _let_31_ = input
245+
local content = _let_31_["content"]
246+
local range = _let_31_["range"]
247+
local function _32_(result)
245248
return buffer["append-prefixed-line"](buf, range["end"], comment_prefix, result)
246249
end
247-
eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _31_})
250+
eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _32_})
248251
return input
249252
else
250253
return nil
@@ -264,9 +267,9 @@ local function comment_word()
264267
end
265268
_2amodule_2a["comment-word"] = comment_word
266269
local function word()
267-
local _let_33_ = extract.word()
268-
local content = _let_33_["content"]
269-
local range = _let_33_["range"]
270+
local _let_34_ = extract.word()
271+
local content = _let_34_["content"]
272+
local range = _let_34_["range"]
270273
if not a["empty?"](content) then
271274
return eval_str({code = content, range = range, origin = "word"})
272275
else
@@ -275,9 +278,9 @@ local function word()
275278
end
276279
_2amodule_2a["word"] = word
277280
local function doc_word()
278-
local _let_35_ = extract.word()
279-
local content = _let_35_["content"]
280-
local range = _let_35_["range"]
281+
local _let_36_ = extract.word()
282+
local content = _let_36_["content"]
283+
local range = _let_36_["range"]
281284
if not a["empty?"](content) then
282285
return doc_str({code = content, range = range, origin = "word"})
283286
else
@@ -286,9 +289,9 @@ local function doc_word()
286289
end
287290
_2amodule_2a["doc-word"] = doc_word
288291
local function def_word()
289-
local _let_37_ = extract.word()
290-
local content = _let_37_["content"]
291-
local range = _let_37_["range"]
292+
local _let_38_ = extract.word()
293+
local content = _let_38_["content"]
294+
local range = _let_38_["range"]
292295
if not a["empty?"](content) then
293296
return def_str({code = content, range = range, origin = "word"})
294297
else
@@ -297,9 +300,9 @@ local function def_word()
297300
end
298301
_2amodule_2a["def-word"] = def_word
299302
local function buf()
300-
local _let_39_ = extract.buf()
301-
local content = _let_39_["content"]
302-
local range = _let_39_["range"]
303+
local _let_40_ = extract.buf()
304+
local content = _let_40_["content"]
305+
local range = _let_40_["range"]
303306
return eval_str({code = content, range = range, origin = "buf"})
304307
end
305308
_2amodule_2a["buf"] = buf
@@ -308,16 +311,16 @@ local function command(code)
308311
end
309312
_2amodule_2a["command"] = command
310313
local function range(start, _end)
311-
local _let_40_ = extract.range(start, _end)
312-
local content = _let_40_["content"]
313-
local range0 = _let_40_["range"]
314+
local _let_41_ = extract.range(start, _end)
315+
local content = _let_41_["content"]
316+
local range0 = _let_41_["range"]
314317
return eval_str({code = content, range = range0, origin = "range"})
315318
end
316319
_2amodule_2a["range"] = range
317320
local function selection(kind)
318-
local _let_41_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
319-
local content = _let_41_["content"]
320-
local range0 = _let_41_["range"]
321+
local _let_42_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
322+
local content = _let_42_["content"]
323+
local range0 = _let_42_["range"]
321324
return eval_str({code = content, range = range0, origin = "selection"})
322325
end
323326
_2amodule_2a["selection"] = selection
@@ -331,15 +334,15 @@ end
331334
_2amodule_locals_2a["wrap-completion-result"] = wrap_completion_result
332335
local function completions(prefix, cb)
333336
local function cb_wrap(results)
334-
local function _43_()
335-
local _44_ = config["get-in"]({"completion", "fallback"})
336-
if (nil ~= _44_) then
337-
return nvim.call_function(_44_, {0, prefix})
337+
local function _44_()
338+
local _45_ = config["get-in"]({"completion", "fallback"})
339+
if (nil ~= _45_) then
340+
return nvim.call_function(_45_, {0, prefix})
338341
else
339-
return _44_
342+
return _45_
340343
end
341344
end
342-
return cb(a.map(wrap_completion_result, (results or _43_())))
345+
return cb(a.map(wrap_completion_result, (results or _44_())))
343346
end
344347
if ("function" == type(client.get("completions"))) then
345348
return client.call("completions", assoc_context({["file-path"] = extract["file-path"](), prefix = prefix, cb = cb_wrap}))

0 commit comments

Comments
 (0)