From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jim Porter Newsgroups: gmane.emacs.bugs Subject: bug#50538: [PATCH] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode Date: Thu, 16 Sep 2021 10:29:47 -0700 Message-ID: <16202af0-9d66-1996-8756-b3d0ff28ac9a@gmail.com> References: <021853bf-0169-c158-ab3d-296b6c144e08@gmail.com> <83r1dufgxu.fsf@gnu.org> <94c7b4ec-813b-515f-d947-116c294dd74b@gmail.com> <716194ea-817f-eaad-f9ce-7d600ad359b1@gmail.com> <83k0jh9jn6.fsf@gnu.org> <87o88s3d87.fsf@gnus.org> <871r5o3biv.fsf@gnus.org> <87fsu4h2oa.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2575"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Alan Mackenzie , 50538@debbugs.gnu.org, Dmitry Gutov To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , Lars Ingebrigtsen Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Sep 16 19:31:13 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 1mQvE7-0000Va-S5 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Sep 2021 19:31:11 +0200 Original-Received: from localhost ([::1]:40184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mQvE6-0001bc-Bu for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 16 Sep 2021 13:31:10 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41224) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mQvDy-0001bN-SV for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 13:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:44926) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mQvDy-0003eS-E6 for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 13:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mQvDy-0000t8-Aj for bug-gnu-emacs@gnu.org; Thu, 16 Sep 2021 13:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 16 Sep 2021 17:31:02 +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.16318134113342 (code B ref 50538); Thu, 16 Sep 2021 17:31:02 +0000 Original-Received: (at 50538) by debbugs.gnu.org; 16 Sep 2021 17:30:11 +0000 Original-Received: from localhost ([127.0.0.1]:56471 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQvCw-0000pm-Rd for submit@debbugs.gnu.org; Thu, 16 Sep 2021 13:30:11 -0400 Original-Received: from mail-pl1-f172.google.com ([209.85.214.172]:42921) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mQvCv-0000pa-Dr for 50538@debbugs.gnu.org; Thu, 16 Sep 2021 13:29:57 -0400 Original-Received: by mail-pl1-f172.google.com with SMTP id n4so4316976plh.9 for <50538@debbugs.gnu.org>; Thu, 16 Sep 2021 10:29:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=aH2s5Qj8Uzmt3jvjtkGMDFigDw6RU5ABCrRvGsP4upU=; b=pAShIusJqnWWlZD2uC0ulYxyZpqhRhrthXZbrUzoh8vYCyXWlQKEZK6rNXAWN6tPOU RviMfOqkUK3qG8MWJWnLBti03byICWjSJAf5aLPKOJXU3Cqnls41OrUgTNO6zYCLcLiJ qDtu2z6gU+7/+vQwjYRXTWIPas5eV5yr/lm55LHuV8O7E2ZaluoqV11ERiuMC5Q+onJj IZl25+lMNMSKVfpzIsawpk8UL/8J+SSloSrv3Sgfs2aLOitkGh5g0iIMCfhj9aw4/Dw+ Fljp2FS1HOysT8et+LZv4mzNp74nY9F2i0K2IkML5hjadJbgpu9NfcTVvjQzV7VvEgpl kBKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=aH2s5Qj8Uzmt3jvjtkGMDFigDw6RU5ABCrRvGsP4upU=; b=6hJ9rhp0eMlUlLfPKEbP6TURcyOuomH97gTF1dT232w5jBSXLLWPuWerleoKF1+cgR UMMP1mIbeXBdqrxfftKDfZKwlaJGTe8t4sYf5HTYZBqysoClHftffuEEYQ3jtoIyTlzk 3IWx38LUR7uBDltJVmvf5Ga4zFXa2ygLO9I2RF/ynB5ggQRmoApQYUuFr34dzSydElQN Za/Crk5inojN/rGp6OkZIjJ6sD+2P/Tm25VEvjSipmVnpUn+ScKwU5G0nLo3iNPkooFB oxR1ZOMQ0if48gt4wO78BPDc9WOugvd4Nc01JrevJX5IP5ogDc/wia3MieN8t2OfEBNE uEgA== X-Gm-Message-State: AOAM531tFskRDMMOac0BQ7KNNB3c1bH5Kn5PakjtIl3XzC4D3wV/6rMw ii8iAZPLhgjxalzOgHK0e0k= X-Google-Smtp-Source: ABdhPJwI6+XJMEplh1RIhf78y9mbqr5lkhal1H+L6xzYFhFan6E4cHABZxLIzO+3/4SCuEPeGs4m2Q== X-Received: by 2002:a17:90a:de0f:: with SMTP id m15mr7523589pjv.114.1631813386933; Thu, 16 Sep 2021 10:29:46 -0700 (PDT) Original-Received: from [192.168.1.2] (cpe-76-168-148-233.socal.res.rr.com. [76.168.148.233]) by smtp.googlemail.com with ESMTPSA id e16sm3679275pfc.214.2021.09.16.10.29.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 16 Sep 2021 10:29:46 -0700 (PDT) In-Reply-To: <87fsu4h2oa.fsf@gmail.com> Content-Language: en-US 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:214490 Archived-At: On 9/16/2021 10:04 AM, João Távora wrote: > > I couldn't understand the initial issue fully, but I can only confirm > that the relationship between cc-mode and electric-pair-mode has been > rocky. I think the situation is similar with electric-layout-mode and > with electric-indent-mode, to a certain degree (though I am not sure for > this last one). Hopefully the following summary will help. My patch is essentially an enhancement of the patch from bug#36474. In that bug, Alan Mackenzie describes the problem: > 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. The fix in that bug was to check if the just-inserted double-quote "is marked with a string fence syntax-table text property". That fixes the issue described in bug#36474, but it's not quite the right logic. CC Mode gives the *last* double-quote on a line the string fence property if a line has unbalanced quotes. Thus, the patch changes the behavior to check the last double-quote on the line, rather than the just-inserted double-quote. The patch makes one other improvement as well: it doesn't check for the string fence property on a double-quote inside a comment. CC Mode doesn't apply string fence properties there, since it's not necessary. Therefore, inside a comment, `c-electric-pair-inhibit-predicate' just defers to the default value of `electric-pair-inhibit-predicate'. As I mentioned earlier in the thread, this isn't quite perfect behavior, but it significantly improves the common case (`electric-pair-mode' with default or "default-like" settings). CC Mode's practice of closing strings at the end of a line - even without a closing quote - just doesn't play nicely with `electric-pair-mode', so barring some major changes to either CC Mode or `electric-pair-mode', I can't think of a way to improve this patch beyond where it's at now.