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

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

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


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

On 9/11/2021 11:26 PM, Eli Zaretskii wrote:
From: Jim Porter <jporterbugs@gmail.com>
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.

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]