Closed jestarray closed 5 months ago
The issue will go away entirely if you maintain balanced parens at all time. This can be done by not deleting the right paren in (cons v acc)
. Instead, press alt-shift-left
to select the whole (cons v acc)
and delete it in one go. It's also quicker.
as editors like vscode don't do this
That's not quite true. vscode seems to be stateful with the delete operation. It tracks whether you are continuously typing, and if so, it will do the smart paren delete. Otherwise, it will not. As an example, consider the following edit, where |
is the caret.
|
(|) ; press (
| ; press backspace
But:
|
(|) ; press (
()| ; press right (this breaks the continuous typing)
(|) ; press left
) ; press backspace
Since vscode is a general editor, I think it makes sense to not assume that users want to always balance parentheses. But you definitely want to balance parens in Racket, so I think the current behavior is perfect already.
The binding for the current behavior is in framework/private/racket.rkt:
(map "~c:backspace" "maybe-delete-empty-brace-pair")
You could bind it with c
instead of ~c
to swap the behaviors on your system:
(map "c:backspace" "maybe-delete-empty-brace-pair")
I personally like the current default behavior. I'm not opposed to an option, but you should be able to change your keybindings to get the behavior you want with the current version.
A certain auto-paren model I'm familiar with (probably from Eclipse?) maintains a sequence of ghost characters after the cursor. They've been halfway auto-inserted, but they haven't been committed to yet. If you backspace past the thing that inserted them, they get deleted too. If you type your own closing delimiters manually, then the ghost ones disappear as you do so. This means that if you type (
followed by backspace, or if you manually type (...)
, the result is the same as it would have been without auto-parens interfering.
Personally, I think there are other usage scenarios auto-parens interfere with that this ghost character design doesn't account for:
)
in my code and move in to insert a (
to match it, I don't want another )
inserted automatically when I do that, giving me ()...)
. At the same time, I think I have experienced at least one editor that attempted to account for that, and I found it rather annoying; the behavior of typing (
would change contextually based on whether there was an extra )
on the next screen that I wasn't paying attention to.[
in my code that should be a (
, and if I type (
followed by the delete key to replace it, I don't want a ghost )
to jump in and get deleted instead. However, in most other situations where characters get auto-inserted, I do want an easy way to delete them right away.It seems like as designers of auto-paren systems try to patch over some of the annoying surprises, other ones spring up. (Edited to add: And considering the contradictory preferences I detailed above, how can I expect otherwise?)
I personally haven't found a design I actually liked, and if I'm going to build habits for a design I don't like, my primary consideration is editor consistency so that my habits are transferrable. The only style of auto-parens most editors implement consistently is turning auto-parens off entirely, so that's my favorite kind. But my second favorite kind would probably be to have various modes that imitated other popular kinds of auto-parens. I think the ghost character model is one of the more self-consistent, such that a certain variety of editors might actually mostly agree on it, so I think that could be a sweet spot worth having as an option.
https://user-images.githubusercontent.com/34615798/132718639-e566f7e7-d08e-4433-a645-aaffff1002bc.mp4
As you can see when I want to delete
(cons v acc)
with BACKSPACE, it surprisingly deletes the closing)
for the lambda too! It always seems to delete parens in pairs as shown by me constantly trying to delete only 1 paren because I want to keep the closing one for the lambda. With this setting disabled it deletes the way I expect. Pressing the DELETE key and does not delete the closing parens I want to keep for the lambda. This also happens when you try to delete 1 quote inside a set of nested quotes: """"Someone mentioned ctrl+backspace does the deletion one would normally expect.
This issue has been discussed before and the default behavior was changed. https://github.com/racket/drracket/issues/201
Enable auto parens should not assume that the user also wants to delete in pairs, instead it should be split into another option for those who don't want to delete parens in pairs as editors like vscode don't do this. The only thing vscode does is when you type an opening
( " { [
, it will automatically add the closing one and sticks your cursor in the middle.