add initial commands
This commit is contained in:
@@ -1,93 +0,0 @@
|
||||
(module conjure-macroexpand.main
|
||||
{require {a aniseed.core
|
||||
nvim aniseed.nvim
|
||||
str aniseed.string
|
||||
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 (a.concat [(.. "; " orig)] (str.split r "\n")) {:break? true})))
|
||||
|
||||
(defn clj-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 wrap-emit [name f]
|
||||
(fn [...]
|
||||
(event.emit name)
|
||||
(f ...)))
|
||||
|
||||
(local dir-str (wrap-emit
|
||||
:doc
|
||||
(client-exec-fn :doc :doc-str)))
|
||||
|
||||
(defn dir-word []
|
||||
(let [{: content : range : node} (extract.word)]
|
||||
(when (not (core.empty? content))
|
||||
(dir-str
|
||||
{:code content
|
||||
:range range
|
||||
:node node
|
||||
:origin :word}))))
|
||||
|
||||
(defn replace-form []
|
||||
(let [buf (vim.api.nvim_win_get_buf 0)
|
||||
win (vim.api.nvim_tabpage_get_win 0)
|
||||
form (extract.form {})]
|
||||
(when form
|
||||
(let [{: content : range : node} form]
|
||||
(eval-str
|
||||
{:code content
|
||||
:range range
|
||||
:node node
|
||||
:origin :replace-form
|
||||
:suppress-hud? true
|
||||
:on-result
|
||||
(fn [result]
|
||||
(buffer.replacerange
|
||||
buf
|
||||
range result)
|
||||
(editor.go-to
|
||||
win
|
||||
(core.get-in range [:start 1])
|
||||
(core.inc (core.get-in range [:start 2]))))})
|
||||
(.. "(clojure.core/macroexpand1 " form ")")))))
|
||||
|
||||
(defn add-buf-mappings []
|
||||
(mapping.buf :CljMacroexpand "cm" #(clj-macroexpand)
|
||||
{:desc "Call macroexpand-all on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpand0 "c0" #(clj-macroexpand "clojure.core/macroexpand")
|
||||
{:desc "Call macroexpand on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpand1 "c1" #(clj-macroexpand "clojure.core/macroexpand-1")
|
||||
{:desc "Call macroexpand-1 on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpandReplace "em!" #(replace-form)
|
||||
{:desc "Call macroexpand-1 on the symbol under the cursor then replace that src with the expansion"})
|
||||
(mapping.buf :CljDirWord "em!" #(dir-word)
|
||||
{:desc "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"}))
|
||||
|
||||
(defn init []
|
||||
(when (or (not nvim.g.conjure_macroexpand_disable_mappings)
|
||||
(= 0 nvim.g.conjure_macroexpand_disable_mappings))
|
||||
(nvim.ex.autocmd
|
||||
:FileType "clojure"
|
||||
(bridge.viml->lua :conjure-macroexpand.main :add-buf-mappings))))
|
||||
@@ -0,0 +1,86 @@
|
||||
(module conjure-macroreplace.main
|
||||
{require {a aniseed.core
|
||||
nvim aniseed.nvim
|
||||
str aniseed.string
|
||||
bridge conjure.bridge
|
||||
client conjure.client
|
||||
eval conjure.eval
|
||||
extract conjure.extract
|
||||
log conjure.log
|
||||
mapping conjure.mapping
|
||||
buffer conjure.buffer
|
||||
editor conjure.editor}})
|
||||
|
||||
;; 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 (a.concat [(.. "; " orig)] (str.split r "\n")) {:break? true})))
|
||||
|
||||
(defn clj-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- dir-word []
|
||||
(let [{: content : range : node} (extract.word)]
|
||||
(when (not (a.empty? content))
|
||||
(let [dir-code (.. "(clojure.repl/dir " content ")")]
|
||||
(clj-client eval.eval-str
|
||||
{:code dir-code
|
||||
:range range
|
||||
:node node
|
||||
:origin :word})))))
|
||||
|
||||
(defn- replace-with-expanded-form []
|
||||
(let [form (extract.form {})]
|
||||
(when form
|
||||
(let [{: content : range} form
|
||||
buf (vim.api.nvim_win_get_buf 0)
|
||||
win (vim.api.nvim_tabpage_get_win 0)
|
||||
me-form (.. "(" (or expand-cmd "clojure.walk/macroexpand-all") " '" content ")")]
|
||||
(clj-client eval.eval-str
|
||||
{:origin :conjure-macroreplace
|
||||
:code me-form
|
||||
:passive? true
|
||||
:on-result
|
||||
(fn [result]
|
||||
(buffer.replace-range
|
||||
buf
|
||||
range result)
|
||||
(editor.go-to
|
||||
win
|
||||
(a.get-in range [:start 1])
|
||||
(a.inc (a.get-in range [:start 2]))))})))))
|
||||
|
||||
|
||||
(defn add-buf-mappings []
|
||||
(mapping.buf :CljMacroexpand "cm" #(clj-macroexpand)
|
||||
{:desc "Call macroexpand-all on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpand0 "c0" #(clj-macroexpand "clojure.core/macroexpand")
|
||||
{:desc "Call macroexpand on the symbol under the cursor"})
|
||||
(mapping.buf :CljMacroexpand1 "c1" #(clj-macroexpand "clojure.core/macroexpand-1")
|
||||
{:desc "Call macroexpand-1 on the symbol under the cursor"})
|
||||
(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"})
|
||||
(mapping.buf :CljDirWord "dw" #(dir-word)
|
||||
{:desc "Calls (clojure.repl/dir ,,,) for the namespace under the cursor"}))
|
||||
|
||||
(defn init []
|
||||
(when (or (not nvim.g.conjure_macroexpand_disable_mappings)
|
||||
(= 0 nvim.g.conjure_macroexpand_disable_mappings))
|
||||
(nvim.ex.autocmd
|
||||
:FileType "clojure"
|
||||
(bridge.viml->lua :conjure-macroreplace.main :add-buf-mappings))))
|
||||
Reference in New Issue
Block a user