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: Sun, 12 Sep 2021 11:05:17 -0700 Message-ID: <94c7b4ec-813b-515f-d947-116c294dd74b@gmail.com> References: <021853bf-0169-c158-ab3d-296b6c144e08@gmail.com> <83r1dufgxu.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------BE38C65897CECAEF07E54E0E" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="31548"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50538@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Sep 12 20:06:17 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 1mPTrt-00082G-Qb for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Sep 2021 20:06:17 +0200 Original-Received: from localhost ([::1]:56460 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mPTrs-0005mW-Oj for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 12 Sep 2021 14:06:16 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:55312) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mPTre-0005f6-IE for bug-gnu-emacs@gnu.org; Sun, 12 Sep 2021 14:06:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60223) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mPTre-0004N4-AP for bug-gnu-emacs@gnu.org; Sun, 12 Sep 2021 14:06:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mPTrd-0004i6-SA for bug-gnu-emacs@gnu.org; Sun, 12 Sep 2021 14:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jim Porter Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 12 Sep 2021 18:06: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.163146992718042 (code B ref 50538); Sun, 12 Sep 2021 18:06:01 +0000 Original-Received: (at 50538) by debbugs.gnu.org; 12 Sep 2021 18:05:27 +0000 Original-Received: from localhost ([127.0.0.1]:43536 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mPTr5-0004gw-4x for submit@debbugs.gnu.org; Sun, 12 Sep 2021 14:05:27 -0400 Original-Received: from mail-pj1-f42.google.com ([209.85.216.42]:38844) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mPTr1-0004gb-Br for 50538@debbugs.gnu.org; Sun, 12 Sep 2021 14:05:25 -0400 Original-Received: by mail-pj1-f42.google.com with SMTP id g13-20020a17090a3c8d00b00196286963b9so4986596pjc.3 for <50538@debbugs.gnu.org>; Sun, 12 Sep 2021 11:05:23 -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; bh=9MKAPc0YM8xaJ48ytt5QDNZ5k4SAfJJZbubQDNH1NKU=; b=iSk6Tyq6dtpODX6pQ1+vVjqd7Jcwxha7YAQhSJAnqMRWgTmJ35hzzfOp5de/EuJg1f C0wr26j9uD6LuONW34iVpj3Ph34QOXeabqwq3bgKD9LPW2zLaQJHa0U5j90oF22ARirx +aHcU99UAP/FLvX+V4Q4goQiRVRifCvaNU9SnjY/gLdlKQPLV/iuctyGjIB/KHno2ySt f0nEdz9h4VNXF5/Ov7EKFFMVJ4Ajrhdl9HcDsB+LLgfVnzh4J6WMPn2gcGlZqcOa90RF GE0uuHrb60prDYmfu+yWGxXk8QNBW0HW9ngZNDsT9XhR4RwnkKzNmJk3vXhBhkzs4Io1 JKiw== 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; bh=9MKAPc0YM8xaJ48ytt5QDNZ5k4SAfJJZbubQDNH1NKU=; b=DsWGTsM7hsN13frucIqAd7BUlbXgLvnALaZNTRqmWzV4wK9tn/LiNrK4HSFVeiD2ZZ miC2VZsKfV0izd3jO77cncWDsHn/pq//A44dOcla0qTbQnElTIkUCP1Xx+W6UnuZQD8Q e+RFq0LNKm2TV+8D1USPj//gWHVTFpuDDWKkw0UTSu/Gnic3jBlxqLnEW+0Sp//Apwt2 jvplGWjXlZ/3rkqqTu3WyMxzJFZeWeYO3zsMWiB2F2ecuUybmcnvfktNkLATtfNd/J+L rBwKHRFHrEdA1lqpWQJ5lkOshtiDjf8TDwg00Aqr12pTG52uoIhxk1A7sKAwo9wT+oGN keAA== X-Gm-Message-State: AOAM53312Ohi66BEYfgzF+ISZoDXnwWqSlDdEyyfV/vT8KStAZh4Bw98 HCHDaeQut7s28BI7vWfmLUZSwzyyZOg= X-Google-Smtp-Source: ABdhPJy+518/PLkibt5CI/+UQgTlKTIyQTFUNIL+1Vt8EPlTPp+5FD64MInUUctm+mabzRwuO6YA0w== X-Received: by 2002:a17:90b:a4a:: with SMTP id gw10mr8678291pjb.245.1631469917074; Sun, 12 Sep 2021 11:05:17 -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 w8sm1179984pfc.93.2021.09.12.11.05.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 12 Sep 2021 11:05:16 -0700 (PDT) In-Reply-To: <83r1dufgxu.fsf@gnu.org> 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:214153 Archived-At: This is a multi-part message in MIME format. --------------BE38C65897CECAEF07E54E0E Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 9/11/2021 11:26 PM, Eli Zaretskii wrote: >> From: Jim Porter >> Date: Sat, 11 Sep 2021 20:58:47 -0700 >> >> There are a few related issues with pairing double quotes in CC mode >> while using `electric-pair-mode'. Hopefully the steps to reproduce below >> will explain the issues. In all the cases, I'd expect >> `electric-pair-mode' to insert a closing quote, but it doesn't. > > Your expected results seem to expect Emacs to assume that a new string > will be inserted, but is that an assumption that is always true? In these cases, I believe that's true (with the default `electric-pair-mode' settings, that is). More broadly, the goal of the patch is to ensure that pairing of double quotes works the same in CC mode as it does in other modes (`ruby-mode', `python-mode', `js-mode', `emacs-lisp-mode', etc), which is why I added `c-mode' to the list of modes to test in `test/lisp/electric-tests.el'. That said, there's one potential case I didn't account for (mostly because it wasn't accounted for in the patch for bug#36474): if a user customizes `electric-pair-inhibit-predicate' to inhibit cases like (2) or (3) in my original message, that won't work right in CC modes, since the default value of `electric-pair-inhibit-predicate' (set by the user) won't be called. Attached is an updated patch that changes the logic of `c-electric-pair-inhibit-predicate' to either a) inhibit insertion of the closing quote, or b) call the default-value of `electric-pair-inhibit-predicate' to determine what to do. This should give users more consistent behavior when customizing `electric-pair-inhibit-predicate'. The tests still pass, although I wasn't able to figure out a good way to add a test for setting `electric-pair-inhibit-predicate' that works with how CC mode overrides it (using `:bindings' in `define-electric-pair-test' didn't work, since the binding is set too late). Hopefully that's ok; if not, I can try and see about making some more extensive changes to the tests to account for this. Note however that this solution isn't perfect: it means a user's custom `electric-pair-inhibit-predicate' can only inhibit *more* than CC mode's default behavior, not less. I think that's a reasonable compromise though, and users who want more direct control can set `electric-pair-inhibit-predicate' inside `c-mode-common-hook'. A "perfect" solution here would probably require adding new customization points to `electric-pair-mode' (e.g. a way for major modes to override how the syntax is analyzed), and I'm not sure the added complexity would be worth it, especially since this code is already a bit tricky. --------------BE38C65897CECAEF07E54E0E Content-Type: text/plain; charset=UTF-8; name="0001-Improve-behavior-of-electric-pair-mode-in-cc-mode.patch" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename*0="0001-Improve-behavior-of-electric-pair-mode-in-cc-mode.patch" RnJvbSAwYjAzOGVmODY4YThjNTU4ZTY2ZDQyMGI5MzgwYjc5MmI0MDllMzg4IE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBKaW0gUG9ydGVyIDxqcG9ydGVyYnVnc0BnbWFpbC5j b20+CkRhdGU6IFN1biwgMTIgU2VwIDIwMjEgMTA6NDQ6NTUgLTA3MDAKU3ViamVjdDogW1BB VENIXSBJbXByb3ZlIGJlaGF2aW9yIG9mICdlbGVjdHJpYy1wYWlyLW1vZGUnIGluICdjYy1t b2RlJwoKVGhpcyBlbnN1cmVzIHRoYXQgcXVvdGVzIGFyZSBwYWlyZWQgY29ycmVjdGx5IHdp dGhpbiBjb21tZW50cywgYWxsb3dzIGZvcgppbnNlcnRpb24gb2YgcXVvdGUgcGFpcnMgaW1t ZWRpYXRlbHkgYmVmb3JlIGFub3RoZXIgcXVvdGUsIGFuZCBh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