Subject: bug#57075: CC Mode 5.35.1 (C/*l); Leaky fontification of xterm.c with font-lock-maximum-decoration set to 2

From: Alan Mackenzie <[email-masked]>
Date: Wed, 10 Aug 2022 18:51:30 +0000

Hello, Po.

On Tue, Aug 09, 2022 at 20:31:32 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode

> Open xterm.c with font-lock-maximum-decoration set to 2, and hold down
> C-v until the entire buffer is fontified.  Then, go to line 2948:
> observe that the following lines in the vicinity are not fontified at
> all:

>   Atom type;        <-----------------------------------
>   Window *toplevels;<-----------------------------------
>   int format, rc;
>   unsigned long nitems, bytes_after;
>   unsigned long i, real_nitems;
>   unsigned char *data = NULL;
>   int frame_extents[4];

> #ifndef USE_XCB
>   int dest_x, dest_y;
>   unsigned long *wmstate;
>   unsigned long wmstate_items, extent_items;
>   unsigned char *wmstate_data = NULL, *extent_data = NULL;
>   XWindowAttributes attrs;<-----------------------------
>   Window child;           <-----------------------------
>   xm_drag_receiver_info xm_info; <----------------------

> Many other other lines in the buffer will also be missing fontification.

Yes.  It's the way level 2 does fontification of types.  Any declaration
which starts with a standard type, like int, char, void, ..... gets
fontified, additionally anything like struct foo *bar, and any type
matching one of the following: 

    ("\\sw+_t" "bool" "complex" "imaginary" "FILE" "lconv" "tm" "va_list"
     "jmp_buf" "Lisp_Object")

..  So the types ending in _t, like xcb_translate_coordinates_cookie_t
are getting fontified too, but not things like Atom or Window *.

The merly partial fontification is the price for the extra speed one
gets from level 2.  To fontify all declarations, we'd need the
algorithms from f-l-maximum-decoration 3, and the speed would pretty
much be down to that of f-l-m-d 3, too.

Sorry nothing better is possible (at the moment).

> Emacs  : GNU Emacs 29.0.50 (build 62, x86_64-pc-linux-gnu)
>  of 2022-08-09
> Package: CC Mode 5.35.1 (C/*l)
> Buffer Style: GNU
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties category-properties 1-bit)

[ CC Mode state dump appreciated, but snipped. ]

-- 
Alan Mackenzie (Nuremberg, Germany).