Fork me on GitHub
#cursive
<
2022-05-04
>
onetom00:05:24

im thinking about a better REPL flow for awhile. here is what i came up with so far: 1. use special REPL files for establishing and working with various contexts of a bigger application, eg. one file per 3rd-party API, database, http layer, etc 2. most REPL files are probably development only and contain destructive operations, which is don't want to execute accidentally in a production Clojure process, so they should live under a directory, eg. <project-root>/dev/, so they are not deployed to production. 3. we should use file-based evaluation, NOT buffer-based, by default, so we can't accidentally load such code through a production REPL 4. the namespaces for these REPL files should be shallow, in case we need to type their names out manually. eg. project.name.datomic-repl (which would reside in dev/project/name/datomic-repl.clj) 5. the x.y.datomic-repl.clj naming scheme - as opposed to x.y.datomic.repl.clj - helps to distinguish multiple REPL files being open in various editors, which might chop off, abbreviate or display with a pale color the x.y.datomic part. 6. we should use rich-comments in such REPL files, so we can just reload them any time without side-effects. and here is the workflow part (position of the caret shown as •): 1. start with this:

(comment
  (-> *1•)

)
where *1 is highlighted. we edit this form:
(comment
  (-> some-seq
      (doto pprint)
      (->> (map :some/key•)
           (keep :other/key)))

)
then eval it and i'd expect a copy of the evaluated form appear above the form itself and my cursor stay in place:
(comment
  (-> some-seq
      (doto pprint)
      (->> (map :some/key)
           (keep :other/key)))

  (-> some-seq
      (doto pprint)
      (->> (map :some/key•)
           (keep :other/key)))

)
so i can keep iterating on the form, while maintaining a history of its evolution, which i can clean up later. i'd also expect the undo operation to remove the copied form, in case im just repeating the same operation for its side-effect. eg. maybe im just polling something manually.

cfleming00:05:14

Somewhat related, one thing I’ve thought of recently which I think would be really useful, similar to https://github.com/cursive-ide/cursive/issues/2623. I’d like a command to be able to execute a rich-comment form from anywhere in the file. So probably a command which pops up a searchable list of all the comment-commands in the current file, and allows me to execute them.

onetom00:05:27

other useful approach which has emerged in my usage is this form:

(comment
  @(def some-var *1)

  @(def some-var
      (-> (some computation) (print-summary)))
  )
so i can see the result of the computation, while also capturing it

cfleming00:05:11

Interesting idea.

onetom00:05:09

@U0567Q30W yes, that bookmarked evaluation is also a great building block, i've just realized in the last 2-3days. i often need to modify some function definition in an NS and re-run a form in another NS, to test out the effect of my change. so far im just using the Re-execute last command option of a Cursive REPL Command, but the last action gets overwritten, when I execute another Cursive REPL Command.

cfleming00:05:33

Yes, definitely, I’ve been feeling that recently too.

👍 2
JAtkins11:05:55

A while back I used a "save command" repl command that saved the text of your current editor selection and your current ns. Was able to run that code again in the future from any context. It's super useful, and it'd be nice to have some more official support for something like that

Baye16:05:47

Hi. How do you get "on the same line" repl eval on Cursive?

imre16:05:10

Cursive doesn't provide that, but there's another plugin on top of Cursive that does: see #clj-extras-plugin

👍 1