diff --git a/fnl/conjure/eval.fnl b/fnl/conjure/eval.fnl index 644a1c0b..04562a5f 100644 --- a/fnl/conjure/eval.fnl +++ b/fnl/conjure/eval.fnl @@ -43,13 +43,13 @@ 2 (. range.end 2)}] (vim.highlight.range - bufnr - namespace - (config.get-in [:highlight :group]) - hl_start - hl_end - :v - true) + bufnr namespace (config.get-in [:highlight :group]) hl_start hl_end + (unpack + ;; https://github.com/neovim/neovim/issues/14090#issuecomment-1047205812 + (if (= 1 (nvim.fn.has "nvim-0.7")) + [{:regtype :v + :inclusive true}] + [:v true]))) (timer.defer (fn [] diff --git a/lua/conjure/eval.lua b/lua/conjure/eval.lua index 8b9eeccb..2e974b11 100644 --- a/lua/conjure/eval.lua +++ b/lua/conjure/eval.lua @@ -51,14 +51,21 @@ local function highlight_range(range) local namespace = vim.api.nvim_create_namespace("conjure_highlight") local hl_start = {(range.start[1] - 1), range.start[2]} local hl_end = {((range["end"])[1] - 1), (range["end"])[2]} - vim.highlight.range(bufnr, namespace, config["get-in"]({"highlight", "group"}), hl_start, hl_end, "v", true) local function _2_() - local function _3_() + if (1 == nvim.fn.has("nvim-0.7")) then + return {{regtype = "v", inclusive = true}} + else + return {"v", true} + end + end + vim.highlight.range(bufnr, namespace, config["get-in"]({"highlight", "group"}), hl_start, hl_end, unpack(_2_())) + local function _3_() + local function _4_() return vim.api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1) end - return pcall(_3_) + return pcall(_4_) end - return timer.defer(_2_, config["get-in"]({"highlight", "timeout"})) + return timer.defer(_3_, config["get-in"]({"highlight", "timeout"})) else return nil end @@ -67,8 +74,8 @@ _2amodule_locals_2a["highlight-range"] = highlight_range local function with_last_result_hook(opts) local buf = nvim.win_get_buf(0) local line = a.dec(a.first(nvim.win_get_cursor(0))) - local function _5_(f) - local function _6_(result) + local function _6_(f) + local function _7_(result) nvim.fn.setreg(config["get-in"]({"eval", "result_register"}), string.gsub(result, "%z", "")) if config["get-in"]({"eval", "inline_results"}) then inline.display({buf = buf, text = (config["get-in"]({"eval", "inline", "prefix"}) .. result), line = line}) @@ -80,9 +87,9 @@ local function with_last_result_hook(opts) return nil end end - return _6_ + return _7_ end - return a.update(opts, "on-result", _5_) + return a.update(opts, "on-result", _6_) end _2amodule_locals_2a["with-last-result-hook"] = with_last_result_hook local function file() @@ -99,7 +106,7 @@ local function assoc_context(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) @@ -108,7 +115,7 @@ 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() @@ -116,22 +123,22 @@ local function client_exec_fn(action, f_name, base_opts) 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 @@ -140,7 +147,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 @@ -150,23 +157,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")) @@ -176,9 +183,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 @@ -191,14 +198,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 @@ -208,9 +215,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 @@ -221,10 +228,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 = ("marked-form [" .. mark0 .. "]")}) editor["go-back"]() @@ -238,13 +245,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 = ("comment-" .. tag), ["suppress-hud?"] = true, ["on-result"] = _31_}) + eval_str({code = content, range = range, origin = ("comment-" .. tag), ["suppress-hud?"] = true, ["on-result"] = _32_}) return input else return nil @@ -264,9 +271,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 @@ -275,9 +282,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 @@ -286,9 +293,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 @@ -297,9 +304,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 @@ -308,16 +315,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 @@ -331,15 +338,15 @@ end _2amodule_locals_2a["wrap-completion-result"] = wrap_completion_result local function completions(prefix, cb) local function cb_wrap(results) - local function _44_() - local _43_ = config["get-in"]({"completion", "fallback"}) - if (nil ~= _43_) then - return nvim.call_function(_43_, {0, prefix}) + local function _45_() + local _44_ = config["get-in"]({"completion", "fallback"}) + if (nil ~= _44_) then + return nvim.call_function(_44_, {0, prefix}) else - return _43_ + return _44_ end end - return cb(a.map(wrap_completion_result, (results or _44_()))) + return cb(a.map(wrap_completion_result, (results or _45_()))) end if ("function" == type(client.get("completions"))) then return client.call("completions", assoc_context({["file-path"] = extract["file-path"](), prefix = prefix, cb = cb_wrap}))