add initial commands
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
local _2afile_2a = "fnl/aniseed/autoload.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.autoload"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local function autoload(name)
|
||||
local res = {["aniseed/autoload-enabled?"] = true, ["aniseed/autoload-module"] = false}
|
||||
local function ensure()
|
||||
if res["aniseed/autoload-module"] then
|
||||
return res["aniseed/autoload-module"]
|
||||
else
|
||||
local m = require(name)
|
||||
do end (res)["aniseed/autoload-module"] = m
|
||||
return m
|
||||
end
|
||||
end
|
||||
local function _2_(t, ...)
|
||||
return ensure()(...)
|
||||
end
|
||||
local function _3_(t, k)
|
||||
return ensure()[k]
|
||||
end
|
||||
local function _4_(t, k, v)
|
||||
ensure()[k] = v
|
||||
return nil
|
||||
end
|
||||
return setmetatable(res, {__call = _2_, __index = _3_, __newindex = _4_})
|
||||
end
|
||||
_2amodule_2a["autoload"] = autoload
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,83 @@
|
||||
local _2afile_2a = "fnl/aniseed/compile.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.compile"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a, fennel, fs, nvim = autoload("conjure-macroreplace.aniseed.core"), autoload("conjure-macroreplace.aniseed.fennel"), autoload("conjure-macroreplace.aniseed.fs"), autoload("conjure-macroreplace.aniseed.nvim")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["fennel"] = fennel
|
||||
_2amodule_locals_2a["fs"] = fs
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
local function wrap_macros(code, opts)
|
||||
local macros_module = "conjure-macroreplace.aniseed.macros"
|
||||
local filename
|
||||
do
|
||||
local _1_ = a.get(opts, "filename")
|
||||
if (nil ~= _1_) then
|
||||
filename = string.gsub(_1_, (nvim.fn.getcwd() .. fs["path-sep"]), "")
|
||||
else
|
||||
filename = _1_
|
||||
end
|
||||
end
|
||||
local function _3_()
|
||||
if filename then
|
||||
return ("\"" .. string.gsub(filename, "\\", "\\\\") .. "\"")
|
||||
else
|
||||
return "nil"
|
||||
end
|
||||
end
|
||||
return ("(local *file* " .. _3_() .. ")" .. "(require-macros \"" .. macros_module .. "\")\n" .. "(wrap-module-body " .. (code or "") .. ")")
|
||||
end
|
||||
_2amodule_2a["wrap-macros"] = wrap_macros
|
||||
local marker_prefix = "ANISEED_"
|
||||
_2amodule_2a["marker-prefix"] = marker_prefix
|
||||
local delete_marker = (marker_prefix .. "DELETE_ME")
|
||||
do end (_2amodule_2a)["delete-marker"] = delete_marker
|
||||
local delete_marker_pat = ("\n[^\n]-\"" .. delete_marker .. "\".-")
|
||||
do end (_2amodule_locals_2a)["delete-marker-pat"] = delete_marker_pat
|
||||
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!"]({compilerEnv = _G, allowedGlobals = false}, opts)), (delete_marker_pat .. "\n"), "\n"), (delete_marker_pat .. "$"), "")
|
||||
end
|
||||
return xpcall(_4_, fnl.traceback)
|
||||
end
|
||||
_2amodule_2a["str"] = str
|
||||
local function file(src, dest, opts)
|
||||
local code = a.slurp(src)
|
||||
local _5_, _6_ = str(code, a["merge!"]({filename = src, ["static?"] = true}, opts))
|
||||
if ((_5_ == false) and (nil ~= _6_)) then
|
||||
local err = _6_
|
||||
return nvim.err_writeln(err)
|
||||
elseif ((_5_ == true) and (nil ~= _6_)) then
|
||||
local result = _6_
|
||||
fs.mkdirp(fs.basename(dest))
|
||||
return a.spit(dest, result)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["file"] = file
|
||||
local function glob(src_expr, src_dir, dest_dir, opts)
|
||||
for _, path in ipairs(fs.relglob(src_dir, src_expr)) do
|
||||
if fs["macro-file-path?"](path) then
|
||||
local dest = (dest_dir .. path)
|
||||
fs.mkdirp(fs.basename(dest))
|
||||
a.spit(dest, a.slurp((src_dir .. path)))
|
||||
else
|
||||
file((src_dir .. path), string.gsub((dest_dir .. path), ".fnl$", ".lua"), opts)
|
||||
end
|
||||
end
|
||||
return nil
|
||||
end
|
||||
_2amodule_2a["glob"] = glob
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,469 @@
|
||||
local _2afile_2a = "fnl/aniseed/core.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.core"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local view = autoload("conjure-macroreplace.aniseed.view")
|
||||
do end (_2amodule_locals_2a)["view"] = view
|
||||
math.randomseed(os.time())
|
||||
local function rand(n)
|
||||
return (math.random() * (n or 1))
|
||||
end
|
||||
_2amodule_2a["rand"] = rand
|
||||
local function nil_3f(x)
|
||||
return (nil == x)
|
||||
end
|
||||
_2amodule_2a["nil?"] = nil_3f
|
||||
local function number_3f(x)
|
||||
return ("number" == type(x))
|
||||
end
|
||||
_2amodule_2a["number?"] = number_3f
|
||||
local function boolean_3f(x)
|
||||
return ("boolean" == type(x))
|
||||
end
|
||||
_2amodule_2a["boolean?"] = boolean_3f
|
||||
local function string_3f(x)
|
||||
return ("string" == type(x))
|
||||
end
|
||||
_2amodule_2a["string?"] = string_3f
|
||||
local function table_3f(x)
|
||||
return ("table" == type(x))
|
||||
end
|
||||
_2amodule_2a["table?"] = table_3f
|
||||
local function function_3f(value)
|
||||
return ("function" == type(value))
|
||||
end
|
||||
_2amodule_2a["function?"] = function_3f
|
||||
local function keys(t)
|
||||
local result = {}
|
||||
if t then
|
||||
for k, _ in pairs(t) do
|
||||
table.insert(result, k)
|
||||
end
|
||||
else
|
||||
end
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["keys"] = keys
|
||||
local function count(xs)
|
||||
if table_3f(xs) then
|
||||
local maxn = table.maxn(xs)
|
||||
if (0 == maxn) then
|
||||
return table.maxn(keys(xs))
|
||||
else
|
||||
return maxn
|
||||
end
|
||||
elseif not xs then
|
||||
return 0
|
||||
else
|
||||
return #xs
|
||||
end
|
||||
end
|
||||
_2amodule_2a["count"] = count
|
||||
local function empty_3f(xs)
|
||||
return (0 == count(xs))
|
||||
end
|
||||
_2amodule_2a["empty?"] = empty_3f
|
||||
local function first(xs)
|
||||
if xs then
|
||||
return xs[1]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["first"] = first
|
||||
local function second(xs)
|
||||
if xs then
|
||||
return xs[2]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["second"] = second
|
||||
local function last(xs)
|
||||
if xs then
|
||||
return xs[count(xs)]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["last"] = last
|
||||
local function inc(n)
|
||||
return (n + 1)
|
||||
end
|
||||
_2amodule_2a["inc"] = inc
|
||||
local function dec(n)
|
||||
return (n - 1)
|
||||
end
|
||||
_2amodule_2a["dec"] = dec
|
||||
local function even_3f(n)
|
||||
return ((n % 2) == 0)
|
||||
end
|
||||
_2amodule_2a["even?"] = even_3f
|
||||
local function odd_3f(n)
|
||||
return not even_3f(n)
|
||||
end
|
||||
_2amodule_2a["odd?"] = odd_3f
|
||||
local function vals(t)
|
||||
local result = {}
|
||||
if t then
|
||||
for _, v in pairs(t) do
|
||||
table.insert(result, v)
|
||||
end
|
||||
else
|
||||
end
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["vals"] = vals
|
||||
local function kv_pairs(t)
|
||||
local result = {}
|
||||
if t then
|
||||
for k, v in pairs(t) do
|
||||
table.insert(result, {k, v})
|
||||
end
|
||||
else
|
||||
end
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["kv-pairs"] = kv_pairs
|
||||
local function run_21(f, xs)
|
||||
if xs then
|
||||
local nxs = count(xs)
|
||||
if (nxs > 0) then
|
||||
for i = 1, nxs do
|
||||
f(xs[i])
|
||||
end
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
else
|
||||
return nil
|
||||
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 _12_(x)
|
||||
if f(x) then
|
||||
return table.insert(result, x)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
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 _14_(x)
|
||||
local mapped = f(x)
|
||||
local function _15_()
|
||||
if (0 == select("#", mapped)) then
|
||||
return nil
|
||||
else
|
||||
return mapped
|
||||
end
|
||||
end
|
||||
return table.insert(result, _15_())
|
||||
end
|
||||
run_21(_14_, xs)
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["map"] = map
|
||||
local function map_indexed(f, xs)
|
||||
return map(f, kv_pairs(xs))
|
||||
end
|
||||
_2amodule_2a["map-indexed"] = map_indexed
|
||||
local function identity(x)
|
||||
return x
|
||||
end
|
||||
_2amodule_2a["identity"] = identity
|
||||
local function reduce(f, init, xs)
|
||||
local result = init
|
||||
local function _16_(x)
|
||||
result = f(result, x)
|
||||
return nil
|
||||
end
|
||||
run_21(_16_, xs)
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["reduce"] = reduce
|
||||
local function some(f, xs)
|
||||
local result = nil
|
||||
local n = 1
|
||||
while (nil_3f(result) and (n <= count(xs))) do
|
||||
local candidate = f(xs[n])
|
||||
if candidate then
|
||||
result = candidate
|
||||
else
|
||||
end
|
||||
n = inc(n)
|
||||
end
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["some"] = some
|
||||
local function butlast(xs)
|
||||
local total = count(xs)
|
||||
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(_20_, kv_pairs(xs)))
|
||||
end
|
||||
_2amodule_2a["butlast"] = butlast
|
||||
local function rest(xs)
|
||||
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(_23_, kv_pairs(xs)))
|
||||
end
|
||||
_2amodule_2a["rest"] = rest
|
||||
local function concat(...)
|
||||
local result = {}
|
||||
local function _24_(xs)
|
||||
local function _25_(x)
|
||||
return table.insert(result, x)
|
||||
end
|
||||
return run_21(_25_, xs)
|
||||
end
|
||||
run_21(_24_, {...})
|
||||
return result
|
||||
end
|
||||
_2amodule_2a["concat"] = concat
|
||||
local function mapcat(f, xs)
|
||||
return concat(unpack(map(f, xs)))
|
||||
end
|
||||
_2amodule_2a["mapcat"] = mapcat
|
||||
local function pr_str(...)
|
||||
local s
|
||||
local function _26_(x)
|
||||
return view.serialise(x, {["one-line"] = true})
|
||||
end
|
||||
s = table.concat(map(_26_, {...}), " ")
|
||||
if (nil_3f(s) or ("" == s)) then
|
||||
return "nil"
|
||||
else
|
||||
return s
|
||||
end
|
||||
end
|
||||
_2amodule_2a["pr-str"] = pr_str
|
||||
local function str(...)
|
||||
local function _28_(acc, s)
|
||||
return (acc .. s)
|
||||
end
|
||||
local function _29_(s)
|
||||
if string_3f(s) then
|
||||
return s
|
||||
else
|
||||
return pr_str(s)
|
||||
end
|
||||
end
|
||||
return reduce(_28_, "", map(_29_, {...}))
|
||||
end
|
||||
_2amodule_2a["str"] = str
|
||||
local function println(...)
|
||||
local function _31_(acc, s)
|
||||
return (acc .. s)
|
||||
end
|
||||
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 _36_(s)
|
||||
if string_3f(s) then
|
||||
return s
|
||||
else
|
||||
return pr_str(s)
|
||||
end
|
||||
end
|
||||
return print(reduce(_31_, "", map_indexed(_34_, map(_36_, {...}))))
|
||||
end
|
||||
_2amodule_2a["println"] = println
|
||||
local function pr(...)
|
||||
return println(pr_str(...))
|
||||
end
|
||||
_2amodule_2a["pr"] = pr
|
||||
local function slurp(path, silent_3f)
|
||||
local _38_, _39_ = io.open(path, "r")
|
||||
if ((_38_ == nil) and (nil ~= _39_)) then
|
||||
local msg = _39_
|
||||
return nil
|
||||
elseif (nil ~= _38_) then
|
||||
local f = _38_
|
||||
local content = f:read("*all")
|
||||
f:close()
|
||||
return content
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["slurp"] = slurp
|
||||
local function spit(path, content)
|
||||
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 ~= _41_) then
|
||||
local f = _41_
|
||||
f:write(content)
|
||||
f:close()
|
||||
return nil
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["spit"] = spit
|
||||
local function merge_21(base, ...)
|
||||
local function _44_(acc, m)
|
||||
if m then
|
||||
for k, v in pairs(m) do
|
||||
acc[k] = v
|
||||
end
|
||||
else
|
||||
end
|
||||
return acc
|
||||
end
|
||||
return reduce(_44_, (base or {}), {...})
|
||||
end
|
||||
_2amodule_2a["merge!"] = merge_21
|
||||
local function merge(...)
|
||||
return merge_21({}, ...)
|
||||
end
|
||||
_2amodule_2a["merge"] = merge
|
||||
local function select_keys(t, ks)
|
||||
if (t and ks) then
|
||||
local function _46_(acc, k)
|
||||
if k then
|
||||
acc[k] = t[k]
|
||||
else
|
||||
end
|
||||
return acc
|
||||
end
|
||||
return reduce(_46_, {}, ks)
|
||||
else
|
||||
return {}
|
||||
end
|
||||
end
|
||||
_2amodule_2a["select-keys"] = select_keys
|
||||
local function get(t, k, d)
|
||||
local res
|
||||
if table_3f(t) then
|
||||
local val = t[k]
|
||||
if not nil_3f(val) then
|
||||
res = val
|
||||
else
|
||||
res = nil
|
||||
end
|
||||
else
|
||||
res = nil
|
||||
end
|
||||
if nil_3f(res) then
|
||||
return d
|
||||
else
|
||||
return res
|
||||
end
|
||||
end
|
||||
_2amodule_2a["get"] = get
|
||||
local function get_in(t, ks, d)
|
||||
local res
|
||||
local function _52_(acc, k)
|
||||
if table_3f(acc) then
|
||||
return get(acc, k)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
res = reduce(_52_, t, ks)
|
||||
if nil_3f(res) then
|
||||
return d
|
||||
else
|
||||
return res
|
||||
end
|
||||
end
|
||||
_2amodule_2a["get-in"] = get_in
|
||||
local function assoc(t, ...)
|
||||
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
|
||||
error("assoc expects even number of arguments after table, found odd number")
|
||||
else
|
||||
end
|
||||
if not nil_3f(k) then
|
||||
t0[k] = v
|
||||
else
|
||||
end
|
||||
if (rem > 0) then
|
||||
assoc(t0, unpack(xs))
|
||||
else
|
||||
end
|
||||
return t0
|
||||
end
|
||||
_2amodule_2a["assoc"] = assoc
|
||||
local function assoc_in(t, ks, v)
|
||||
local path = butlast(ks)
|
||||
local final = last(ks)
|
||||
local t0 = (t or {})
|
||||
local function _59_(acc, k)
|
||||
local step = get(acc, k)
|
||||
if nil_3f(step) then
|
||||
return get(assoc(acc, k, {}), k)
|
||||
else
|
||||
return step
|
||||
end
|
||||
end
|
||||
assoc(reduce(_59_, t0, path), final, v)
|
||||
return t0
|
||||
end
|
||||
_2amodule_2a["assoc-in"] = assoc_in
|
||||
local function update(t, k, f)
|
||||
return assoc(t, k, f(get(t, k)))
|
||||
end
|
||||
_2amodule_2a["update"] = update
|
||||
local function update_in(t, ks, f)
|
||||
return assoc_in(t, ks, f(get_in(t, ks)))
|
||||
end
|
||||
_2amodule_2a["update-in"] = update_in
|
||||
local function constantly(v)
|
||||
local function _61_()
|
||||
return v
|
||||
end
|
||||
return _61_
|
||||
end
|
||||
_2amodule_2a["constantly"] = constantly
|
||||
return _2amodule_2a
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,308 @@
|
||||
-- Bring vim into local scope.
|
||||
local vim = vim
|
||||
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
|
||||
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")
|
||||
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")
|
||||
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,
|
||||
}
|
||||
|
||||
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
|
||||
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)
|
||||
end
|
||||
|
||||
local function pcall_ret(status, ...)
|
||||
if status then
|
||||
return ...
|
||||
end
|
||||
end
|
||||
|
||||
local function nil_wrap(fn)
|
||||
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,
|
||||
})
|
||||
|
||||
local function getenv(k)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
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)
|
||||
end
|
||||
|
||||
-- `nvim.$method(...)` redirects to `nvim.api.nvim_$method(...)`
|
||||
-- `nvim.fn.$method(...)` redirects to `vim.api.nvim_call_function($method, {...})`
|
||||
-- TODO `nvim.ex.$command(...)` is approximately `:$command {...}.join(" ")`
|
||||
-- `nvim.print(...)` is approximately `echo vim.inspect(...)`
|
||||
-- `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(...)
|
||||
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,
|
||||
})
|
||||
-- vim:et ts=2 sw=2
|
||||
@@ -0,0 +1,63 @@
|
||||
local _2afile_2a = "fnl/aniseed/env.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.env"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local compile, fennel, fs, nvim = autoload("conjure-macroreplace.aniseed.compile"), autoload("conjure-macroreplace.aniseed.fennel"), autoload("conjure-macroreplace.aniseed.fs"), autoload("conjure-macroreplace.aniseed.nvim")
|
||||
do end (_2amodule_locals_2a)["compile"] = compile
|
||||
_2amodule_locals_2a["fennel"] = fennel
|
||||
_2amodule_locals_2a["fs"] = fs
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
local config_dir = nvim.fn.stdpath("config")
|
||||
do end (_2amodule_locals_2a)["config-dir"] = config_dir
|
||||
local function quiet_require(m)
|
||||
local ok_3f, err = nil, nil
|
||||
local function _1_()
|
||||
return require(m)
|
||||
end
|
||||
ok_3f, err = pcall(_1_)
|
||||
if (not ok_3f and not err:find(("module '" .. m .. "' not found"))) then
|
||||
return nvim.ex.echoerr(err)
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_locals_2a["quiet-require"] = quiet_require
|
||||
local function init(opts)
|
||||
local opts0
|
||||
if ("table" == type(opts)) then
|
||||
opts0 = opts
|
||||
else
|
||||
opts0 = {}
|
||||
end
|
||||
local glob_expr = "**/*.fnl"
|
||||
local fnl_dir = nvim.fn.expand((opts0.input or (config_dir .. fs["path-sep"] .. "fnl")))
|
||||
local lua_dir = nvim.fn.expand((opts0.output or (config_dir .. fs["path-sep"] .. "lua")))
|
||||
if opts0.output then
|
||||
package.path = (package.path .. ";" .. lua_dir .. fs["path-sep"] .. "?.lua")
|
||||
else
|
||||
end
|
||||
local function _5_(path)
|
||||
if fs["macro-file-path?"](path) then
|
||||
return path
|
||||
else
|
||||
return string.gsub(path, ".fnl$", ".lua")
|
||||
end
|
||||
end
|
||||
if (((false ~= opts0.compile) or os.getenv("ANISEED_ENV_COMPILE")) and fs["glob-dir-newer?"](fnl_dir, lua_dir, glob_expr, _5_)) then
|
||||
fennel["add-path"]((fnl_dir .. fs["path-sep"] .. "?.fnl"))
|
||||
compile.glob(glob_expr, fnl_dir, lua_dir, opts0)
|
||||
else
|
||||
end
|
||||
return quiet_require((opts0.module or "init"))
|
||||
end
|
||||
_2amodule_2a["init"] = init
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,72 @@
|
||||
local _2afile_2a = "fnl/aniseed/eval.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.eval"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a, compile, fennel, fs, nvim = autoload("conjure-macroreplace.aniseed.core"), autoload("conjure-macroreplace.aniseed.compile"), autoload("conjure-macroreplace.aniseed.fennel"), autoload("conjure-macroreplace.aniseed.fs"), autoload("conjure-macroreplace.aniseed.nvim")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["compile"] = compile
|
||||
_2amodule_locals_2a["fennel"] = fennel
|
||||
_2amodule_locals_2a["fs"] = fs
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
local function str(code, opts)
|
||||
local fnl = fennel.impl()
|
||||
local function _1_()
|
||||
return fnl.eval(compile["wrap-macros"](code, opts), a.merge({compilerEnv = _G}, opts))
|
||||
end
|
||||
return xpcall(_1_, fnl.traceback)
|
||||
end
|
||||
_2amodule_2a["str"] = str
|
||||
local function clean_values(vals)
|
||||
local function _2_(val)
|
||||
if a["table?"](val) then
|
||||
return (compile["delete-marker"] ~= a.first(val))
|
||||
else
|
||||
return true
|
||||
end
|
||||
end
|
||||
return a.filter(_2_, vals)
|
||||
end
|
||||
_2amodule_locals_2a["clean-values"] = clean_values
|
||||
local function clean_error(err)
|
||||
return string.gsub(string.gsub(err, "^%b[string .-%b]:%d+: ", ""), "^Compile error in .-:%d+\n%s+", "")
|
||||
end
|
||||
_2amodule_2a["clean-error"] = clean_error
|
||||
local function repl(opts)
|
||||
local eval_values = nil
|
||||
local fnl = fennel.impl()
|
||||
local opts0 = (opts or {})
|
||||
local co
|
||||
local function _4_()
|
||||
local function _5_(_241)
|
||||
eval_values = clean_values(_241)
|
||||
return nil
|
||||
end
|
||||
local function _6_(_241, _242)
|
||||
return (opts0["error-handler"] or nvim.err_writeln)(clean_error(_242))
|
||||
end
|
||||
return fnl.repl(a.merge({compilerEnv = _G, pp = a.identity, readChunk = coroutine.yield, onValues = _5_, onError = _6_}, opts0))
|
||||
end
|
||||
co = coroutine.create(_4_)
|
||||
coroutine.resume(co)
|
||||
coroutine.resume(co, compile["wrap-macros"](nil, opts0))
|
||||
eval_values = nil
|
||||
local function _7_(code)
|
||||
ANISEED_STATIC_MODULES = false
|
||||
coroutine.resume(co, code)
|
||||
local prev_eval_values = eval_values
|
||||
eval_values = nil
|
||||
return prev_eval_values
|
||||
end
|
||||
return _7_
|
||||
end
|
||||
_2amodule_2a["repl"] = repl
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,55 @@
|
||||
local _2afile_2a = "fnl/aniseed/fennel.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.fennel"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a, fs, nvim, str = autoload("conjure-macroreplace.aniseed.core"), autoload("conjure-macroreplace.aniseed.fs"), autoload("conjure-macroreplace.aniseed.nvim"), autoload("conjure-macroreplace.aniseed.string")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["fs"] = fs
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
_2amodule_locals_2a["str"] = str
|
||||
local function sync_rtp(compiler)
|
||||
local fnl_suffix = (fs["path-sep"] .. "fnl" .. fs["path-sep"] .. "?.fnl")
|
||||
local lua_suffix = (fs["path-sep"] .. "lua" .. fs["path-sep"] .. "?.fnl")
|
||||
local rtps = nvim.list_runtime_paths()
|
||||
local fnl_paths
|
||||
local function _1_(_241)
|
||||
return (_241 .. fnl_suffix)
|
||||
end
|
||||
fnl_paths = a.map(_1_, rtps)
|
||||
local lua_paths
|
||||
local function _2_(_241)
|
||||
return (_241 .. lua_suffix)
|
||||
end
|
||||
lua_paths = a.map(_2_, rtps)
|
||||
do end (compiler)["macro-path"] = str.join(";", a.concat(fnl_paths, lua_paths))
|
||||
return nil
|
||||
end
|
||||
_2amodule_2a["sync-rtp"] = sync_rtp
|
||||
local state = {["compiler-loaded?"] = false}
|
||||
_2amodule_locals_2a["state"] = state
|
||||
local function impl()
|
||||
local compiler = require("conjure-macroreplace.aniseed.deps.fennel")
|
||||
if not state["compiler-loaded?"] then
|
||||
state["compiler-loaded?"] = true
|
||||
sync_rtp(compiler)
|
||||
else
|
||||
end
|
||||
return compiler
|
||||
end
|
||||
_2amodule_2a["impl"] = impl
|
||||
local function add_path(path)
|
||||
local fnl = impl()
|
||||
do end (fnl)["macro-path"] = (fnl["macro-path"] .. ";" .. path)
|
||||
return nil
|
||||
end
|
||||
_2amodule_2a["add-path"] = add_path
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,58 @@
|
||||
local _2afile_2a = "fnl/aniseed/fs.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.fs"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a, nvim = autoload("conjure-macroreplace.aniseed.core"), autoload("conjure-macroreplace.aniseed.nvim")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
local function basename(path)
|
||||
return nvim.fn.fnamemodify(path, ":h")
|
||||
end
|
||||
_2amodule_2a["basename"] = basename
|
||||
local function mkdirp(dir)
|
||||
return nvim.fn.mkdir(dir, "p")
|
||||
end
|
||||
_2amodule_2a["mkdirp"] = mkdirp
|
||||
local function relglob(dir, expr)
|
||||
local dir_len = a.inc(string.len(dir))
|
||||
local function _1_(_241)
|
||||
return string.sub(_241, dir_len)
|
||||
end
|
||||
return a.map(_1_, nvim.fn.globpath(dir, expr, true, true))
|
||||
end
|
||||
_2amodule_2a["relglob"] = relglob
|
||||
local function glob_dir_newer_3f(a_dir, b_dir, expr, b_dir_path_fn)
|
||||
local newer_3f = false
|
||||
for _, path in ipairs(relglob(a_dir, expr)) do
|
||||
if (nvim.fn.getftime((a_dir .. path)) > nvim.fn.getftime((b_dir .. b_dir_path_fn(path)))) then
|
||||
newer_3f = true
|
||||
else
|
||||
end
|
||||
end
|
||||
return newer_3f
|
||||
end
|
||||
_2amodule_2a["glob-dir-newer?"] = glob_dir_newer_3f
|
||||
local path_sep
|
||||
do
|
||||
local os = string.lower(jit.os)
|
||||
if (("linux" == os) or ("osx" == os) or ("bsd" == os)) then
|
||||
path_sep = "/"
|
||||
else
|
||||
path_sep = "\\"
|
||||
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
|
||||
@@ -0,0 +1,305 @@
|
||||
;; All of Aniseed's macros in one place.
|
||||
;; Can't be compiled to Lua directly.
|
||||
|
||||
;; Automatically loaded through require-macros for all Aniseed based evaluations.
|
||||
|
||||
(fn nil? [x]
|
||||
(= :nil (type x)))
|
||||
|
||||
(fn seq? [x]
|
||||
(not (nil? (. x 1))))
|
||||
|
||||
(fn str [x]
|
||||
(if (= :string (type x))
|
||||
x
|
||||
(tostring x)))
|
||||
|
||||
(fn sorted-each [f x]
|
||||
(let [acc []]
|
||||
(each [k v (pairs x)]
|
||||
(table.insert acc [k v]))
|
||||
(table.sort
|
||||
acc
|
||||
(fn [a b]
|
||||
(< (str (. a 1)) (str (. b 1)))))
|
||||
(each [_ [k v] (ipairs acc)]
|
||||
(f k v))))
|
||||
|
||||
(fn contains? [t target]
|
||||
(var seen? false)
|
||||
(each [k v (pairs t)]
|
||||
(when (= k target)
|
||||
(set seen? true)))
|
||||
seen?)
|
||||
|
||||
(fn ensure-sym [x]
|
||||
(if (= :string (type x))
|
||||
(sym x)
|
||||
x))
|
||||
|
||||
;; This marker can be used by a post-processor to delete a useless byproduct line.
|
||||
(local delete-marker :ANISEED_DELETE_ME)
|
||||
|
||||
;; We store all locals under this for later splatting.
|
||||
(local locals-key :aniseed/locals)
|
||||
|
||||
;; Various symbols we want to use multiple times.
|
||||
;; Avoids the compiler complaining that we're introducing locals without gensym.
|
||||
(local mod-name-sym (sym :*module-name*))
|
||||
(local mod-sym (sym :*module*))
|
||||
(local mod-locals-sym (sym :*module-locals*))
|
||||
(local autoload-sym (sym :autoload))
|
||||
|
||||
;; Upserts the existence of the module for subsequent def forms and expands the
|
||||
;; bound function calls into the current context.
|
||||
;;
|
||||
;; On subsequent interactive calls it will expand the existing module into your
|
||||
;; current context. This should be used by Conjure as you enter a buffer.
|
||||
;;
|
||||
;; (module foo
|
||||
;; {require {nvim aniseed.nvim}}
|
||||
;; {:some-optional-base :table-of-things
|
||||
;; :to-base :the-module-off-of})
|
||||
;;
|
||||
;; (module foo) ;; expands foo into your current context
|
||||
(fn module [mod-name mod-fns mod-base]
|
||||
(let [;; So we can check for existing values and know if we're in an interactive eval.
|
||||
;; If the module doesn't exist we're compiling and can skip interactive tooling.
|
||||
existing-mod (. package.loaded (tostring mod-name))
|
||||
|
||||
;; Determine if we're in an interactive eval or not.
|
||||
|
||||
;; We don't count userdata / other types as an existing module since we
|
||||
;; can't really work with anything other than a table. If it's not a
|
||||
;; table it's probably not a module Aniseed can work with in general
|
||||
;; since it's assumed all Aniseed modules are table based.
|
||||
|
||||
;; We can also completely disable the interactive mode which is used by
|
||||
;; `aniseed.env` but can also be enabled by others. Sadly this works
|
||||
;; through global variables but still!
|
||||
interactive? (and (table? existing-mod)
|
||||
(not _G.ANISEED_STATIC_MODULES))
|
||||
|
||||
;; The final result table that gets returned from the macro.
|
||||
;; This is the best way I've found to introduce many (local ...) forms from one macro.
|
||||
result `[,delete-marker
|
||||
|
||||
;; We can't refer to things like (local (foo bar) (10 foo)).
|
||||
;; So we need to define them in an earlier local.
|
||||
(local ,mod-name-sym ,(tostring mod-name))
|
||||
|
||||
;; Only expose the module table if it doesn't exist yet.
|
||||
(local ,mod-sym ,(if interactive?
|
||||
`(. package.loaded ,mod-name-sym)
|
||||
`(do
|
||||
(tset package.loaded ,mod-name-sym ,(or mod-base {}))
|
||||
(. package.loaded ,mod-name-sym))))
|
||||
|
||||
;; As we def values we insert them into locals.
|
||||
;; This table is then expanded in subsequent interactive evals.
|
||||
(local ,mod-locals-sym ,(if interactive?
|
||||
`(. ,mod-sym ,locals-key)
|
||||
`(do
|
||||
(tset ,mod-sym ,locals-key {})
|
||||
(. ,mod-sym ,locals-key))))]
|
||||
|
||||
;; Bindings that are returned from the macro.
|
||||
;; (=> :some-symbol :some-value)
|
||||
keys []
|
||||
vals []
|
||||
=> (fn [k v]
|
||||
(table.insert keys k)
|
||||
(table.insert vals v))]
|
||||
|
||||
;; For each function / value pair...
|
||||
(when mod-fns
|
||||
(sorted-each
|
||||
(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)]
|
||||
;; 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))))
|
||||
args)))
|
||||
mod-fns)
|
||||
|
||||
;; Only require autoload if it's used.
|
||||
(when (contains? mod-fns autoload-sym)
|
||||
(table.insert result `(local ,autoload-sym (. (require "conjure-macroreplace.aniseed.autoload") :autoload)))))
|
||||
|
||||
;; When we have some keys insert the key/vals pairs locals.
|
||||
;; If this is empty we end up generating invalid Lua.
|
||||
(when (seq? keys)
|
||||
(table.insert result `(local ,(list (unpack keys)) (values ,(unpack vals))))
|
||||
|
||||
;; We also bind these exposed locals into *module-locals* for future splatting.
|
||||
(each [_ k (ipairs keys)]
|
||||
(if (sym? k)
|
||||
;; Normal symbols can just be assigned into module-locals.
|
||||
(table.insert result `(tset ,mod-locals-sym ,(tostring k) ,k))
|
||||
|
||||
;; Tables mean we're using Fennel destructure syntax.
|
||||
;; So we need to unpack the assignments so they can be used later in interactive evals.
|
||||
(sorted-each
|
||||
(fn [k v]
|
||||
(table.insert
|
||||
result
|
||||
`(tset ,mod-locals-sym ,(tostring k) ,v)))
|
||||
k))))
|
||||
|
||||
;; Now we can expand any existing locals into the current scope.
|
||||
;; Since this will only happen in interactive evals we can generate messy code.
|
||||
(when interactive?
|
||||
;; Expand exported values into the current scope, except aniseed/locals.
|
||||
(sorted-each
|
||||
(fn [k v]
|
||||
(when (not= k locals-key)
|
||||
(table.insert result `(local ,(sym k) (. ,mod-sym ,k)))))
|
||||
existing-mod)
|
||||
|
||||
;; Expand locals into the current scope.
|
||||
(when (. existing-mod locals-key)
|
||||
(sorted-each
|
||||
(fn [k v]
|
||||
(table.insert result `(local ,(sym k) (. ,mod-locals-sym ,k))))
|
||||
(. existing-mod locals-key))))
|
||||
|
||||
result))
|
||||
|
||||
(fn def- [name value]
|
||||
`[,delete-marker
|
||||
(local ,name ,value)
|
||||
(tset ,mod-locals-sym ,(tostring name) ,name)])
|
||||
|
||||
(fn def [name value]
|
||||
`[,delete-marker
|
||||
(local ,name ,value)
|
||||
(tset ,mod-sym ,(tostring name) ,name)])
|
||||
|
||||
(fn defn- [name ...]
|
||||
`[,delete-marker
|
||||
(fn ,name ,...)
|
||||
(tset ,mod-locals-sym ,(tostring name) ,name)])
|
||||
|
||||
(fn defn [name ...]
|
||||
`[,delete-marker
|
||||
(fn ,name ,...)
|
||||
(tset ,mod-sym ,(tostring name) ,name)])
|
||||
|
||||
(fn defonce- [name value]
|
||||
`(def- ,name (or (. ,mod-sym ,(tostring name)) ,value)))
|
||||
|
||||
(fn defonce [name value]
|
||||
`(def ,name (or (. ,mod-sym ,(tostring name)) ,value)))
|
||||
|
||||
(fn deftest [name ...]
|
||||
`(let [tests# (or (. ,mod-sym :aniseed/tests
|
||||
) {})]
|
||||
(tset tests# ,(tostring name) (fn [,(sym :t)] ,...))
|
||||
(tset ,mod-sym :aniseed/tests tests#)))
|
||||
|
||||
(fn time [...]
|
||||
`(let [start# (vim.loop.hrtime)
|
||||
result# (do ,...)
|
||||
end# (vim.loop.hrtime)]
|
||||
(print (.. "Elapsed time: " (/ (- end# start#) 1000000) " msecs"))
|
||||
result#))
|
||||
|
||||
;; Checks surrounding scope for *module* and, if found, makes sure *module* is
|
||||
;; inserted after `last-expr` (and therefore *module* is returned)
|
||||
(fn wrap-last-expr [last-expr]
|
||||
(if (in-scope? mod-sym)
|
||||
`(do ,last-expr ,mod-sym)
|
||||
last-expr))
|
||||
|
||||
;; Used by aniseed.compile to wrap the entire body of a file, replacing the
|
||||
;; last expression with another wrapper; `wrap-last-expr` which handles the
|
||||
;; module's return value.
|
||||
;;
|
||||
;; i.e.
|
||||
;; (wrap-module-body
|
||||
;; (module foo)
|
||||
;; (def x 1)
|
||||
;; (vim.cmd "...")) ; vim.cmd returns a string which becomes the returned value
|
||||
;; ; for the entire file once compiled
|
||||
;; --> expands to:
|
||||
;; (do
|
||||
;; (module foo)
|
||||
;; (def x 1)
|
||||
;; (wrap-last-expr (vim.cmd "...")))
|
||||
;; --> expands to:
|
||||
;; (do
|
||||
;; (module foo)
|
||||
;; (def x 1)
|
||||
;; (do
|
||||
;; (vim.cmd "...")
|
||||
;; *module*))
|
||||
(fn wrap-module-body [...]
|
||||
(let [body# [...]
|
||||
last-expr# (table.remove body#)]
|
||||
(table.insert body# `(wrap-last-expr ,last-expr#))
|
||||
`(do ,(unpack body#))))
|
||||
|
||||
(fn conditional-let [branch bindings ...]
|
||||
(assert (= 2 (length bindings)) "expected a single binding pair")
|
||||
|
||||
(let [[bind-expr value-expr] bindings]
|
||||
(if
|
||||
;; Simple symbols
|
||||
;; [foo bar]
|
||||
(sym? bind-expr)
|
||||
`(let [,bind-expr ,value-expr]
|
||||
(,branch ,bind-expr ,...))
|
||||
|
||||
;; List / values destructure
|
||||
;; [(a b) c]
|
||||
(list? bind-expr)
|
||||
(do
|
||||
;; Even if the user isn't using the first slot, we will.
|
||||
;; [(_ val) (pcall #:foo)]
|
||||
;; => [(bindGENSYM12345 val) (pcall #:foo)]
|
||||
(when (= '_ (. bind-expr 1))
|
||||
(tset bind-expr 1 (gensym "bind")))
|
||||
|
||||
`(let [,bind-expr ,value-expr]
|
||||
(,branch ,(. bind-expr 1) ,...)))
|
||||
|
||||
;; Sequential and associative table destructure
|
||||
;; [[a b] c]
|
||||
;; [{: a : b} c]
|
||||
(table? bind-expr)
|
||||
`(let [value# ,value-expr
|
||||
,bind-expr (or value# {})]
|
||||
(,branch value# ,...))
|
||||
|
||||
;; We should never get here, but just in case.
|
||||
(assert (.. "unknown bind-expr type: " (type bind-expr))))))
|
||||
|
||||
(fn if-let [bindings ...]
|
||||
(assert (<= (length [...]) 2) (.. "if-let does not support more than two branches"))
|
||||
(conditional-let 'if bindings ...))
|
||||
|
||||
(fn when-let [bindings ...]
|
||||
(conditional-let 'when bindings ...))
|
||||
|
||||
{:module module
|
||||
:def- def- :def def
|
||||
:defn- defn- :defn defn
|
||||
:defonce- defonce- :defonce defonce
|
||||
:if-let if-let
|
||||
:when-let when-let
|
||||
:wrap-last-expr wrap-last-expr
|
||||
:wrap-module-body wrap-module-body
|
||||
:deftest deftest
|
||||
:time time}
|
||||
@@ -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}
|
||||
@@ -0,0 +1,12 @@
|
||||
local _2afile_2a = "fnl/aniseed/nvim.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.nvim"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = require("conjure-macroreplace.aniseed.deps.nvim")
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
@@ -0,0 +1,63 @@
|
||||
local _2afile_2a = "fnl/aniseed/nvim/util.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.nvim.util"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local nvim = autoload("conjure-macroreplace.aniseed.nvim")
|
||||
do end (_2amodule_locals_2a)["nvim"] = nvim
|
||||
local function normal(keys)
|
||||
return nvim.ex.silent(("exe \"normal! " .. keys .. "\""))
|
||||
end
|
||||
_2amodule_2a["normal"] = normal
|
||||
local function fn_bridge(viml_name, mod, lua_name, opts)
|
||||
local _let_1_ = (opts or {})
|
||||
local range = _let_1_["range"]
|
||||
local _return = _let_1_["return"]
|
||||
local function _2_()
|
||||
if range then
|
||||
return " range"
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
local function _3_()
|
||||
if (_return ~= false) then
|
||||
return "return"
|
||||
else
|
||||
return "call"
|
||||
end
|
||||
end
|
||||
local function _4_()
|
||||
if range then
|
||||
return "\" . a:firstline . \", \" . a:lastline . \", "
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
return nvim.ex.function_((viml_name .. "(...)" .. _2_() .. "\n " .. _3_() .. " luaeval(\"require('" .. mod .. "')['" .. lua_name .. "'](" .. _4_() .. "unpack(_A))\", a:000)\n endfunction"))
|
||||
end
|
||||
_2amodule_2a["fn-bridge"] = fn_bridge
|
||||
local function with_out_str(f)
|
||||
nvim.ex.redir("=> g:aniseed_nvim_util_out_str")
|
||||
do
|
||||
local ok_3f, err = pcall(f)
|
||||
nvim.ex.redir("END")
|
||||
nvim.ex.echon("")
|
||||
nvim.ex.redraw()
|
||||
if not ok_3f then
|
||||
error(err)
|
||||
else
|
||||
end
|
||||
end
|
||||
return string.gsub(nvim.g.aniseed_nvim_util_out_str, "^(\n?)(.*)$", "%2%1")
|
||||
end
|
||||
_2amodule_2a["with-out-str"] = with_out_str
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,61 @@
|
||||
local _2afile_2a = "fnl/aniseed/setup.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.setup"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a, env, eval, nvim = autoload("conjure-macroreplace.aniseed.core"), autoload("conjure-macroreplace.aniseed.env"), autoload("conjure-macroreplace.aniseed.eval"), autoload("conjure-macroreplace.aniseed.nvim")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["env"] = env
|
||||
_2amodule_locals_2a["eval"] = eval
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
local function init()
|
||||
if (1 == nvim.fn.has("nvim-0.7")) then
|
||||
local function _1_(cmd)
|
||||
local ok_3f, res = eval.str(cmd.args, {})
|
||||
if ok_3f then
|
||||
return nvim.echo(res)
|
||||
else
|
||||
return nvim.err_writeln(res)
|
||||
end
|
||||
end
|
||||
nvim.create_user_command("AniseedEval", _1_, {nargs = 1})
|
||||
local function _3_(cmd)
|
||||
local code
|
||||
local function _4_()
|
||||
if ("" == cmd.args) then
|
||||
return nvim.buf_get_name(nvim.get_current_buf())
|
||||
else
|
||||
return cmd.args
|
||||
end
|
||||
end
|
||||
code = a.slurp(_4_())
|
||||
if code then
|
||||
local ok_3f, res = eval.str(code, {})
|
||||
if ok_3f then
|
||||
return nvim.echo(res)
|
||||
else
|
||||
return nvim.err_writeln(res)
|
||||
end
|
||||
else
|
||||
return nvim.err_writeln(("File '" .. (cmd.args or "nil") .. "' not found"))
|
||||
end
|
||||
end
|
||||
nvim.create_user_command("AniseedEvalFile", _3_, {nargs = "?", complete = "file"})
|
||||
else
|
||||
end
|
||||
if nvim.g["aniseed#env"] then
|
||||
return env.init(nvim.g["aniseed#env"])
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["init"] = init
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,84 @@
|
||||
local _2afile_2a = "fnl/aniseed/string.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.string"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a = autoload("conjure-macroreplace.aniseed.core")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
local function join(...)
|
||||
local args = {...}
|
||||
local function _2_(...)
|
||||
if (2 == a.count(args)) then
|
||||
return args
|
||||
else
|
||||
return {"", a.first(args)}
|
||||
end
|
||||
end
|
||||
local _let_1_ = _2_(...)
|
||||
local sep = _let_1_[1]
|
||||
local xs = _let_1_[2]
|
||||
local len = a.count(xs)
|
||||
local result = {}
|
||||
if (len > 0) then
|
||||
for i = 1, len do
|
||||
local x = xs[i]
|
||||
local _3_
|
||||
if ("string" == type(x)) then
|
||||
_3_ = x
|
||||
elseif (nil == x) then
|
||||
_3_ = x
|
||||
else
|
||||
_3_ = a["pr-str"](x)
|
||||
end
|
||||
if (_3_ ~= nil) then
|
||||
table.insert(result, _3_)
|
||||
else
|
||||
end
|
||||
end
|
||||
else
|
||||
end
|
||||
return table.concat(result, sep)
|
||||
end
|
||||
_2amodule_2a["join"] = join
|
||||
local function split(s, pat)
|
||||
local done_3f = false
|
||||
local acc = {}
|
||||
local index = 1
|
||||
while not done_3f do
|
||||
local start, _end = string.find(s, pat, index)
|
||||
if ("nil" == type(start)) then
|
||||
table.insert(acc, string.sub(s, index))
|
||||
done_3f = true
|
||||
else
|
||||
table.insert(acc, string.sub(s, index, (start - 1)))
|
||||
index = (_end + 1)
|
||||
end
|
||||
end
|
||||
return acc
|
||||
end
|
||||
_2amodule_2a["split"] = split
|
||||
local function blank_3f(s)
|
||||
return (a["empty?"](s) or not string.find(s, "[^%s]"))
|
||||
end
|
||||
_2amodule_2a["blank?"] = blank_3f
|
||||
local function triml(s)
|
||||
return string.gsub(s, "^%s*(.-)", "%1")
|
||||
end
|
||||
_2amodule_2a["triml"] = triml
|
||||
local function trimr(s)
|
||||
return string.gsub(s, "(.-)%s*$", "%1")
|
||||
end
|
||||
_2amodule_2a["trimr"] = trimr
|
||||
local function trim(s)
|
||||
return string.gsub(s, "^%s*(.-)%s*$", "%1")
|
||||
end
|
||||
_2amodule_2a["trim"] = trim
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,157 @@
|
||||
local _2afile_2a = "fnl/aniseed/test.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.test"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local autoload = (require("conjure-macroreplace.aniseed.autoload")).autoload
|
||||
local a, fs, nvim, str = autoload("conjure-macroreplace.aniseed.core"), autoload("conjure-macroreplace.aniseed.fs"), autoload("conjure-macroreplace.aniseed.nvim"), autoload("conjure-macroreplace.aniseed.string")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["fs"] = fs
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
_2amodule_locals_2a["str"] = str
|
||||
local function ok_3f(_1_)
|
||||
local _arg_2_ = _1_
|
||||
local tests = _arg_2_["tests"]
|
||||
local tests_passed = _arg_2_["tests-passed"]
|
||||
return (tests == tests_passed)
|
||||
end
|
||||
_2amodule_2a["ok?"] = ok_3f
|
||||
local function display_results(results, prefix)
|
||||
do
|
||||
local _let_3_ = results
|
||||
local tests = _let_3_["tests"]
|
||||
local tests_passed = _let_3_["tests-passed"]
|
||||
local assertions = _let_3_["assertions"]
|
||||
local assertions_passed = _let_3_["assertions-passed"]
|
||||
local function _4_()
|
||||
if ok_3f(results) then
|
||||
return "OK"
|
||||
else
|
||||
return "FAILED"
|
||||
end
|
||||
end
|
||||
a.println((prefix .. " " .. _4_() .. " " .. tests_passed .. "/" .. tests .. " tests and " .. assertions_passed .. "/" .. assertions .. " assertions passed"))
|
||||
end
|
||||
return results
|
||||
end
|
||||
_2amodule_2a["display-results"] = display_results
|
||||
local function run(mod_name)
|
||||
local mod = _G.package.loaded[mod_name]
|
||||
local tests = (a["table?"](mod) and mod["aniseed/tests"])
|
||||
if a["table?"](tests) then
|
||||
local results = {tests = #tests, ["tests-passed"] = 0, assertions = 0, ["assertions-passed"] = 0}
|
||||
for label, f in pairs(tests) do
|
||||
local test_failed = false
|
||||
a.update(results, "tests", a.inc)
|
||||
do
|
||||
local prefix = ("[" .. mod_name .. "/" .. label .. "]")
|
||||
local fail
|
||||
local function _5_(desc, ...)
|
||||
test_failed = true
|
||||
local function _6_(...)
|
||||
if desc then
|
||||
return (" (" .. desc .. ")")
|
||||
else
|
||||
return ""
|
||||
end
|
||||
end
|
||||
return a.println((str.join({prefix, " ", ...}) .. _6_(...)))
|
||||
end
|
||||
fail = _5_
|
||||
local begin
|
||||
local function _7_()
|
||||
return a.update(results, "assertions", a.inc)
|
||||
end
|
||||
begin = _7_
|
||||
local pass
|
||||
local function _8_()
|
||||
return a.update(results, "assertions-passed", a.inc)
|
||||
end
|
||||
pass = _8_
|
||||
local t
|
||||
local function _9_(e, r, desc)
|
||||
begin()
|
||||
if (e == r) then
|
||||
return pass()
|
||||
else
|
||||
return fail(desc, "Expected '", a["pr-str"](e), "' but received '", a["pr-str"](r), "'")
|
||||
end
|
||||
end
|
||||
local function _11_(e, r, desc)
|
||||
begin()
|
||||
local se = a["pr-str"](e)
|
||||
local sr = a["pr-str"](r)
|
||||
if (se == sr) then
|
||||
return pass()
|
||||
else
|
||||
return fail(desc, "Expected (with pr) '", se, "' but received '", sr, "'")
|
||||
end
|
||||
end
|
||||
local function _13_(r, desc)
|
||||
begin()
|
||||
if r then
|
||||
return pass()
|
||||
else
|
||||
return fail(desc, "Expected truthy result but received '", a["pr-str"](r), "'")
|
||||
end
|
||||
end
|
||||
t = {["="] = _9_, ["pr="] = _11_, ["ok?"] = _13_}
|
||||
local _15_, _16_ = nil, nil
|
||||
local function _17_()
|
||||
return f(t)
|
||||
end
|
||||
_15_, _16_ = pcall(_17_)
|
||||
if ((_15_ == false) and (nil ~= _16_)) then
|
||||
local err = _16_
|
||||
fail("Exception: ", err)
|
||||
else
|
||||
end
|
||||
end
|
||||
if not test_failed then
|
||||
a.update(results, "tests-passed", a.inc)
|
||||
else
|
||||
end
|
||||
end
|
||||
return display_results(results, ("[" .. mod_name .. "]"))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["run"] = run
|
||||
local function run_all()
|
||||
local function _21_(totals, results)
|
||||
for k, v in pairs(results) do
|
||||
totals[k] = (v + totals[k])
|
||||
end
|
||||
return totals
|
||||
end
|
||||
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 _23_(path)
|
||||
return require(string.gsub(string.match(path, ("^test" .. sep .. "fnl" .. sep .. "(.-).fnl$")), sep, "."))
|
||||
end
|
||||
a["run!"](_23_, nvim.fn.globpath(("test" .. sep .. "fnl"), "**/*-test.fnl", false, true))
|
||||
end
|
||||
if ok_3f(run_all()) then
|
||||
return nvim.ex.q()
|
||||
else
|
||||
return nvim.ex.cq()
|
||||
end
|
||||
end
|
||||
_2amodule_2a["suite"] = suite
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,19 @@
|
||||
local _2afile_2a = "fnl/aniseed/view.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.aniseed.view"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local fnl = require("conjure-macroreplace.aniseed.fennel")
|
||||
do end (_2amodule_locals_2a)["fnl"] = fnl
|
||||
local function serialise(...)
|
||||
return fnl.impl().view(...)
|
||||
end
|
||||
_2amodule_2a["serialise"] = serialise
|
||||
return _2amodule_2a
|
||||
@@ -0,0 +1,116 @@
|
||||
local _2afile_2a = "fnl/conjure-macroreplace/main.fnl"
|
||||
local _2amodule_name_2a = "conjure-macroreplace.main"
|
||||
local _2amodule_2a
|
||||
do
|
||||
package.loaded[_2amodule_name_2a] = {}
|
||||
_2amodule_2a = package.loaded[_2amodule_name_2a]
|
||||
end
|
||||
local _2amodule_locals_2a
|
||||
do
|
||||
_2amodule_2a["aniseed/locals"] = {}
|
||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||
end
|
||||
local a, bridge, buffer, client, editor, eval, extract, log, mapping, nvim, str = require("conjure-macroreplace.aniseed.core"), require("conjure.bridge"), require("conjure.buffer"), require("conjure.client"), require("conjure.editor"), require("conjure.eval"), require("conjure.extract"), require("conjure.log"), require("conjure.mapping"), require("conjure-macroreplace.aniseed.nvim"), require("conjure-macroreplace.aniseed.string")
|
||||
do end (_2amodule_locals_2a)["a"] = a
|
||||
_2amodule_locals_2a["bridge"] = bridge
|
||||
_2amodule_locals_2a["buffer"] = buffer
|
||||
_2amodule_locals_2a["client"] = client
|
||||
_2amodule_locals_2a["editor"] = editor
|
||||
_2amodule_locals_2a["eval"] = eval
|
||||
_2amodule_locals_2a["extract"] = extract
|
||||
_2amodule_locals_2a["log"] = log
|
||||
_2amodule_locals_2a["mapping"] = mapping
|
||||
_2amodule_locals_2a["nvim"] = nvim
|
||||
_2amodule_locals_2a["str"] = str
|
||||
local function current_form()
|
||||
local form = extract.form({})
|
||||
if form then
|
||||
local _let_1_ = form
|
||||
local content = _let_1_["content"]
|
||||
return content
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_locals_2a["current-form"] = current_form
|
||||
local function clj_client(f, args)
|
||||
return client["with-filetype"]("clojure", f, args)
|
||||
end
|
||||
_2amodule_locals_2a["clj-client"] = clj_client
|
||||
local function output_expanded(orig)
|
||||
local function _3_(r)
|
||||
return log.append(a.concat({("; " .. orig)}, str.split(r, "\n")), {["break?"] = true})
|
||||
end
|
||||
return _3_
|
||||
end
|
||||
_2amodule_locals_2a["output-expanded"] = output_expanded
|
||||
local function clj_macroexpand(expand_cmd)
|
||||
local form = current_form()
|
||||
local me_form = ("(" .. (expand_cmd or "clojure.walk/macroexpand-all") .. " '" .. form .. ")")
|
||||
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 dir_word()
|
||||
local _let_4_ = extract.word()
|
||||
local content = _let_4_["content"]
|
||||
local range = _let_4_["range"]
|
||||
local node = _let_4_["node"]
|
||||
if not a["empty?"](content) then
|
||||
local dir_code = ("(clojure.repl/dir " .. content .. ")")
|
||||
return clj_client(eval["eval-str"], {code = dir_code, range = range, node = node, origin = "word"})
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_locals_2a["dir-word"] = dir_word
|
||||
local function replace_with_expanded_form()
|
||||
local form = extract.form({})
|
||||
if form then
|
||||
local _let_6_ = form
|
||||
local content = _let_6_["content"]
|
||||
local range = _let_6_["range"]
|
||||
local buf = vim.api.nvim_win_get_buf(0)
|
||||
local win = vim.api.nvim_tabpage_get_win(0)
|
||||
local me_form = ("(" .. (__fnl_global__expand_2dcmd or "clojure.walk/macroexpand-all") .. " '" .. content .. ")")
|
||||
local function _7_(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
|
||||
return clj_client(eval["eval-str"], {origin = "conjure-macroreplace", code = me_form, ["passive?"] = true, ["on-result"] = _7_})
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_locals_2a["replace-with-expanded-form"] = replace_with_expanded_form
|
||||
local function add_buf_mappings()
|
||||
local function _9_()
|
||||
return clj_macroexpand()
|
||||
end
|
||||
mapping.buf("CljMacroexpand", "cm", _9_, {desc = "Call macroexpand-all on the symbol under the cursor"})
|
||||
local function _10_()
|
||||
return clj_macroexpand("clojure.core/macroexpand")
|
||||
end
|
||||
mapping.buf("CljMacroexpand0", "c0", _10_, {desc = "Call macroexpand on the symbol under the cursor"})
|
||||
local function _11_()
|
||||
return clj_macroexpand("clojure.core/macroexpand-1")
|
||||
end
|
||||
mapping.buf("CljMacroexpand1", "c1", _11_, {desc = "Call macroexpand-1 on the symbol under the cursor"})
|
||||
local function _12_()
|
||||
return replace_with_expanded_form()
|
||||
end
|
||||
mapping.buf("CljMacroexpandReplace", "mr", _12_, {desc = "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
||||
local function _13_()
|
||||
return dir_word()
|
||||
end
|
||||
return mapping.buf("CljDirWord", "dw", _13_, {desc = "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"})
|
||||
end
|
||||
_2amodule_2a["add-buf-mappings"] = add_buf_mappings
|
||||
local function init()
|
||||
if (not nvim.g.conjure_macroexpand_disable_mappings or (0 == nvim.g.conjure_macroexpand_disable_mappings)) then
|
||||
return nvim.ex.autocmd("FileType", "clojure", bridge["viml->lua"]("conjure-macroreplace.main", "add-buf-mappings"))
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
_2amodule_2a["init"] = init
|
||||
return _2amodule_2a
|
||||
Reference in New Issue
Block a user