Subject: bug#36474: closed (Re: bug#36474: Acknowledgement (Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode))

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 08 Jul 2019 09:37:02 +0000

Your bug report

#36474: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
36474: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=36474
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#36474: Acknowledgement (Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode)
From: Alan Mackenzie <[email-masked]>
To: [email-masked]
Date: Mon, 8 Jul 2019 09:36:27 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

The bug has been fixed in CC Mode.

On Tue, Jul 02, 2019 at 13:17:01 +0000, GNU bug Tracking System wrote:
> Thank you for filing a new bug report with debbugs.gnu.org.

> This is an automatically generated reply to let you know your message
> has been received.

> Your message is being forwarded to the package maintainers and other
> interested parties for their attention; they will reply in due course.

> Your message has been sent to the package maintainer(s):
>  [email-masked]

> If you wish to submit further information on this problem, please
> send it to [email-masked].

> Please do not send mail to [email-masked] unless you wish
> to report a problem with the Bug-tracking system.

> -- 
> 36474: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=36474
> GNU Bug Tracking System
> Contact [email-masked] with problems

-- 
Alan Mackenzie (Nuremberg, Germany).

Subject: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode
From: Alan Mackenzie <[email-masked]>
To: João Távora <[email-masked]>, [email-masked]
Date: Tue, 2 Jul 2019 13:16:32 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello João and Emacs.

This is a follow up bug to bug #36423: 27.0.50; electric-pair-mode not
working properly depending of file content.

Start the Emacs master (up to date state as of 2019-07-02T14:30 +0000)
with emacs -Q, put the following in a C++ Mode buffer and enable
electric-pair-mode:

"foo\n

.  Type a " at the end of foo.  electric-pair-mode wrongly inserts two
"s.

Diagnosis: electric-pair--unbalanced-strings-p works after the (single)
newly typed " has been stripped from the buffer.  It attempts to
determine whether there are any open strings after the point of
insertion.  It does this by using parse-partial-sexp, and checks (nth 3
<result>) as evidence of an open string.

This does not work in CC Mode, since although there is an open string
marker (with a string fence syntax-table property on it) this is
"closed" (from parse-partial-sexp's point of view) by the string fence
property on the newline at the end of the line.
electric-pair--unbalanced-strings-p thus returns the wrong result.

A more suitable algorithm might look something like this: check whether
the newly inserted " has a string fence syntax-table text property.
(Its insertion will have already triggered the before- and
after-change-functions which set this property.)  If so, there is an
open string.  Of course, this only applies to CC Mode modes.

-- 
Alan Mackenzie (Nuremberg, Germany).