Subject: bug#23298: 25.0.92; electric-pair-delete-pair doesn't check if parens are balanced

From: Stefan Kangas <[email-masked]>
Date: Tue, 11 Aug 2020 19:52:12 -0700

Lars Ingebrigtsen <[email-masked]> writes:

> Mohammed Sadik <[email-masked]> writes:
>
>> When pressing Backspace key, with electric-pair-mode enabled,
>> it unconditionally deletes the following char, if its the matching pair.
>> Ideally, it may better check if it breaks the equilibrium of
>> braces/quotes.
>>
>> Eg: code: (char-before (point))
>>                              |_ point location
>> If my point (cursor) is just before the last paren (the cursor is
>> blinking on the last paren), and I press backspace until the beginning
>> of "point"[0], and then one char back[1], it just deletes the bracket,
>> without checking if the parens are balanced.
>>
>> code:
>>         [0] (char-before ()
>>                          |_point location
>>         [1] (char-before
>>                         |_ point location
>>
>> This could be the case of quotes, braces, etc.
>
> (I'm going through old Emacs bug reports that haven't received any
> response.)
>
> Or a simpler example:
>
> (foo ()
>
> If you put point after the next-to-last character, then hitting DEL will
> delete the last pair:
>
> (foo
>
> But...  I don't think this is a bug?  electric-pair-mode doesn't promise
> to keep things balanced globally, but delete the matching pair if you
> delete an opening parenthesis?  I think.
>
> Does that tally with what everybody else would expect?

Do we have any electric-pair-mode users who could comment on this?

Best regards,
Stefan Kangas