BetterThanTomorrow / calva

Clojure & ClojureScript Interactive Programming for VS Code
https://marketplace.visualstudio.com/items?itemName=betterthantomorrow.calva
Other
1.68k stars 217 forks source link

Feature request: Cursive-style quick surround #1565

Open w9 opened 2 years ago

w9 commented 2 years ago

I really like Cursive's "Surround selection on typing quote or brace" option where one could surround a balanced form by simply typing "(" to the left of the form. i.e., typing "(" at

│(+ 2 2)

gives

(│(+ 2 2))

This is more frequently what I want, as opposed to what's currently done:

(│)(+ 2 2)

This behavior can be implemented by slurping as far as possible after adding that pair of parentheses. So that typing "[" at:

(set │1 2 3)

should give

(set [│1 2 3])

The above behavior is best paired with the behavior that when you type ")", "]" or "}", barfing operation is executed until the cursor is out of the form, that is, typing "]" at

(set [1 2│ 3 4])

should give

(set [1 2]│ 3 4)

It also means that in order to have the original behavior (paren-balance only), you simply type "(" immediately followed by ")".

https://cursive-ide.com/userguide/paredit.html#:~:text=opening%20a%20balanced%20form%20will%20wrap%20the%20selection%2C%20otherwise%20the%20selection%20will%20be%20deleted%20and%20replaced%20with%20the%20empty%20delimiters.

bpringe commented 2 years ago

I think I've seen @PEZ discuss this with someone at some point, but I didn't see another issue for it when I looked just now. I'd like to see what he has to say. It seems like a nice feature.

bpringe commented 2 years ago

So, there are the "wrap around" paredit commands, mentioned here: https://calva.io/paredit/.

Maybe those commands or the underlying functionality can be used when the related opening or closing character is typed.

PEZ commented 2 years ago

Depending on keyboard layout this shortcuts example might help: https://calva.io/customizing/#wrap-using-like-cursive

If we ever get Parinfer to work, we'll get this behaviour.