From: Alan Mackenzie <acm@muc.de>
To: Konstantin Kharlamov <hi-angel@yandex.ru>
Cc: acm@muc.de, 33163@debbugs.gnu.org
Subject: bug#33163: Adding a " in c++-mode fills the whole file with red
Date: 28 Oct 2018 10:49:06 -0000 [thread overview]
Message-ID: <20181028104906.70695.qmail@mail.muc.de> (raw)
In-Reply-To: <mailman.2795.1540562775.1284.bug-gnu-emacs@gnu.org>
In article <mailman.2795.1540562775.1284.bug-gnu-emacs@gnu.org> you wrote:
> This long-standing problem appears occasionally, and only disappears if
> you kill the buffer completely, then reopen the file. I never got to
> report it because I never could find steps to reproduce it… until now
> :) Nvm the non-sense code, I reduced testcase as far as I managed.
> # Steps to reproduce:
> 1. Save the following text in `test.cpp`
> int main() {
> puts(It's");
> auto foo = []()-> void { };
> puts("It's");
> }
> 2. Open `emacs -Q ./test.cpp`
> 3. Now, the text lacks a quote in the first `puts(It's");`. Add it so
> it looks like `puts("It's");`. Essentially, if you'd compile it with
> g++, it lacks any syntax error besides `puts` being undeclared.
> # Expected
> The line with `auto foo…` is not red.
> # Actual
> The line with `auto foo…` (in particular) becomes red.
Thanks for taking the trouble to report this bug. Thanks even more for
condensing it down to a minimal test case.
The following patch should fix it. Would you please apply the patch,
recompile .../lisp/progmodes/cc-mode.el, load the new file in to your
Emacs (or restart Emacs), then try it out on your real C++ code. Then
please let me know whether it's working or not, and if not, how it's
going wrong. Thanks!
> # Additional information
> Emacs version GNU Emacs 27.0.50 (build 1, x86_64-pc-linux-gnu, GTK+
> Version 3.22.30) of 2018-10-01, build with -flto.
diff -r 2f7029fa229d cc-mode.el
--- a/cc-mode.el Sun Oct 14 20:01:07 2018 +0000
+++ b/cc-mode.el Sun Oct 28 10:20:38 2018 +0000
@@ -1216,21 +1216,21 @@
(if (eq beg-literal-type 'string)
(setq c-new-BEG (min (car beg-limits) c-new-BEG))))
- ((< c-new-END (point-max))
- (goto-char (1+ c-new-END)) ; might be a newline.
+ ((< end (point-max))
+ (goto-char (1+ end)) ; might be a newline.
;; In the following regexp, the initial \n caters for a newline getting
;; joined to a preceding \ by the removal of what comes between.
(re-search-forward "[\n\r]?\\(\\\\\\(.\\|\n\\|\r\\)\\|[^\\\n\r]\\)*"
nil t)
;; We're at an EOLL or point-max.
- (setq c-new-END (min (1+ (point)) (point-max)))
- (goto-char c-new-END)
- (if (equal (c-get-char-property (1- (point)) 'syntax-table) '(15))
- (if (memq (char-before) '(?\n ?\r))
+ (setq c-new-END (max c-new-END (min (1+ (point)) (point-max))))
+ (if (equal (c-get-char-property (point) 'syntax-table) '(15))
+ (if (memq (char-after) '(?\n ?\r))
;; Normally terminated invalid string.
- (progn
+ (let ((eoll-1 (point)))
+ (forward-char)
(backward-sexp)
- (c-clear-char-property (1- c-new-END) 'syntax-table)
+ (c-clear-char-property eoll-1 'syntax-table)
(c-clear-char-property (point) 'syntax-table))
;; Opening " at EOB.
(c-clear-char-property (1- (point)) 'syntax-table))
@@ -1238,7 +1238,7 @@
;; Opening " on last line of text (without EOL).
(c-clear-char-property (point) 'syntax-table))))
- (t (goto-char c-new-END)
+ (t (goto-char end) ; point-max
(if (c-search-backward-char-property 'syntax-table '(15) c-new-BEG)
(c-clear-char-property (point) 'syntax-table))))
@@ -1327,9 +1327,9 @@
(while (progn
(setq s (parse-partial-sexp (point) c-new-END nil
nil s 'syntax-table))
- (and (not (nth 3 s))
- (< (point) c-new-END)
- (not (memq (char-before) c-string-delims)))))
+ (and (< (point) c-new-END)
+ (or (not (nth 3 s))
+ (not (memq (char-before) c-string-delims))))))
;; We're at the start of a string.
(memq (char-before) c-string-delims)))
(if (c-unescaped-nls-in-string-p (1- (point)))
--
Alan Mackenzie (Nuremberg, Germany).
next prev parent reply other threads:[~2018-10-28 10:49 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-26 14:05 bug#33163: Adding a " in c++-mode fills the whole file with red Konstantin Kharlamov
[not found] ` <mailman.2795.1540562775.1284.bug-gnu-emacs@gnu.org>
2018-10-28 10:49 ` Alan Mackenzie [this message]
2018-10-28 11:21 ` Konstantin Kharlamov
2018-10-29 18:46 ` Konstantin Kharlamov
2018-10-30 12:01 ` Alan Mackenzie
2018-11-26 10:56 ` Konstantin Kharlamov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181028104906.70695.qmail@mail.muc.de \
--to=acm@muc.de \
--cc=33163@debbugs.gnu.org \
--cc=hi-angel@yandex.ru \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).