GNU bug report logs -
#50538
[PATCH] 28.0.50; electric-pair-mode fails to pair double quotes in some cases in CC mode
Previous Next
Reported by: Jim Porter <jporterbugs <at> gmail.com>
Date: Sun, 12 Sep 2021 03:59:02 UTC
Severity: normal
Tags: patch
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
On 9/11/2021 11:26 PM, Eli Zaretskii wrote:
>> From: Jim Porter <jporterbugs <at> 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.
[0001-Improve-behavior-of-electric-pair-mode-in-cc-mode.patch (text/plain, attachment)]
This bug report was last modified 3 years and 249 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.