add tap-root
This commit is contained in:
parent
694569b5ec
commit
087f5efd6f
@ -1,31 +1,32 @@
|
|||||||
(module conjure-expand.main
|
(module conjure-expand.main)
|
||||||
{require {a aniseed.core
|
|
||||||
nvim aniseed.nvim
|
(local a (require "aniseed.core"))
|
||||||
str aniseed.string
|
(local nvim (require "aniseed.nvim"))
|
||||||
bridge conjure.bridge
|
(local str (require "aniseed.string"))
|
||||||
client conjure.client
|
(local bridge (require "conjure.bridge"))
|
||||||
eval conjure.eval
|
(local client (require "conjure.client"))
|
||||||
extract conjure.extract
|
(local eval (require "conjure.eval"))
|
||||||
log conjure.log
|
(local extract (require "conjure.extract"))
|
||||||
mapping conjure.mapping
|
(local log (require "conjure.log"))
|
||||||
buffer conjure.buffer
|
(local mapping (require "conjure.mapping"))
|
||||||
editor conjure.editor}})
|
(local buffer (require "conjure.buffer"))
|
||||||
|
(local editor (require "conjure.editor"))
|
||||||
|
|
||||||
;; Adapted from conjure.eval/current-form
|
;; Adapted from conjure.eval/current-form
|
||||||
(defn- current-form []
|
(fn current-form []
|
||||||
(let [form (extract.form {})]
|
(let [form (extract.form {})]
|
||||||
(when form
|
(when form
|
||||||
(let [{: content} form]
|
(let [{: content} form]
|
||||||
content))))
|
content))))
|
||||||
|
|
||||||
(defn- clj-client [f args]
|
(fn clj-client [f args]
|
||||||
(client.with-filetype "clojure" f args))
|
(client.with-filetype "clojure" f args))
|
||||||
|
|
||||||
(defn- output-expanded [orig]
|
(fn output-expanded [orig]
|
||||||
(fn [r]
|
(fn [r]
|
||||||
(log.append (a.concat [(.. "; " orig)] (str.split r "\n")) {:break? true})))
|
(log.append (a.concat [(.. "; " orig)] (str.split r "\n")) {:break? true})))
|
||||||
|
|
||||||
(defn clj-macroexpand [expand-cmd]
|
(fn clj-macroexpand [expand-cmd]
|
||||||
(let [form (current-form)
|
(let [form (current-form)
|
||||||
me-form (.. "(" (or expand-cmd "clojure.walk/macroexpand-all") " '" form ")")]
|
me-form (.. "(" (or expand-cmd "clojure.walk/macroexpand-all") " '" form ")")]
|
||||||
(clj-client eval.eval-str
|
(clj-client eval.eval-str
|
||||||
@ -34,7 +35,7 @@
|
|||||||
:passive? true
|
:passive? true
|
||||||
:on-result (output-expanded me-form)})))
|
:on-result (output-expanded me-form)})))
|
||||||
|
|
||||||
(defn- dir-word []
|
(fn dir-word []
|
||||||
(let [{: content : range : node} (extract.word)]
|
(let [{: content : range : node} (extract.word)]
|
||||||
(when (not (a.empty? content))
|
(when (not (a.empty? content))
|
||||||
(let [dir-code (.. "(clojure.repl/dir " content ")")]
|
(let [dir-code (.. "(clojure.repl/dir " content ")")]
|
||||||
@ -44,13 +45,13 @@
|
|||||||
:node node
|
:node node
|
||||||
:origin :word})))))
|
:origin :word})))))
|
||||||
|
|
||||||
(defn- replace-with-expanded-form []
|
(fn replace-with-expanded-form []
|
||||||
(let [form (extract.form {})]
|
(let [form (extract.form {})]
|
||||||
(when form
|
(when form
|
||||||
(let [{: content : range} form
|
(let [{: content : range} form
|
||||||
buf (vim.api.nvim_win_get_buf 0)
|
buf (vim.api.nvim_win_get_buf 0)
|
||||||
win (vim.api.nvim_tabpage_get_win 0)
|
win (vim.api.nvim_tabpage_get_win 0)
|
||||||
me-form (.. "(" (or expand-cmd "clojure.walk/macroexpand-all") " '" content ")")]
|
me-form (.. "(clojure.walk/macroexpand-all '" content ")")]
|
||||||
(clj-client eval.eval-str
|
(clj-client eval.eval-str
|
||||||
{:origin :conjure-macroreplace
|
{:origin :conjure-macroreplace
|
||||||
:code me-form
|
:code me-form
|
||||||
@ -65,8 +66,18 @@
|
|||||||
(a.get-in range [:start 1])
|
(a.get-in range [:start 1])
|
||||||
(a.inc (a.get-in range [:start 2]))))})))))
|
(a.inc (a.get-in range [:start 2]))))})))))
|
||||||
|
|
||||||
|
(fn tap-root []
|
||||||
|
(let [{: content : range : node} (extract.form {"root?" true})]
|
||||||
|
(when (not (a.empty? content))
|
||||||
|
(let [tap-code (.. "(tap> " content ")")]
|
||||||
|
(clj-client eval.eval-str
|
||||||
|
{:code tap-code
|
||||||
|
:range range
|
||||||
|
:node node
|
||||||
|
:origin :tap})))))
|
||||||
|
|
||||||
(defn add-buf-mappings []
|
|
||||||
|
(fn add-buf-mappings []
|
||||||
(mapping.buf :CljMacroexpand "cm" #(clj-macroexpand)
|
(mapping.buf :CljMacroexpand "cm" #(clj-macroexpand)
|
||||||
{:desc "Call macroexpand-all on the symbol under the cursor"})
|
{:desc "Call macroexpand-all on the symbol under the cursor"})
|
||||||
(mapping.buf :CljMacroexpand0 "c0" #(clj-macroexpand "clojure.core/macroexpand")
|
(mapping.buf :CljMacroexpand0 "c0" #(clj-macroexpand "clojure.core/macroexpand")
|
||||||
@ -76,9 +87,11 @@
|
|||||||
(mapping.buf :CljMacroexpandReplace "mr" #(replace-with-expanded-form)
|
(mapping.buf :CljMacroexpandReplace "mr" #(replace-with-expanded-form)
|
||||||
{:desc "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
{:desc "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
||||||
(mapping.buf :CljDirWord "dw" #(dir-word)
|
(mapping.buf :CljDirWord "dw" #(dir-word)
|
||||||
{:desc "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"}))
|
{:desc "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"})
|
||||||
|
(mapping.buf :CljEvalTap "et" #(tap-root)
|
||||||
|
{:desc "Calls (tap> ,,,) for the root form under the cursor"}))
|
||||||
|
|
||||||
(defn init []
|
(fn init []
|
||||||
(when (or (not nvim.g.conjure_macroexpand_disable_mappings)
|
(when (or (not nvim.g.conjure_macroexpand_disable_mappings)
|
||||||
(= 0 nvim.g.conjure_macroexpand_disable_mappings))
|
(= 0 nvim.g.conjure_macroexpand_disable_mappings))
|
||||||
(nvim.ex.autocmd
|
(nvim.ex.autocmd
|
||||||
|
@ -10,18 +10,17 @@ do
|
|||||||
_2amodule_2a["aniseed/locals"] = {}
|
_2amodule_2a["aniseed/locals"] = {}
|
||||||
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
_2amodule_locals_2a = (_2amodule_2a)["aniseed/locals"]
|
||||||
end
|
end
|
||||||
local a, bridge, buffer, client, editor, eval, extract, log, mapping, nvim, str = require("conjure-expand.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-expand.aniseed.nvim"), require("conjure-expand.aniseed.string")
|
local a = require("conjure-expand.aniseed.core")
|
||||||
do end (_2amodule_locals_2a)["a"] = a
|
local nvim = require("conjure-expand.aniseed.nvim")
|
||||||
_2amodule_locals_2a["bridge"] = bridge
|
local str = require("conjure-expand.aniseed.string")
|
||||||
_2amodule_locals_2a["buffer"] = buffer
|
local bridge = require("conjure.bridge")
|
||||||
_2amodule_locals_2a["client"] = client
|
local client = require("conjure.client")
|
||||||
_2amodule_locals_2a["editor"] = editor
|
local eval = require("conjure.eval")
|
||||||
_2amodule_locals_2a["eval"] = eval
|
local extract = require("conjure.extract")
|
||||||
_2amodule_locals_2a["extract"] = extract
|
local log = require("conjure.log")
|
||||||
_2amodule_locals_2a["log"] = log
|
local mapping = require("conjure.mapping")
|
||||||
_2amodule_locals_2a["mapping"] = mapping
|
local buffer = require("conjure.buffer")
|
||||||
_2amodule_locals_2a["nvim"] = nvim
|
local editor = require("conjure.editor")
|
||||||
_2amodule_locals_2a["str"] = str
|
|
||||||
local function current_form()
|
local function current_form()
|
||||||
local form = extract.form({})
|
local form = extract.form({})
|
||||||
if form then
|
if form then
|
||||||
@ -32,24 +31,20 @@ local function current_form()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_2amodule_locals_2a["current-form"] = current_form
|
|
||||||
local function clj_client(f, args)
|
local function clj_client(f, args)
|
||||||
return client["with-filetype"]("clojure", f, args)
|
return client["with-filetype"]("clojure", f, args)
|
||||||
end
|
end
|
||||||
_2amodule_locals_2a["clj-client"] = clj_client
|
|
||||||
local function output_expanded(orig)
|
local function output_expanded(orig)
|
||||||
local function _3_(r)
|
local function _3_(r)
|
||||||
return log.append(a.concat({("; " .. orig)}, str.split(r, "\n")), {["break?"] = true})
|
return log.append(a.concat({("; " .. orig)}, str.split(r, "\n")), {["break?"] = true})
|
||||||
end
|
end
|
||||||
return _3_
|
return _3_
|
||||||
end
|
end
|
||||||
_2amodule_locals_2a["output-expanded"] = output_expanded
|
|
||||||
local function clj_macroexpand(expand_cmd)
|
local function clj_macroexpand(expand_cmd)
|
||||||
local form = current_form()
|
local form = current_form()
|
||||||
local me_form = ("(" .. (expand_cmd or "clojure.walk/macroexpand-all") .. " '" .. 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)})
|
return clj_client(eval["eval-str"], {origin = "conjure-macroexpand", code = me_form, ["passive?"] = true, ["on-result"] = output_expanded(me_form)})
|
||||||
end
|
end
|
||||||
_2amodule_2a["clj-macroexpand"] = clj_macroexpand
|
|
||||||
local function dir_word()
|
local function dir_word()
|
||||||
local _let_4_ = extract.word()
|
local _let_4_ = extract.word()
|
||||||
local content = _let_4_["content"]
|
local content = _let_4_["content"]
|
||||||
@ -62,7 +57,6 @@ local function dir_word()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_2amodule_locals_2a["dir-word"] = dir_word
|
|
||||||
local function replace_with_expanded_form()
|
local function replace_with_expanded_form()
|
||||||
local form = extract.form({})
|
local form = extract.form({})
|
||||||
if form then
|
if form then
|
||||||
@ -71,7 +65,7 @@ local function replace_with_expanded_form()
|
|||||||
local range = _let_6_["range"]
|
local range = _let_6_["range"]
|
||||||
local buf = vim.api.nvim_win_get_buf(0)
|
local buf = vim.api.nvim_win_get_buf(0)
|
||||||
local win = vim.api.nvim_tabpage_get_win(0)
|
local win = vim.api.nvim_tabpage_get_win(0)
|
||||||
local me_form = ("(" .. (__fnl_global__expand_2dcmd or "clojure.walk/macroexpand-all") .. " '" .. content .. ")")
|
local me_form = ("(clojure.walk/macroexpand-all '" .. content .. ")")
|
||||||
local function _7_(result)
|
local function _7_(result)
|
||||||
buffer["replace-range"](buf, range, 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})))
|
return editor["go-to"](win, a["get-in"](range, {"start", 1}), a.inc(a["get-in"](range, {"start", 2})))
|
||||||
@ -81,30 +75,44 @@ local function replace_with_expanded_form()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_2amodule_locals_2a["replace-with-expanded-form"] = replace_with_expanded_form
|
local function tap_root()
|
||||||
|
local _let_9_ = extract.form({["root?"] = true})
|
||||||
|
local content = _let_9_["content"]
|
||||||
|
local range = _let_9_["range"]
|
||||||
|
local node = _let_9_["node"]
|
||||||
|
if not a["empty?"](content) then
|
||||||
|
local tap_code = ("(tap> " .. content .. ")")
|
||||||
|
return clj_client(eval["eval-str"], {code = tap_code, range = range, node = node, origin = "tap"})
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
local function add_buf_mappings()
|
local function add_buf_mappings()
|
||||||
local function _9_()
|
local function _11_()
|
||||||
return clj_macroexpand()
|
return clj_macroexpand()
|
||||||
end
|
end
|
||||||
mapping.buf("CljMacroexpand", "cm", _9_, {desc = "Call macroexpand-all on the symbol under the cursor"})
|
mapping.buf("CljMacroexpand", "cm", _11_, {desc = "Call macroexpand-all on the symbol under the cursor"})
|
||||||
local function _10_()
|
local function _12_()
|
||||||
return clj_macroexpand("clojure.core/macroexpand")
|
return clj_macroexpand("clojure.core/macroexpand")
|
||||||
end
|
end
|
||||||
mapping.buf("CljMacroexpand0", "c0", _10_, {desc = "Call macroexpand on the symbol under the cursor"})
|
mapping.buf("CljMacroexpand0", "c0", _12_, {desc = "Call macroexpand on the symbol under the cursor"})
|
||||||
local function _11_()
|
local function _13_()
|
||||||
return clj_macroexpand("clojure.core/macroexpand-1")
|
return clj_macroexpand("clojure.core/macroexpand-1")
|
||||||
end
|
end
|
||||||
mapping.buf("CljMacroexpand1", "c1", _11_, {desc = "Call macroexpand-1 on the symbol under the cursor"})
|
mapping.buf("CljMacroexpand1", "c1", _13_, {desc = "Call macroexpand-1 on the symbol under the cursor"})
|
||||||
local function _12_()
|
local function _14_()
|
||||||
return replace_with_expanded_form()
|
return replace_with_expanded_form()
|
||||||
end
|
end
|
||||||
mapping.buf("CljMacroexpandReplace", "mr", _12_, {desc = "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
mapping.buf("CljMacroexpandReplace", "mr", _14_, {desc = "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
||||||
local function _13_()
|
local function _15_()
|
||||||
return dir_word()
|
return dir_word()
|
||||||
end
|
end
|
||||||
return mapping.buf("CljDirWord", "dw", _13_, {desc = "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"})
|
mapping.buf("CljDirWord", "dw", _15_, {desc = "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"})
|
||||||
|
local function _16_()
|
||||||
|
return tap_root()
|
||||||
|
end
|
||||||
|
return mapping.buf("CljEvalTap", "et", _16_, {desc = "Calls (tap> ,,,) for the root form under the cursor"})
|
||||||
end
|
end
|
||||||
_2amodule_2a["add-buf-mappings"] = add_buf_mappings
|
|
||||||
local function init()
|
local function init()
|
||||||
if (not nvim.g.conjure_macroexpand_disable_mappings or (0 == nvim.g.conjure_macroexpand_disable_mappings)) then
|
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-expand.main", "add-buf-mappings"))
|
return nvim.ex.autocmd("FileType", "clojure", bridge["viml->lua"]("conjure-expand.main", "add-buf-mappings"))
|
||||||
@ -112,5 +120,4 @@ local function init()
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_2amodule_2a["init"] = init
|
|
||||||
return _2amodule_2a
|
return _2amodule_2a
|
Loading…
x
Reference in New Issue
Block a user