Skip to content

Integrating with Clay and data visualisation tools

Oliver Caldwell edited this page May 21, 2023 · 1 revision

Placing the following code in .lnvim.fnl with Olical/nvim-local-fennel installed will give you the <localleader>ev mapping in Clojure buffers. This allows you to send the root form under your cursor to Clay for rendering.

(module viz.lnvim
  {autoload {a aniseed.core
             str aniseed.string
             nvim aniseed.nvim
             eval conjure.eval
             extract conjure.extract}})

(defn eval-clojure-for-viz []
  (eval.eval-str
    {:origin "custom-clay-wrapper"
     :code (str.join
             ""
             ["(scicloj.clay.v2.api/handle-form! `" (a.get (extract.form {:root? true}) :content) ")"])}))

(defn on-filetype []
  (nvim.buf_set_keymap
    0 :n "<localleader>ev" ""
    {:callback eval-clojure-for-viz}))

(def augroup (nvim.create_augroup :viz.lnvim {}))
(nvim.create_autocmd
  :Filetype
  {:group augroup
   :pattern ["clojure"]
   :callback on-filetype})