GNU bug report logs -
#36474
Algorithm in electric-pair--unbalanced-strings-p unsuitable for CC Mode
Previous Next
Reported by: Alan Mackenzie <acm <at> muc.de>
Date: Tue, 2 Jul 2019 13:17:01 UTC
Severity: normal
Done: Alan Mackenzie <acm <at> muc.de>
Bug is archived. No further changes may be made.
Full log
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
Hello João and Emacs.
This is a follow up bug to bug #36423: 27.0.50; electric-pair-mode not
working properly depending of file content.
Start the Emacs master (up to date state as of 2019-07-02T14:30 +0000)
with emacs -Q, put the following in a C++ Mode buffer and enable
electric-pair-mode:
"foo\n
. Type a " at the end of foo. electric-pair-mode wrongly inserts two
"s.
Diagnosis: electric-pair--unbalanced-strings-p works after the (single)
newly typed " has been stripped from the buffer. It attempts to
determine whether there are any open strings after the point of
insertion. It does this by using parse-partial-sexp, and checks (nth 3
<result>) as evidence of an open string.
This does not work in CC Mode, since although there is an open string
marker (with a string fence syntax-table property on it) this is
"closed" (from parse-partial-sexp's point of view) by the string fence
property on the newline at the end of the line.
electric-pair--unbalanced-strings-p thus returns the wrong result.
A more suitable algorithm might look something like this: check whether
the newly inserted " has a string fence syntax-table text property.
(Its insertion will have already triggered the before- and
after-change-functions which set this property.) If so, there is an
open string. Of course, this only applies to CC Mode modes.
--
Alan Mackenzie (Nuremberg, Germany).
This bug report was last modified 5 years and 314 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.