From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Mackenzie Newsgroups: gmane.emacs.bugs Subject: bug#50538: [PATCH v3] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode Date: Sun, 26 Sep 2021 20:58:36 +0000 Message-ID: References: <021853bf-0169-c158-ab3d-296b6c144e08@gmail.com> <83r1dufgxu.fsf@gnu.org> <94c7b4ec-813b-515f-d947-116c294dd74b@gmail.com> <456ed31d-77dc-cc2d-2fe9-8fcd379e04c6@gmail.com> <543ebfcc-d032-f0cd-f605-3f0607fe1df1@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29284"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50538@debbugs.gnu.org To: Jim Porter Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 26 22:59:27 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mUbF8-0007Qm-V9 for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Sep 2021 22:59:26 +0200 Original-Received: from localhost ([::1]:37104 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mUbF7-0005Np-9n for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 26 Sep 2021 16:59:25 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:48322) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mUbEk-0005N7-65 for bug-gnu-emacs@gnu.org; Sun, 26 Sep 2021 16:59:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:55558) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mUbEj-00072p-Un for bug-gnu-emacs@gnu.org; Sun, 26 Sep 2021 16:59:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mUbEj-0000oj-Sq for bug-gnu-emacs@gnu.org; Sun, 26 Sep 2021 16:59: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: Sun, 26 Sep 2021 20:59:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 50538 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 50538-submit@debbugs.gnu.org id=B50538.16326899273121 (code B ref 50538); Sun, 26 Sep 2021 20:59:01 +0000 Original-Received: (at 50538) by debbugs.gnu.org; 26 Sep 2021 20:58:47 +0000 Original-Received: from localhost ([127.0.0.1]:38871 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mUbEV-0000oH-0b for submit@debbugs.gnu.org; Sun, 26 Sep 2021 16:58:47 -0400 Original-Received: from colin.muc.de ([193.149.48.1]:59304 helo=mail.muc.de) by debbugs.gnu.org with smtp (Exim 4.84_2) (envelope-from ) id 1mUbET-0000o4-9Y for 50538@debbugs.gnu.org; Sun, 26 Sep 2021 16:58:45 -0400 Original-Received: (qmail 64010 invoked by uid 3782); 26 Sep 2021 20:58:38 -0000 Original-Received: from acm.muc.de (p4fe150ab.dip0.t-ipconnect.de [79.225.80.171]) (using STARTTLS) by colin.muc.de (tmda-ofmipd) with ESMTP; Sun, 26 Sep 2021 22:58:37 +0200 Original-Received: (qmail 16077 invoked by uid 1000); 26 Sep 2021 20:58:36 -0000 Content-Disposition: inline In-Reply-To: <543ebfcc-d032-f0cd-f605-3f0607fe1df1@gmail.com> X-Submission-Agent: TMDA/1.3.x (Ph3nix) X-Primary-Address: acm@muc.de X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:215620 Archived-At: Hello, Jim. There's one thing I'm a bit uncertain about in the patch for cc-mode.el. On Wed, Sep 22, 2021 at 19:01:11 -0700, Jim Porter wrote: > Ok, I've attached an updated patch that should apply cleanly on top of > the patches for bug#49518. The tests still pass locally for me. If > there's anything else that needs fixed/adjusted, just let me know. [ .... ] > diff --git a/lisp/progmodes/cc-mode.el b/lisp/progmodes/cc-mode.el > index 8b30241449..80137590c7 100644 > --- a/lisp/progmodes/cc-mode.el > +++ b/lisp/progmodes/cc-mode.el > @@ -2549,18 +2549,26 @@ c-electric-pair-inhibit-predicate > At the time of call, point is just after the newly inserted CHAR. > -When CHAR is \", t will be returned unless the \" is marked with > -a string fence syntax-table text property. For other characters, > -the default value of `electric-pair-inhibit-predicate' is called > -and its value returned. > +When CHAR is \" and not within a comment, t will be returned if > +the quotes on the current line are already balanced (i.e. if the > +last \" is not marked with a string fence syntax-table text > +property). For other cases, the default value of > +`electric-pair-inhibit-predicate' is called and its value > +returned. > This function is the appropriate value of > `electric-pair-inhibit-predicate' for CC Mode modes, which mark > invalid strings with such a syntax table text property on the > opening \" and the next unescaped end of line." > - (if (eq char ?\") > - (not (equal (get-text-property (1- (point)) 'c-fl-syn-tab) '(15))) > - (funcall (default-value 'electric-pair-inhibit-predicate) char))) > + (or (and (eq char ?\") > + (not (memq (cadr (c-semi-pp-to-literal (1- (point)))) '(c c++))) > + (let ((last-quote (save-match-data > + (save-excursion > + (goto-char (c-point 'eoll)) > + (search-backward "\""))))) > + (not (equal (c-get-char-property last-quote 'c-fl-syn-tab) > + '(15))))) > + (funcall (default-value 'electric-pair-inhibit-predicate) char))) In the line starting (or (and (eq char ?\"), don't we still need an `if' form? I think that otherwise, if any of the sub-forms of the `and' return nil, we will call (default-value 'electric-pair-inhibit-predicate), which surely isn't what we want. If we have a ", we want the CC Mode function to do all the work, only delegating to the standard function when we don't have a ". Or have I missed something? [ .... ] -- Alan Mackenzie (Nuremberg, Germany).