Calva Paredit Just got Majorly Better

Dear Clojurians, I am super happy to announce that Calva’s Paredit feature has been completely rewritten from the very ground and up. It was mainly done as a way to make maintaining Calva easier, but at the same time Calva users get a much more stable, complete, and useful structural editing tool.

I will not bore you with details. Instead I’d like to promote the Calva Paredit documentation page, which now has become a Paredit Visual Guide (much inspired by the Animated Guide).

The page describes each Paredit command with cerafully crafted prose, as well as with GIF animations like this:

(Who of you can tell which edit is happening there? :smile:)

If you have friends who wonder what Paredit is, and what it can do for them, please give them the link to that page. I am biased of course, but I do think it might be one of the best resources to figure out Paredit.

Please give this Paredit version a spin. I’d love me some feedback. You’ll need VS Code, and the Calva Extension

It was a while since I posted about Calva developments here. A lot more than this Paredit update has happened since. Please see the Changelog if you are curious: https://github.com/BetterThanTomorrow/calva/releases

Also, I’d like to point out that I am now sponsorable via GitHub Sponsors:
https://github.com/sponsors/PEZ :heart:

Happy Coding!

7 Likes

I am quite happy with the structural cursor/editing tech that we have in Calva. It makes it easy to compose whatever navigation and editing.

Over at /r/Clojure it was mentioned pushing forms around at will. I gave it a quick go, and now I think I’ll add the Push Sexpr Left/Right commands to the Calva palette:

Neat, huh? What more editings do you think would fit?

OT: Do you notice how fast the clj-kondo linter is to spot when something in the code does not spark joy? Immediately when (apply) lacks enough arguments it gets squiggled.

3 Likes

My paredit fuu normally involves:

  • Grow s-exp selection
  • Shrink s-exp selection

Growing would select the symbol, then the symbols inside the form, then the form, and then the symbols inside that form, and so on, until the whole buffer is selected.

Shrinking reverses that until we’re back at having no selection.

Now add:

  • Wrap parens/quote/bracket/curly, etc.

Now you can take any selection and wrap it with the parens you want which should automatically put the cursor at the front after wrapping.

  • Navigation next/previous symbol.
  • Navigation inside/outside forms.

With that you can now move around anywhere in the code. And with the prior tools you can select any relevant chunk of it.

Finally, add:

  • Raise s-exp
  • Split s-exp
  • Join s-exp

So you can wrap by selecting and wrapping. Now you can also unwrap by selecting and doing a raise. And you can split/join siblings.

Oh, and I use re-wrap as well, to change parens type.

Seems like Calva has all these except for re-wrap.

1 Like

Thanks! Interesting that you don’t mention slurping and barfing. You don’t use them much?

Could you elaborate some on what this does?

I never really found when to leverage slurp/barf. In fact, at first I think the emphasis on slurp and barf made me confused about structural editing and it took me a while to enjoy paredit because I kept trying to work with slurp and barf to no avail. I might be missing the knowledge of how to leverage them effectively.

Re-wrap is like say you have the cursor here:

{:a 1 :b| 2}

And you want to change the { } to a [ ] you can do a re-wrap-to-square-bracket and it’ll make the change to:

[:a 1 :b| 2]
1 Like

Thanks for expelling that. A new Calva is out. With rewrap:

2 Likes

I realised that all Calva selection commands actually should be pushed on the grow selection stack, so that they can be shrunk. Hence this PR:

TL;DR;

4 Likes