From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#36474: Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode Date: Tue, 2 Jul 2019 13:16:32 +0000 Message-ID: <20190702131632.GA30597@ACM> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="113110"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mutt/1.10.1 (2018-07-13) To: joaotavora@gmail.com, 36474@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Jul 02 15:17:22 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hiIev-000TGA-5Y for geb-bug-gnu-emacs@m.gmane.org; Tue, 02 Jul 2019 15:17:21 +0200 Original-Received: from localhost ([::1]:53550 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiIeu-0005bm-6b for geb-bug-gnu-emacs@m.gmane.org; Tue, 02 Jul 2019 09:17:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58235) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiIeo-0005bb-LH for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:17:15 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hiIei-0005Lx-Ne for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:17:10 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:37836) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hiIeb-0005Hb-UP for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:17:05 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1hiIeb-0004oi-Nc for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:17:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Mackenzie Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 02 Jul 2019 13:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 36474 X-GNU-PR-Package: emacs X-Debbugs-Original-To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.156207340818492 (code B ref -1); Tue, 02 Jul 2019 13:17:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 2 Jul 2019 13:16:48 +0000 Original-Received: from localhost ([127.0.0.1]:46657 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hiIeN-0004oB-H0 for submit@debbugs.gnu.org; Tue, 02 Jul 2019 09:16:48 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:52331) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hiIeL-0004o3-42 for submit@debbugs.gnu.org; Tue, 02 Jul 2019 09:16:45 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58156) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hiIeJ-0005To-Tq for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:16:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hiIeI-00054T-Ut for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:16:43 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:64382 helo=mail.muc.de) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1hiIeH-00050A-9C for bug-gnu-emacs@gnu.org; Tue, 02 Jul 2019 09:16:42 -0400 Original-Received: (qmail 38769 invoked by uid 3782); 2 Jul 2019 13:16:33 -0000 Original-Received: from acm.muc.de (p4FE15D94.dip0.t-ipconnect.de [79.225.93.148]) by colin.muc.de (tmda-ofmipd) with ESMTP; Tue, 02 Jul 2019 15:16:32 +0200 Original-Received: (qmail 30708 invoked by uid 1000); 2 Jul 2019 13:16:32 -0000 Content-Disposition: inline X-Delivery-Agent: TMDA/1.1.12 (Macallan) X-Primary-Address: acm@muc.de X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:161955 Archived-At: 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 ) 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).