Initial implementation
This commit is contained in:
parent
29bee0bfb1
commit
4610711eaa
38
README.md
Normal file
38
README.md
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
# ConjureMacroexpand
|
||||||
|
|
||||||
|
Adds commands `ConjureMacroexpand`, `ConjureMacroexpand0` and
|
||||||
|
`ConjureMacroexpand1` that will macro-expand the form under the cursor, using
|
||||||
|
[Conjure](https://github.com/Olical/conjure)'s REPL connection.
|
||||||
|
|
||||||
|
This is the one bit of functionality missing from Conjure that kept
|
||||||
|
[vim-fireplace](https://github.com/tpope/vim-fireplace/) in my Neovim config.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
Using [vim-plug](https://github.com/junegunn/vim-plug):
|
||||||
|
|
||||||
|
```viml
|
||||||
|
Plug 'walterl/conjure-macroexpand'
|
||||||
|
```
|
||||||
|
|
||||||
|
## Mappings
|
||||||
|
|
||||||
|
* `<LocalLeader>cm` - Calls `clojure.walk/macroexpand-all` on the form under the cursor.
|
||||||
|
* `<LocalLeader>c0` - Calls `clojure.core/macroexpand` on the form under the cursor.
|
||||||
|
* `<LocalLeader>c1` - Calls `clojure.core/macroexpand-1` on the form under the cursor.
|
||||||
|
|
||||||
|
## Configuration
|
||||||
|
|
||||||
|
Disable mappings:
|
||||||
|
|
||||||
|
```viml
|
||||||
|
set g:conjure_macroexpand_disable_mappings = 1
|
||||||
|
```
|
||||||
|
|
||||||
|
## Unlicenced (just like Conjure)
|
||||||
|
|
||||||
|
Find the full [unlicense](http://unlicense.org/) in the `UNLICENSE` file, but here's a snippet.
|
||||||
|
|
||||||
|
> This is free and unencumbered software released into the public domain.
|
||||||
|
>
|
||||||
|
> Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.
|
25
UNLICENSE
Normal file
25
UNLICENSE
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
This is free and unencumbered software released into the public domain.
|
||||||
|
|
||||||
|
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||||
|
distribute this software, either in source code form or as a compiled
|
||||||
|
binary, for any purpose, commercial or non-commercial, and by any
|
||||||
|
means.
|
||||||
|
|
||||||
|
In jurisdictions that recognize copyright laws, the author or authors
|
||||||
|
of this software dedicate any and all copyright interest in the
|
||||||
|
software to the public domain. We make this dedication for the benefit
|
||||||
|
of the public at large and to the detriment of our heirs and
|
||||||
|
successors. We intend this dedication to be an overt act of
|
||||||
|
relinquishment in perpetuity of all present and future rights to this
|
||||||
|
software under copyright law.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||||
|
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||||
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||||
|
OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
|
For more information, please refer to <http://unlicense.org>
|
||||||
|
|
@ -1,4 +1,49 @@
|
|||||||
(module conjure-macroexpand.main)
|
(module conjure-macroexpand.main
|
||||||
|
{require {a aniseed.core
|
||||||
|
nvim aniseed.nvim
|
||||||
|
bridge conjure.bridge
|
||||||
|
client conjure.client
|
||||||
|
eval conjure.eval
|
||||||
|
extract conjure.extract
|
||||||
|
log conjure.log
|
||||||
|
mapping conjure.mapping}})
|
||||||
|
|
||||||
|
;; Adapted from conjure.eval/current-form
|
||||||
|
(defn- current-form []
|
||||||
|
(let [form (extract.form {})]
|
||||||
|
(when form
|
||||||
|
(let [{: content} form]
|
||||||
|
content))))
|
||||||
|
|
||||||
|
(defn- clj-client [f args]
|
||||||
|
(client.with-filetype "clojure" f args))
|
||||||
|
|
||||||
|
(defn- output-expanded [orig]
|
||||||
|
(fn [r]
|
||||||
|
(log.append [(.. "; " orig) r] {:break? true})))
|
||||||
|
|
||||||
|
(defn conjure-macroexpand [expand-cmd]
|
||||||
|
(let [form (current-form)
|
||||||
|
me-form (.. "(" (or expand-cmd "clojure.walk/macroexpand-all") " '" form ")")]
|
||||||
|
(clj-client eval.eval-str
|
||||||
|
{:origin :conjure-macroexpand
|
||||||
|
:code me-form
|
||||||
|
:passive? true
|
||||||
|
:on-result (output-expanded me-form)})))
|
||||||
|
|
||||||
(defn init []
|
(defn init []
|
||||||
(print "Hello, World!"))
|
(nvim.ex.command_
|
||||||
|
"ConjureMacroexpand"
|
||||||
|
(bridge.viml->lua :conjure-macroexpand.main :conjure-macroexpand))
|
||||||
|
(nvim.ex.command_
|
||||||
|
"ConjureMacroexpand0"
|
||||||
|
(bridge.viml->lua :conjure-macroexpand.main :conjure-macroexpand {:args "\"clojure.core/macroexpand\""}))
|
||||||
|
(nvim.ex.command_
|
||||||
|
"ConjureMacroexpand1"
|
||||||
|
(bridge.viml->lua :conjure-macroexpand.main :conjure-macroexpand {:args "\"clojure.core/macroexpand-1\""}))
|
||||||
|
|
||||||
|
(when (or (not nvim.g.conjure_macroexpand_disable_mappings)
|
||||||
|
(= 0 nvim.g.conjure_macroexpand_disable_mappings))
|
||||||
|
(mapping.buf :n nil "cm" ":ConjureMacroexpand<CR>")
|
||||||
|
(mapping.buf :n nil "c0" ":ConjureMacroexpand0<CR>")
|
||||||
|
(mapping.buf :n nil "c1" ":ConjureMacroexpand1<CR>")))
|
||||||
|
@ -25,27 +25,101 @@ autoload = _1_
|
|||||||
local function _2_(...)
|
local function _2_(...)
|
||||||
local ok_3f_0_, val_0_ = nil, nil
|
local ok_3f_0_, val_0_ = nil, nil
|
||||||
local function _2_()
|
local function _2_()
|
||||||
return {}
|
return {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")}
|
||||||
end
|
end
|
||||||
ok_3f_0_, val_0_ = pcall(_2_)
|
ok_3f_0_, val_0_ = pcall(_2_)
|
||||||
if ok_3f_0_ then
|
if ok_3f_0_ then
|
||||||
_0_["aniseed/local-fns"] = {}
|
_0_["aniseed/local-fns"] = {require = {a = "conjure-macroexpand.aniseed.core", bridge = "conjure.bridge", client = "conjure.client", eval = "conjure.eval", extract = "conjure.extract", log = "conjure.log", mapping = "conjure.mapping", nvim = "conjure-macroexpand.aniseed.nvim"}}
|
||||||
return val_0_
|
return val_0_
|
||||||
else
|
else
|
||||||
return print(val_0_)
|
return print(val_0_)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local _local_0_ = _2_(...)
|
local _local_0_ = _2_(...)
|
||||||
|
local a = _local_0_[1]
|
||||||
|
local bridge = _local_0_[2]
|
||||||
|
local client = _local_0_[3]
|
||||||
|
local eval = _local_0_[4]
|
||||||
|
local extract = _local_0_[5]
|
||||||
|
local log = _local_0_[6]
|
||||||
|
local mapping = _local_0_[7]
|
||||||
|
local nvim = _local_0_[8]
|
||||||
local _2amodule_2a = _0_
|
local _2amodule_2a = _0_
|
||||||
local _2amodule_name_2a = "conjure-macroexpand.main"
|
local _2amodule_name_2a = "conjure-macroexpand.main"
|
||||||
do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end
|
do local _ = ({nil, _0_, nil, {{}, nil, nil, nil}})[2] end
|
||||||
|
local current_form
|
||||||
|
do
|
||||||
|
local v_0_
|
||||||
|
local function current_form0()
|
||||||
|
local form = extract.form({})
|
||||||
|
if form then
|
||||||
|
local _let_0_ = form
|
||||||
|
local content = _let_0_["content"]
|
||||||
|
return content
|
||||||
|
end
|
||||||
|
end
|
||||||
|
v_0_ = current_form0
|
||||||
|
local t_0_ = (_0_)["aniseed/locals"]
|
||||||
|
t_0_["current-form"] = v_0_
|
||||||
|
current_form = v_0_
|
||||||
|
end
|
||||||
|
local clj_client
|
||||||
|
do
|
||||||
|
local v_0_
|
||||||
|
local function clj_client0(f, args)
|
||||||
|
return client["with-filetype"]("clojure", f, args)
|
||||||
|
end
|
||||||
|
v_0_ = clj_client0
|
||||||
|
local t_0_ = (_0_)["aniseed/locals"]
|
||||||
|
t_0_["clj-client"] = v_0_
|
||||||
|
clj_client = v_0_
|
||||||
|
end
|
||||||
|
local output_expanded
|
||||||
|
do
|
||||||
|
local v_0_
|
||||||
|
local function output_expanded0(orig)
|
||||||
|
local function _3_(r)
|
||||||
|
return log.append({("; " .. orig), r}, {["break?"] = true})
|
||||||
|
end
|
||||||
|
return _3_
|
||||||
|
end
|
||||||
|
v_0_ = output_expanded0
|
||||||
|
local t_0_ = (_0_)["aniseed/locals"]
|
||||||
|
t_0_["output-expanded"] = v_0_
|
||||||
|
output_expanded = v_0_
|
||||||
|
end
|
||||||
|
local conjure_macroexpand
|
||||||
|
do
|
||||||
|
local v_0_
|
||||||
|
do
|
||||||
|
local v_0_0
|
||||||
|
local function conjure_macroexpand0(expand_cmd)
|
||||||
|
local form = current_form()
|
||||||
|
local me_form = ("(" .. (expand_cmd or "clojure.walk/macroexpand-all") .. " '" .. form .. ")")
|
||||||
|
return clj_client(eval["eval-str"], {["on-result"] = output_expanded(me_form), ["passive?"] = true, code = me_form, origin = "conjure-macroexpand"})
|
||||||
|
end
|
||||||
|
v_0_0 = conjure_macroexpand0
|
||||||
|
_0_["conjure-macroexpand"] = v_0_0
|
||||||
|
v_0_ = v_0_0
|
||||||
|
end
|
||||||
|
local t_0_ = (_0_)["aniseed/locals"]
|
||||||
|
t_0_["conjure-macroexpand"] = v_0_
|
||||||
|
conjure_macroexpand = v_0_
|
||||||
|
end
|
||||||
local init
|
local init
|
||||||
do
|
do
|
||||||
local v_0_
|
local v_0_
|
||||||
do
|
do
|
||||||
local v_0_0
|
local v_0_0
|
||||||
local function init0()
|
local function init0()
|
||||||
return print("Hello, World!")
|
nvim.ex.command_("ConjureMacroexpand", bridge["viml->lua"]("conjure-macroexpand.main", "conjure-macroexpand"))
|
||||||
|
nvim.ex.command_("ConjureMacroexpand0", bridge["viml->lua"]("conjure-macroexpand.main", "conjure-macroexpand", {args = "\"clojure.core/macroexpand\""}))
|
||||||
|
nvim.ex.command_("ConjureMacroexpand1", bridge["viml->lua"]("conjure-macroexpand.main", "conjure-macroexpand", {args = "\"clojure.core/macroexpand-1\""}))
|
||||||
|
if (not nvim.g.conjure_macroexpand_disable_mappings or (0 == nvim.g.conjure_macroexpand_disable_mappings)) then
|
||||||
|
mapping.buf("n", nil, "cm", ":ConjureMacroexpand<CR>")
|
||||||
|
mapping.buf("n", nil, "c0", ":ConjureMacroexpand0<CR>")
|
||||||
|
return mapping.buf("n", nil, "c1", ":ConjureMacroexpand1<CR>")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
v_0_0 = init0
|
v_0_0 = init0
|
||||||
_0_["init"] = v_0_0
|
_0_["init"] = v_0_0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user