Fork me on GitHub
#cursive
<
2020-03-06
>
gibb06:03:31

Can I evalute an expression (send to REPL) and have the output as a comment in my text file without touching a mouse pointer?

cfleming08:03:10

Not right now, I have a plan to allow users to create configurable commands which will allow this.

gibb08:03:14

Awesome - typical nice to have extension. I already use the custom REPL command stuff extensively and enjoy it a lot!

onetom08:03:40

Is it possible to redefine the REPL prompt I see in Cursive? I've tried the following and it seems to work in a command-line REPL:

(ns user
  (:require clojure.main))

(defn repl-prompt [] (printf "=== %s ===\n=> " (ns-name *ns*)))

(alter-var-root #'clojure.main/repl-prompt (constantly #'repl-prompt))
it works like this:
$ clj
Clojure 1.10.1
=== user ===
=> (defn repl-prompt [] (printf "=== %s === !!!\n=> " (ns-name *ns*)))
#'user/repl-prompt
=== user === !!!
=> 

cfleming09:03:30

Not at the moment, no - currently Cursive doesn’t actually show a prompt at all. Being able to configure some kind of context information is an interesting idea, though, that might be possible.

onetom09:03:15

You mean it would already be possible right now?

onetom09:03:13

My immediate use-case is that I'm connected to an in-memory db while im developing an importer, but then i want to be able to switch to a persisted version, when my importer worked on new data. I would like to provide this for others as "a shell"

cfleming09:03:21

No, I mean that it would probably be possible without too much work. I was thinking about an expression in the REPL run config which would be evaluated behind the scenes after each REPL eval. The returned value could be shown in the overlay in the bottom right of the editor or something like that.

onetom09:03:23

For now I think I can just create a REPL command, assign it to some convenient function key and that could just print my current work context... Iike how the namespace is reflected in the REPL tab, though I usually just keep it as user, so my REPLs are indistinguishable. Would be useful if I could see the Deps project root folder name too or something like that. If there would be a REPL prompt hook, we could just program anything there...

onetom09:03:40

I've also experienced something funny around that overlay. Notice how the stdout got interpreted as the current namespace. That gave me the idea that I could somehow control that information programmatically 😉

cfleming09:03:06

That’s really weird, what sort of REPL is that? clojure.main?

cfleming09:03:27

It looks more like nREPL, but I don’t see how that could happen.

onetom16:03:41

Yes, that's an nREPL with Run with Deps option. I haven't narrowed the phenomena down yet, but it's roughly going thru this pipeline:

(-> "x.tsv" io/resource io/reader
    clojure-csv.core/parse-csv
    semantic-csv.core/mappify
    (on-every 1e4 •)
    (d/transact conn)
    deref)
where on-every is defined as
(defn on-every
  "Wrap s in a lazy sequence that will call f, presumably for side effects,
   on every nth element of s during consumption.
   
   Source: "
  [n f s]
  (let [g (cons (comp first (juxt identity f)) (repeat (dec n) identity))]
    (map #(% %2) (rest (cycle g)) s)))
to provide some visual feedback while the lines of my tsv file are consumed.

onetom16:03:02

but i suspect that the culprit can be that function, because a, it's printing a non-ascii character b, it's flushing the output

(defn • [& args] (print "•") (flush))

cfleming20:03:39

With an nREPL REPL, those values should only be set by the server explicitly sending the current namespace back to the client, it should never come from stdout.

👍 4
onetom17:03:21

As I see my nrepl is a bundled one on the latest stable version:

-classpath "/Users/onetom/JetBrains/apps/IDEA-U/ch-0/201.6073.9/IntelliJ IDEA 2020.1 EAP.app.plugins/clojure-plugin/lib/nrepl-0.6.0.jar
Maybe the latest 0.7.0-alpha3 fixes it. They mentioned some fixes around streaming printing in the changelog: https://github.com/nrepl/nrepl/blob/master/CHANGELOG.md

onetom08:03:36

I'm thinking about creating a Datomic admin interface, where I can dynamically set a session name, user name, which then gets added as some attributes on the "datomic.tx" entity of my operations

onetom08:03:19

it would be also nice to summarize what kind of environment am i currently operating in (as in which database am i connected to and stuff like that

tekacs23:03:29

I've defined a macro which has a form that looks like this: (defmymacro ::namespaced-keyword [args go here] forms go here)

tekacs23:03:40

i.e. akin to defn but with a namespaced keyword instead of a symbol in the second position

tekacs23:03:58

would anyone happen to know if there's something that I could tell Cursive to resolve that as in order to get argument behaviour?

tekacs23:03:15

as it stands my only choice seems to be defn, which requires me to use a symbol in the second position 😞

isak23:03:41

@tekacs I don't think there is a way, but you can easily convert from symbol to keyword inside your macro if you really need that, no?

tekacs23:03:06

I was hoping to use namespaced keyword to get Cursive to autocomplete the keyword for me

tekacs23:03:12

because there's actually two macros which need to share that value

tekacs23:03:27

and so if I can write (defsomething ::something) in namespace foo

tekacs23:03:02

and then (defdownstream :foo/something) elsewhere

tekacs23:03:12

then I get those to line up more easily and for Cursive to realize they're the same definition

tekacs23:03:14

renaming, etc.

tekacs23:03:34

I could of course import and use something/whatever via :refer :all, etc.

isak23:03:35

ah, then I think you'll need to wait until cursive releases the expanded macro recognition thing

tekacs23:03:43

I haven't heard about that 🙂

tekacs23:03:46

oh interesting, thank you for sharing 🙂