Fork me on GitHub
#reveal
<
2022-02-20
>
jlmr11:02:54

I’m trying to cleanly integrate Tutkain (Clojure plugin for Sublime Text) with reveal. Tutkain only works with plain socket repls so I’ve been trying the following (shamelessly copied from inspired by @seancorfield): I have the following mini-library:

(ns jlmr.socket-reveal
  (:require
   [clojure.core.server :as s]
   [clojure.main :as m]
   [vlaaad.reveal :as r]))

(defonce ui (atom (r/ui)))

(add-tap @ui)

(defn- submit-eval
  [form]
  (let [value (eval form)]
    (@ui value)
    value))

(defn repl
  []
  (m/repl :init s/repl-init :read s/repl-read :eval submit-eval))
And I have the following alias in my deps.edn:
{:extra-deps {vlaaad/reveal {:mvn/version "RELEASE"}
              jlmr/socket-reveal {:local/root "/Users/jelmer/Code/socket-reveal"}}
   :jvm-opts ["-Dclojure.server.repl={:address,\"0.0.0.0\",:port,50505,:accept,jlmr.socket-reveal/repl}"]}
When I connect to the socket repl with Tutkain, as expected the Reveal ui appears. However values don’t appear in Reveal when I eval them from the editor. Anyone any idea how I can fix this?

flowthing14:02:16

Hey there! Glad to see a Tutkain user in the wild. 🙂 I’ll be able to help you more when I'm front of my computer, but evaluating (jlmr.socket-reveal/repl) after connecting with Tutkain might work.

flowthing15:02:50

I don't use Reveal a lot myself, but this is definitely a use case I want Tutkain to support, so if you encounter any issues or rough edges, I'd like to hear about them so I can fix them. Would you prefer evaluation results to only show up in Reveal and not have them show up in Tutkain at all?

jlmr16:02:20

Hi! Yes after years of messing with Atom and VS Code I’m trying to get back to my first editor of choice, but I’ll have to get a decent Clojure experience going there before I can really make the switch back.

jlmr16:02:38

I’ll try your suggestion tonight, but I’m having trouble understanding why it would help. jlmr.socket-reveal/repl is called just as Tutkain connects and all evaluations should be passed to it.

flowthing16:02:15

It works because Tutkain starts its own REPL immediately after connecting.

jlmr16:02:19

Tutkain can connect and forms evaled in the editor seem to work.

jlmr16:02:57

I assume that’s how Tutkain implements breaking evaluations and so on?

flowthing16:02:06

That's part of it, yes.

jlmr16:02:27

Ok good to know, will tinker on it more later today.

flowthing16:02:08

Sure thing. I'd be happy to help if you come across any issues or if there's some way I can improve Tutkain to make working with Reveal easier. Feel free to join #tutkain and hit me up there if necessary.

👍 1
jlmr17:02:19

I indeed got it working by connecting to a regular socket and binding a key to evaluate ((requiring-resolve 'jlmr.socket-reveal/repl)) . Only oddity I notice that each time I switch tabs the namespace symbol gets evaluated or something and appears in reveal.

flowthing17:02:02

Indeed — Tutkain auto-switches namespaces by default. You'll probably want to disable that in Tutkain's settings (Preferences » Package Settings » Tutkain on macOS), auto_switch_namespace.

flowthing17:02:13

A feature that lets you automatically evaluate code after connecting might be useful... will think on that.

jlmr18:02:39

Thanks! I think you’ve got yourself another Tutkain user 🙂

flowthing19:02:07

Cool! That makes you user number three, I believe. 😛

🤯 1
flowthing19:02:36

Oh, in case you only want your evaluation results to show up in Reveal (and not in Tutkain at all), you might want to add "output": "panel" to your tutkain_connect key binding and set auto_show_output_panel (new in 0.13.0, just released) to false.

vlaaad09:02:28

Hmm, can't you use r/repl? It's basically the same thing, but with submitting to Reveal window built in

jlmr10:02:08

@U47G49KHQ I did try r/repl, but I prefer r/ui 🙂

vlaaad10:02:56

May I ask why? It supports all m/repl options...

vlaaad10:02:40

r/repl is basically a wrapper of m/repl with all the necessary wrappings to give the best repl experience

vlaaad10:02:45

r/repl is very similar to jlmr.socket-reveal/repl…

vlaaad10:02:58

https://github.com/vlaaad/reveal/blob/master/src/vlaaad/reveal/repl.clj — here is r/repl source, it’s mostly the same, but it also wraps printing and showing thrown exceptions, adds a tap sink…

jlmr10:02:12

Basically I like the ui of r/ui better, the fact that you can open extra panels at the bottom etc. Or have I missed that that’s possible with r/repl as well?

vlaaad10:02:49

It’s totally possible

vlaaad10:02:48

r/repl is a wrapper of m/repl that forwards repl output to r/ui

jlmr10:02:08

I’m not sure I understand correctly: so I connect Tutkain to a socket-repl :accepting vlaaad.reveal/repl , connect Tutkain to it and then…. evaluate something to open the regular ui?

vlaaad10:02:31

mm no, I connected to a simple clojure.core.server/repl

vlaaad10:02:11

I took this example from tutkain readme:

clj -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}"

jlmr10:02:41

and then open another nested vlaaad.reveal/repl I guess. I will try that out later today

vlaaad10:02:44

and only changed it to add reveal to its classpath, e.g. clj -A:reveal -J…

vlaaad10:02:28

I connected to it, and then run ((requiring-resolve 'vlaaad.reveal/repl))

flowthing10:02:37

Yeah, so what you do now, but instead of ((requiring-resolve 'jlmr.socket-reveal/repl)), do ((requiring-resolve 'vlaaad.reveal/repl)).

jlmr10:02:44

Yes tried it out quickly and it works perfectly!!!

🎉 2
jlmr10:02:47

Thanks both!

vlaaad10:02:58

To summarize: 1. start a normal repl with reveal on the classpath: clj -Sdeps '{:deps {vlaaad/reveal {:mvn/version "1.3.265"}}}' -J-Dclojure.server.repl="{:port 5555 :accept clojure.core.server/repl}" 2. In sublime, use tutkain to connect to localhost:5555 3. evaluate ((requiring-resolve 'vlaaad.reveal/repl))

☝️ 1
💯 1
jlmr11:02:42

Also has the benefit of being much simpler than what I was trying

jlmr11:02:16

So in this case simple was actually easy as well 😅

rich 1