init commit
This commit is contained in:
parent
ebeff7b1e4
commit
9c34381aa5
@ -32,13 +32,58 @@
|
||||
:passive? true
|
||||
:on-result (output-expanded me-form)})))
|
||||
|
||||
(defn wrap-emit [name f]
|
||||
(fn [...]
|
||||
(event.emit name)
|
||||
(f ...)))
|
||||
|
||||
(local dir-str (wrap-emit
|
||||
:doc
|
||||
(client-exec-fn :doc :doc-str)))
|
||||
|
||||
(defn dir-word []
|
||||
(let [{: content : range : node} (extract.word)]
|
||||
(when (not (core.empty? content))
|
||||
(dir-str
|
||||
{:code content
|
||||
:range range
|
||||
:node node
|
||||
:origin :word}))))
|
||||
|
||||
(defn replace-form []
|
||||
(let [buf (vim.api.nvim_win_get_buf 0)
|
||||
win (vim.api.nvim_tabpage_get_win 0)
|
||||
form (extract.form {})]
|
||||
(when form
|
||||
(let [{: content : range : node} form]
|
||||
(eval-str
|
||||
{:code content
|
||||
:range range
|
||||
:node node
|
||||
:origin :replace-form
|
||||
:suppress-hud? true
|
||||
:on-result
|
||||
(fn [result]
|
||||
(buffer.replacerange
|
||||
buf
|
||||
range result)
|
||||
(editor.go-to
|
||||
win
|
||||
(core.get-in range [:start 1])
|
||||
(core.inc (core.get-in range [:start 2]))))})
|
||||
(.. "(clojure.core/macroexpand1 " form ")")))))
|
||||
|
||||
(defn add-buf-mappings []
|
||||
(mapping.buf :CljMacroexpand "cm" #(clj-macroexpand)
|
||||
{:desc "Call macroexpand-all on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpand0 "c0" #(clj-macroexpand "clojure.core/macroexpand")
|
||||
{:desc "Call macroexpand on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpand1 "c1" #(clj-macroexpand "clojure.core/macroexpand-1")
|
||||
{:desc "Call macroexpand-1 on the symbol under the cursor"}))
|
||||
{:desc "Call macroexpand-1 on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpandReplace "em!" #(replace-form)
|
||||
{:desc "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
||||
(mapping.buf :CljDirWord "em!" #(dir-word)
|
||||
{:desc "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"}))
|
||||
|
||||
(defn init []
|
||||
(when (or (not nvim.g.conjure_macroexpand_disable_mappings)
|
||||
|
@ -47,7 +47,7 @@ local function str(code, opts)
|
||||
ANISEED_STATIC_MODULES = (true == a.get(opts, "static?"))
|
||||
local fnl = fennel.impl()
|
||||
local function _4_()
|
||||
return string.gsub(string.gsub(fnl.compileString(wrap_macros(code, opts), a["merge!"]({allowedGlobals = false, compilerEnv = _G}, opts)), (delete_marker_pat .. "\n"), "\n"), (delete_marker_pat .. "$"), "")
|
||||
return string.gsub(string.gsub(fnl.compileString(wrap_macros(code, opts), a["merge!"]({compilerEnv = _G, allowedGlobals = false}, opts)), (delete_marker_pat .. "\n"), "\n"), (delete_marker_pat .. "$"), "")
|
||||
end
|
||||
return xpcall(_4_, fnl.traceback)
|
||||
end
|
||||
|
@ -150,33 +150,44 @@ local function run_21(f, xs)
|
||||
end
|
||||
end
|
||||
_2amodule_2a["run!"] = run_21
|
||||
local function complement(f)
|
||||
local function _11_(...)
|
||||
return not f(...)
|
||||
end
|
||||
return _11_
|
||||
end
|
||||
_2amodule_2a["complement"] = complement
|
||||
local function filter(f, xs)
|
||||
local result = {}
|
||||
local function _11_(x)
|
||||
local function _12_(x)
|
||||
if f(x) then
|
||||
return table.insert(result, x)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
run_21(_11_, xs)
|
||||
run_21(_12_, xs)
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["filter"] = filter
|
||||
local function remove(f, xs)
|
||||
return filter(complement(f), xs)
|
||||
end
|
||||
_2amodule_2a["remove"] = remove
|
||||
local function map(f, xs)
|
||||
local result = {}
|
||||
local function _13_(x)
|
||||
local function _14_(x)
|
||||
local mapped = f(x)
|
||||
local function _14_()
|
||||
local function _15_()
|
||||
if (0 == select("#", mapped)) then
|
||||
return nil
|
||||
else
|
||||
return mapped
|
||||
end
|
||||
end
|
||||
return table.insert(result, _14_())
|
||||
return table.insert(result, _15_())
|
||||
end
|
||||
run_21(_13_, xs)
|
||||
run_21(_14_, xs)
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["map"] = map
|
||||
@ -190,11 +201,11 @@ end
|
||||
_2amodule_2a["identity"] = identity
|
||||
local function reduce(f, init, xs)
|
||||
local result = init
|
||||
local function _15_(x)
|
||||
local function _16_(x)
|
||||
result = f(result, x)
|
||||
return nil
|
||||
end
|
||||
run_21(_15_, xs)
|
||||
run_21(_16_, xs)
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["reduce"] = reduce
|
||||
@ -214,34 +225,34 @@ end
|
||||
_2amodule_2a["some"] = some
|
||||
local function butlast(xs)
|
||||
local total = count(xs)
|
||||
local function _19_(_17_)
|
||||
local _arg_18_ = _17_
|
||||
local n = _arg_18_[1]
|
||||
local v = _arg_18_[2]
|
||||
local function _20_(_18_)
|
||||
local _arg_19_ = _18_
|
||||
local n = _arg_19_[1]
|
||||
local v = _arg_19_[2]
|
||||
return (n ~= total)
|
||||
end
|
||||
return map(second, filter(_19_, kv_pairs(xs)))
|
||||
return map(second, filter(_20_, kv_pairs(xs)))
|
||||
end
|
||||
_2amodule_2a["butlast"] = butlast
|
||||
local function rest(xs)
|
||||
local function _22_(_20_)
|
||||
local _arg_21_ = _20_
|
||||
local n = _arg_21_[1]
|
||||
local v = _arg_21_[2]
|
||||
local function _23_(_21_)
|
||||
local _arg_22_ = _21_
|
||||
local n = _arg_22_[1]
|
||||
local v = _arg_22_[2]
|
||||
return (n ~= 1)
|
||||
end
|
||||
return map(second, filter(_22_, kv_pairs(xs)))
|
||||
return map(second, filter(_23_, kv_pairs(xs)))
|
||||
end
|
||||
_2amodule_2a["rest"] = rest
|
||||
local function concat(...)
|
||||
local result = {}
|
||||
local function _23_(xs)
|
||||
local function _24_(x)
|
||||
local function _24_(xs)
|
||||
local function _25_(x)
|
||||
return table.insert(result, x)
|
||||
end
|
||||
return run_21(_24_, xs)
|
||||
return run_21(_25_, xs)
|
||||
end
|
||||
run_21(_23_, {...})
|
||||
run_21(_24_, {...})
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["concat"] = concat
|
||||
@ -251,10 +262,10 @@ end
|
||||
_2amodule_2a["mapcat"] = mapcat
|
||||
local function pr_str(...)
|
||||
local s
|
||||
local function _25_(x)
|
||||
local function _26_(x)
|
||||
return view.serialise(x, {["one-line"] = true})
|
||||
end
|
||||
s = table.concat(map(_25_, {...}), " ")
|
||||
s = table.concat(map(_26_, {...}), " ")
|
||||
if (nil_3f(s) or ("" == s)) then
|
||||
return "nil"
|
||||
else
|
||||
@ -263,41 +274,41 @@ local function pr_str(...)
|
||||
end
|
||||
_2amodule_2a["pr-str"] = pr_str
|
||||
local function str(...)
|
||||
local function _27_(acc, s)
|
||||
local function _28_(acc, s)
|
||||
return (acc .. s)
|
||||
end
|
||||
local function _28_(s)
|
||||
local function _29_(s)
|
||||
if string_3f(s) then
|
||||
return s
|
||||
else
|
||||
return pr_str(s)
|
||||
end
|
||||
end
|
||||
return reduce(_27_, "", map(_28_, {...}))
|
||||
return reduce(_28_, "", map(_29_, {...}))
|
||||
end
|
||||
_2amodule_2a["str"] = str
|
||||
local function println(...)
|
||||
local function _30_(acc, s)
|
||||
local function _31_(acc, s)
|
||||
return (acc .. s)
|
||||
end
|
||||
local function _33_(_31_)
|
||||
local _arg_32_ = _31_
|
||||
local i = _arg_32_[1]
|
||||
local s = _arg_32_[2]
|
||||
local function _34_(_32_)
|
||||
local _arg_33_ = _32_
|
||||
local i = _arg_33_[1]
|
||||
local s = _arg_33_[2]
|
||||
if (1 == i) then
|
||||
return s
|
||||
else
|
||||
return (" " .. s)
|
||||
end
|
||||
end
|
||||
local function _35_(s)
|
||||
local function _36_(s)
|
||||
if string_3f(s) then
|
||||
return s
|
||||
else
|
||||
return pr_str(s)
|
||||
end
|
||||
end
|
||||
return print(reduce(_30_, "", map_indexed(_33_, map(_35_, {...}))))
|
||||
return print(reduce(_31_, "", map_indexed(_34_, map(_36_, {...}))))
|
||||
end
|
||||
_2amodule_2a["println"] = println
|
||||
local function pr(...)
|
||||
@ -305,12 +316,12 @@ local function pr(...)
|
||||
end
|
||||
_2amodule_2a["pr"] = pr
|
||||
local function slurp(path, silent_3f)
|
||||
local _37_, _38_ = io.open(path, "r")
|
||||
if ((_37_ == nil) and (nil ~= _38_)) then
|
||||
local msg = _38_
|
||||
local _38_, _39_ = io.open(path, "r")
|
||||
if ((_38_ == nil) and (nil ~= _39_)) then
|
||||
local msg = _39_
|
||||
return nil
|
||||
elseif (nil ~= _37_) then
|
||||
local f = _37_
|
||||
elseif (nil ~= _38_) then
|
||||
local f = _38_
|
||||
local content = f:read("*all")
|
||||
f:close()
|
||||
return content
|
||||
@ -320,12 +331,12 @@ local function slurp(path, silent_3f)
|
||||
end
|
||||
_2amodule_2a["slurp"] = slurp
|
||||
local function spit(path, content)
|
||||
local _40_, _41_ = io.open(path, "w")
|
||||
if ((_40_ == nil) and (nil ~= _41_)) then
|
||||
local msg = _41_
|
||||
local _41_, _42_ = io.open(path, "w")
|
||||
if ((_41_ == nil) and (nil ~= _42_)) then
|
||||
local msg = _42_
|
||||
return error(("Could not open file: " .. msg))
|
||||
elseif (nil ~= _40_) then
|
||||
local f = _40_
|
||||
elseif (nil ~= _41_) then
|
||||
local f = _41_
|
||||
f:write(content)
|
||||
f:close()
|
||||
return nil
|
||||
@ -335,7 +346,7 @@ local function spit(path, content)
|
||||
end
|
||||
_2amodule_2a["spit"] = spit
|
||||
local function merge_21(base, ...)
|
||||
local function _43_(acc, m)
|
||||
local function _44_(acc, m)
|
||||
if m then
|
||||
for k, v in pairs(m) do
|
||||
acc[k] = v
|
||||
@ -344,7 +355,7 @@ local function merge_21(base, ...)
|
||||
end
|
||||
return acc
|
||||
end
|
||||
return reduce(_43_, (base or {}), {...})
|
||||
return reduce(_44_, (base or {}), {...})
|
||||
end
|
||||
_2amodule_2a["merge!"] = merge_21
|
||||
local function merge(...)
|
||||
@ -353,14 +364,14 @@ end
|
||||
_2amodule_2a["merge"] = merge
|
||||
local function select_keys(t, ks)
|
||||
if (t and ks) then
|
||||
local function _45_(acc, k)
|
||||
local function _46_(acc, k)
|
||||
if k then
|
||||
acc[k] = t[k]
|
||||
else
|
||||
end
|
||||
return acc
|
||||
end
|
||||
return reduce(_45_, {}, ks)
|
||||
return reduce(_46_, {}, ks)
|
||||
else
|
||||
return {}
|
||||
end
|
||||
@ -387,14 +398,14 @@ end
|
||||
_2amodule_2a["get"] = get
|
||||
local function get_in(t, ks, d)
|
||||
local res
|
||||
local function _51_(acc, k)
|
||||
local function _52_(acc, k)
|
||||
if table_3f(acc) then
|
||||
return get(acc, k)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
res = reduce(_51_, t, ks)
|
||||
res = reduce(_52_, t, ks)
|
||||
if nil_3f(res) then
|
||||
return d
|
||||
else
|
||||
@ -403,10 +414,10 @@ local function get_in(t, ks, d)
|
||||
end
|
||||
_2amodule_2a["get-in"] = get_in
|
||||
local function assoc(t, ...)
|
||||
local _let_54_ = {...}
|
||||
local k = _let_54_[1]
|
||||
local v = _let_54_[2]
|
||||
local xs = (function (t, k) local mt = getmetatable(t) if "table" == type(mt) and mt.__fennelrest then return mt.__fennelrest(t, k) else return {(table.unpack or unpack)(t, k)} end end)(_let_54_, 3)
|
||||
local _let_55_ = {...}
|
||||
local k = _let_55_[1]
|
||||
local v = _let_55_[2]
|
||||
local xs = (function (t, k, e) local mt = getmetatable(t) if 'table' == type(mt) and mt.__fennelrest then return mt.__fennelrest(t, k) elseif e then local rest = {} for k, v in pairs(t) do if not e[k] then rest[k] = v end end return rest else return {(table.unpack or unpack)(t, k)} end end)(_let_55_, 3)
|
||||
local rem = count(xs)
|
||||
local t0 = (t or {})
|
||||
if odd_3f(rem) then
|
||||
@ -428,7 +439,7 @@ local function assoc_in(t, ks, v)
|
||||
local path = butlast(ks)
|
||||
local final = last(ks)
|
||||
local t0 = (t or {})
|
||||
local function _58_(acc, k)
|
||||
local function _59_(acc, k)
|
||||
local step = get(acc, k)
|
||||
if nil_3f(step) then
|
||||
return get(assoc(acc, k, {}), k)
|
||||
@ -436,7 +447,7 @@ local function assoc_in(t, ks, v)
|
||||
return step
|
||||
end
|
||||
end
|
||||
assoc(reduce(_58_, t0, path), final, v)
|
||||
assoc(reduce(_59_, t0, path), final, v)
|
||||
return t0
|
||||
end
|
||||
_2amodule_2a["assoc-in"] = assoc_in
|
||||
@ -449,10 +460,10 @@ local function update_in(t, ks, f)
|
||||
end
|
||||
_2amodule_2a["update-in"] = update_in
|
||||
local function constantly(v)
|
||||
local function _60_()
|
||||
local function _61_()
|
||||
return v
|
||||
end
|
||||
return _60_
|
||||
return _61_
|
||||
end
|
||||
_2amodule_2a["constantly"] = constantly
|
||||
return _2amodule_2a
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,175 +4,257 @@ local api = vim.api
|
||||
local inspect = vim.inspect
|
||||
|
||||
local function extend(t, o)
|
||||
local mt = getmetatable(t)
|
||||
for k, v in pairs(o) do
|
||||
rawset(mt, k, v)
|
||||
end
|
||||
return t
|
||||
local mt = getmetatable(t)
|
||||
for k, v in pairs(o) do
|
||||
rawset(mt, k, v)
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
||||
-- Equivalent to `echo vim.inspect(...)`
|
||||
local function nvim_print(...)
|
||||
if select("#", ...) == 1 then
|
||||
api.nvim_out_write(inspect((...)))
|
||||
else
|
||||
api.nvim_out_write(inspect {...})
|
||||
end
|
||||
api.nvim_out_write("\n")
|
||||
if select("#", ...) == 1 then
|
||||
api.nvim_out_write(inspect((...)))
|
||||
else
|
||||
api.nvim_out_write(inspect({ ... }))
|
||||
end
|
||||
api.nvim_out_write("\n")
|
||||
end
|
||||
|
||||
--- Equivalent to `echo` EX command
|
||||
local function nvim_echo(...)
|
||||
for i = 1, select("#", ...) do
|
||||
local part = select(i, ...)
|
||||
api.nvim_out_write(tostring(part))
|
||||
-- vim.api.nvim_out_write("\n")
|
||||
api.nvim_out_write(" ")
|
||||
end
|
||||
api.nvim_out_write("\n")
|
||||
for i = 1, select("#", ...) do
|
||||
local part = select(i, ...)
|
||||
api.nvim_out_write(tostring(part))
|
||||
-- vim.api.nvim_out_write("\n")
|
||||
api.nvim_out_write(" ")
|
||||
end
|
||||
api.nvim_out_write("\n")
|
||||
end
|
||||
|
||||
local window_options = {
|
||||
arab = true; arabic = true; breakindent = true; breakindentopt = true;
|
||||
bri = true; briopt = true; cc = true; cocu = true;
|
||||
cole = true; colorcolumn = true; concealcursor = true; conceallevel = true;
|
||||
crb = true; cuc = true; cul = true; cursorbind = true;
|
||||
cursorcolumn = true; cursorline = true; diff = true; fcs = true;
|
||||
fdc = true; fde = true; fdi = true; fdl = true;
|
||||
fdm = true; fdn = true; fdt = true; fen = true;
|
||||
fillchars = true; fml = true; fmr = true; foldcolumn = true;
|
||||
foldenable = true; foldexpr = true; foldignore = true; foldlevel = true;
|
||||
foldmarker = true; foldmethod = true; foldminlines = true; foldnestmax = true;
|
||||
foldtext = true; lbr = true; lcs = true; linebreak = true;
|
||||
list = true; listchars = true; nu = true; number = true;
|
||||
numberwidth = true; nuw = true; previewwindow = true; pvw = true;
|
||||
relativenumber = true; rightleft = true; rightleftcmd = true; rl = true;
|
||||
rlc = true; rnu = true; scb = true; scl = true;
|
||||
scr = true; scroll = true; scrollbind = true; signcolumn = true;
|
||||
spell = true; statusline = true; stl = true; wfh = true;
|
||||
wfw = true; winbl = true; winblend = true; winfixheight = true;
|
||||
winfixwidth = true; winhighlight = true; winhl = true; wrap = true;
|
||||
arab = true,
|
||||
arabic = true,
|
||||
breakindent = true,
|
||||
breakindentopt = true,
|
||||
bri = true,
|
||||
briopt = true,
|
||||
cc = true,
|
||||
cocu = true,
|
||||
cole = true,
|
||||
colorcolumn = true,
|
||||
concealcursor = true,
|
||||
conceallevel = true,
|
||||
crb = true,
|
||||
cuc = true,
|
||||
cul = true,
|
||||
cursorbind = true,
|
||||
cursorcolumn = true,
|
||||
cursorline = true,
|
||||
diff = true,
|
||||
fcs = true,
|
||||
fdc = true,
|
||||
fde = true,
|
||||
fdi = true,
|
||||
fdl = true,
|
||||
fdm = true,
|
||||
fdn = true,
|
||||
fdt = true,
|
||||
fen = true,
|
||||
fillchars = true,
|
||||
fml = true,
|
||||
fmr = true,
|
||||
foldcolumn = true,
|
||||
foldenable = true,
|
||||
foldexpr = true,
|
||||
foldignore = true,
|
||||
foldlevel = true,
|
||||
foldmarker = true,
|
||||
foldmethod = true,
|
||||
foldminlines = true,
|
||||
foldnestmax = true,
|
||||
foldtext = true,
|
||||
lbr = true,
|
||||
lcs = true,
|
||||
linebreak = true,
|
||||
list = true,
|
||||
listchars = true,
|
||||
nu = true,
|
||||
number = true,
|
||||
numberwidth = true,
|
||||
nuw = true,
|
||||
previewwindow = true,
|
||||
pvw = true,
|
||||
relativenumber = true,
|
||||
rightleft = true,
|
||||
rightleftcmd = true,
|
||||
rl = true,
|
||||
rlc = true,
|
||||
rnu = true,
|
||||
scb = true,
|
||||
scl = true,
|
||||
scr = true,
|
||||
scroll = true,
|
||||
scrollbind = true,
|
||||
signcolumn = true,
|
||||
spell = true,
|
||||
statusline = true,
|
||||
stl = true,
|
||||
wfh = true,
|
||||
wfw = true,
|
||||
winbl = true,
|
||||
winblend = true,
|
||||
winfixheight = true,
|
||||
winfixwidth = true,
|
||||
winhighlight = true,
|
||||
winhl = true,
|
||||
wrap = true,
|
||||
}
|
||||
|
||||
local function validate(conf)
|
||||
assert(type(conf) == 'table')
|
||||
local type_names = {
|
||||
t='table', s='string', n='number', b='boolean', f='function', c='callable',
|
||||
['table']='table', ['string']='string', ['number']='number',
|
||||
['boolean']='boolean', ['function']='function', ['callable']='callable',
|
||||
['nil']='nil', ['thread']='thread', ['userdata']='userdata',
|
||||
}
|
||||
for k, v in pairs(conf) do
|
||||
if not (v[3] and v[1] == nil) and type(v[1]) ~= type_names[v[2]] then
|
||||
error(string.format("validation_failed: %q: expected %s, received %s", k, type_names[v[2]], type(v[1])))
|
||||
end
|
||||
end
|
||||
return true
|
||||
assert(type(conf) == "table")
|
||||
local type_names = {
|
||||
t = "table",
|
||||
s = "string",
|
||||
n = "number",
|
||||
b = "boolean",
|
||||
f = "function",
|
||||
c = "callable",
|
||||
["table"] = "table",
|
||||
["string"] = "string",
|
||||
["number"] = "number",
|
||||
["boolean"] = "boolean",
|
||||
["function"] = "function",
|
||||
["callable"] = "callable",
|
||||
["nil"] = "nil",
|
||||
["thread"] = "thread",
|
||||
["userdata"] = "userdata",
|
||||
}
|
||||
for k, v in pairs(conf) do
|
||||
if not (v[3] and v[1] == nil) and type(v[1]) ~= type_names[v[2]] then
|
||||
error(string.format("validation_failed: %q: expected %s, received %s", k, type_names[v[2]], type(v[1])))
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function make_meta_accessor(get, set, del)
|
||||
validate {
|
||||
get = {get, 'f'};
|
||||
set = {set, 'f'};
|
||||
del = {del, 'f', true};
|
||||
}
|
||||
local mt = {}
|
||||
if del then
|
||||
function mt:__newindex(k, v)
|
||||
if v == nil then
|
||||
return del(k)
|
||||
end
|
||||
return set(k, v)
|
||||
end
|
||||
else
|
||||
function mt:__newindex(k, v)
|
||||
return set(k, v)
|
||||
end
|
||||
end
|
||||
function mt:__index(k)
|
||||
return get(k)
|
||||
end
|
||||
return setmetatable({}, mt)
|
||||
validate({
|
||||
get = { get, "f" },
|
||||
set = { set, "f" },
|
||||
del = { del, "f", true },
|
||||
})
|
||||
local mt = {}
|
||||
if del then
|
||||
function mt:__newindex(k, v)
|
||||
if v == nil then
|
||||
return del(k)
|
||||
end
|
||||
return set(k, v)
|
||||
end
|
||||
else
|
||||
function mt:__newindex(k, v)
|
||||
return set(k, v)
|
||||
end
|
||||
end
|
||||
function mt:__index(k)
|
||||
return get(k)
|
||||
end
|
||||
return setmetatable({}, mt)
|
||||
end
|
||||
|
||||
local function pcall_ret(status, ...)
|
||||
if status then return ... end
|
||||
if status then
|
||||
return ...
|
||||
end
|
||||
end
|
||||
|
||||
local function nil_wrap(fn)
|
||||
return function(...)
|
||||
return pcall_ret(pcall(fn, ...))
|
||||
end
|
||||
return function(...)
|
||||
return pcall_ret(pcall(fn, ...))
|
||||
end
|
||||
end
|
||||
|
||||
local fn = setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local f = function(...) return api.nvim_call_function(k, {...}) end
|
||||
rawset(t, k, f)
|
||||
return f
|
||||
end
|
||||
__index = function(t, k)
|
||||
local f = function(...)
|
||||
return api.nvim_call_function(k, { ... })
|
||||
end
|
||||
rawset(t, k, f)
|
||||
return f
|
||||
end,
|
||||
})
|
||||
|
||||
local function getenv(k)
|
||||
local v = fn.getenv(k)
|
||||
if v == vim.NIL then
|
||||
return nil
|
||||
end
|
||||
return v
|
||||
local v = fn.getenv(k)
|
||||
if v == vim.NIL then
|
||||
return nil
|
||||
end
|
||||
return v
|
||||
end
|
||||
|
||||
local function new_win_accessor(winnr)
|
||||
local function get(k)
|
||||
if winnr == nil and type(k) == 'number' then
|
||||
return new_win_accessor(k)
|
||||
end
|
||||
return api.nvim_win_get_var(winnr or 0, k)
|
||||
end
|
||||
local function set(k, v) return api.nvim_win_set_var(winnr or 0, k, v) end
|
||||
local function del(k) return api.nvim_win_del_var(winnr or 0, k) end
|
||||
return make_meta_accessor(nil_wrap(get), set, del)
|
||||
local function get(k)
|
||||
if winnr == nil and type(k) == "number" then
|
||||
return new_win_accessor(k)
|
||||
end
|
||||
return api.nvim_win_get_var(winnr or 0, k)
|
||||
end
|
||||
local function set(k, v)
|
||||
return api.nvim_win_set_var(winnr or 0, k, v)
|
||||
end
|
||||
local function del(k)
|
||||
return api.nvim_win_del_var(winnr or 0, k)
|
||||
end
|
||||
return make_meta_accessor(nil_wrap(get), set, del)
|
||||
end
|
||||
|
||||
local function new_win_opt_accessor(winnr)
|
||||
local function get(k)
|
||||
if winnr == nil and type(k) == 'number' then
|
||||
return new_win_opt_accessor(k)
|
||||
end
|
||||
return api.nvim_win_get_option(winnr or 0, k)
|
||||
end
|
||||
local function set(k, v) return api.nvim_win_set_option(winnr or 0, k, v) end
|
||||
return make_meta_accessor(nil_wrap(get), set)
|
||||
local function get(k)
|
||||
if winnr == nil and type(k) == "number" then
|
||||
return new_win_opt_accessor(k)
|
||||
end
|
||||
return api.nvim_win_get_option(winnr or 0, k)
|
||||
end
|
||||
local function set(k, v)
|
||||
return api.nvim_win_set_option(winnr or 0, k, v)
|
||||
end
|
||||
return make_meta_accessor(nil_wrap(get), set)
|
||||
end
|
||||
|
||||
local function new_buf_accessor(bufnr)
|
||||
local function get(k)
|
||||
if bufnr == nil and type(k) == 'number' then
|
||||
return new_buf_accessor(k)
|
||||
end
|
||||
return api.nvim_buf_get_var(bufnr or 0, k)
|
||||
end
|
||||
local function set(k, v) return api.nvim_buf_set_var(bufnr or 0, k, v) end
|
||||
local function del(k) return api.nvim_buf_del_var(bufnr or 0, k) end
|
||||
return make_meta_accessor(nil_wrap(get), set, del)
|
||||
local function get(k)
|
||||
if bufnr == nil and type(k) == "number" then
|
||||
return new_buf_accessor(k)
|
||||
end
|
||||
return api.nvim_buf_get_var(bufnr or 0, k)
|
||||
end
|
||||
local function set(k, v)
|
||||
return api.nvim_buf_set_var(bufnr or 0, k, v)
|
||||
end
|
||||
local function del(k)
|
||||
return api.nvim_buf_del_var(bufnr or 0, k)
|
||||
end
|
||||
return make_meta_accessor(nil_wrap(get), set, del)
|
||||
end
|
||||
|
||||
local function new_buf_opt_accessor(bufnr)
|
||||
local function get(k)
|
||||
if window_options[k] then
|
||||
return api.nvim_err_writeln(k.." is a window option, not a buffer option")
|
||||
end
|
||||
if bufnr == nil and type(k) == 'number' then
|
||||
return new_buf_opt_accessor(k)
|
||||
end
|
||||
return api.nvim_buf_get_option(bufnr or 0, k)
|
||||
end
|
||||
local function set(k, v)
|
||||
if window_options[k] then
|
||||
return api.nvim_err_writeln(k.." is a window option, not a buffer option")
|
||||
end
|
||||
return api.nvim_buf_set_option(bufnr or 0, k, v)
|
||||
end
|
||||
return make_meta_accessor(nil_wrap(get), set)
|
||||
local function get(k)
|
||||
if window_options[k] then
|
||||
return api.nvim_err_writeln(k .. " is a window option, not a buffer option")
|
||||
end
|
||||
if bufnr == nil and type(k) == "number" then
|
||||
return new_buf_opt_accessor(k)
|
||||
end
|
||||
return api.nvim_buf_get_option(bufnr or 0, k)
|
||||
end
|
||||
local function set(k, v)
|
||||
if window_options[k] then
|
||||
return api.nvim_err_writeln(k .. " is a window option, not a buffer option")
|
||||
end
|
||||
return api.nvim_buf_set_option(bufnr or 0, k, v)
|
||||
end
|
||||
return make_meta_accessor(nil_wrap(get), set)
|
||||
end
|
||||
|
||||
-- `nvim.$method(...)` redirects to `nvim.api.nvim_$method(...)`
|
||||
@ -182,39 +264,45 @@ end
|
||||
-- `nvim.echo(...)` is approximately `echo table.concat({...}, '\n')`
|
||||
-- Both methods cache the inital lookup in the metatable, but there is api small overhead regardless.
|
||||
return setmetatable({
|
||||
print = nvim_print;
|
||||
echo = nvim_echo;
|
||||
fn = rawget(vim, "fn") or fn;
|
||||
validate = validate;
|
||||
g = rawget(vim, 'g') or make_meta_accessor(nil_wrap(api.nvim_get_var), api.nvim_set_var, api.nvim_del_var);
|
||||
v = rawget(vim, 'v') or make_meta_accessor(nil_wrap(api.nvim_get_vvar), api.nvim_set_vvar);
|
||||
o = rawget(vim, 'o') or make_meta_accessor(api.nvim_get_option, api.nvim_set_option);
|
||||
w = new_win_accessor(nil);
|
||||
b = new_buf_accessor(nil);
|
||||
env = rawget(vim, "env") or make_meta_accessor(getenv, fn.setenv);
|
||||
wo = rawget(vim, "wo") or new_win_opt_accessor(nil);
|
||||
bo = rawget(vim, "bo") or new_buf_opt_accessor(nil);
|
||||
buf = {
|
||||
line = api.nvim_get_current_line;
|
||||
nr = api.nvim_get_current_buf;
|
||||
};
|
||||
ex = setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local command = k:gsub("_$", "!")
|
||||
local f = function(...)
|
||||
return api.nvim_command(table.concat(vim.tbl_flatten {command, ...}, " "))
|
||||
end
|
||||
rawset(t, k, f)
|
||||
return f
|
||||
end
|
||||
});
|
||||
print = nvim_print,
|
||||
echo = nvim_echo,
|
||||
fn = rawget(vim, "fn") or fn,
|
||||
validate = validate,
|
||||
g = rawget(vim, "g") or make_meta_accessor(nil_wrap(api.nvim_get_var), api.nvim_set_var, api.nvim_del_var),
|
||||
v = rawget(vim, "v") or make_meta_accessor(nil_wrap(api.nvim_get_vvar), api.nvim_set_vvar),
|
||||
o = rawget(vim, "o") or make_meta_accessor(api.nvim_get_option, api.nvim_set_option),
|
||||
w = new_win_accessor(nil),
|
||||
b = new_buf_accessor(nil),
|
||||
env = rawget(vim, "env") or make_meta_accessor(getenv, fn.setenv),
|
||||
wo = rawget(vim, "wo") or new_win_opt_accessor(nil),
|
||||
bo = rawget(vim, "bo") or new_buf_opt_accessor(nil),
|
||||
buf = {
|
||||
line = api.nvim_get_current_line,
|
||||
nr = api.nvim_get_current_buf,
|
||||
},
|
||||
ex = setmetatable({}, {
|
||||
__index = function(t, k)
|
||||
local command = k:gsub("_$", "!")
|
||||
local f = function(...)
|
||||
local flattened = nil
|
||||
if vim.iter then
|
||||
flattened = vim.iter({ command, ... }):flatten():totable()
|
||||
else
|
||||
flattened = vim.tbl_flatten({ command, ... })
|
||||
end
|
||||
return api.nvim_command(table.concat(flattened, " "))
|
||||
end
|
||||
rawset(t, k, f)
|
||||
return f
|
||||
end,
|
||||
}),
|
||||
}, {
|
||||
__index = function(t, k)
|
||||
local f = api['nvim_'..k]
|
||||
if f then
|
||||
rawset(t, k, f)
|
||||
end
|
||||
return f
|
||||
end
|
||||
__index = function(t, k)
|
||||
local f = api["nvim_" .. k]
|
||||
if f then
|
||||
rawset(t, k, f)
|
||||
end
|
||||
return f
|
||||
end,
|
||||
})
|
||||
-- vim:et ts=2 sw=2
|
||||
|
@ -41,10 +41,6 @@ local function glob_dir_newer_3f(a_dir, b_dir, expr, b_dir_path_fn)
|
||||
return newer_3f
|
||||
end
|
||||
_2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f
|
||||
local function macro_file_path_3f(path)
|
||||
return a["string?"](string.match(path, "macros?.fnl$"))
|
||||
end
|
||||
_2amodule_2a["macro-file-path?"] = macro_file_path_3f
|
||||
local path_sep
|
||||
do
|
||||
local os = string.lower(jit.os)
|
||||
@ -55,4 +51,8 @@ do
|
||||
end
|
||||
end
|
||||
_2amodule_2a["path-sep"] = path_sep
|
||||
local function macro_file_path_3f(path)
|
||||
return (a["string?"](string.match(path, "macros?.fnl$")) or a["string?"](string.match(path, (path_sep .. "macros?" .. path_sep))))
|
||||
end
|
||||
_2amodule_2a["macro-file-path?"] = macro_file_path_3f
|
||||
return _2amodule_2a
|
||||
|
@ -117,10 +117,17 @@
|
||||
(fn [mod-fn args]
|
||||
(if (seq? args)
|
||||
;; If it's sequential, we execute the fn for side effects.
|
||||
;; Works for (require-macros :name) (deprecated in Fennel 0.4.0).
|
||||
(each [_ arg (ipairs args)]
|
||||
(=> (sym :_) `(,mod-fn ,(tostring arg))))
|
||||
;; When arg is ALSO sequential it means we're sending multiple args for side effects.
|
||||
;; This works well for (import-macros bind :name)
|
||||
(=> (sym :_)
|
||||
(if (seq? arg)
|
||||
`(,mod-fn ,(unpack arg))
|
||||
`(,mod-fn ,(tostring arg)))))
|
||||
|
||||
;; Otherwise we need to bind the execution to a name.
|
||||
;; Works for simple (require :name) calls, binding the result.
|
||||
(sorted-each
|
||||
(fn [bind arg]
|
||||
(=> (ensure-sym bind) `(,mod-fn ,(tostring arg))))
|
||||
|
27
lua/conjure-macroexpand/aniseed/macros/autocmds.fnl
Normal file
27
lua/conjure-macroexpand/aniseed/macros/autocmds.fnl
Normal file
@ -0,0 +1,27 @@
|
||||
(fn autocmd [event opt]
|
||||
`(vim.api.nvim_create_autocmd
|
||||
,event ,opt))
|
||||
|
||||
(fn autocmds [...]
|
||||
(var form `(do))
|
||||
(each [_ v (ipairs [...])]
|
||||
(table.insert form (autocmd (unpack v))))
|
||||
(table.insert form 'nil)
|
||||
form)
|
||||
|
||||
(fn augroup [name ...]
|
||||
(var cmds `(do))
|
||||
(var group (sym :group))
|
||||
(each [_ v (ipairs [...])]
|
||||
(let [(event opt) (unpack v)]
|
||||
(tset opt :group group)
|
||||
(table.insert cmds (autocmd event opt))))
|
||||
(table.insert cmds 'nil)
|
||||
`(let [,group
|
||||
(vim.api.nvim_create_augroup ,name {:clear true})]
|
||||
,cmds
|
||||
,group))
|
||||
|
||||
{:autocmd autocmd
|
||||
:autocmds autocmds
|
||||
:augroup augroup}
|
@ -132,16 +132,20 @@ local function run_all()
|
||||
end
|
||||
return totals
|
||||
end
|
||||
return display_results(a.reduce(_21_, {tests = 0, ["tests-passed"] = 0, assertions = 0, ["assertions-passed"] = 0}, a.filter(a["table?"], a.map(run, a.keys(_G.package.loaded)))), "[total]")
|
||||
local function _22_(mod_name)
|
||||
local mod = a.get(_G.package.loaded, mod_name)
|
||||
return (not a["table?"](mod) or getmetatable(mod))
|
||||
end
|
||||
return display_results(a.reduce(_21_, {tests = 0, ["tests-passed"] = 0, assertions = 0, ["assertions-passed"] = 0}, a.filter(a["table?"], a.map(run, a.remove(_22_, a.keys(_G.package.loaded))))), "[total]")
|
||||
end
|
||||
_2amodule_2a["run-all"] = run_all
|
||||
local function suite()
|
||||
do
|
||||
local sep = fs["path-sep"]
|
||||
local function _22_(path)
|
||||
local function _23_(path)
|
||||
return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, "."))
|
||||
end
|
||||
a["run!"](_22_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true))
|
||||
a["run!"](_23_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true))
|
||||
end
|
||||
if ok_3f(run_all()) then
|
||||
return nvim.ex.q()
|
||||
|
@ -48,19 +48,68 @@ local function clj_macroexpand(expand_cmd)
|
||||
return clj_client(eval["eval-str"], {origin = "conjure-macroexpand", code = me_form, ["passive?"] = true, ["on-result"] = output_expanded(me_form)})
|
||||
end
|
||||
_2amodule_2a["clj-macroexpand"] = clj_macroexpand
|
||||
local function wrap_emit(name, f)
|
||||
local function _4_(...)
|
||||
event.emit(name)
|
||||
return f(...)
|
||||
end
|
||||
return _4_
|
||||
end
|
||||
_2amodule_2a["wrap-emit"] = wrap_emit
|
||||
local dir_str = wrap_emit("doc", __fnl_global__client_2dexec_2dfn("doc", "doc-str"))
|
||||
local function dir_word()
|
||||
local _let_5_ = extract.word()
|
||||
local content = _let_5_["content"]
|
||||
local range = _let_5_["range"]
|
||||
local node = _let_5_["node"]
|
||||
if not core["empty?"](content) then
|
||||
return dir_str({code = content, range = range, node = node, origin = "word"})
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["dir-word"] = dir_word
|
||||
local function replace_form()
|
||||
local buf = vim.api.nvim_win_get_buf(0)
|
||||
local win = vim.api.nvim_tabpage_get_win(0)
|
||||
local form = extract.form({})
|
||||
if form then
|
||||
local _let_7_ = form
|
||||
local content = _let_7_["content"]
|
||||
local range = _let_7_["range"]
|
||||
local node = _let_7_["node"]
|
||||
local function _8_(result)
|
||||
buffer.replacerange(buf, range, result)
|
||||
return editor["go-to"](win, core["get-in"](range, {"start", 1}), core.inc(core["get-in"](range, {"start", 2})))
|
||||
end
|
||||
__fnl_global__eval_2dstr({code = content, range = range, node = node, origin = "replace-form", ["suppress-hud?"] = true, ["on-result"] = _8_})
|
||||
return ("(clojure.core/macroexpand1 " .. form .. ")")
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["replace-form"] = replace_form
|
||||
local function add_buf_mappings()
|
||||
local function _4_()
|
||||
local function _10_()
|
||||
return clj_macroexpand()
|
||||
end
|
||||
mapping.buf("CljMacroexpand", "cm", _4_, {desc = "Call macroexpand-all on the symbol under the cursor"})
|
||||
local function _5_()
|
||||
mapping.buf("CljMacroexpand", "cm", _10_, {desc = "Call macroexpand-all on the symbol under the cursor"})
|
||||
local function _11_()
|
||||
return clj_macroexpand("clojure.core/macroexpand")
|
||||
end
|
||||
mapping.buf("CljMacroexpand0", "c0", _5_, {desc = "Call macroexpand on the symbol under the cursor"})
|
||||
local function _6_()
|
||||
mapping.buf("CljMacroexpand0", "c0", _11_, {desc = "Call macroexpand on the symbol under the cursor"})
|
||||
local function _12_()
|
||||
return clj_macroexpand("clojure.core/macroexpand-1")
|
||||
end
|
||||
return mapping.buf("CljMacroexpand1", "c1", _6_, {desc = "Call macroexpand-1 on the symbol under the cursor"})
|
||||
mapping.buf("CljMacroexpand1", "c1", _12_, {desc = "Call macroexpand-1 on the symbol under the cursor"})
|
||||
local function _13_()
|
||||
return replace_form()
|
||||
end
|
||||
mapping.buf("CljMacroexpandReplace", "em!", _13_, {desc = "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
||||
local function _14_()
|
||||
return dir_word()
|
||||
end
|
||||
return mapping.buf("CljDirWord", "em!", _14_, {desc = "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"})
|
||||
end
|
||||
_2amodule_2a["add-buf-mappings"] = add_buf_mappings
|
||||
local function init()
|
||||
|
Loading…
x
Reference in New Issue
Block a user