Skip to content

Commit

Permalink
Merge pull request #520 from julienvincent/context-override
Browse files Browse the repository at this point in the history
Allow overriding opts context in eval-str
  • Loading branch information
Olical authored Jul 28, 2023
2 parents e28f36f + 5314007 commit 50a7654
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 61 deletions.
7 changes: 4 additions & 3 deletions fnl/conjure/eval.fnl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@
(with-last-result-hook opts))))

(defn- assoc-context [opts]
(set opts.context
(or nvim.b.conjure#context
(extract.context)))
(when (not opts.context)
(set opts.context
(or nvim.b.conjure#context
(extract.context))))
opts)

(defn- client-exec-fn [action f-name base-opts]
Expand Down
119 changes: 61 additions & 58 deletions lua/conjure/eval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,15 @@ local function file()
end
_2amodule_2a["file"] = file
local function assoc_context(opts)
opts.context = (nvim.b["conjure#context"] or extract.context())
if not opts.context then
opts.context = (nvim.b["conjure#context"] or extract.context())
else
end
return opts
end
_2amodule_locals_2a["assoc-context"] = assoc_context
local function client_exec_fn(action, f_name, base_opts)
local function _9_(opts)
local function _10_(opts)
local opts0 = a.merge(opts, base_opts, {action = action, ["file-path"] = extract["file-path"]()})
assoc_context(opts0)
opts0.preview = preview(opts0)
Expand All @@ -108,30 +111,30 @@ local function client_exec_fn(action, f_name, base_opts)
else
end
if opts0["jumping?"] then
local function _11_()
local function _12_()
do
local win = nvim.get_current_win()
local buf = nvim.get_current_buf()
nvim.fn.settagstack(win, {items = {{tagname = opts0.code, bufnr = buf, from = a.concat({buf}, nvim.win_get_cursor(win), {0}), matchnr = 0}}}, "a")
end
return nu.normal("m'")
end
pcall(_11_)
pcall(_12_)
else
end
return client.call(f_name, opts0)
end
return _9_
return _10_
end
_2amodule_locals_2a["client-exec-fn"] = client_exec_fn
local function apply_gsubs(code)
if code then
local function _16_(code0, _13_)
local _arg_14_ = _13_
local name = _arg_14_[1]
local _arg_15_ = _arg_14_[2]
local pat = _arg_15_[1]
local rep = _arg_15_[2]
local function _17_(code0, _14_)
local _arg_15_ = _14_
local name = _arg_15_[1]
local _arg_16_ = _arg_15_[2]
local pat = _arg_16_[1]
local rep = _arg_16_[2]
local ok_3f, val_or_err = pcall(string.gsub, code0, pat, rep)
if ok_3f then
return val_or_err
Expand All @@ -140,7 +143,7 @@ local function apply_gsubs(code)
return code0
end
end
return a.reduce(_16_, code, a["kv-pairs"]((nvim.b["conjure#eval#gsubs"] or nvim.g["conjure#eval#gsubs"])))
return a.reduce(_17_, code, a["kv-pairs"]((nvim.b["conjure#eval#gsubs"] or nvim.g["conjure#eval#gsubs"])))
else
return nil
end
Expand All @@ -150,23 +153,23 @@ local function eval_str(opts)
highlight_range(opts.range)
event.emit("eval", "str")
a.update(opts, "code", apply_gsubs)
local function _19_()
local function _20_()
if opts["passive?"] then
return opts
else
return with_last_result_hook(opts)
end
end
client_exec_fn("eval", "eval-str")(_19_())
client_exec_fn("eval", "eval-str")(_20_())
return nil
end
_2amodule_2a["eval-str"] = eval_str
local function wrap_emit(name, f)
local function _20_(...)
local function _21_(...)
event.emit(name)
return f(...)
end
return _20_
return _21_
end
_2amodule_2a["wrap-emit"] = wrap_emit
local doc_str = wrap_emit("doc", client_exec_fn("doc", "doc-str"))
Expand All @@ -176,9 +179,9 @@ do end (_2amodule_locals_2a)["def-str"] = def_str
local function current_form(extra_opts)
local form = extract.form({})
if form then
local _let_21_ = form
local content = _let_21_["content"]
local range = _let_21_["range"]
local _let_22_ = form
local content = _let_22_["content"]
local range = _let_22_["range"]
eval_str(a.merge({code = content, range = range, origin = "current-form"}, extra_opts))
return form
else
Expand All @@ -191,14 +194,14 @@ local function replace_form()
local win = nvim.tabpage_get_win(0)
local form = extract.form({})
if form then
local _let_23_ = form
local content = _let_23_["content"]
local range = _let_23_["range"]
local function _24_(result)
local _let_24_ = form
local content = _let_24_["content"]
local range = _let_24_["range"]
local function _25_(result)
buffer["replace-range"](buf, range, result)
return editor["go-to"](win, a["get-in"](range, {"start", 1}), a.inc(a["get-in"](range, {"start", 2})))
end
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _24_})
eval_str({code = content, range = range, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _25_})
return form
else
return nil
Expand All @@ -208,9 +211,9 @@ _2amodule_2a["replace-form"] = replace_form
local function root_form()
local form = extract.form({["root?"] = true})
if form then
local _let_26_ = form
local content = _let_26_["content"]
local range = _let_26_["range"]
local _let_27_ = form
local content = _let_27_["content"]
local range = _let_27_["range"]
return eval_str({code = content, range = range, origin = "root-form"})
else
return nil
Expand All @@ -221,10 +224,10 @@ local function marked_form(mark)
local comment_prefix = client.get("comment-prefix")
local mark0 = (mark or extract["prompt-char"]())
local ok_3f, err = nil, nil
local function _28_()
local function _29_()
return editor["go-to-mark"](mark0)
end
ok_3f, err = pcall(_28_)
ok_3f, err = pcall(_29_)
if ok_3f then
current_form({origin = str.join({"marked-form [", mark0, "]"})})
editor["go-back"]()
Expand All @@ -238,13 +241,13 @@ local function insert_result_comment(tag, input)
local buf = nvim.win_get_buf(0)
local comment_prefix = (config["get-in"]({"eval", "comment_prefix"}) or client.get("comment-prefix"))
if input then
local _let_30_ = input
local content = _let_30_["content"]
local range = _let_30_["range"]
local function _31_(result)
local _let_31_ = input
local content = _let_31_["content"]
local range = _let_31_["range"]
local function _32_(result)
return buffer["append-prefixed-line"](buf, range["end"], comment_prefix, result)
end
eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _31_})
eval_str({code = content, range = range, origin = str.join({"comment-", tag}), ["suppress-hud?"] = true, ["on-result"] = _32_})
return input
else
return nil
Expand All @@ -264,9 +267,9 @@ local function comment_word()
end
_2amodule_2a["comment-word"] = comment_word
local function word()
local _let_33_ = extract.word()
local content = _let_33_["content"]
local range = _let_33_["range"]
local _let_34_ = extract.word()
local content = _let_34_["content"]
local range = _let_34_["range"]
if not a["empty?"](content) then
return eval_str({code = content, range = range, origin = "word"})
else
Expand All @@ -275,9 +278,9 @@ local function word()
end
_2amodule_2a["word"] = word
local function doc_word()
local _let_35_ = extract.word()
local content = _let_35_["content"]
local range = _let_35_["range"]
local _let_36_ = extract.word()
local content = _let_36_["content"]
local range = _let_36_["range"]
if not a["empty?"](content) then
return doc_str({code = content, range = range, origin = "word"})
else
Expand All @@ -286,9 +289,9 @@ local function doc_word()
end
_2amodule_2a["doc-word"] = doc_word
local function def_word()
local _let_37_ = extract.word()
local content = _let_37_["content"]
local range = _let_37_["range"]
local _let_38_ = extract.word()
local content = _let_38_["content"]
local range = _let_38_["range"]
if not a["empty?"](content) then
return def_str({code = content, range = range, origin = "word"})
else
Expand All @@ -297,9 +300,9 @@ local function def_word()
end
_2amodule_2a["def-word"] = def_word
local function buf()
local _let_39_ = extract.buf()
local content = _let_39_["content"]
local range = _let_39_["range"]
local _let_40_ = extract.buf()
local content = _let_40_["content"]
local range = _let_40_["range"]
return eval_str({code = content, range = range, origin = "buf"})
end
_2amodule_2a["buf"] = buf
Expand All @@ -308,16 +311,16 @@ local function command(code)
end
_2amodule_2a["command"] = command
local function range(start, _end)
local _let_40_ = extract.range(start, _end)
local content = _let_40_["content"]
local range0 = _let_40_["range"]
local _let_41_ = extract.range(start, _end)
local content = _let_41_["content"]
local range0 = _let_41_["range"]
return eval_str({code = content, range = range0, origin = "range"})
end
_2amodule_2a["range"] = range
local function selection(kind)
local _let_41_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
local content = _let_41_["content"]
local range0 = _let_41_["range"]
local _let_42_ = extract.selection({kind = (kind or nvim.fn.visualmode()), ["visual?"] = not kind})
local content = _let_42_["content"]
local range0 = _let_42_["range"]
return eval_str({code = content, range = range0, origin = "selection"})
end
_2amodule_2a["selection"] = selection
Expand All @@ -331,15 +334,15 @@ end
_2amodule_locals_2a["wrap-completion-result"] = wrap_completion_result
local function completions(prefix, cb)
local function cb_wrap(results)
local function _43_()
local _44_ = config["get-in"]({"completion", "fallback"})
if (nil ~= _44_) then
return nvim.call_function(_44_, {0, prefix})
local function _44_()
local _45_ = config["get-in"]({"completion", "fallback"})
if (nil ~= _45_) then
return nvim.call_function(_45_, {0, prefix})
else
return _44_
return _45_
end
end
return cb(a.map(wrap_completion_result, (results or _43_())))
return cb(a.map(wrap_completion_result, (results or _44_())))
end
if ("function" == type(client.get("completions"))) then
return client.call("completions", assoc_context({["file-path"] = extract["file-path"](), prefix = prefix, cb = cb_wrap}))
Expand Down

0 comments on commit 50a7654

Please sign in to comment.