bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#50538: [PATCH v4] 28.0.50; electric-pair-mode fails to pair double q


From: Jim Porter
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

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.

Attachment: 0001-Improve-behavior-of-electric-pair-mode-in-cc-mode.patch
Description: Text document


reply via email to

[Prev in Thread] Current Thread [Next in Thread]