Subject: bug#10941: [24.0.93.3] cc-mode: error in message buffer when "typing fast", characters eaten

From: Alan Mackenzie <[email-masked]>
Date: Fri, 30 Mar 2012 22:19:21 +0000

Hello, Paul.

On Fri, Mar 30, 2012 at 01:11:05AM +0300, Paul Pogonyshev wrote:
> Alan Mackenzie wrote:
> > > Sometimes (quite often) when opening a different syntax region --- a
> > > quoted string, or block comment --- in C++ mode, the first character
> > > after it gets eaten with some error message shown in the echo area.  I
> > > managed to create a surefire (at least here) way to reproduce it.

> > What exactly do you mean by "opening a different syntax region"?  Do you
> > mean moving point into it, or scrolling to see it?

> Just typing, similarly to the testcase.  When you quickly type an
> opening quote (") or inline comment starter (/*) and then instantly
> continue typing whatever is going to be inside, this error happens.
> Far from always, but often enough to be annoying.

Thanks for the description.

I think I've found the trouble.  It was a simple mistake in calculating a
search limit.  I don't understand how this only bites when the buffer is
newly loaded, but whatever.

Would you please try out this patch and let me know whether it solves the
problem.

diff -r 002a49d7b836 cc-engine.el
--- a/cc-engine.el	Fri Mar 16 13:14:22 2012 +0000
+++ b/cc-engine.el	Fri Mar 30 22:13:40 2012 +0000
@@ -5414,7 +5414,7 @@
 	  new-beg new-end need-new-beg need-new-end)
       ;; Locate the barrier before the changed region
       (goto-char  (if beg-lit-limits (car beg-lit-limits) beg))
-      (c-syntactic-skip-backward "^;{}" (max (- beg 2048) (point-min)))
+      (c-syntactic-skip-backward "^;{}" (c-determine-limit 512))
       (setq new-beg (point))
 
       ;; Remove the syntax-table/category properties from each pertinent <...>
@@ -5426,8 +5426,7 @@
 
       ;; Locate the barrier after END.
       (goto-char (if end-lit-limits (cdr end-lit-limits) end))
-      (c-syntactic-re-search-forward "[;{}]"
-				     (min (+ end 2048) (point-max)) 'end)
+      (c-syntactic-re-search-forward "[;{}]" (c-determine-+ve-limit 512) 'end)
       (setq new-end (point))
 
       ;; Remove syntax-table properties from the remaining pertinent <...>

> Paul

-- 
Alan Mackenzie (Nuremberg, Germany).