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 v4] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode Date: Mon, 27 Sep 2021 21:57:07 -0700 Message-ID: <36deabe8-9b2b-2c04-5d99-2c0a4b03abde@gmail.com> 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: multipart/mixed; boundary="------------9BDCAD5E7620D2D638BF2968" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="3981"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 50538@debbugs.gnu.org To: Alan Mackenzie Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Sep 28 06:58: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 1mV5C3-0000oc-N6 for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Sep 2021 06:58:15 +0200 Original-Received: from localhost ([::1]:53384 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mV5C1-0003yu-SG for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 28 Sep 2021 00:58:13 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:51038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mV5Bq-0003yk-KL for bug-gnu-emacs@gnu.org; Tue, 28 Sep 2021 00:58:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:60064) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mV5Bq-0001To-Bh for bug-gnu-emacs@gnu.org; Tue, 28 Sep 2021 00:58:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mV5Bp-0003gx-NB for bug-gnu-emacs@gnu.org; Tue, 28 Sep 2021 00:58: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: Tue, 28 Sep 2021 04:58: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.163280503614128 (code B ref 50538); Tue, 28 Sep 2021 04:58:01 +0000 Original-Received: (at 50538) by debbugs.gnu.org; 28 Sep 2021 04:57:16 +0000 Original-Received: from localhost ([127.0.0.1]:43377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mV5B6-0003fn-9f for submit@debbugs.gnu.org; Tue, 28 Sep 2021 00:57:16 -0400 Original-Received: from mail-pj1-f48.google.com ([209.85.216.48]:36474) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mV5B3-0003fX-Ok for 50538@debbugs.gnu.org; Tue, 28 Sep 2021 00:57:14 -0400 Original-Received: by mail-pj1-f48.google.com with SMTP id u1-20020a17090ae00100b0019ec31d3ba2so835352pjy.1 for <50538@debbugs.gnu.org>; Mon, 27 Sep 2021 21:57:13 -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=d7CT7BUZYDgesJdKdJGxiypm0Q+hwM/+6aIf3k4zytA=; b=PpLnJeShsGewD/A48dZZINMGZvtyXPpvQSYiW10sFQiAx475aWpO3spq7tFbBThMsR oWAGniufe4o0AeJ/xsxXkimtDCtULZ7wyll7asLtI0CGePbFc+Answ3ub+NPzV9weLnO 6yTmE5hXfcdxDDFM+P3EzXvL7jK5o+r/W5F8xftaC0LZKSrKh0pwN+AA0QNtLCZ0dNo6 T3Ef0qyjQ7dVBgDndLdirajjpl5+JSnlg4d+03Pflo7iCuSQfF+jZ20XwkAKHd1C7GKH dJX2NZSTA3hC9fmhDjgbihpNuFk0XeeMSRVNxtpt/o9Lp96Pt4EbnQpqdUsF6u/lg4Bl c7Rg== 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=d7CT7BUZYDgesJdKdJGxiypm0Q+hwM/+6aIf3k4zytA=; b=rDY4rOdpiLO87eKIoGAl91cn7+m+7LtCT+xyUjAeXdgtjuJehpDFrMJPWfsKzdKWbH VZqFkq+RGrFPzML52QD6bk7aPms1NfjLnSoCidbKCfkfSKqAhMNmbOFqC77MyhmJW0Do fyIiAO18a+dKbin7gXOM76JLhUbXDLEfp0ISmTEOAiC65b0Cxup+rmAUNyU99APgJmip KVYdLuZN/XAMnN8225XkEOsDhYptOJ4dnwBaOOfP1zzq3aHWX01yyn861TFtdgMTGLEd //BEPhCXVr7v682t/Eh6JER90E74KevGbwqITh9apR+nugyok4vqpLVEanawoJSliMzd 4JFw== X-Gm-Message-State: AOAM530vMoWfstVRBB3e4uV4TmdEMCtLWmp3ycVhzrWR3N8/WDaDJfG5 fxVA75nDoG1A1ZUQSSe4+RLkJnXGYec= X-Google-Smtp-Source: ABdhPJzCqwcAIaMg+76lJrdUcuA5PCmvwcFzNHNiBmdNUQOFcNpHXH8PbilfajUmnwMXy02M5U0ZgA== X-Received: by 2002:a17:90a:910:: with SMTP id n16mr3173570pjn.246.1632805027669; Mon, 27 Sep 2021 21:57:07 -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 gk14sm710962pjb.35.2021.09.27.21.57.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 27 Sep 2021 21:57:06 -0700 (PDT) In-Reply-To: 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:215727 Archived-At: This is a multi-part message in MIME format. --------------9BDCAD5E7620D2D638BF2968 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 9/26/2021 1:58 PM, Alan Mackenzie wrote: > > 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: [snip] >> - (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? I don't have a strong opinion on this either way, so here's a patch that uses an `if' form as you suggest. However, I introduced the `or' form in response to Eli's concern[1]: On 9/11/2021 11:26 PM, Eli Zaretskii wrote: > 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? It could be that the user wants to modify the existing string > instead, in which case your suggested patches will require the user > to delete more quotes than previously. I discussed the pros and cons in my followup[2]: > 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 [override `c-electric-pair-inhibit-predicate'].[3] Personally, I'm fine with letting CC Mode do all the work here, and requiring users to advise this function if they want a different behavior. It's probably easier to be sure that things don't break by using the `if' form patch, though I think the previous `or' form patch should be pretty robust too. [1] https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-09/msg00976.html [2] https://lists.gnu.org/archive/html/bug-gnu-emacs/2021-09/msg01014.html [3] My explanation in the original message was incorrect, so I've fixed it here. --------------9BDCAD5E7620D2D638BF2968 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" RnJvbSA1YzEyZmUwOWY3YWM3MTBiMmMyZjI3OWUwZmFhMDRiZTg2NTJkYjBmIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBKaW0gUG9ydGVyIDxqcG9ydGVyYnVnc0BnbWFpbC5j b20+CkRhdGU6IFRodSwgMTYgU2VwIDIwMjEgMTQ6MzI6MTcgLTA3MDAKU3ViamVjdDogW1BB VENIXSBJbXByb3ZlIGJlaGF2aW9yIG9mICdlbGVjdHJpYy1wYWlyLW1vZGUnIGluICdjYy1t b2RlJwoKVGh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y5lbApAQCAtMzIsNiArMzIsOSBAQAogKHJlcXVp cmUgJ2VsZWMtcGFpcikKIChyZXF1aXJlICdjbC1saWIpCiAKKzs7IFdoZW4gcnVubmluZyB0 ZXN0cyBpbiBjLW1vZGUsIHVzZSBzaW5nbGUtbGluZSBjb21tZW50cyAoLy8pLgorKGFkZC1o b29rICdjLW1vZGUtaG9vayAobGFtYmRhICgpIChjLXRvZ2dsZS1jb21tZW50LXN0eWxlIC0x KSkpCisKIChkZWZ1biBjYWxsLXdpdGgtc2F2ZWQtZWxlY3RyaWMtbW9kZXMgKGZuKQogICAo bGV0ICgoc2F2ZWQtZWxlY3RyaWMgKGlmIGVsZWN0cmljLXBhaXItbW9kZSAxIC0xKSkKICAg ICAgICAgKHNhdmVkLWxheW91dCAoaWYgZWxlY3RyaWMtbGF5b3V0LW1vZGUgMSAtMSkpCkBA IC0xNzQsNyArMTc3LDcgQEAgZGVmaW5lLWVsZWN0cmljLXBhaXItdGVzdAogICAgICAgICAg IGV4cGVjdGVkLXN0cmluZwogICAgICAgICAgIGV4cGVjdGVkLXBvaW50CiAgICAgICAgICAg YmluZGluZ3MKLSAgICAgICAgICAobW9kZXMgJyhxdW90ZSAocnVieS1tb2RlIGpzLW1vZGUg cHl0aG9uLW1vZGUpKSkKKyAgICAgICAgICAobW9kZXMgJyhxdW90ZSAocnVieS1tb2RlIGpz LW1vZGUgcHl0aG9uLW1vZGUgYy1tb2RlKSkpCiAgICAgICAgICAgKHRlc3QtaW4tY29tbWVu dHMgdCkKICAgICAgICAgICAodGVzdC1pbi1zdHJpbmdzIHQpCiAgICAgICAgICAgKHRlc3Qt aW4tY29kZSB0KQotLSAKMi4yNS4xCgo= --------------9BDCAD5E7620D2D638BF2968--