Fork me on GitHub

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.


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;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.


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


@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


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


I keep portal open to the side


to view data


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


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....


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


I don't ususally evaluate individual functions


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


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


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


for the sake of discussion, when I was doing Java I used this a few times . I don't know if this is useful for clojure / Calva. I also noticed Bookmarks functionality there . And noticed VS Code has something like that: . I'll try it and see how it works for clojure


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


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.


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


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


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


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


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.


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


thanks for all the help.

🙏 1
Lukas Domagala14:01:59

you could use to build a command that does “jump to bookmark” -> “eval top level” -> “go back”

👍 1

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

Lukas Domagala14:01:10

result would popup in the repl?


Yeah, but who has that open? 😃


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


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


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 …


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 … 🙂


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


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. 😃


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 🙂


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 😅❤️


It's not!


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


wdyt @U0ETXRFEW - would this warrant an feature ?

Lukas Domagala15:02:06

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


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. 😃


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


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


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.


> 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:


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


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


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)


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


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.

Alexander Kouznetsov19:04:01

I also created an issue for reverse search Some of the ideas listed here wouldn’t work if the command you ran was only in the repl window and you since cleared it.


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


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.


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


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

❤️ 1