Fork me on GitHub
#calva
<
2022-01-28
>
Eugen11:01:04

hi, I am curious what is your take on REPL driven developement with Calva. I tend to do the following: • open a file with Rich comment at the end - few hundred lines of clojure • scroll to the end, load the file and run a piece of code in rich comment • scroooool up and make some changes to the function in top of file • scroool down and try it again. Is there a way to avoid this scrolling ? Can I bookmark the function / place in the file so I can navigate to it easily ? How do you guys do it?

Lukas Domagala12:01:10

I do it the same way and have the same feelings as you. One thing that helped and is counter intuitive: have your comment in a different file, that way you can jump back and forth between the change and the eval by hitting “ctrl+tab” instead of scrolling. I also played with the bookmarks extension but it doesn’t feel as nice as I hoped. What I’m actually thinking about is a “run eval before last” command, so I can eval a defn in the code and rerun the call with a hotkey. But I’m sure there’s a better design then just hardcoding “history -1” as the target.

pez12:01:43

Wonderful questions! I tend to: • Have many Rich comment blocks in the file. Certainly one below the function I am working with. • Try to avoid big functions (I am quite bad at this. But anyway, if a function gets me to start scrolling a lot I take that as a strong clue.) • Sometimes I open the same file side by side (or below). In one of the panes I am scrolled to the function and in the other I am scrolled to the RC. Then cmd+k cmd+right/left/up/down will move between these. • If it is very much the same forms in the RC that I evaluate over and over again, I create a custom code snippet for it. See https://www.youtube.com/watch?v=fJpDztSR53E&amp;t=2s for an example Also worth noting here, is that my workflow of 1:1 - function:RC has special support. Calva has a command Add Rich Comment that will create a rich comment block below the current top level form, or jump to it if it already is one there.

1
Eugen13:01:41

thanks, will try it out. I do sometimes refactor other peoples code and then I can't always make functions small You usually want to go with smaller changesets

Eugen13:01:17

@U0ETXRFEW: Would it be hard to have what @U02EMBDU2JU is suggesting with history of repl executions ? I can imagine some keys to open history and use arrows to navigate the history. The last execution could be pre-selected

pez13:01:32

I think the same-file-side-by-side way should work when functions are long. Have you tried that?

Eugen13:01:53

I keep portal open to the side

Eugen13:01:59

to view data

pez13:01:34

Maybe place the same file above/below each other. The pane with the rich comment form could be sized pretty small.

pez13:01:32

The problem with the history is that it is complicated to know which evaluations should be added there and which not. So if you evaluate a large function a few times you would have to navigate past that a few times to reach your test expression. Maybe we could make it such that only RCF evals get added....

Eugen13:01:08

that could be an option - I ususally load the whole file and re-run rich comments

Eugen13:01:22

I don't ususally evaluate individual functions

Eugen13:01:55

one feature that I really use when using history is reverse search - with ctrl+R + type pieces of the thing I am running

Eugen13:01:08

this is ususally good enough

Lukas Domagala13:01:12

> Maybe we could make it such that only RCF evals get added.... I like that idea. Currently only stuff you eval inside the “repl window” gets added to history. If we add evals inside RCFs we would get the whole “eval last history item” for free

Lukas Domagala13:01:06

plus I hope most people don’t type into the repl directly anyway

pez13:01:23

We could also consider supporting one RFC/file some way.

Lukas Domagala13:01:49

yeah, a “jump to next RFC” command might be helpful on top of these ideas

Eugen14:01:41

for the sake of discussion, when I was doing Java I used this a few times https://www.jetbrains.com/help/idea/viewing-structure-of-a-source-file.html . I don't know if this is useful for clojure / Calva. I also noticed Bookmarks functionality there https://www.jetbrains.com/help/idea/viewing-structure-of-a-source-file.html . And noticed VS Code has something like that: https://docs.microsoft.com/en-us/visualstudio/ide/setting-bookmarks-in-code?view=vs-2022 . I'll try it and see how it works for clojure

Eugen14:01:13

initial use seems simple and straightforward. @U02EMBDU2JU and @U0ETXRFEW - I think it's what I need - I will get back with more feedback once I use it for some time

orestis14:01:14

Vim has the concept of “marks” where you can set them arbitrarily all over the file, for navigation etc. Conjure (the Clojure vim plugin) has the ability to evaluate the top level form at any mark.

orestis14:01:54

So you would mark the form you want inside a RCF, then go edit your function, eval the function normally and then eval the mark. No need to scroll

Eugen14:01:55

I can add bookmarks with ctrl+alt+k , jump to previous with ctrl+alt+j and also list all of them

orestis14:01:32

Then perhaps Calva could eval at a bookmark? Not sure how the shortcut could work though.

pez14:01:38

@U7PBP4UVA It dates back to vi and even ed I think. Wonderful feature!

pez14:01:46

I don't think we need a special command for eval at a bookmark. Jumping to it and alt+enter, then jumping back, takes you far.

Eugen14:01:16

yes, bookmarks is a generic extension - to be used with any language / file . I think it is going to be enough

Eugen14:01:36

thanks for all the help.

🙏 1
Lukas Domagala14:01:59

you could use https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command to build a command that does “jump to bookmark” -> “eval top level” -> “go back”

