This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-29
Channels
- # announcements (44)
- # architecture (12)
- # babashka (45)
- # beginners (56)
- # calva (16)
- # cider (34)
- # clj-kondo (6)
- # clojure (47)
- # clojure-austin (2)
- # clojure-brasil (3)
- # clojure-europe (39)
- # clojure-germany (2)
- # clojure-nl (1)
- # clojure-norway (39)
- # clojurescript (7)
- # cursive (1)
- # datahike (2)
- # datomic (28)
- # emacs (8)
- # gratitude (3)
- # humbleui (4)
- # hyperfiddle (45)
- # kaocha (1)
- # lsp (94)
- # nbb (2)
- # off-topic (29)
- # practicalli (8)
- # releases (2)
- # shadow-cljs (6)
- # squint (17)
- # tools-deps (12)
- # vim (11)
Using Conjure/Fennel, is there some simple way to create a mapping that would take the Clojure form under the cursor, wrap it in a time
call (as a simple example), and execute it?
I've started reading about plugin development with Fennel, but it'll take a little while before I'm familiar enough to do stuff like this. Just wondering if there's any "shortcut" in Conjure for doing things like this.
here is a related snippet that I use to send a form to the clojure REPL using the current filename, which is part of what you want:
(vim.keymap.set :n :<localleader>cs #(vim.cmd (.. "ConjureEval (nextjournal.clerk/show! \"" (vim.fn.expand "%:p") "\")")))
and https://github.com/Olical/conjure/blob/31a1626273e2bab479b6b8416a137f9edaba7daa/fnl/conjure/extract.fnl#L11-L17 in conjure is what gets the current form
so with those two together, what you're looking for should be
(set extract (require :conjure.extract))
(vim.keymap.set :n :<localleader>et #(vim.cmd (.. "ConjureEval (time " (. (extract.form {}) :content) ")")))
@U02G8N0EX44 amazing, thanks very much!
I think you meant (local extract ...)
instead of set
, but otherwise it works just as I wanted. This is a nice bit of ergonomics.
Any idea how to make it work when the form contains linebreaks?
(vim.keymap.set :n :<leader>et #(vim.cmd (.. "ConjureEval (print " (. (extract.form {}) :content) ")")))
; eval (command): (print {:x "1" :y "2"})
; (out) {:x 1, :y 2}
nil
; --------------------------------------------------------------------------------
; eval (command): (print {:x "1"
; (err) Syntax error reading source at (REPL:1:1).
; (err) EOF while reading, starting at line 1
Not going through :ConjureEval
but calling the conjure fnl function directly would probably do it
maybe adapting https://github.com/Olical/conjure/blob/31a1626273e2bab479b6b8416a137f9edaba7daa/fnl/conjure/eval.fnl#L170-L180 (is my guess)
Sweet, that does it:
(defn time-form [extra-opts]
(let [form (extract.form {})]
(when form
(let [{: content : range} form]
(eval.eval-str
(a.merge
{:code (str.join ["(time " content ")"])
:range range
:origin :current-form}
extra-opts))
form))))
(vim.keymap.set :n :<leader>et #(time-form {}))
Thanks again, @U02G8N0EX44!nice! it is a fun idea to be able to do custom wrappings like this
Yeah, there's potential to do some interesting things. You can tap> or time forms, render charts using Reveal/Portal/etc., execute your HoneySQL data structures as queries, and so on. One thing that would improve this is if it didn't work by gluing strings together, but it's good enough for me for now.