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/16/2021 1:49 PM, Alan Mackenzie wrote:
> There were two or three minor problems with the patch:
>
> 1-/. CC Mode doesn't use syntax-ppss at all. This was because way back
> when, syntax-ppss was buggy, and even now doesn't do the right thing for
> CC Mode in some edge cases (e.g. with the buffer narrowed and point-min
> inside a string or comment). Instead it uses its own internal syntactic
> cacheing, largely centred around the function c-semi-pp-to-literal.
>
> 2/- Rather than using get-text-property and friends directly, CC Mode
> uses the macros c-get-char-property, etc. This is (?was) to maintain
> compatibility with XEmacs.
>
> 3/- (A bit more serious) The patch looks for the last " in the current
> line without taking account of any escaped new lines. There is already
> a CC Mode macro which does all the work here, c-point, which can be given
> the argument 'eoll for "end of logical line".
Thanks, I've incorporated all these changes into the attached patch. The
only difference between my patch and the version you provided was to
keep the `(search-backward "\"")' portion from my patch, since the code
needs to find the last double-quote, not the end of line.
As an aside, it's probably worth explaining why my patch searches for
the last double-quote in the first place. As far as I understand CC
Mode, when there's an unterminated double-quote on a line, both the
quote and the newline have a string fence property applied to them. This
means we could check the newline for that property, *but* there's no
guarantee a newline actually exists: `(c-point 'eoll)' could actually
point to the end of the buffer. To get around that, we search backwards
for the last double-quote of the (logical) line, since that's guaranteed
to exist.
If we wanted to, we could avoid searching backwards for the last
double-quote when a newline exists, but I'm not sure the gain in
performance (likely very small) is worth the extra code complexity.
[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.