👍 1
pez14:01:47

Then you won't see the result. Just sayn' 😃

Lukas Domagala14:01:10

result would popup in the repl?

pez14:01:29

Yeah, but who has that open? 😃

pez14:01:22

Haha. Me too at times. But I often get away with Show hover after the eval.

Lukas Domagala14:01:02

or the middle part could be “tap top level form” to send it to portal or something

Eugen14:01:28

I think people who use Calva / Clojure more "on ocasion" don't get to develop deep workflows and stick with simple stuff. This is my opinion of course, totally subjective. (I do devops, and clojure is a part of the day),

Lukas Domagala14:01:34

You are correct, sadly. After I convinced a friend of mine to try clojure he asked for an IDE. I told him to use Calva and he was kind of annoyed by it. Turns out he had a repl running in the terminal and was typing into it… He was a lot happier after I showed him the “correct” workflow

pez14:01:18

You should have showed him the Fire up a Getting Started REPL command. 😃

Lukas Domagala14:01:03

I did, but I’ve had multiple people tell me: “I’ll do that once I played around with it myself” …

Lukas Domagala14:01:45

thats like: I’ll use your API and once I’m finished I’ll read your docs.

Lukas Domagala14:01:53

but people are people …

pez14:01:28

I think that is a good way to learn. At least as long as you remember to go back to the room you where suggested to start in.

Lukas Domagala14:01:06

as long as you don’t end up typing into a lein repl in the vscode terminal … 🙂

pez14:01:37

I think that is fine. But it makes unhappy that he sort of blamed Calva for the shitty experience. 😃

pez14:01:29

It goes to show that the getting started repl is a good approach in that it tries to guide the beginner past the room with the lein repl in it. 😃

Eugen14:01:30

yeah, gone or the good ol' days of RTFM today kids don't have time for that 🙂

Lukas Domagala14:01:31

yeah. I think he was aware he’s doing something wrong, but didn’t know how to do it right without spending “too much” time on it. But I think I kind of derailed the original discussion, sorry 🙂

pez14:01:15

You do that often, @U02EMBDU2JU! And I love you for it, so please keep doing it, ❤️

Lukas Domagala14:01:13

I think thats not sarcasm 😅❤️

pez14:01:13

It's not!

Eugen13:02:19

about the bookmarks - it does not work so well since it's a line bookmark not a function / language element bookmark . So when the lines change the bookmarks don't change with the code

Eugen13:02:38

wdyt @U0ETXRFEW - would this warrant an feature ?

Lukas Domagala15:02:06

good point @U011NGC5FFY, I’d vote yes, especially if you build it 🙂

pez15:02:40

Have you tried the extension Inline Bookmarks? It lets define regex patterns that it will bookmark, So if you give it a pattern like (?<=\(comment\n\s*).*, you will be able to jump into the first line of all RFCs in the file and project. And it will give you an outline with the bookmarks as well. It's a bit slow to scan the workspace, and a bit quirky, but anyway. 😃

Eugen15:02:33

I will give that a try. @U02EMBDU2JU - I don't think I can streatch myself that thin unfortunatelly

Eugen15:02:51

@U0ETXRFEW: I wonder if we can have bookmarks with comments or #_{:bookmark "ID"}

pez15:02:54

If you look in the outline of my screenshot you will see that two of the bookmarks start with comments. But you can certainly use any. convention you like and just use a regex that matches that.

pithyless20:02:41

> Is there a way to avoid this scrolling ? In Emacs CIDER, what I will do is inside my (comment ,,,) I'll create a temporary (deftest ,,,) that just runs the code I'm interested in running (may, but does not actually need to have any is checks, etc). Then I eval the test and run cider-test-run-test. After that I will scroll back to wherever I'm working on (can even jump to different namespaces) and after evaling some changes will run cider-test-rerun-test. The trick is this will eval the code from the deftest without actually needing my cursor to be anywhere near it. I think you could come up with a similar workflow using the Calva test shortcuts: https://calva.io/test-runner/

pithyless20:02:21

^ Just realized this is a couple-days-old thread, but I do find this workflow useful.

pez20:02:50

That's brilliant, @U05476190! Should work with Calva just the same as it does with CIDER.

pithyless20:02:01

I see Calva has a run-failing-tests shortcut, but it may be helpful if there was also a rerun-previous-test shortcut (assuming you have easy access to that info)

pez20:02:26

Calva uses cider-nrepl for this so if it is available there it should be entirely possible,

bringe03:02:58

I don’t see an op for that in the cider-nrepl docs, but it probably would be pretty easy to remember the info for the last run test in Calva (when one is run individually) and just run it again when the re-run command is executed.

Max17:01:51

Ran into paredit commands not working with multiple cursors again, figured it couldn’t hurt to bump it here: https://github.com/BetterThanTomorrow/calva/issues/610 Are there big technical challenges to getting that working, or is it a bandwidth/priority thing?

pez18:01:30

It'll probably be one of the most challenging tasks we've ever faced. Well, maybe with the exception of Parinfer. But it could also be a bit easier than that. I honestly don't know.

pez18:01:10

I miss it every day. So agree it would be wonderful to solve it.

Max00:01:23

Thank you for all your hard work on calva! In general it’s a pleasure to use

❤️ 1