Fork me on GitHub
#cursive
<
2022-09-20
>
Cora (she/her)21:09:35

it would be so nice if cursive had protection from more protection from deletes causing unbalanced parens

R.A. Porter21:09:20

Are you using paredit or parinfer? I've found that, as long as the file is formatted correctly, parinfer is slightly better about maintaining balance.

Cora (she/her)21:09:59

paredit, but I'm using built-in facilities for deleting a line, and the vim plugin's line deletion

cfleming22:09:28

Just so I’m clear, you mean that e.g. if a line is deleted, that the parens are rebalanced?

Cora (she/her)22:09:02

any full forms (including opening and closing) on that line are deleted, any parameters within a form are deleted, any closing parens/curlies/brackets are moved up to the end of the previous line

Cora (she/her)22:09:43

evil-cleverparens and lispy handle this in the emacs world

cfleming22:09:02

What you’re describing is basically what parinfer does. It works on general edits to the document, and tries to always fix up the parens correctly. It’s not perfect, but it’s pretty close these days.

Cora (she/her)22:09:28

doesn't that require specific indentation?

Cora (she/her)22:09:28

whatever I use has to be workable by an entire team with lots of different editors

cfleming22:09:49

It requires the indentation to be within various (sane, imo) parameters, yes. However, Cursive won’t automatically reformat files which don’t conform, it will just mark where the problems are and turn parinfer off for that file until they’re fixed.

cfleming22:09:36

I have plans to make parinfer more local, i.e. only operate at the level of a top-level form, but that’s just a pipe dream at the moment.

Cora (she/her)22:09:25

I don't think this is an option for my team 😞

cfleming22:09:22

Unfortunately there’s not much middle ground here. IntelliJ has hundreds and hundreds of editing actions, and I can’t modify all of them to fix up parens.

R.A. Porter22:09:34

I've tended to run cljfmt prior to commit to ensure compatibility, but that only works if everyone else is also good with cljfmt's choices.

Cora (she/her)22:09:52

one of my coworkers pointed out the same issue with "I love Cursive except" and I tried to find a solution to no avail

Cora (she/her)22:09:35

deleting whole lines is the main use case for me and the two people I've spoken to about this feature.

Cora (she/her)22:09:49

I suppose I'd need to make my own intellij extension to work around this

Cora (she/her)22:09:13

thanks for chiming in @U0567Q30W!

cfleming22:09:20

Probably, yes. But I bet you’d quickly find a lot of other cases you’d like to work too.

Cora (she/her)22:09:23

and thanks for the input @U01GXCWSRMW

cfleming22:09:56

Do evil-cleverparens and lispy work generally for any emacs action, or do they just monkey-patch certain common actions?

cfleming22:09:05

Or do they require the user to use their own variants?

Cora (she/her)22:09:00

evil-cleverparens (the one I use) uses their own function as the key binding in place of the default

Cora (she/her)22:09:48

so if I checkout what is bound to dd (delete line, in vim) it has evil-cp-delete (evil-cleverparens functions start with evil-cp )

cfleming22:09:09

Ok, so it only works for certain actions. That’s really hard to do in IntelliJ land, because the actions work together in various ways, and are surprisingly complicated due to things like code folding and language injection.

Cora (she/her)22:09:10

I need to run, headed out to dinner with my family. I'm happy to discuss it more later!

cfleming22:09:21

No worries.

Cora (she/her)22:09:33

ahhh yeah I can see it getting real complicated. this is probably why there are a million bridge extensions between different extensions in emacs-land. like if cursive had something equivalent it would be a vim-cursive extension that makes them play well together

cfleming22:09:09

Yeah, I don’t know how extensible IdeaVim is, I don’t use it myself.

Cora (she/her)22:09:22

that seems like a good place to start

Cora (she/her)00:09:14

so with ideavim I can execute those options (and more) from key combinations and I think even from functions. I imagine I can hack together something that would be similar to what I want

Cora (she/her)01:09:23

I wonder how backspace keeps parens balanced. because deleting a line is really just jumping to the end of the line and deleting using backspace until it jumps you to the next line

Cora (she/her)01:09:30

because deleting a line using it could just be programatically hopping to the end of the line and backspaceing until the whole line is gone. balance maintained

cfleming03:09:13

Yep that would work. I’d have to check the code for the details, but IIRC backspace just jumps over closers, and for openers if they immediately precede the corresponding closer then both are deleted. A more efficient method would be to count the openers and closers on a line (maintaining a stack to check matching) and then depending on whether the final count is positive or negative you stack some closers at the end of the previous line or some openers at the start of the following line.

cfleming03:09:47

But there are lots of edge cases too - what to do if they’re unbalanced, you might be inside a long string, or you might have a string ending at the beginning of the line, or starting at the end of the line. If you insert openers at the start of the following line then do you indent the affected forms? etc etc

cfleming03:09:56

And before you know it you have an ad hoc, informally-specified, bug-ridden, slow implementation of half of parinfer 🙂

Cora (she/her)04:09:15

sure but this is more like a 95/5 where just exploiting backspace would work for the vast majority of cases. I likely can't have perfection without a massive amount of work and so I'll take what I can get

cfleming04:09:34

That’s fair enough, for sure.