bug#58883:
Alan Mackenzie <[email protected]> Tue, 8 Nov 2022 14:32:01 +0000
| Newsgroups | gmane.emacs.cc-mode.general |
|---|---|
| Message-ID | <Y2poYZz34Ur1LT40@ACM> |
Hello, Po. On Tue, Nov 08, 2022 at 20:29:30 +0800, Po Lu wrote: > Alan Mackenzie <[email protected]> writes: > > I'm gradually fixing it. > Thanks. I hope Emacs 29 will not be released without the fix. > > The mechanism is that when C Mode sees what it takes to be a type, from > > the context, c-forward-type returns the symbol 'maybe. > > Later on in the processing, the analysis of the C code "confirms" that > > this 'maybe actually is a type, and it gets promoted to 'found, and > > entered into the c-found-types list. At the same time, other occurrences > > of the type throughout the buffer are fontified as types. > > This mechanism is not foolproof, and goes wrong when a statement is > > partially typed. Rather than correcting the mistakenly fontified > > "types", which would be more difficult, I'm concentrating on not > > promoting a 'maybe type to a 'found type too enthusiasically. > Right, but there are some things that simply cannot work with that > approach. Imagine the following code being typed by the user: > foo (ptr) > struct foobar *ptr; > { > register struct frobar *ptr_fast; > ptr_fast = ptr; > only for him to realize that "oops, struct frobar is not a type!" and > correct it to: > register struct foobar *ptr_fast; > by which time it is too late, and "struct frobar" is now in > c-found-types, with all the ensuing consequences. I don't think this happens for struct/union/enum/class/... tags anymore. But I think it still does for other types of types. Mostly having a mis-typed identifier in c-found-types shouldn't annoy too much, unless it's some other sort of identifier in the code. > > The problem here is that CC Mode isn't a compiler, and doesn't do very > > deep analysis on the source. The new mode with tree sitter will likely > > do much better on such troublesome sources in the future. Sorry! > But it worked fine in Emacs 28... There were loud complaints around 18 months ago about CC Mode's fontification being "random", together with pressure to fix it. The thread on emacs-devel was started by Daniel Colascione on 2021-06-03 with subject line "cc-mode fontification feels random". The current compromise arose out of that thread. As I say, I think CC Mode has pretty much reached the end of the road as far as indentation and (particularly) fontification go. Any fix of one particular problem leads to other problems springing up. I think we must look forward to the upcoming tree-sitter new modes. I will be trying to break these with CC Mode's test suite and 20 years' worth of bug reports with unusual cases in them. ;-) -- Alan Mackenzie (Nuremberg, Germany).