123 lines
4.7 KiB
Lua
123 lines
4.7 KiB
Lua
local _2afile_2a = "fnl/conjure-macroexpand/main.fnl"
|
|
local _2amodule_name_2a = "conjure-macroexpand.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, client, eval, extract, log, mapping, nvim, str = require("conjure-macroexpand.aniseed.core"), require("conjure.bridge"), require("conjure.client"), require("conjure.eval"), require("conjure.extract"), require("conjure.log"), require("conjure.mapping"), require("conjure-macroexpand.aniseed.nvim"), require("conjure-macroexpand.aniseed.string")
|
|
do end (_2amodule_locals_2a)["a"] = a
|
|
_2amodule_locals_2a["bridge"] = bridge
|
|
_2amodule_locals_2a["client"] = client
|
|
_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 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 _10_()
|
|
return clj_macroexpand()
|
|
end
|
|
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", _11_, {desc = "Call macroexpand on the symbol under the cursor"})
|
|
local function _12_()
|
|
return clj_macroexpand("clojure.core/macroexpand-1")
|
|
end
|
|
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()
|
|
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-macroexpand.main", "add-buf-mappings"))
|
|
else
|
|
return nil
|
|
end
|
|
end
|
|
_2amodule_2a["init"] = init
|
|
return _2amodule_2a |